/[ascend]/branches/adrian/pygtk/canvas/contextmenutool.py
ViewVC logotype

Diff of /branches/adrian/pygtk/canvas/contextmenutool.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2627 by jpye, Thu Feb 24 01:43:46 2011 UTC revision 2628 by grivan, Wed May 16 20:40:56 2012 UTC
# Line 8  import blockproperties Line 8  import blockproperties
8  import canvasproperties  import canvasproperties
9  import undo  import undo
10    
11    import ascpy
12    
13  class ContextMenuTool(Tool):  class ContextMenuTool(Tool):
14      """      """
15      Context menu for blocks and connectors on the canvas, intended to be      Context menu for blocks and connectors on the canvas, intended to be
# Line 47  class ContextMenuTool(Tool): Line 49  class ContextMenuTool(Tool):
49          menublockparams.connect("activate",self.blockproperties, window, context, context.view.hovered_item, 1)          menublockparams.connect("activate",self.blockproperties, window, context, context.view.hovered_item, 1)
50          menu.add(menublockparams)          menu.add(menublockparams)
51                    
52            menudefault = gtk.MenuItem("_Set Default Values")
53            menudefault.connect("activate",self.defaultvalues,window ,context,context.view.hovered_item)
54            menu.add(menudefault)
55            
56          #menublockmethod = gtk.MenuItem("_Custom Method(s)")          #menublockmethod = gtk.MenuItem("_Custom Method(s)")
57          #menublockmethod.connect("activate",self.blockproperties, window, context, context.view.hovered_item, 2)          #menublockmethod.connect("activate",self.blockproperties, window, context, context.view.hovered_item, 2)
58          #menu.add(menublockmethod)          #menu.add(menublockmethod)
# Line 54  class ContextMenuTool(Tool): Line 60  class ContextMenuTool(Tool):
60          menublockinstance = gtk.MenuItem("_Instance")          menublockinstance = gtk.MenuItem("_Instance")
61          menublockinstance.connect("activate",self.blockproperties, window, context, context.view.hovered_item, 3)          menublockinstance.connect("activate",self.blockproperties, window, context, context.view.hovered_item, 3)
62          menu.add(menublockinstance)          menu.add(menublockinstance)
63            '''
64            menublockstreams = gtk.MenuItem("_Streams")
65            menublockstreams.connect("activate",self.setstream, window, context, context.view.hovered_item)
66            menu.add(menublockstreams)
67                '''
68          #menuinfo = gtk.MenuItem("_Info",True)          #menuinfo = gtk.MenuItem("_Info",True)
69          #menuinfo.connect("activate",self.info,window,context,context.view.hovered_item)              #menuinfo.connect("activate",self.info,window,context,context.view.hovered_item)    
70          #menu.add(menuinfo)          #menu.add(menuinfo)
# Line 73  class ContextMenuTool(Tool): Line 83  class ContextMenuTool(Tool):
83              menublockinstance.set_sensitive(False)              menublockinstance.set_sensitive(False)
84              #menublockmethod.set_sensitive(False)              #menublockmethod.set_sensitive(False)
85              menublockparams.set_sensitive(False)              menublockparams.set_sensitive(False)
86                menudefault.set_sensitive(False)
87                '''menublockstreams.set_sensitive(False)'''
88    
89                            
90          if not hasattr(context.view.hovered_item,'blockinstance'):          if not hasattr(context.view.hovered_item,'blockinstance'):
# Line 136  class ContextMenuTool(Tool): Line 148  class ContextMenuTool(Tool):
148                    
149      def canvasproperties(self, widget, window, context):      def canvasproperties(self, widget, window, context):
150          canvasproperties.CanvasProperties(window).run()          canvasproperties.CanvasProperties(window).run()
151        '''
152        def setstream(self, widget, window, context, item):
153            print window.ascwrap.streams
154        '''
155        def defaultvalues(self,widget,window,context,item):
156            print widget,window,context,item.blockinstance
157            
158            model = str(self.view.canvas)
159            #print model
160            self.view.canvas.saved_model = model
161            self.view.canvas.saved_data = {}
162        
163            window.ascwrap.library.loadString(model,"canvasmodel")
164            t = window.ascwrap.library.findType(str(item.blockinstance.blocktype.type.getName()));
165            try:
166                m =t.getMethod('default_self');
167            except:
168                return
169            i = t.getSimulation('sim',False);
170            i.build()
171            i.run(m);
172            fv = i.getFixedVariables();
173            for i in fv:
174                for param in item.blockinstance.params:
175                    if param == i.getName():
176                        item.blockinstance.params[param].value = i.getValue();
177                        item.blockinstance.params[param].fix = True

Legend:
Removed from v.2627  
changed lines
  Added in v.2628

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22