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

Revision 4424, 41.1 KB (checked in by DrewCormier, 6 years ago)

not passing around the application to the creator anymore because that was stupid

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            self.compDescrBox.Enable(True)
339            MainFrame.LoadConfiguration(self)
340        else:
341            self.menuComponent.Enable(wxID_COMPFRAMEMENUCOMPONENTGENERATE,False)
342            self.compDescrBox.Enable(False)
343
344        self.Available_Ints = []
345        self.importStandardIdl()
346       
347       
348    def OnCompFrameActivate(self, event):
349        if self.calledByParent == True:
350            self.active_comp = self.parent.active_comp
351            self.displayPorts()
352            self.displayProps()
353           
354            if self.active_comp.ace == True:
355                self.ACEcheckBox.SetValue(True)
356            else:
357                self.ACEcheckBox.SetValue(False)
358           
359            if self.active_comp.timing == True:
360                self.TimingcheckBox.SetValue(True)
361            else:
362                self.TimingcheckBox.SetValue(False)
363           
364            if self.active_comp.AssemblyController == True:
365                self.AssemblyCcheckBox.SetValue(True)
366            else:
367                self.AssemblyCcheckBox.SetValue(False)
368           
369            if self.active_comp.generate == False:
370                self.AddPortBtn.Enable(False)
371                self.RemoveBtn.Enable(False)
372                self.ACEcheckBox.Enable(False)
373                self.TimingcheckBox.Enable(False)
374            else:
375                self.AddPortBtn.Enable(True)
376                self.RemoveBtn.Enable(True)
377                self.ACEcheckBox.Enable(True)
378                self.TimingcheckBox.Enable(True)
379           
380            self.compNameBox.Clear()
381            self.compNameBox.WriteText(self.active_comp.name)
382
383            self.compDescrBox.Clear()
384            self.compDescrBox.WriteText(self.active_comp.description)
385           
386            if self.active_comp.type != 'resource':
387                self.deviceChoice.Clear()
388                self.deviceChoice.Enable(False)
389                self.nodeChoice.Enable(False)
390            else:
391                self.deviceChoice.Enable(True)
392                self.nodeChoice.Enable(True)
393                self.displayPlatformInfo()
394           
395            self.menuFile.Enable(wxID_COMPFRAMEMENUFILENEW,False)
396            self.menuFile.Enable(wxID_COMPFRAMEMENUFILEOPEN,False)
397           
398            self.calledByParent = False
399           
400           
401################################################################################
402## File Menu / Frame Functionality
403################################################################################
404    def OnMenuFileSaveasMenu(self, event):
405        self.ComponentSave(True)
406        event.Skip()
407
408    def OnMenuFileSaveMenu(self, event):
409        self.ComponentSave(False)
410        event.Skip()
411
412    def OnMenuFileNewMenu(self, event):
413        self.active_comp = CC.Component("component1")
414        self.ACEcheckBox.SetValue(False)
415        self.TimingcheckBox.SetValue(False)
416        self.AssemblyCcheckBox.SetValue(False)
417        self.AddPortBtn.Enable(True)
418        self.RemoveBtn.Enable(True)
419        self.displayPorts()
420        self.compNameBox.Clear()
421        self.compNameBox.WriteText(self.active_comp.name)
422        self.compDescrBox.Clear()
423        self.compDescrBox.WriteText("Enter brief description of component")
424        event.Skip()
425
426    def OnMenuFileOpenMenu(self, event):
427        if len(self.homeDir) > 0:
428            tmpdir = self.homeDir
429        else:
430            tmpdir = os.path.expanduser("~")
431            if tmpdir == "~":
432                tmpdir = "/home"
433               
434        tmpwildcard = "Component Files (*.cmp)|*.cmp"
435        dlg = wx.FileDialog(self, "Choose a file", tmpdir, "", tmpwildcard, wx.OPEN)
436        try:
437            returnCode = dlg.ShowModal()
438            if returnCode == wx.ID_OK:
439                tmpPath = dlg.GetPath()
440            elif returnCode == wx.ID_CANCEL:
441                dlg.Destroy()
442                return
443        finally:
444            dlg.Destroy()
445           
446        f = open(tmpPath,'r')
447        tmpObject = cPickle.load(f)
448        if tmpObject[0] == 'component':
449            self.ComponentOpen(tmpPath,tmpObject[1])
450
451        event.Skip()
452
453    def ComponentSave(self,saveasFlag):
454        if saveasFlag == True or self.saveComponentPath == None:
455            tempLn = self.compNameBox.GetLineText(0)
456            if tempLn == '':
457                errorMsg(self,'Please enter a component name first')
458                return           
459            self.active_comp.name = tempLn
460
461            tempDescr = self.compDescrBox.GetLineText(0)
462            if tempDescr == '':
463                errorMsg(self,'Please enter a component description first')
464                return
465            self.active_comp.description = tempDescr
466           
467            if len(self.homeDir) > 0:
468                tmpdir = self.homeDir
469            else:
470                tmpdir = os.path.expanduser("~")
471                if tmpdir == "~":
472                    tmpdir = "/home"
473                   
474            dlg = wx.FileDialog(self, "Choose a file", tmpdir, tempLn + '.cmp', "Component File (*.cmp)|*.cmp", wx.SAVE)
475            try:
476                returnCode = dlg.ShowModal()
477                if returnCode == wx.ID_OK:
478                    self.saveComponentPath = dlg.GetPath()
479                elif returnCode == wx.ID_CANCEL:
480                    dlg.Destroy()
481                    return
482            finally:
483                dlg.Destroy()
484           
485        f = open(self.saveComponentPath,'w')
486        cPickle.dump(('component',self.active_comp),f)
487
488    def ComponentOpen(self,newPath,newComp):
489        if newPath != None:
490            if self.saveComponentPath != None:
491                dlg = wx.MessageDialog(self, 'Do you want to save your changes to the active component first?',
492                      'Error', wx.YES_NO | wx.ICON_INFORMATION)
493                try:
494                    returnCode = dlg.ShowModal()
495                    if returnCode == wx.ID_YES:
496                        self.ComponentSave(False)
497                    elif returnCode == wx.ID_CANCEL:
498                        dlg.Destroy()
499                        return
500                finally:
501                    dlg.Destroy()
502           
503            self.saveComponentPath = newPath
504           
505        self.active_comp = newComp
506        self.displayPorts()
507        self.displayProps()
508       
509        if self.active_comp.ace == True:
510            self.ACEcheckBox.SetValue(True)
511        else:
512            self.ACEcheckBox.SetValue(False)
513
514        if not hasattr(self.active_comp,'timing'):
515            self.active_comp.timing = False
516        if self.active_comp.timing == True:
517            self.TimingcheckBox.SetValue(True)
518        else:
519            self.TimingcheckBox.SetValue(False)
520       
521        if self.active_comp.AssemblyController == True:
522            self.AssemblyCcheckBox.SetValue(True)
523        else:
524            self.AssemblyCcheckBox.SetValue(False)
525       
526        if self.active_comp.generate == False:
527            self.AddPortBtn.Enable(False)
528            self.RemoveBtn.Enable(False)
529        else:
530            self.AddPortBtn.Enable(True)
531            self.RemoveBtn.Enable(True)
532       
533        self.compNameBox.Clear()
534        self.compNameBox.WriteText(self.active_comp.name)
535       
536        self.compDescrBox.Clear()
537        self.compDescrBox.WriteText(self.active_comp.implementation.description)
538   
539    def OnCloseBtnButton(self, event):
540        if self.parent == None:
541            self.Show(False)
542            self.Close()
543            return
544        tempLn = self.compNameBox.GetLineText(0)
545        if tempLn == '':
546            errorMsg(self,'Please enter a component name first')
547            return   
548
549        for c in self.parent.active_wave.components:
550            if c != self.active_comp and c.name == tempLn:
551                errorMsg(self,'Invalid name - a component by that name already exists')
552                return
553       
554        #Component names with spaces do not work
555        if tempLn.find(' ') != -1:
556            errorMsg(self,'Resource names can not have spaces in them.\nReplacing spaces with "_".')
557            tempLn = tempLn.replace(' ','_')
558           
559           
560        self.active_comp.changeName(tempLn)
561               
562        self.MakeModal(False)
563        self.parent.displayComps()
564        self.parent.displayNodes()
565        self.Show(False)
566        event.Skip()
567
568    def OnCompFrameClose(self, event):
569        self.MakeModal(False)
570        if self.parent != None:
571            self.parent.displayComps() 
572        self.Show(False)
573        event.Skip()
574   
575   
576################################################################################
577## Miscellaneous Functionality
578################################################################################
579
580    def importStandardIdl(self):   
581        #temporarily change self.parent to self so this works
582        #normally this function looks at the MainFrame - but not in standalone
583        changedParent = False 
584        if self.parent == None:
585            self.parent = self
586            changedParent = True     
587           
588        if os.path.isfile(self.parent.ossieIncludePath + "cf.idl"):
589            cfIdl_file = self.parent.ossieIncludePath + "cf.idl"
590        else:
591            tmpstr = "Cannot find cf.idl in the OSSIE installation location:\n"
592            tmpstr += self.parent.ossieIncludePath
593            errorMsg(self.parent,tmpstr)
594
595        # for each file in the standardinterfaces directory, import all available
596        # interfaces (skip standardIdl files)
597        idlList = os.listdir(self.parent.stdIdlPath)
598        if len(idlList) <= 0:
599            tmpstr = "Can't find any files in: " + self.parent.stdIdlPath
600            errorMsg(self.parent,tmpstr)
601            return
602       
603        # Add the CF interfaces first - in case another file includes them, we
604        # don't want them asscociated with anything other than cf.idl
605        self.Available_Ints.extend(importIDL.getInterfaces(cfIdl_file))
606       
607        for idl_file in idlList:
608            # standardIdl files are not included because they are aggregates of the other interfaces
609            if 'standardIdl' in idl_file:
610                continue
611
612            if 'customInterfaces' in idl_file:
613                continue
614           
615            if idl_file[-3:] != "idl":
616                continue
617           
618            tempInts = importIDL.getInterfaces(self.parent.stdIdlPath+idl_file)
619            for t in tempInts:
620                if t not in self.Available_Ints:
621                   # print "Testing: " + t.name + " " + idl_file + " " + str(len(self.Available_Ints))
622                    self.Available_Ints.append(t)
623                    if t.name == 'timingStatus':
624                        self.timing_interface = CC.Interface(t.name, t.nameSpace, t.operations, t.filename, t.fullpath)
625                        self.timing_port = CC.Port('send_timing_report', self.timing_interface, "Uses", "data")
626#                    print "CF.py: " + t.name + "  " + str(len(t.operations))
627                   
628        if changedParent == True:
629            self.parent = None
630
631
632    def OnACEcheckBoxCheckbox(self, event):
633        if self.ACEcheckBox.GetValue() == True:
634            self.active_comp.ace = True
635        else:
636            self.active_comp.ace = False
637        event.Skip()
638
639    def OnTimingcheckBoxCheckbox(self, event):
640        if self.TimingcheckBox.GetValue() == True:
641            self.active_comp.timing = True
642        else:
643            self.active_comp.timing = False
644        event.Skip()
645
646    def OnAssemblyCcheckBoxCheckbox(self, event):
647        if self.AssemblyCcheckBox.GetValue() == True:
648            if self.parent != None:
649                for x in self.parent.active_wave.components:
650                    x.AssemblyController = False
651            self.active_comp.AssemblyController = True
652        else:
653            self.active_comp.AssemblyController = False
654        event.Skip()
655
656################################################################################
657## Port Functionality
658################################################################################
659
660    def displayPorts(self):
661        self.PortBox.DeleteAllItems()
662        troot = self.PortBox.AddRoot("the_root")
663        usesRoot = self.PortBox.AppendItem(troot,'Uses',image=0)
664        provRoot = self.PortBox.AppendItem(troot,'Provides',image=1)
665       
666        for p in self.active_comp.ports:
667            if p.type == 'Uses':
668                tnm = p.name + "::" + p.interface.name
669                t1 = self.PortBox.AppendItem(usesRoot,tnm)
670                self.PortBox.SetPyData(t1,p)
671               
672            if p.type == 'Provides':
673                tnm = p.name + "::" + p.interface.name
674                t2 = self.PortBox.AppendItem(provRoot,tnm)
675                self.PortBox.SetPyData(t2,p)
676        self.PortBox.Expand(usesRoot)
677        self.PortBox.Expand(provRoot)
678
679    def AddPort(self):
680        if self.active_comp.generate == False:
681            return
682        dlg = PortDialog.create(self)
683        try:
684            dlg.ShowModal()
685        finally:
686            dlg.Destroy()
687           
688        self.displayPorts()
689       
690    def RemovePort(self):
691        if self.active_comp.generate == False:
692            return
693        dlg = wx.MessageDialog(self, '("Are you sure you want to remove this port?")',
694          'Error', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_INFORMATION)
695        try:
696            if dlg.ShowModal() == wx.ID_NO:
697                return
698        finally:
699            dlg.Destroy()
700   
701        sn = self.PortBox.GetSelection()
702        if sn == self.PortBox.GetRootItem():
703            return
704        elif self.PortBox.GetItemParent(sn) == self.PortBox.GetRootItem():
705            # a main level component
706            return
707        else:
708            # a child component (port)
709            tc = self.PortBox.GetPyData(sn)
710            ti = self.active_comp.ports.index(tc)
711            del self.active_comp.ports[ti]
712       
713        self.displayPorts()
714
715
716    def OnAddPortBtnButton(self, event):
717        self.AddPort()   
718        event.Skip()
719       
720    def OnRemoveBtnButton(self, event):
721        self.RemovePort()
722        event.Skip()
723
724    def OnPortBoxPopupExpandMenu(self, event):
725        troot = self.PortBox.GetRootItem()
726        cid1,cookie1 = self.PortBox.GetFirstChild(troot)
727        cid2,cookie2 = self.PortBox.GetNextChild(troot,cookie1)
728        self.PortBox.Expand(cid1)
729        self.PortBox.Expand(cid2)
730        event.Skip()
731
732    def OnPortBoxRightUp(self, event):
733        sn = self.PortBox.GetSelection()
734       
735        if sn == self.PortBox.GetRootItem():
736            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPREMOVE,False)
737        elif self.PortBox.GetItemParent(sn) == self.PortBox.GetRootItem():
738            # a main level item
739            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPREMOVE,False)
740        else:
741            # a child component (ports in our case)
742            for x in self.portBoxPopup.GetMenuItems():
743                x.Enable(True)
744               
745        if self.active_comp.generate == False:
746            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPADD,False)
747            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPREMOVE,False)
748        else:
749            self.portBoxPopup.Enable(wxID_COMPFRAMEPORTBOXPOPUPADD,True)
750                   
751        self.PortBox.PopupMenu(self.portBoxPopup)           
752        event.Skip()
753
754    def OnPortBoxPopupRemoveMenu(self, event):
755        self.RemovePort()
756        event.Skip()
757
758    def OnPortBoxPopupAddMenu(self, event):
759        self.AddPort()
760        event.Skip()
761
762   
763       
764################################################################################
765## Deployment Functionality
766################################################################################
767
768    def displayDevices(self):
769        if self.parent == None:
770            return
771       
772        pos = self.nodeChoice.GetSelection()
773        if pos == wx.NOT_FOUND:
774            return
775       
776        tmpNode = self.nodeChoice.GetClientData(pos)
777       
778       
779        self.deviceChoice.Clear()
780        for x in tmpNode.Devices:
781            if x.type == 'executabledevice' or x.type == 'loadabledevice':
782                self.deviceChoice.Append(unicode(x.name),x)
783           
784    def displayPlatformInfo(self):
785        if self.parent == None:
786            return
787       
788        self.deviceChoice.Clear()
789        self.nodeChoice.Clear()
790       
791        for x in self.parent.active_plat.nodes:
792            self.nodeChoice.Append(x.name,x)
793       
794        tmpNode = None
795        if self.active_comp.device != None:       
796            for x in self.parent.active_plat.nodes:
797                for d in x.Devices:
798                    if d == self.active_comp.device:
799                        tmpNode = x
800            if tmpNode != None:
801                pos = self.nodeChoice.FindString(tmpNode.name)
802                self.nodeChoice.SetSelection(pos)
803                for d in tmpNode.Devices:
804                    self.deviceChoice.Append(d.name,d)
805                pos = self.deviceChoice.FindString(self.active_comp.device.name)
806                self.deviceChoice.SetSelection(pos)
807           
808            else:
809                tmpstr = 'ERROR! Cannot find the ' + self.active_comp.device.name
810                tmpstr += ' device in current Platform configuration.'               
811                tmpstr += '\nSetting device assignment to None.'
812                errorMsg(self,tmpstr)
813                self.active_comp.device = None
814
815    def OnNodeChoiceChoice(self, event):
816        pos = self.nodeChoice.GetSelection()
817        if pos == wx.NOT_FOUND:
818            return
819        self.displayDevices()
820
821    def OnDeviceChoiceChoice(self, event):
822        pos = self.deviceChoice.GetSelection()
823        if pos == wx.NOT_FOUND:
824            return
825       
826        tmpDev = self.deviceChoice.GetClientData(pos)
827        self.active_comp.device = tmpDev
828
829    def OnTemplateChoiceChoice(self, event):
830        pos = self.templateChoice.GetSelection()
831        if pos == wx.NOT_FOUND:
832            return
833       
834        tmpTmpl = self.templateChoice.GetStringSelection()
835        self.template = tmpTmpl
836       
837       
838    ############################################################################
839    ## Properties Functionality
840    ############################################################################   
841    def OnaddPropButton(self, event):
842        self.AddProperty()
843        event.Skip()
844   
845    def OnRemovePropButton(self, event):
846        #sel = self.propList.GetFirstSelected()
847        self.RemoveProperty()
848        event.Skip()
849
850    def displayProps(self):
851        self.propList.DeleteAllItems()
852        pCount = 0
853        for p in self.active_comp.properties:
854            if p.elementType == "Simple":
855                self.propList.InsertStringItem(pCount,p.name)
856                self.propList.SetStringItem(pCount,1,str(p.value))
857            if p.elementType == "SimpleSequence":
858                self.propList.InsertStringItem(pCount,p.name)
859                ts = "["
860                for x in p.values:
861                    ts += x + ","
862                ts = ts[:-1] + "]"
863                self.propList.SetStringItem(pCount,1,ts)
864            self.propList.SetItemData(pCount,self.active_comp.properties.index(p))
865               
866    def OnPropListListItemRightClick(self, event):
867        self.propList.PopupMenu(self.propListPopup)           
868        event.Skip()
869       
870    def EditProperty(self):
871        sel = self.propList.GetFocusedItem()
872        if self < 0:
873            return
874        item = self.propList.GetItem(sel)
875        tmpind = item.GetData()                # the index of the property is stored with the item
876        dlg = PropertiesDialog.create(self)
877        dlg.active_prop = self.active_comp.properties[tmpind]
878        dlg.editable = self.active_comp.generate
879        dlg.calledByParent = True
880        try:
881            dlg.ShowModal()
882        finally:
883            dlg.Destroy()
884           
885        self.displayProps()
886       
887    def AddProperty(self):
888        dlg = PropertiesDialog.create(self)
889        dlg.active_prop = None
890        dlg.editable = self.active_comp.generate
891        dlg.calledByParent = True
892        try:
893            dlg.ShowModal()
894        finally:
895            dlg.Destroy()
896           
897        self.displayProps()
898   
899    def RemoveProperty(self):
900        sel = self.propList.GetFocusedItem()
901        if sel >= 0:
902            tmpstr = "Are you sure you want to remove this property?"
903            if owdMsg(self,tmpstr):
904                for p in self.active_comp.properties:
905                    if p.name == self.propList.GetItemText(sel):
906                        ti = self.active_comp.properties.index(p)
907                        del self.active_comp.properties[ti]
908                        self.propList.DeleteItem(sel)
909                        break
910            self.displayProps()
911
912    def OnPropsListPopupEditMenu(self, event):
913        self.EditProperty()
914        event.Skip()
915       
916    def OnPropsListPopupRemoveMenu(self, event):
917        self.RemoveProperty()
918        event.Skip()
919       
920    def OnPropsListPopupAddMenu(self, event):
921        self.AddProperty()
922        event.Skip()
923
924    def OnPropListLeftDclick(self,event):
925        self.EditProperty()
926        event.Skip()
927
928    ############################################################################
929    ## Generate the Component XML and C++
930    ############################################################################
931    def OnMenuComponentGenerateMenu(self, event):
932       
933        #select which template to use
934        if self.template == "basic_ports":
935            import wavedev.generate.templates.basic_ports.genStructure as genStruct
936        elif self.template == "custom_ports":
937            import wavedev.generate.templates.custom_ports.genStructure as genStruct
938        elif self.template == "py_comp":
939            import wavedev.generate.templates.py_comp.genStructure as genStruct
940            errorMsg(self.parent, "WARNING: " + self.template + " does not work yet.  Useless code will be generated"  )
941        else:
942            errorMsg(self.parent, self.template + " is not supported in OnMenuComponentGenerateMenu witin the componentFrame")
943            return
944 
945        tempLn = self.compNameBox.GetLineText(0)
946        if tempLn == '':
947            errorMsg(self,'Please enter a component name first')
948            return
949           
950        self.active_comp.name = tempLn
951   
952        tempDescr = self.compDescrBox.GetLineText(0)
953        if tempDescr == '':
954            errorMsg(self,'Please enter a component description first')
955            return
956
957        self.active_comp.description = tempDescr
958
959        dlg = wx.DirDialog(self)
960        dlg.SetMessage("Please select the place to generate the code")
961        dlg.SetPath(os.getcwd())
962        try:
963            if dlg.ShowModal() == wx.ID_OK:
964                savepath = dlg.GetPath()
965            else:
966                return
967        finally:
968            dlg.Destroy()
969       
970        if savepath[len(savepath)-1] != '/':
971            savepath = savepath + '/'
972       
973        self.path = savepath
974        self.path = self.path + self.active_comp.name
975       
976        if os.path.exists(self.path) == False:
977                os.mkdir(self.path)
978               
979                #if os.path.exists(self.path + '/aclocal.d') == False:   
980                #    os.mkdir(self.path + '/aclocal.d')
981                #for f in os.listdir('generate/aclocal.d/'):
982                #    if not os.path.isdir(f):
983                #        shutil.copy('generate/aclocal.d/' + f,self.path + '/aclocal.d')
984                if self.template != "py_comp":
985                    shutil.copy('generate/reconf',self.path)
986                shutil.copy('generate/LICENSE',self.path)
987       
988        if self.active_comp.timing:
989                found_timing = False
990                for p in self.active_comp.ports:
991                        if p.interface.name == 'timingStatus':
992                                found_timing = True
993                if not found_timing:
994                        self.active_comp.ports.append(self.timing_port)
995       
996        gen = genStruct.genAll(savepath,None)
997        gen.writeCompMakefile(self.active_comp,self.path)
998        gen.writeConfAC(self.path, self.active_comp.name, self.active_comp.ace, False, self.installPath)
999        gen.genCompFiles(self.active_comp)
1000       
1001        component_gen.gen_scd(self.active_comp, savepath)
1002        component_gen.gen_spd(self.active_comp, savepath)
1003        component_gen.gen_prf(self.active_comp, savepath)
1004
1005class App(wx.App):
1006    def OnInit(self):
1007        self.main = create(None)
1008        self.main.Show()
1009
1010        #self.SetTopWindow(self.frame)
1011        return True
1012
1013    def OnExit(self):
1014        self.ExitMainLoop()    # inherited from wx.App
1015
1016def newComponentFrame():
1017    wx.InitAllImageHandlers()
1018    application = App()
1019   
1020    application.main.active_comp = CC.Component("component1")
1021    application.main.calledByParent = False
1022    application.main.displayPorts()
1023    application.main.compNameBox.WriteText("component1")
1024    application.main.compDescrBox.WriteText("Enter component description here")
1025    if application.main.active_comp.ace == True:
1026        application.main.ACEcheckBox.SetValue(True)
1027    else:
1028        application.main.ACEcheckBox.SetValue(False)
1029       
1030    if application.main.active_comp.timing == True:
1031        application.main.TimingcheckBox.SetValue(True)
1032    else:
1033        application.main.TimingcheckBox.SetValue(False)
1034     
1035    application.main.deviceChoice.Enable(False)
1036    application.main.nodeChoice.Enable(False)
1037    application.MainLoop()
1038 
1039
1040       
1041################################################################################
1042## If Component Developer is run as a seperate application
1043################################################################################
1044
1045if __name__ == "__main__":
1046    newComponentFrame()
Note: See TracBrowser for help on using the browser.