root/WaveDev/branches/osx/WaveDev/wavedev/ComponentFrame.py @ 5086

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

adding a generate button since osx will not display the menu

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