root/tools/WaveDev/branches/WaveDev-0.6.2/WaveDev/wavedev/ComponentFrame.py @ 5936

Revision 5936, 42.0 KB (checked in by jgaeddert, 5 years ago)

importing custominterfaces properly

  • Property svn:eol-style set to native
Line 
1#Boa:Frame:CompFrame
2
3## Copyright 2005, 2006, 2007 Virginia Polytechnic Institute and State University
4##
5## This file is part of the OSSIE Waveform Developer.
6##
7## OSSIE Waveform Developer is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 2 of the License, or
10## (at your option) any later version.
11##
12## OSSIE Waveform Developer is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with OSSIE Waveform Developer; if not, write to the Free Software
19## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
21import wx
22import wx.gizmos
23from wx.lib.anchors import LayoutAnchors
24import wx.grid
25import PortDialog
26import os, shutil, commands
27import importIDL
28import ComponentClass as CC
29from errorMsg import *
30import XML_gen.component_gen as component_gen
31import cPickle
32import PropertiesDialog
33import MainFrame
34import string
35
36def create(parent):
37    return CompFrame(parent)
38
39[wxID_COMPFRAME, wxID_COMPFRAMEACECHECKBOX, wxID_COMPFRAMETIMINGCHECKBOX, wxID_COMPFRAMEADDPORTBTN,
40 wxID_COMPFRAMEADDPROP, wxID_COMPFRAMEASSEMBLYCCHECKBOX,
41 wxID_COMPFRAMECLOSEBTN, wxID_COMPFRAMECOMPNAMEBOX, wxID_COMPFRAMECOMPDESCRBOX,
42 wxID_COMPFRAMEDEVICECHOICE, wxID_COMPFRAMENODECHOICE, wxID_COMPFRAMEPORTBOX,
43 wxID_COMPFRAMEPROPLIST, wxID_COMPFRAMEREMOVEBTN, wxID_COMPFRAMEREMOVEPROP,
44 wxID_COMPFRAMESTATICTEXT1, wxID_COMPFRAMESTATICTEXT2,
45 wxID_COMPFRAMESTATICTEXT3, wxID_COMPFRAMESTATICTEXT4,
46 wxID_COMPFRAMESTATICTEXT5, wxID_COMPFRAMESTATICTEXT6,
47 wxID_COMPFRAMESTATICTEXT7, wxID_COMPFRAMESTATICTEXT8, wxID_COMPFRAMESTATUSBARCOMPONENT,
48 wxID_COMPFRAMESTATICLINE1, wxID_COMPFRAMETEMPLATECHOICE,
49] = [wx.NewId() for _init_ctrls in range(26)]
50
51[wxID_COMPFRAMEMENUFILENEW, wxID_COMPFRAMEMENUFILEOPEN,
52 wxID_COMPFRAMEMENUFILESAVE, wxID_COMPFRAMEMENUFILESAVEAS,
53] = [wx.NewId() for _init_coll_menuFile_Items in range(4)]
54
55[wxID_COMPFRAMEPORTBOXPOPUPADD, wxID_COMPFRAMEPORTBOXPOPUPEXPAND,
56 wxID_COMPFRAMEPORTBOXPOPUPREMOVE,
57] = [wx.NewId() for _init_coll_portBoxPopup_Items in range(3)]
58
59[wxID_COMPFRAMEPROPLISTPOPUPADD, wxID_COMPFRAMEPROPLISTPOPUPEDIT,
60 wxID_COMPFRAMEPROPLISTPOPUPREMOVE,
61] = [wx.NewId() for _init_coll_propListPopup_Items in range(3)]
62
63[wxID_COMPFRAMEMENUCOMPONENTGENERATE] = [wx.NewId() for _init_coll_menuComponent_Items in range(1)]
64
65class CompFrame(wx.Frame):
66    def _init_coll_menuComponent_Items(self, parent):
67        # generated method, don't edit
68
69        parent.Append(help=u'', id=wxID_COMPFRAMEMENUCOMPONENTGENERATE,
70              kind=wx.ITEM_NORMAL, text=u'Generate Component')
71        self.Bind(wx.EVT_MENU, self.OnMenuComponentGenerateMenu,
72              id=wxID_COMPFRAMEMENUCOMPONENTGENERATE)
73
74    def _init_coll_menuBar1_Menus(self, parent):
75        # generated method, don't edit
76
77        parent.Append(menu=self.menuFile, title='File')
78        parent.Append(menu=self.menuComponent, title=u'Component')
79
80    def _init_coll_imageListPorts_Images(self, parent):
81        # generated method, don't edit
82
83        parent.Add(bitmap=wx.Bitmap(u'uses.bmp', wx.BITMAP_TYPE_BMP),
84              mask=wx.NullBitmap)
85        parent.Add(bitmap=wx.Bitmap(u'provides.bmp', wx.BITMAP_TYPE_BMP),
86              mask=wx.NullBitmap)
87
88    def _init_coll_menuFile_Items(self, parent):
89        # generated method, don't edit
90        parent.Append(help='', id=wxID_COMPFRAMEMENUFILENEW,
91              kind=wx.ITEM_NORMAL, text='New')
92        parent.Append(help='', id=wxID_COMPFRAMEMENUFILEOPEN,
93              kind=wx.ITEM_NORMAL, text=u'Open')
94        parent.Append(help='', id=wxID_COMPFRAMEMENUFILESAVE,
95              kind=wx.ITEM_NORMAL, text='Save')
96        parent.Append(help='', id=wxID_COMPFRAMEMENUFILESAVEAS,
97              kind=wx.ITEM_NORMAL, text='Save As')
98        self.Bind(wx.EVT_MENU, self.OnMenuFileSaveasMenu,
99              id=wxID_COMPFRAMEMENUFILESAVEAS)
100        self.Bind(wx.EVT_MENU, self.OnMenuFileSaveMenu,
101              id=wxID_COMPFRAMEMENUFILESAVE)
102        self.Bind(wx.EVT_MENU, self.OnMenuFileNewMenu,
103              id=wxID_COMPFRAMEMENUFILENEW)
104        self.Bind(wx.EVT_MENU, self.OnMenuFileOpenMenu,
105              id=wxID_COMPFRAMEMENUFILEOPEN)
106
107    def _init_coll_portBoxPopup_Items(self, parent):
108        # generated method, don't edit
109
110        parent.Append(help='', id=wxID_COMPFRAMEPORTBOXPOPUPADD,
111              kind=wx.ITEM_NORMAL, text=u'Add')
112        parent.Append(help='', id=wxID_COMPFRAMEPORTBOXPOPUPREMOVE,
113              kind=wx.ITEM_NORMAL, text=u'Remove')
114        parent.AppendSeparator()
115        parent.Append(help='', id=wxID_COMPFRAMEPORTBOXPOPUPEXPAND,
116              kind=wx.ITEM_NORMAL, text=u'Expand All')
117        self.Bind(wx.EVT_MENU, self.OnPortBoxPopupRemoveMenu,
118              id=wxID_COMPFRAMEPORTBOXPOPUPREMOVE)
119        self.Bind(wx.EVT_MENU, self.OnPortBoxPopupExpandMenu,
120              id=wxID_COMPFRAMEPORTBOXPOPUPEXPAND)
121        self.Bind(wx.EVT_MENU, self.OnPortBoxPopupAddMenu,
122              id=wxID_COMPFRAMEPORTBOXPOPUPADD)
123
124    def _init_coll_propListPopup_Items(self, parent):
125
126        parent.Append(help='', id=wxID_COMPFRAMEPROPLISTPOPUPADD,
127              kind=wx.ITEM_NORMAL, text=u'Add')
128        parent.Append(help='', id=wxID_COMPFRAMEPROPLISTPOPUPREMOVE,
129              kind=wx.ITEM_NORMAL, text=u'Remove')
130        parent.AppendSeparator()
131        parent.Append(help='', id=wxID_COMPFRAMEPROPLISTPOPUPEDIT,
132              kind=wx.ITEM_NORMAL, text=u'Edit')
133        self.Bind(wx.EVT_MENU, self.OnPropsListPopupRemoveMenu,
134              id=wxID_COMPFRAMEPROPLISTPOPUPREMOVE)
135        self.Bind(wx.EVT_MENU, self.OnPropsListPopupEditMenu,
136              id=wxID_COMPFRAMEPROPLISTPOPUPEDIT)
137        self.Bind(wx.EVT_MENU, self.OnPropsListPopupAddMenu,
138              id=wxID_COMPFRAMEPROPLISTPOPUPADD)
139
140    def _init_coll_propList_Columns(self, parent):
141        # generated method, don't edit
142
143        parent.InsertColumn(col=0, format=wx.LIST_FORMAT_LEFT,
144              heading=u'Properties', width=155)
145        parent.InsertColumn(col=1, format=wx.LIST_FORMAT_LEFT,
146              heading=u'Values', width=155)
147
148    def _init_utils(self):
149        # generated method, don't edit
150        self.menuFile = wx.Menu(title='')
151
152        self.menuComponent = wx.Menu(title='')
153
154        self.menuBar1 = wx.MenuBar()
155
156        self.portBoxPopup = wx.Menu(title='')
157       
158        self.propListPopup = wx.Menu(title='')
159
160        self.imageListPorts = wx.ImageList(height=16, width=16)
161        self._init_coll_imageListPorts_Images(self.imageListPorts)
162
163        self._init_coll_menuFile_Items(self.menuFile)
164        self._init_coll_menuComponent_Items(self.menuComponent)
165        self._init_coll_menuBar1_Menus(self.menuBar1)
166        self._init_coll_portBoxPopup_Items(self.portBoxPopup)
167        self._init_coll_propListPopup_Items(self.propListPopup)
168
169    def _init_ctrls(self, prnt, _availableTemplates):
170        # generated method, don't edit
171        wx.Frame.__init__(self, id=wxID_COMPFRAME, name='CompFrame',
172              parent=prnt, pos=wx.Point(553, 276), size=wx.Size(656, 544),
173              style=wx.DEFAULT_FRAME_STYLE, title=u'OSSIE Component Editor')
174        self._init_utils()
175        self.SetClientSize(wx.Size(856, 544))
176        self.SetMenuBar(self.menuBar1)
177#        self.Center(wx.BOTH)
178        self.Bind(wx.EVT_CLOSE, self.OnCompFrameClose)
179        self.Bind(wx.EVT_ACTIVATE, self.OnCompFrameActivate)
180
181        self.statusBarComponent = wx.StatusBar(id=wxID_COMPFRAMESTATUSBARCOMPONENT,
182              name='statusBarComponent', parent=self, style=0)
183        self.SetStatusBar(self.statusBarComponent)
184
185        self.AddPortBtn = wx.Button(id=wxID_COMPFRAMEADDPORTBTN, label='Add Port',
186              name='AddPortBtn', parent=self, pos=wx.Point(387, 216),
187              size=wx.Size(100, 30), style=0)
188        self.AddPortBtn.Bind(wx.EVT_BUTTON, self.OnAddPortBtnButton,
189              id=wxID_COMPFRAMEADDPORTBTN)
190
191        self.RemoveBtn = wx.Button(id=wxID_COMPFRAMEREMOVEBTN, label='Remove Port',
192              name='RemoveBtn', parent=self, pos=wx.Point(387, 259),
193              size=wx.Size(100, 30), style=0)
194        self.RemoveBtn.Bind(wx.EVT_BUTTON, self.OnRemoveBtnButton,
195              id=wxID_COMPFRAMEREMOVEBTN)
196
197        self.addProp = wx.Button(id=wxID_COMPFRAMEADDPROP, label=u'Add Property',
198              name=u'addProp', parent=self, pos=wx.Point(384, 356),
199              size=wx.Size(100, 30), style=0)
200        self.addProp.Enable(True)
201        self.addProp.Bind(wx.EVT_BUTTON, self.OnaddPropButton,
202              id=wxID_COMPFRAMEADDPROP)
203
204        self.removeProp = wx.Button(id=wxID_COMPFRAMEREMOVEPROP,
205              label=u'Remove Property', name=u'removeProp', parent=self,
206              pos=wx.Point(384, 404), size=wx.Size(120, 32), style=0)
207        self.removeProp.Enable(True)
208        self.removeProp.Bind(wx.EVT_BUTTON, self.OnRemovePropButton,
209              id=wxID_COMPFRAMEREMOVEPROP)
210
211        self.staticText2 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT2,
212              label='Ports', name='staticText2', parent=self, pos=wx.Point(167,
213              89), size=wx.Size(65, 17), style=0)
214
215        self.CloseBtn = wx.Button(id=wxID_COMPFRAMECLOSEBTN, label='Close',
216              name='CloseBtn', parent=self, pos=wx.Point(530, 424),
217              size=wx.Size(85, 32), style=0)
218        self.CloseBtn.Bind(wx.EVT_BUTTON, self.OnCloseBtnButton,
219              id=wxID_COMPFRAMECLOSEBTN)
220
221        self.TimingcheckBox = wx.CheckBox(id=wxID_COMPFRAMETIMINGCHECKBOX,
222              label=u'Timing Port Support', name=u'TimingcheckBox', parent=self,
223              pos=wx.Point(634, 126), size=wx.Size(185, 21), style=0)
224        self.TimingcheckBox.SetValue(False)
225        self.TimingcheckBox.Bind(wx.EVT_CHECKBOX, self.OnTimingcheckBoxCheckbox,
226              id=wxID_COMPFRAMETIMINGCHECKBOX)
227
228        self.ACEcheckBox = wx.CheckBox(id=wxID_COMPFRAMEACECHECKBOX,
229              label=u'ACE Support', name=u'ACEcheckBox', parent=self,
230              pos=wx.Point(634, 157), size=wx.Size(125, 21), style=0)
231        self.ACEcheckBox.SetValue(False)
232        self.ACEcheckBox.Bind(wx.EVT_CHECKBOX, self.OnACEcheckBoxCheckbox,
233              id=wxID_COMPFRAMEACECHECKBOX)
234
235        self.PortBox = wx.TreeCtrl(id=wxID_COMPFRAMEPORTBOX, name=u'PortBox',
236              parent=self, pos=wx.Point(40, 112), size=wx.Size(312, 185),
237              style=wx.SIMPLE_BORDER | wx.TR_HAS_BUTTONS | wx.TR_HIDE_ROOT)
238        self.PortBox.SetImageList(self.imageListPorts)
239        self.PortBox.SetBestFittingSize(wx.Size(312, 185))
240        self.PortBox.Bind(wx.EVT_RIGHT_UP, self.OnPortBoxRightUp)
241
242        self.AssemblyCcheckBox = wx.CheckBox(id=wxID_COMPFRAMEASSEMBLYCCHECKBOX,
243              label=u'Assembly Controller', name=u'AssemblyCcheckBox',
244              parent=self, pos=wx.Point(384, 126), size=wx.Size(165, 21),
245              style=0)
246        self.AssemblyCcheckBox.SetValue(False)
247        self.AssemblyCcheckBox.Bind(wx.EVT_CHECKBOX,
248              self.OnAssemblyCcheckBoxCheckbox,
249              id=wxID_COMPFRAMEASSEMBLYCCHECKBOX)
250
251        self.compNameBox = wx.TextCtrl(id=wxID_COMPFRAMECOMPNAMEBOX,
252              name=u'compNameBox', parent=self, pos=wx.Point(138, 10),
253              size=wx.Size(215, 25), style=0, value=u'')
254
255        self.staticText1 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT1,
256              label=u'Component Name:', name='staticText1', parent=self,
257              pos=wx.Point(24, 13), size=wx.Size(110, 17), style=0)
258
259        self.compDescrBox = wx.TextCtrl(id=wxID_COMPFRAMECOMPDESCRBOX,
260              name=u'compDescrBox', parent=self, pos=wx.Point(110, 40),
261              size=wx.Size(243, 50), style=wx.TE_BESTWRAP | wx.TE_MULTILINE, value=u'')
262
263        self.staticText1_1 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT8,
264              label=u'Description:', name='staticText8', parent=self,
265              pos=wx.Point(24, 43), size=wx.Size(110, 17), style=0)
266
267        self.deviceChoice = wx.Choice(choices=[], id=wxID_COMPFRAMEDEVICECHOICE,
268              name=u'deviceChoice', parent=self, pos=wx.Point(453, 93),
269              size=wx.Size(136, 28), style=0)
270        self.deviceChoice.SetBestFittingSize(wx.Size(136, 28))
271        self.deviceChoice.Bind(wx.EVT_CHOICE, self.OnDeviceChoiceChoice,
272              id=wxID_COMPFRAMEDEVICECHOICE)
273
274        self.staticText3 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT3,
275              label=u'Waveform Deployment Settings', name='staticText3', parent=self,
276              pos=wx.Point(384, 24), size=wx.Size(100, 35), style=wx.TE_BESTWRAP | wx.TE_MULTILINE)
277
278        self.staticText3.SetFont(wx.Font(8,wx.SWISS,wx.NORMAL,wx.BOLD,True,u'Sans'))
279       
280        self.nodeChoice = wx.Choice(choices=[], id=wxID_COMPFRAMENODECHOICE,
281              name=u'nodeChoice', parent=self, pos=wx.Point(453, 60),
282              size=wx.Size(136, 28), style=0)
283        self.nodeChoice.Bind(wx.EVT_CHOICE, self.OnNodeChoiceChoice,
284              id=wxID_COMPFRAMENODECHOICE)
285
286        self.staticText4 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT4,
287              label=u'Node', name='staticText4', parent=self, pos=wx.Point(384,
288              65), size=wx.Size(41, 17), style=0)
289
290        self.staticText5 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT5,
291              label=u'Device', name='staticText5', parent=self,
292              pos=wx.Point(384, 98), size=wx.Size(51, 17), style=0)
293       
294        self.staticText6 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT6,
295              label=u'Component Generation Options', name='staticText6', parent=self,
296              pos=wx.Point(634, 24), size=wx.Size(100, 35), style=wx.TE_BESTWRAP | wx.TE_MULTILINE)
297        self.staticText6.SetFont(wx.Font(8,wx.SWISS,wx.NORMAL,wx.BOLD,True,u'Sans'))
298       
299        self.staticText7 = wx.StaticText(id=wxID_COMPFRAMESTATICTEXT7,
300              label=u'Template', name='staticText7', parent=self,
301              pos=wx.Point(634, 65), size=wx.Size(222, 17), style=0)
302       
303        self.propList = wx.ListView(id=wxID_COMPFRAMEPROPLIST, name=u'propList',
304              parent=self, pos=wx.Point(40, 320), size=wx.Size(312, 160),
305              style=wx.LC_SINGLE_SEL | wx.VSCROLL | wx.LC_REPORT | wx.LC_VRULES | wx.LC_HRULES | wx.SIMPLE_BORDER)
306        self.propList.SetBestFittingSize(wx.Size(312, 160))
307        self._init_coll_propList_Columns(self.propList)
308        #self.propList.Bind(wx.EVT_RIGHT_UP, self.OnPropListRightUp)
309        self.propList.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.OnPropListListItemRightClick)
310        self.propList.Bind(wx.EVT_LEFT_DCLICK,self.OnPropListLeftDclick)
311
312        self.staticLine1 = wx.StaticLine(id=wxID_COMPFRAMESTATICLINE1,
313              name='staticLine1', parent=self, pos=wx.Point(610, 17),
314              size=wx.Size(1, 200), style=wx.LI_VERTICAL)
315       
316        self.templateChoice = wx.Choice(choices=_availableTemplates,
317              id=wxID_COMPFRAMETEMPLATECHOICE,
318              name=u'templateChoice', parent=self, pos=wx.Point(703, 60),
319              size=wx.Size(136, 28), style=0)
320        self.templateChoice.SetBestFittingSize(wx.Size(136, 28))
321        self.templateChoice.Bind(wx.EVT_CHOICE, self.OnTemplateChoiceChoice,
322              id=wxID_COMPFRAMETEMPLATECHOICE)
323             
324    def __init__(self, parent):
325        # Constructor for ComponentFrame
326        availableTemplates = commands.getoutput("cd generate/templates; ls -I __init__.py -I __init__.pyc")
327        availableTemplates = availableTemplates.split()
328        self._init_ctrls(parent,availableTemplates)
329       
330        self.templateChoice.SetSelection(0)
331        self.template = self.templateChoice.GetStringSelection()
332         
333        self.parent = parent
334               
335        self.saveComponentPath = None
336        self.calledByParent = False
337       
338        if parent == None:  #OSSIE Component Editor being run in stand-alone mode
339            self.menuComponent.Enable(wxID_COMPFRAMEMENUCOMPONENTGENERATE,True)
340            self.compDescrBox.Enable(True)
341            MainFrame.LoadConfiguration(self)
342        else:
343            self.menuComponent.Enable(wxID_COMPFRAMEMENUCOMPONENTGENERATE,False)
344            self.compDescrBox.Enable(False)
345
346        self.Available_Ints = []
347        self.importStandardIdl()
348       
349       
350    def OnCompFrameActivate(self, event):
351        if self.calledByParent == True:
352            self.active_comp = self.parent.active_comp
353            self.displayPorts()
354            self.displayProps()
355           
356            if self.active_comp.ace == True:
357                self.ACEcheckBox.SetValue(True)
358            else:
359                self.ACEcheckBox.SetValue(False)
360           
361            if self.active_comp.timing == True:
362                self.TimingcheckBox.SetValue(True)
363            else:
364                self.TimingcheckBox.SetValue(False)
365           
366            if self.active_comp.AssemblyController == True:
367                self.AssemblyCcheckBox.SetValue(True)
368            else:
369                self.AssemblyCcheckBox.SetValue(False)
370           
371            if self.active_comp.generate == False:
372                self.AddPortBtn.Enable(False)
373                self.RemoveBtn.Enable(False)
374                self.ACEcheckBox.Enable(False)
375                self.TimingcheckBox.Enable(False)
376            else:
377                self.AddPortBtn.Enable(True)
378                self.RemoveBtn.Enable(True)
379                self.ACEcheckBox.Enable(True)
380                self.TimingcheckBox.Enable(True)
381           
382            self.compNameBox.Clear()
383            self.compNameBox.WriteText(self.active_comp.name)
384
385            self.compDescrBox.Clear()
386            self.compDescrBox.WriteText(self.active_comp.description)
387           
388            if self.active_comp.type != 'resource':
389                self.deviceChoice.Clear()
390                self.deviceChoice.Enable(False)
391                self.nodeChoice.Enable(False)
392            else:
393                self.deviceChoice.Enable(True)
394                self.nodeChoice.Enable(True)
395                self.displayPlatformInfo()
396           
397            self.menuFile.Enable(wxID_COMPFRAMEMENUFILENEW,False)
398            self.menuFile.Enable(wxID_COMPFRAMEMENUFILEOPEN,False)
399           
400            self.calledByParent = False
401           
402           
403################################################################################
404## File Menu / Frame Functionality
405################################################################################
406    def OnMenuFileSaveasMenu(self, event):
407        self.ComponentSave(True)
408        event.Skip()
409
410    def OnMenuFileSaveMenu(self, event):
411        self.ComponentSave(False)
412        event.Skip()
413
414    def OnMenuFileNewMenu(self, event):
415        self.active_comp = CC.Component("component1")
416        self.ACEcheckBox.SetValue(False)
417        self.TimingcheckBox.SetValue(False)
418        self.AssemblyCcheckBox.SetValue(False)
419        self.AddPortBtn.Enable(True)
420        self.RemoveBtn.Enable(True)
421        self.displayPorts()
422        self.compNameBox.Clear()
423        self.compNameBox.WriteText(self.active_comp.name)
424        self.compDescrBox.Clear()
425        self.compDescrBox.WriteText("Enter brief description of component")
426        event.Skip()
427
428    def OnMenuFileOpenMenu(self, event):
429        if len(self.homeDir) > 0:
430            tmpdir = self.homeDir
431        else:
432            tmpdir = os.path.expanduser("~")
433            if tmpdir == "~":
434                tmpdir = "/home"
435               
436        tmpwildcard = "Component Files (*.cmp)|*.cmp"
437        dlg = wx.FileDialog(self, "Choose a file", tmpdir, "", tmpwildcard, wx.OPEN)
438        try:
439            returnCode = dlg.ShowModal()
440            if returnCode == wx.ID_OK:
441                tmpPath = dlg.GetPath()
442            elif returnCode == wx.ID_CANCEL:
443                dlg.Destroy()
444                return
445        finally:
446            dlg.Destroy()
447           
448        f = open(tmpPath,'r')
449        tmpObject = cPickle.load(f)
450        if tmpObject[0] == 'component':
451            self.ComponentOpen(tmpPath,tmpObject[1])
452
453        event.Skip()
454
455    def ComponentSave(self,saveasFlag):
456        if saveasFlag == True or self.saveComponentPath == None:
457            tempLn = self.compNameBox.GetLineText(0)
458            if tempLn == '':
459                errorMsg(self,'Please enter a component name first')
460                return           
461            self.active_comp.name = tempLn
462
463            tempDescr = self.compDescrBox.GetLineText(0)
464            if tempDescr == '':
465                errorMsg(self,'Please enter a component description first')
466                return
467            self.active_comp.description = tempDescr
468           
469            if len(self.homeDir) > 0:
470                tmpdir = self.homeDir
471            else:
472                tmpdir = os.path.expanduser("~")
473                if tmpdir == "~":
474                    tmpdir = "/home"
475                   
476            dlg = wx.FileDialog(self, "Choose a file", tmpdir, tempLn + '.cmp', "Component File (*.cmp)|*.cmp", wx.SAVE)
477            try:
478                returnCode = dlg.ShowModal()
479                if returnCode == wx.ID_OK:
480                    self.saveComponentPath = dlg.GetPath()
481                elif returnCode == wx.ID_CANCEL:
482                    dlg.Destroy()
483                    return
484            finally:
485                dlg.Destroy()
486           
487        f = open(self.saveComponentPath,'w')
488        cPickle.dump(('component',self.active_comp),f)
489
490    def ComponentOpen(self,newPath,newComp):
491        if newPath != None:
492            if self.saveComponentPath != None:
493                dlg = wx.MessageDialog(self, 'Do you want to save your changes to the active component first?',
494                      'Error', wx.YES_NO | wx.ICON_INFORMATION)
495                try:
496                    returnCode = dlg.ShowModal()
497                    if returnCode == wx.ID_YES:
498                        self.ComponentSave(False)
499                    elif returnCode == wx.ID_CANCEL:
500                        dlg.Destroy()
501                        return
502                finally:
503                    dlg.Destroy()
504           
505            self.saveComponentPath = newPath
506           
507        self.active_comp = newComp
508        self.displayPorts()
509        self.displayProps()
510       
511        if self.active_comp.ace == True:
512            self.ACEcheckBox.SetValue(True)
513        else:
514            self.ACEcheckBox.SetValue(False)
515
516        if not hasattr(self.active_comp,'timing'):
517            self.active_comp.timing = False
518        if self.active_comp.timing == True:
519            self.TimingcheckBox.SetValue(True)
520        else:
521            self.TimingcheckBox.SetValue(False)
522       
523        if self.active_comp.AssemblyController == True:
524            self.AssemblyCcheckBox.SetValue(True)
525        else:
526            self.AssemblyCcheckBox.SetValue(False)
527       
528        if self.active_comp.generate == False:
529            self.AddPortBtn.Enable(False)
530            self.RemoveBtn.Enable(False)
531        else:
532            self.AddPortBtn.Enable(True)
533            self.RemoveBtn.Enable(True)
534       
535        self.compNameBox.Clear()
536        self.compNameBox.WriteText(self.active_comp.name)
537       
538        self.compDescrBox.Clear()
539        self.compDescrBox.WriteText(self.active_comp.implementation.description)
540   
541    def OnCloseBtnButton(self, event):
542        if self.parent == None:
543            self.Show(False)
544            self.Close()
545            return
546        tempLn = self.compNameBox.GetLineText(0)
547        if tempLn == '':
548            errorMsg(self,'Please enter a component name first')
549            return   
550
551        for c in self.parent.active_wave.components:
552            if c != self.active_comp and c.name == tempLn:
553                errorMsg(self,'Invalid name - a component by that name already exists')
554                return
555       
556        #Component names with spaces do not work
557        if tempLn.find(' ') != -1:
558            errorMsg(self,'Resource names can not have spaces in them.\nReplacing spaces with "_".')
559            tempLn = tempLn.replace(' ','_')
560           
561           
562        self.active_comp.changeName(tempLn)
563               
564        self.MakeModal(False)
565        self.parent.displayComps()
566        self.parent.displayNodes()
567        self.Show(False)
568        event.Skip()
569
570    def OnCompFrameClose(self, event):
571        self.MakeModal(False)
572        if self.parent != None:
573            self.parent.displayComps() 
574        self.Show(False)
575        event.Skip()
576   
577   
578################################################################################
579## Miscellaneous Functionality
580################################################################################
581
582    def importStandardIdl(self):   
583        '''Imports IDL from cf, standardinterfaces, and custominterfaces'''
584        #temporarily change self.parent to self so this works
585        #normally this function looks at the MainFrame - but not in standalone
586        changedParent = False 
587        if self.parent == None:
588            self.parent = self
589            changedParent = True     
590           
591        if os.path.isfile(self.parent.ossieIncludePath + "cf.idl"):
592            cfIdl_file = self.parent.ossieIncludePath + "cf.idl"
593        else:
594            tmpstr = "Cannot find cf.idl in the OSSIE installation location:\n"
595            tmpstr += self.parent.ossieIncludePath
596            errorMsg(self.parent,tmpstr)
597
598        # for each file in the standardinterfaces directory, import all available
599        # interfaces (skip standardIdl files)
600
601        standard_idl_list = os.listdir(self.parent.stdIdlPath)
602        custom_idl_list = os.listdir(self.parent.customIdlPath)
603
604        if len(standard_idl_list) <= 0:
605            tmpstr = "Can't find any files in: " + self.parent.stdIdlPath
606            errorMsg(self.parent,tmpstr)
607            return
608       
609        # Add the CF interfaces first - in case another file includes them, we
610        # don't want them asscociated with anything other than cf.idl
611        self.Available_Ints.extend(importIDL.getInterfaces(cfIdl_file))
612       
613        # import standard interfaces
614        for standard_idl_file in standard_idl_list:
615            # standardIdl files are not included because they are aggregates of the other interfaces
616            if 'standardIdl' in standard_idl_file:
617                continue
618
619            if string.lower(os.path.splitext(standard_idl_file)[1]) != ".idl":
620                # ignore non idl files
621                continue
622           
623            tempInts = importIDL.getInterfaces(self.parent.stdIdlPath+standard_idl_file)
624            for t in tempInts:
625                if t not in self.Available_Ints:
626                    self.Available_Ints.append(t)
627                   
628        # import custom interfaces
629        for custom_idl_file in custom_idl_list:
630            # ignore aggregate 'customInterfaces.idl' file
631            if 'customInterfaces' in custom_idl_file:
632                continue
633
634            if string.lower(os.path.splitext(custom_idl_file)[1]) != ".idl":
635                # ignore non idl files
636                continue
637           
638            tempInts = importIDL.getInterfaces(self.parent.customIdlPath+custom_idl_file)
639            for t in tempInts:
640                if t not in self.Available_Ints:
641                   # print "Testing: " + t.name + " " + idl_file + " " + str(len(self.Available_Ints))
642                    self.Available_Ints.append(t)
643                    if t.name == 'timingStatus':
644                        self.timing_interface = CC.Interface(t.name, t.nameSpace, t.operations, t.filename, t.fullpath)
645                        self.timing_port = CC.Port('send_timing_report', self.timing_interface, "Uses", "data")
646#                    print "CF.py: " + t.name + "  " + str(len(t.operations))
647                   
648        if changedParent == True:
649            self.parent = None
650
651
652
653    def OnACEcheckBoxCheckbox(self, event):
654        if self.ACEcheckBox.GetValue() == True:
655            self.active_comp.ace = True
656        else:
657            self.active_comp.ace = False
658        event.Skip()
659
660    def OnTimingcheckBoxCheckbox(self, event):
661        if self.TimingcheckBox.GetValue() == True:
662            self.active_comp.timing = True
663        else:
664            self.active_comp.timing = False
665        event.Skip()
666
667    def OnAssemblyCcheckBoxCheckbox(self, event):
668        if self.AssemblyCcheckBox.GetValue() == True:
669            if self.parent != None:
670                for x in self.parent.active_wave.components:
671                    x.AssemblyController = False
672            self.active_comp.AssemblyController = True
673        else:
674            self.active_comp.AssemblyController = False
675        event.Skip()
676
677################################################################################
678## Port Functionality
679################################################################################
680
681    def displayPorts(self):
682        self.PortBox.DeleteAllItems()
683        troot = self.PortBox.AddRoot("the_root")
684        usesRoot = self.PortBox.AppendItem(troot,'Uses',image=0)
685        provRoot = self.PortBox.AppendItem(troot,'Provides',image=1)
686       
687        for p in self.active_comp.ports:
688            if p.type == 'Uses':
689                tnm = p.name + "::" + p.interface.name
690                t1 = self.PortBox.AppendItem(usesRoot,tnm)
691                self.PortBox.SetPyData(t1,p)
692               
693            if p.type == 'Provides':
694                tnm = p.name + "::" + p.interface.name
695                t2 = self.PortBox.AppendItem(provRoot,tnm)
696                self.PortBox.SetPyData(t2,p)
697        self.PortBox.Expand(usesRoot)
698        self.PortBox.Expand(provRoot)
699
700    def AddPort(self):
701        if self.active_comp.generate == False:
702            return
703        dlg = PortDialog.create(self)
704        try:
705            dlg.ShowModal()
706        finally:
707            dlg.Destroy()
708           
709        self.displayPorts()
710       
711    def RemovePort(self):
712        if self.active_comp.generate == False:
713            return
714        dlg = wx.MessageDialog(self, '("Are you sure you want to remove this port?")',
715          'Error', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_INFORMATION)
716        try:
717            if dlg.ShowModal() == wx.ID_NO:
718                return
719        finally:
720            dlg.Destroy()
721   
722        sn = self.PortBox.GetSelection()
723        if sn == self.PortBox.GetRootItem():
724            return
725        elif self.PortBox.GetItemParent(sn) == self.PortBox.GetRootItem():
726            # a main level component
727            return
728        else:
729            # a child component (port)
730            tc = self.PortBox.GetPyData(sn)
731            ti = self.active_comp.ports.index(tc)
732            del self.active_comp.ports[ti]
733       
734        self.displayPorts()
735
736
737    def OnAddPortBtnButton(self, event):
738        self.AddPort()   
739        event.Skip()
740       
741    def OnRemoveBtnButton(self, event):
742        self.RemovePort()
743        event.Skip()
744
745    def OnPortBoxPopupExpandMenu(self, event):
746        troot = self.PortBox.GetRootItem()
747        cid1,cookie1 = self.PortBox.GetFirstChild(troot)
748        cid2,cookie2 = self.PortBox.GetNextChild(troot,cookie1)
749        self.PortBox.Expand(cid1)
750        self.PortBox.Expand(cid2)
751        event.Skip()
752
753    def OnPortBoxRightUp(self, event):
754        sn = self.PortBox.GetSelection()
755       
756        if sn == self.PortBox.GetRootItem():
757            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPREMOVE,False)
758        elif self.PortBox.GetItemParent(sn) == self.PortBox.GetRootItem():
759            # a main level item
760            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPREMOVE,False)
761        else:
762            # a child component (ports in our case)
763            for x in self.portBoxPopup.GetMenuItems():
764                x.Enable(True)
765               
766        if self.active_comp.generate == False:
767            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPADD,False)
768            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPREMOVE,False)
769        else:
770            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPADD,True)
771                   
772        self.PortBox.PopupMenu(self.portBoxPopup)           
773        event.Skip()
774
775    def OnPortBoxPopupRemoveMenu(self, event):
776        self.RemovePort()
777        event.Skip()
778
779    def OnPortBoxPopupAddMenu(self, event):
780        self.AddPort()
781        event.Skip()
782
783   
784       
785################################################################################
786## Deployment Functionality
787################################################################################
788
789    def displayDevices(self):
790        if self.parent == None:
791            return
792       
793        pos = self.nodeChoice.GetSelection()
794        if pos == wx.NOT_FOUND:
795            return
796       
797        tmpNode = self.nodeChoice.GetClientData(pos)
798       
799       
800        self.deviceChoice.Clear()
801        for x in tmpNode.Devices:
802            if x.type == 'executabledevice' or x.type == 'loadabledevice':
803                self.deviceChoice.Append(unicode(x.name),x)
804           
805    def displayPlatformInfo(self):
806        if self.parent == None:
807            return
808       
809        self.deviceChoice.Clear()
810        self.nodeChoice.Clear()
811       
812        for x in self.parent.active_plat.nodes:
813            self.nodeChoice.Append(x.name,x)
814       
815        tmpNode = None
816        if self.active_comp.device != None:       
817            for x in self.parent.active_plat.nodes:
818                for d in x.Devices:
819                    if d == self.active_comp.device:
820                        tmpNode = x
821            if tmpNode != None:
822                pos = self.nodeChoice.FindString(tmpNode.name)
823                self.nodeChoice.SetSelection(pos)
824                for d in tmpNode.Devices:
825                    self.deviceChoice.Append(d.name,d)
826                pos = self.deviceChoice.FindString(self.active_comp.device.name)
827                self.deviceChoice.SetSelection(pos)
828           
829            else:
830                tmpstr = 'ERROR! Cannot find the ' + self.active_comp.device.name
831                tmpstr += ' device in current Platform configuration.'               
832                tmpstr += '\nSetting device assignment to None.'
833                errorMsg(self,tmpstr)
834                self.active_comp.device = None
835
836    def OnNodeChoiceChoice(self, event):
837        pos = self.nodeChoice.GetSelection()
838        if pos == wx.NOT_FOUND:
839            return
840        self.displayDevices()
841
842    def OnDeviceChoiceChoice(self, event):
843        pos = self.deviceChoice.GetSelection()
844        if pos == wx.NOT_FOUND:
845            return
846       
847        tmpDev = self.deviceChoice.GetClientData(pos)
848        self.active_comp.device = tmpDev
849
850    def OnTemplateChoiceChoice(self, event):
851        pos = self.templateChoice.GetSelection()
852        if pos == wx.NOT_FOUND:
853            return
854       
855        tmpTmpl = self.templateChoice.GetStringSelection()
856        self.template = tmpTmpl
857       
858       
859    ############################################################################
860    ## Properties Functionality
861    ############################################################################   
862    def OnaddPropButton(self, event):
863        self.AddProperty()
864        event.Skip()
865   
866    def OnRemovePropButton(self, event):
867        #sel = self.propList.GetFirstSelected()
868        self.RemoveProperty()
869        event.Skip()
870
871    def displayProps(self):
872        self.propList.DeleteAllItems()
873        pCount = 0
874        for p in self.active_comp.properties:
875            if p.elementType == "Simple":
876                self.propList.InsertStringItem(pCount,p.name)
877                self.propList.SetStringItem(pCount,1,str(p.value))
878            if p.elementType == "SimpleSequence":
879                self.propList.InsertStringItem(pCount,p.name)
880                ts = "["
881                for x in p.values:
882                    ts += x + ","
883                ts = ts[:-1] + "]"
884                self.propList.SetStringItem(pCount,1,ts)
885            self.propList.SetItemData(pCount,self.active_comp.properties.index(p))
886               
887    def OnPropListListItemRightClick(self, event):
888        self.propList.PopupMenu(self.propListPopup)           
889        event.Skip()
890       
891    def EditProperty(self):
892        sel = self.propList.GetFocusedItem()
893        if self < 0:
894            return
895        item = self.propList.GetItem(sel)
896        tmpind = item.GetData()                # the index of the property is stored with the item
897        dlg = PropertiesDialog.create(self)
898        dlg.active_prop = self.active_comp.properties[tmpind]
899        dlg.editable = self.active_comp.generate
900        dlg.calledByParent = True
901        try:
902            dlg.ShowModal()
903        finally:
904            dlg.Destroy()
905           
906        self.displayProps()
907       
908    def AddProperty(self):
909        dlg = PropertiesDialog.create(self)
910        dlg.active_prop = None
911        dlg.editable = self.active_comp.generate
912        dlg.calledByParent = True
913        try:
914            dlg.ShowModal()
915        finally:
916            dlg.Destroy()
917           
918        self.displayProps()
919   
920    def RemoveProperty(self):
921        sel = self.propList.GetFocusedItem()
922        if sel >= 0:
923            tmpstr = "Are you sure you want to remove this property?"
924            if owdMsg(self,tmpstr):
925                for p in self.active_comp.properties:
926                    if p.name == self.propList.GetItemText(sel):
927                        ti = self.active_comp.properties.index(p)
928                        del self.active_comp.properties[ti]
929                        self.propList.DeleteItem(sel)
930                        break
931            self.displayProps()
932
933    def OnPropsListPopupEditMenu(self, event):
934        self.EditProperty()
935        event.Skip()
936       
937    def OnPropsListPopupRemoveMenu(self, event):
938        self.RemoveProperty()
939        event.Skip()
940       
941    def OnPropsListPopupAddMenu(self, event):
942        self.AddProperty()
943        event.Skip()
944
945    def OnPropListLeftDclick(self,event):
946        self.EditProperty()
947        event.Skip()
948
949    ############################################################################
950    ## Generate the Component XML and C++
951    ############################################################################
952    def OnMenuComponentGenerateMenu(self, event):
953       
954        #select which template to use
955        if self.template == "basic_ports":
956            import WaveDev.wavedev.generate.templates.basic_ports.genStructure as genStruct
957        elif self.template == "custom_ports":
958            import WaveDev.wavedev.generate.templates.custom_ports.genStructure as genStruct
959        elif self.template == "py_comp":
960            import WaveDev.wavedev.generate.templates.py_comp.genStructure as genStruct
961        else:
962            errorMsg(self.parent, self.template + " is not supported in OnMenuComponentGenerateMenu witin the componentFrame")
963            return
964 
965        tempLn = self.compNameBox.GetLineText(0)
966        if tempLn == '':
967            errorMsg(self,'Please enter a component name first')
968            return
969           
970        self.active_comp.name = tempLn
971   
972        tempDescr = self.compDescrBox.GetLineText(0)
973        if tempDescr == '':
974            errorMsg(self,'Please enter a component description first')
975            return
976
977        self.active_comp.description = tempDescr
978
979        dlg = wx.DirDialog(self)
980        dlg.SetMessage("Please select the place to generate the code")
981        dlg.SetPath(os.getcwd())
982        try:
983            if dlg.ShowModal() == wx.ID_OK:
984                savepath = dlg.GetPath()
985            else:
986                return
987        finally:
988            dlg.Destroy()
989       
990        if savepath[len(savepath)-1] != '/':
991            savepath = savepath + '/'
992       
993        self.path = savepath
994        self.path = self.path + self.active_comp.name
995       
996        if os.path.exists(self.path) == False:
997                os.mkdir(self.path)
998               
999                #if os.path.exists(self.path + '/aclocal.d') == False:   
1000                #    os.mkdir(self.path + '/aclocal.d')
1001                #for f in os.listdir('generate/aclocal.d/'):
1002                #    if not os.path.isdir(f):
1003                #        shutil.copy('generate/aclocal.d/' + f,self.path + '/aclocal.d')
1004                if self.template != "py_comp":
1005                    shutil.copy('generate/reconf',self.path)
1006                shutil.copy('generate/LICENSE',self.path)
1007       
1008        if self.active_comp.timing:
1009                found_timing = False
1010                for p in self.active_comp.ports:
1011                        if p.interface.name == 'timingStatus':
1012                                found_timing = True
1013                if not found_timing:
1014                        self.active_comp.ports.append(self.timing_port)
1015       
1016        gen = genStruct.genAll(savepath,None)
1017        gen.writeCompMakefile(self.active_comp,self.path)
1018        gen.writeConfAC(self.path, self.active_comp.name, self.active_comp.ace, False, self.installPath)
1019        gen.genCompFiles(self.active_comp)
1020       
1021        component_gen.gen_scd(self.active_comp, savepath)
1022        component_gen.gen_spd(self.active_comp, savepath)
1023        component_gen.gen_prf(self.active_comp, savepath)
1024
1025class App(wx.App):
1026    def OnInit(self):
1027        self.name = 'comp_frame_app'
1028        self.main = create(None)
1029        self.main.Show()
1030
1031        #self.SetTopWindow(self.frame)
1032        return True
1033
1034    def OnExit(self):
1035        self.ExitMainLoop()    # inherited from wx.App
1036
1037def newComponentFrame():
1038    wx.InitAllImageHandlers()
1039    application = App()
1040   
1041    application.main.active_comp = CC.Component("component1")
1042    application.main.calledByParent = False
1043    application.main.displayPorts()
1044    application.main.compNameBox.WriteText("component1")
1045    application.main.compDescrBox.WriteText("Enter component description here")
1046    if application.main.active_comp.ace == True:
1047        application.main.ACEcheckBox.SetValue(True)
1048    else:
1049        application.main.ACEcheckBox.SetValue(False)
1050       
1051    if application.main.active_comp.timing == True:
1052        application.main.TimingcheckBox.SetValue(True)
1053    else:
1054        application.main.TimingcheckBox.SetValue(False)
1055     
1056    application.main.deviceChoice.Enable(False)
1057    application.main.nodeChoice.Enable(False)
1058    application.MainLoop()
1059 
1060
1061       
1062################################################################################
1063## If Component Developer is run as a seperate application
1064################################################################################
1065
1066if __name__ == "__main__":
1067    newComponentFrame()
Note: See TracBrowser for help on using the browser.