root/experimental/ALF/trunk/alf/ALF.py @ 4464

Revision 4464, 27.4 KB (checked in by DrewCormier, 6 years ago)

changing around the way the das file name is created. strip method may not be robust enough

Line 
1#! /bin/env python
2import wx
3from wx.lib import ogl
4from wavedev import ComponentClass as CC
5from wavedev import WaveformClass
6from omniORB import CORBA, PortableServer
7import CosNaming
8import CF, CF__POA
9import customInterfaces
10import standardInterfaces
11import sys
12import importWaveform
13import importResource
14import ALFshapes, ALFtiming
15
16import os
17import importIDL
18import amara
19import ALFutils
20
21import wx.lib.foldpanelbar as fpb
22
23#----------------------------------------------------------------------
24# Create unique IDs for menu items and toolbar items for associating
25# events with a particular action
26[wxID_TOOLBAR_TIMING_TOOL, wxID_TOOLBAR_REFRESH_TOOL,
27wxID_TOOLBAR_TIMING_DISPLAY_TOOL] = [wx.NewId() for x in range(3)]
28
29[wxID_NSBOX_POPUP_DISPLAY, wxID_NSBOX_POPUP_UNINSTALL] = [wx.NewId() for x in range(2)]
30
31[wxID_INSTALLBOX_POPUP_INSTALL] = [wx.NewId() for x in range(1)]
32
33#----------------------------------------------------------------------
34class alfApp(wx.App):
35    def OnInit(self):
36        self.main = alfFrame(None)
37        self.main.Show()
38        self.SetTopWindow(self.main)
39        return True
40
41#----------------------------------------------------------------------
42class alfFrame(wx.Frame):
43    def _init_ctrls(self, parent):
44        wx.Frame.__init__(self, id=-1, name='CompFrame',
45            parent=parent, pos=wx.DefaultPosition, size=wx.Size(1100, 544),
46            style=wx.DEFAULT_FRAME_STYLE, title=u'ALF - Waveform Debugger')
47       
48        # Initialize graphics
49        ogl.OGLInitialize()
50        ALFshapes.initializeColours()
51
52        # Create the sash window and layout
53        self._leftWindow = wx.SashLayoutWindow(self, 101, wx.DefaultPosition,
54            wx.Size(240, 400), wx.NO_BORDER | wx.SW_3D | wx.CLIP_CHILDREN)
55           
56        self._leftWindow.SetDefaultSize(wx.Size(240, 400))
57        self._leftWindow.SetOrientation(wx.LAYOUT_VERTICAL)
58        self._leftWindow.SetAlignment(wx.LAYOUT_LEFT)
59        self._leftWindow.SetSashVisible(wx.SASH_RIGHT, True)
60        self._leftWindow.SetExtraBorderSize(10)
61
62        self.ID_WINDOW_TOP = 100
63        self.ID_WINDOW_LEFT = 101
64        self.ID_WINDOW_RIGHT = 102
65        self.ID_WINDOW_BOTTOM = 103
66
67        self._leftWindow.Bind(wx.EVT_SASH_DRAGGED_RANGE, self.OnFoldPanelBarDrag,
68            id=100, id2=103)
69        self.Bind(wx.EVT_SIZE, self.OnFoldPanelSize)
70       
71        # Instantiate the main canvas
72        self.canvas = MainWindow(self, self)
73
74        # Create the fold panel and add its windows
75        self._fpb_pnl = None
76        self.CreateFoldPanel()
77       
78        # Create the status and toolbars
79        self.CreateStatusBar(1, wx.ST_SIZEGRIP)
80        self.CreateToolBar()
81
82        # Make a popup box for the Naming Service / Manage Waveforms functionality
83        self.nsBoxPopup = wx.Menu(title=u'')
84        self.init_nsBoxPopup_Items(self.nsBoxPopup)
85       
86        # Make a popup box for the Launch Waveforms functionality
87        self.installBoxPopup = wx.Menu(title=u'')
88        self.init_installBoxPopup_Items(self.installBoxPopup)
89
90        self.setupToolbar()
91
92    def __init__(self,parent):
93        self.active_wave = None
94        self.timing_display = None
95        self.tools = None
96        self.waveform_displays = {}
97
98        self._init_ctrls(parent)
99        self.Available_Ints = ALFutils.importStandardIdl(self)
100        self.rootContext = None
101        self.domMgr = None
102        self.init_CORBA()
103       
104        ALFutils.LoadConfiguration(self)
105
106        self.waveformData = {}
107        self.tool_frames = []
108        self.last_waveform_data_update = None
109        self.dasXML_list = []
110        self.availableWaveforms = {}
111       
112        if self.rootContext != None:
113            self.DisplayInstalledWaveforms()
114            self.DisplayAvailableWaveforms()
115       
116 
117    def init_CORBA(self):
118        """Initialize an orb and try to connect to the DomainManager"""
119
120        orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
121        obj = orb.resolve_initial_references("NameService")
122        try:
123            self.rootContext = obj._narrow(CosNaming.NamingContext)
124        except:
125            ts = "Failed to narrow the root naming context.\n"
126            ts += "Are the Naming Service and nodeBooter running?"
127            errorMsg(self, ts)
128            self.rootContext = None
129            self.domMgr = None
130            return
131       
132        if self.rootContext is None:
133            errorMsg(self,"Failed to narrow the root naming context")
134            self.domMgr = None
135            return
136
137        name = [CosNaming.NameComponent("DomainName1",""),
138            CosNaming.NameComponent("DomainManager","")]
139           
140        try:
141            obj = self.rootContext.resolve(name)
142        except:
143            errorMsg(self,"DomainManger name not found")
144            self.domMgr = None
145            return
146
147        self.domMgr = obj._narrow(CF.DomainManager)
148 
149    #---------------------------------------------------------------
150    # Setup the display
151    #---------------------------------------------------------------
152    def init_nsBoxPopup_Items(self, parent):
153        """Setup the popup menu for the Naming Service / Manage Waveforms box"""
154
155        parent.Append(help='', id=wxID_NSBOX_POPUP_DISPLAY, kind=wx.ITEM_NORMAL, text=u'Display')
156        parent.Append(help='', id=wxID_NSBOX_POPUP_UNINSTALL, kind=wx.ITEM_NORMAL, text=u'Uninstall')
157        self.nsBox.Bind(wx.EVT_MENU, self.OnNsBoxPopupDisplayMenu, id=wxID_NSBOX_POPUP_DISPLAY)
158        self.nsBox.Bind(wx.EVT_MENU, self.OnNsBoxPopupUninstallMenu, id=wxID_NSBOX_POPUP_UNINSTALL)
159   
160    def init_installBoxPopup_Items(self, parent):
161        """Setup the popup menu for the Launch Waveforms box"""
162
163        parent.Append(help='', id=wxID_INSTALLBOX_POPUP_INSTALL, kind=wx.ITEM_NORMAL, text=u'Install')
164        self.installBox.Bind(wx.EVT_MENU, self.OnInstallBoxPopupInstallMenu, id=wxID_INSTALLBOX_POPUP_INSTALL)
165       
166    def CreateFoldPanel(self):
167        self._fpb_pnl = fpb.FoldPanelBar(self._leftWindow, -1, wx.DefaultPosition,
168            wx.Size(-1,-1), fpb.FPB_DEFAULT_STYLE, 0)
169       
170        # Create the image list for the fold button icons
171        Images = wx.ImageList(16,16)
172        Images.Add(ALFutils.GetExpandedIconBitmap())
173        Images.Add(ALFutils.GetCollapsedIconBitmap())
174           
175        # Add the Launch Waveforms box
176        item = self._fpb_pnl.AddFoldPanel("Launch Waveforms", collapsed=False,foldIcons=Images)
177        self.installBox = wx.TreeCtrl(name=u'installBox', parent=item,
178            size = wx.Size(-1,300), style = wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS | wx.SIMPLE_BORDER)
179        self._fpb_pnl.AddFoldPanelWindow(item, self.installBox, fpb.FPB_ALIGN_WIDTH, 4)
180        self.installBox.Bind(wx.EVT_RIGHT_UP, self.OnInstallBoxRightUp)
181        self.installBox.Bind(wx.EVT_LEFT_DCLICK, self.OnInstallBoxLeftDclick)
182
183        # Add the Manage Waveforms box
184        item = self._fpb_pnl.AddFoldPanel("Manage Waveforms", collapsed=False,foldIcons=Images)
185        self.nsBox = wx.TreeCtrl(name=u'nsBox', parent=item,
186            size = wx.Size(-1,370), style = wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS | wx.SIMPLE_BORDER)
187        self.nsBox.Bind(wx.EVT_RIGHT_UP, self.OnNsBoxRightUp)
188        self.nsBox.Bind(wx.EVT_LEFT_DCLICK, self.OnNsBoxLeftDclick)
189        self._fpb_pnl.AddFoldPanelWindow(item, self.nsBox, fpb.FPB_ALIGN_WIDTH, 4)
190
191        self._leftWindow.SizeWindows()
192       
193       
194    def setupToolbar(self):
195        toolbar = self.GetToolBar()
196        tsize = (20,20)
197        test_bmp = wx.ArtProvider.GetBitmap(wx.ART_REDO, wx.ART_TOOLBAR, tsize)
198        toolbar.AddSimpleTool(wxID_TOOLBAR_REFRESH_TOOL,test_bmp,shortHelpString="Refresh")
199        toolbar.AddSeparator()
200       
201        time_img = wx.Image('timing.png',type=wx.BITMAP_TYPE_PNG)
202        time_img.Rescale(24,24)
203        time_bmp = wx.BitmapFromImage(time_img)
204        toolbar.AddCheckTool(wxID_TOOLBAR_TIMING_TOOL,time_bmp,shortHelp="Enable Timing")
205        self.timing_view_state = False
206
207       
208        time_img = wx.Image('timing_display.png',type=wx.BITMAP_TYPE_PNG)
209        time_img.Rescale(24,24)
210        time_bmp = wx.BitmapFromImage(time_img)
211        toolbar.AddCheckTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL,time_bmp,shortHelp="Toggle Timing Display")
212       
213        toolbar.AddSeparator()
214       
215        toolbar.Bind(wx.EVT_TOOL, self.OnToolBarClick)
216       
217        toolbar.Realize()
218
219    # ---------------------------------------------------
220    # Event handling for toolbar
221    # ---------------------------------------------------
222    def OnToolBarClick(self,event):
223        tb = self.GetToolBar()
224        if event.GetId() == wxID_TOOLBAR_TIMING_TOOL:
225            if tb.GetToolState(wxID_TOOLBAR_TIMING_TOOL):
226                if self.active_wave == None:
227                    errorMsg(self,"Please select and display a waveform first!")       
228                    tb.ToggleTool(wxID_TOOLBAR_TIMING_TOOL, False)
229                    return
230                tb.EnableTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, True)
231                tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_TOOL, "Disable Timing")
232                self.timing_display = ALFtiming.TimingDisplay(self.active_wave.naming_context, self)
233            else:
234                self.timing_display = None
235                tb.EnableTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, False)
236                tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_TOOL, "Enable Timing")
237                self.refreshDisplay()
238
239        if event.GetId() == wxID_TOOLBAR_TIMING_DISPLAY_TOOL:
240            if tb.GetToolState(wxID_TOOLBAR_TIMING_DISPLAY_TOOL):
241                tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, "Disable Timing Graphics")
242                self.timing_view_state = True
243            else:
244                tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, "Enable Timing Graphics")
245                self.timing_view_state = False
246       
247        # Refresh the display: Naming Service, Waveform List, and Canvas
248        elif event.GetId() == wxID_TOOLBAR_REFRESH_TOOL:
249            self.refreshDisplay(True)
250            self.DisplayInstalledWaveforms()
251            self.DisplayAvailableWaveforms()
252            tb.ToggleTool(wxID_TOOLBAR_REFRESH_TOOL, False)
253           
254    def processTimingEvent(self, component_name, port_name, function_name, description, time_s, time_us, number_samples):
255        if self.active_wave == None or (self.active_wave.naming_context not in component_name):
256            errorMsg(self,"Cannot find waveform containing: " + component_name)
257
258        cname = component_name[component_name.rfind('/')+1:]
259        if self.active_wave != None:
260            for comp in self.active_wave.components:
261                if comp.name == cname:
262                    comp.shape.processTimingEvent(port_name, function_name, description, time_s, time_us, number_samples)
263
264
265       
266    # ---------------------------------------------------------
267    # Event handling for the FoldPanel
268    # --------------------------------------------------------
269    def OnFoldPanelSize(self, event):
270        wx.LayoutAlgorithm().LayoutWindow(self, self.canvas)
271        event.Skip()
272   
273    def OnFoldPanelBarDrag(self, event):
274        if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
275            return
276               
277        if event.GetId() == self.ID_WINDOW_LEFT:
278            self._leftWindow.SetDefaultSize(wx.Size(event.GetDragRect().width, 400))
279               
280        # Leaves bits of itself behind sometimes
281        wx.LayoutAlgorithm().LayoutWindow(self, self.canvas)
282        self.canvas.Refresh()
283           
284        event.Skip()
285
286    # ---------------------------------------------------------
287    # Event handling for Naming Service / Manage Waveforms box
288    # --------------------------------------------------------
289    def OnNsBoxRightUp(self, event):
290        self.nsBox.PopupMenu(self.nsBoxPopup)
291        event.Skip()
292
293    def OnNsBoxLeftDclick(self, event):
294        self.DisplayWaveform()
295   
296    def OnNsBoxPopupDisplayMenu(self, event):
297        self.DisplayWaveform()
298
299    def OnNsBoxPopupUninstallMenu(self, event):
300        self.UninstallWaveform()
301
302    def DisplayWaveform(self):
303        sn = self.nsBox.GetSelection()
304        if sn == self.nsBox.GetRootItem():
305            errorMsg(self,'Please select a waveform!')
306            return
307        snPrnt = self.nsBox.GetItemParent(sn)
308        if snPrnt != self.nsBox.GetRootItem():
309            errorMsg(self,'Please select a waveform!')
310            return
311
312        wave_name = self.nsBox.GetItemText(sn)
313        app = self.nsBox.GetPyData(sn)
314        if app is None:
315            errorMsg(self,'No application associated with this entry!')
316            return
317           
318        # Check to see if a waveform is already active
319        if self.active_wave != None:
320            self.refreshDisplay(True)
321
322        # Set item bold and all others set to plain text
323        troot = self.nsBox.GetRootItem()
324        if self.nsBox.GetChildrenCount(troot) <= 0:
325            return
326        cid1,cookie1 = self.nsBox.GetFirstChild(troot)
327        self.nsBox.SetItemBold(cid1, False)
328        for x in range(self.nsBox.GetChildrenCount(troot,recursively=False)-1):
329            cid2,cookie2 = self.nsBox.GetNextChild(troot,cookie1)
330            self.nsBox.SetItemBold(cid2, False)
331            cid1 = cid2
332            cookie1 = cookie2
333
334        self.nsBox.SetItemBold(sn, True)
335        self.nsBox.SelectItem(sn, False)
336
337        # Check to see if this waveform has previously been displayed
338        # If so, then update the display and return
339        if self.waveform_displays.has_key(wave_name):
340            # Clear the canvas and get ready to display the waveform
341            #print "already imported this waveform .... displaying..."
342            tmpdisplay = self.waveform_displays[wave_name]
343#            self.refreshDisplay(True)
344            self.active_wave = tmpdisplay.waveform
345            self.canvas.updateDisplay(tmpdisplay)
346            return
347
348        sadfile = app._get_profile()
349
350        sadfile = sadfile.replace('//','')
351        wav_name = sadfile.replace('.sad.xml','')
352
353        # for framework versions <= r2983
354        sadpath = '/sdr' + sadfile
355       
356        # for framework versions > r2983
357        # _get_profile() has returned nothing
358        # assume sad name follows a specific format
359        # and that it is in /sdr/dom/waveforms/
360        wav_name = app._get_name()
361        tmp_name = wav_name.replace('OSSIE::', '')
362        sadpath = '/sdr/dom/waveforms/' + tmp_name + '.sad.xml'
363
364        self.active_wave = importWaveform.getWaveform(sadpath, self, self.Available_Ints)
365        self.active_wave.naming_context = str(wave_name)
366
367        tmpdisplay = self.AddWaveformShape(self.active_wave)
368        self.waveform_displays[wave_name] = tmpdisplay
369
370        self.canvas.updateDisplay(tmpdisplay)
371
372           
373    def DisplayInstalledWaveforms(self):
374        self.nsBox.DeleteAllItems()
375        nsRoot = self.nsBox.AddRoot("ns_root")
376       
377        if self.domMgr == None or self.rootContext == None:
378            return
379
380        dom_obj = self.rootContext.resolve([CosNaming.NameComponent("DomainName1","")])
381        dom_context = dom_obj._narrow(CosNaming.NamingContext)
382        if dom_context is None:
383            return
384
385        appSeq =  self.domMgr._get_applications()
386
387 
388        # for framework <= r2983
389        '''
390        members = dom_context.list(1000)
391        for m in members[0]:
392            wav_name = str(m.binding_name[0].id)
393            wav_obj = dom_context.resolve([CosNaming.NameComponent(wav_name,"")])
394            wav_context = wav_obj._narrow(CosNaming.NamingContext)
395            if wav_context is None:
396                continue
397
398            contextApp = None
399            foundApp = False
400
401            # cycle through all the installed applications
402            for app in appSeq:
403                # get all of the available component instances in the application
404                compNameCon = app._get_componentNamingContexts()
405
406                # attempt to match the installed waveforms to one of the
407                # available waveform names
408                for compElementType in  compNameCon:
409                    if wav_name in compElementType.elementId:
410                        waveformApp = app
411                        foundApp = True
412                        #print compElementType.componentId + " " + compElementType.elementId
413                        break
414
415            if not foundApp:
416               print "Could not find associated application for: " + wav_name
417               continue
418
419            t1 = self.nsBox.AppendItem(nsRoot,wav_name)
420            self.nsBox.SetPyData(t1,waveformApp)
421           
422            # Set item bold if it is the active waveform
423            if self.active_wave is not None:
424                if self.active_wave.naming_context == wav_name:
425                    self.nsBox.SetItemBold(t1, True)
426        ''' 
427
428        # for framework > r2983
429        wave_count = 0
430        for app in appSeq:
431            wav_name = app._get_name()
432            # TODO: set up counter for the waveform name or get the counter
433            # from the framework
434            t1 = self.nsBox.AppendItem(nsRoot,wav_name)
435            self.nsBox.SetPyData(t1,app)
436        # TODO: set one of the applications as bold
437       
438         
439        self.nsBox.SortChildren(nsRoot)
440
441    # ---------------------------------------------------------
442    # Event handling and control for Launch Waveforms box
443    # --------------------------------------------------------
444    def DisplayAvailableWaveforms(self):
445        self.installBox.DeleteAllItems()
446        self.availableWaveforms.clear()
447        installRoot = self.installBox.AddRoot("install_root")
448       
449        for dirpath, dirnames, filenames in os.walk(self.installpath):
450            sad_file = None
451            das_file = None
452            for fname in filenames:
453                if fname.find(".sad.xml") != -1:
454                    # make sure that the '.sad.xml' comes at the end of the file name
455                    if fname[-8:] == ".sad.xml":   
456                        sad_file = fname
457                        full_sad_file = dirpath + "/" + fname
458                        # for framework > r2983, assume DAS file has the same waveform
459                        # name as the sad file, and assume that both files are in the
460                        # same directory.  similar to c_wavLoader.
461                        das_file = fname.replace(".sad.xml", "") + "_DAS.xml"
462                        full_das_file = dirpath + "/" + das_file
463
464                # for framework <= r2983:
465                # if fname.find("_DAS.xml") != -1:
466                #     # make sure that the '_DAS.xml' comes at the end of the file name
467                #     if fname[-8:] == "_DAS.xml":   
468                #         das_file = fname
469                #         full_das_file = dirpath + "/" + fname
470
471
472            if (sad_file == None and das_file != None) or (sad_file != None and das_file == None):
473                #errorMsg(self, "Could not find both a SAD file and a DAS in this directory:\n " + dirpath)
474                continue
475           
476            if sad_file == None or das_file == None:
477                continue
478           
479            wavename = sad_file[:-8]
480            if self.availableWaveforms.has_key(wavename):
481                errorMsg(self, "Conflicting waveform name: " + wavename)
482                continue
483               
484            self.availableWaveforms[wavename] = (sad_file, full_sad_file, das_file, full_das_file)
485
486        # Populate the display at the Domain level
487        for waveform in self.availableWaveforms.keys():
488            t1 = self.installBox.AppendItem(installRoot,waveform)
489            self.installBox.SetPyData(t1,self.availableWaveforms[waveform])
490            self.installBox.SetItemBold(t1,False)
491
492        self.installBox.SortChildren(installRoot)
493
494    def OnInstallBoxRightUp(self, event):
495        self.installBox.PopupMenu(self.installBoxPopup)
496        event.Skip()
497   
498    def OnInstallBoxPopupInstallMenu(self, event):
499        self.InstallWaveform()
500        event.Skip()
501       
502    def OnInstallBoxLeftDclick(self, event):
503        self.InstallWaveform()
504        event.Skip()
505
506    def InstallWaveform(self):
507        selection = self.installBox.GetSelection()
508        name_SAD, absolute_name_SAD, name_DAS, absolute_name_DAS = self.installBox.GetPyData(selection)
509       
510        sadxml = importResource.stripDoctype(absolute_name_SAD)
511        doc_sad = amara.parse(sadxml)
512        app_name = str(doc_sad.softwareassembly.name)
513        _appFacProps = []
514        devMgrSeq = self.domMgr._get_deviceManagers()
515        available_dev_seq = []
516        for devmgr in range(len(devMgrSeq)):
517            devMgr = devMgrSeq[devmgr]
518            curr_devSeq = devMgr._get_registeredDevices()
519            for dev in range(len(curr_devSeq)):
520                curr_dev = curr_devSeq[dev]
521                available_dev_seq.append(curr_dev._get_identifier())
522                #print curr_dev._get_identifier()
523
524        clean_SAD = absolute_name_SAD.split("/sdr/dom")
525        name_SAD = clean_SAD[1]
526        self.domMgr.installApplication(name_SAD)
527       
528        dasxml = importResource.stripDoctype(absolute_name_DAS)
529        doc_das = amara.parse(dasxml)
530
531        for device_assignment in doc_das.deploymentenforcement.deviceassignmentsequence.deviceassignmenttype:
532            if device_assignment.assigndeviceid not in available_dev_seq:
533                ts = "Could not find the required device: " + str(device_assignment.assigndeviceid)
534                ts += "\nAborting install"
535                errorMsg(self, ts)
536                return
537               
538        _devSeq = self.BuildDevSeq(absolute_name_DAS)
539        _applicationFactories = self.domMgr._get_applicationFactories()
540
541        app_factory_num = -1
542        for app_num in range(len(_applicationFactories)):
543            if _applicationFactories[app_num]._get_name()==app_name:
544                app_factory_num = app_num
545                break
546   
547        if app_factory_num == -1:
548            print "Application factory not found"
549            sys.exit(-1)
550
551        try:
552            app = _applicationFactories[app_factory_num].create(_applicationFactories[app_factory_num]._get_name(),_appFacProps,_devSeq)
553        except:
554            print "Unable to create application - make sure that all appropriate nodes are installed"
555            return(None)
556       
557        # start the application
558        app.start()
559       
560        naming_context_list = app._get_componentNamingContexts()
561        naming_context = naming_context_list[0].elementId.split("/")
562        application_name = app._get_name()
563
564        # for framework <= r2983:
565        # waveform_name = naming_context[0]
566       
567        # for framework > r2983
568        # naming_context[0] now returns a component name, not a waveform instance name
569        waveform_name = application_name
570       
571#        self.refreshDisplay()
572        self.DisplayInstalledWaveforms()
573
574    def UninstallWaveform(self):
575        selection = self.nsBox.GetSelection()
576        waveform_name = self.nsBox.GetItemText(selection)
577        if self.active_wave is not None:
578            if self.active_wave.naming_context == waveform_name:
579                self.refreshDisplay(True)
580        if self.waveform_displays.has_key(waveform_name):
581            # close any tool frames associated with waveform display
582            tmp_display = self.waveform_displays[waveform_name]
583            while len(tmp_display.tool_frames) > 0:
584                tf = tmp_display.tool_frames.pop()
585                tf.Close()
586            self.waveform_displays.pop(waveform_name)
587        app_ref = self.nsBox.GetPyData(selection)
588#        self.domMgr.uninstallApplication(app_ref._get_identifier()) # not sure if we need this or not
589        app_ref.releaseObject()
590#        self.refreshDisplay()
591        self.DisplayInstalledWaveforms()
592                                       
593
594    def BuildDevSeq(self, dasXML):
595        das = amara.binderytools.bind_file(dasXML)
596        ds = []
597        for x in das.deploymentenforcement.deviceassignmentsequence.deviceassignmenttype:
598            ds.append(CF.DeviceAssignmentType(str(x.componentid),str(x.assigndeviceid)))
599        return ds
600   
601
602    #----------------------------------------------------------------------------
603    # Waveform level controls and functions
604    #----------------------------------------------------------------------------
605    def refreshDisplay(self, init = False):
606#        self.DisplayInstalledWaveforms()
607       
608        dc = wx.ClientDC(self.canvas)
609        self.canvas.PrepareDC(dc)
610
611        if init:
612            if self.active_wave != None and self.timing_view_state:
613                for comp in self.active_wave.components:
614                    for gauge in comp.shape.gauge_shapes:
615                        gauge.gauge.Show(False)
616                   
617            self.active_wave = None
618            self.timing_display = None
619
620            self.canvas.diagram.RemoveAllShapes()
621            self.canvas.shapes = []
622           
623            tb = self.GetToolBar()
624            tb.ToggleTool(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, False)
625            self.timing_view_state = False
626            tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_DISPLAY_TOOL, "Enable Timing Graphics")
627            tb.ToggleTool(wxID_TOOLBAR_TIMING_TOOL, False)
628            tb.SetToolShortHelp(wxID_TOOLBAR_TIMING_TOOL, "Enable Timing")
629            #self.canvas.diagram = ogl.Diagram()
630            #self.canvas.SetDiagram(self.canvas.diagram)
631            #self.canvas.diagram.SetCanvas(self.canvas)
632       
633        self.canvas.Refresh()
634
635    def AddWaveformShape(self, waveform):
636        tmpdisplay = ALFshapes.WaveformShapes(waveform, self.canvas)
637        for comp in waveform.components:
638            tmpdisplay.AddComponentShape(comp)
639        tmpdisplay.ConnectComponents()
640
641        return tmpdisplay
642
643
644    def updateWaveformData(self, data):
645        for d in data:
646            self.waveformData[d[0]] = d[1]
647
648        self.last_waveform_data_update = self.waveformData.copy()
649
650        for frame in self.tool_frames:
651            if hasattr(frame, 'updateWaveformData'):
652                frame.updateWaveformData(self.waveformData)
653
654    def removeToolFrame(self, frame):
655        if frame not in self.tool_frames:
656            return
657        else:
658            index = self.tool_frames.index(frame)
659            del self.tool_frames[index]
660   
661   
662   
663#----------------------------------------------------------------------
664class MainWindow(ogl.ShapeCanvas):
665    def __init__(self, parent, frame):
666        ogl.ShapeCanvas.__init__(self, parent)
667
668        maxWidth  = 2100
669        maxHeight = 1000
670        self.SetScrollbars(20, 20, maxWidth/20, maxHeight/20)
671
672        self.frame = frame
673        self.SetBackgroundColour("LIGHT BLUE") #wxWHITE)
674        self.diagram = ogl.Diagram()
675        self.SetDiagram(self.diagram)
676        self.diagram.SetCanvas(self)
677        self.shapes = []
678
679        dsBrush = wx.Brush("WHEAT", wx.SOLID)
680       
681    def updateDisplay(self, waveformdisplay):
682        dc = wx.ClientDC(self)
683        self.PrepareDC(dc)
684        for compshape in waveformdisplay.shapes:
685            self.AddShape(compshape)
686            compshape.Show(True)
687       
688        self. diagram.Redraw(dc)
689        self.Refresh()
690                                                                       
691    def OnDestroy(self, evt):
692        # Do some cleanup
693        for shape in self.diagram.GetShapeList():
694            if shape.GetParent() == None:
695                shape.SetCanvas(None)
696                shape.Destroy()
697        self.diagram.Destroy()
698
699
700#----------------------------------------------------------------------
701
702def errorMsg(self,msg):
703    dlg = wx.MessageDialog(self,msg,'Error', wx.OK | wx.ICON_INFORMATION)
704    try:
705        dlg.ShowModal()
706    finally:
707        dlg.Destroy()
708    return
709                               
710
711def main():
712    app = alfApp(0)
713    app.MainLoop()
714
715if __name__ == '__main__':
716    main()
Note: See TracBrowser for help on using the browser.