root/WaveDev/trunk/WaveDev/wavedev/ComponentFrame.py @ 4224

Revision 4224, 41.3 KB (checked in by DrewCormier, 6 years ago)

missing a tag

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