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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2007 - (hide annotations) (download) (as text)
Mon Apr 27 06:09:29 2009 UTC (9 years, 11 months ago) by jpye
Original Path: trunk/pygtk/canvas/contextmenutool.py
File MIME type: text/x-python
File size: 3347 byte(s)
Break ASCEND into dev package and main package.
Fix up gtksourceview syntax rules, add more keywords, remove C cruft.
Add tools/scons/ascend.py tool for detecting ASCEND when building software using SCons.
DTAR now fails if dpkg-buildpackage fails, keeps temp files hanging around for inspection.
Plots generated by 'plot.a4l' no longer add legend if no labels specified.
Committing python bindings for FPROPS. Much testing remains to be done there.

1 jpye 1945 from gaphas.tool import Tool
2     import pygtk
3     pygtk.require('2.0')
4     import gtk
5 jpye 2005 import info
6     import blockinstance
7 jpye 1945
8     class ContextMenuTool(Tool):
9     """
10     Context menu for blocks and connectors on the canvas, intended to be
11     the main mouse-based way by which interaction with blocks occurs (blocks
12     renamed, parameters specified, values examined, etc).
13     Code for performing these tasks should not be here; this should just
14     hook into the appropriate code in the Application layer.
15     """
16     def __init__(self):
17     pass
18    
19     def on_button_press(self, context, event):
20     if event.button != 3:
21 jpye 2005 context.ungrab()
22 jpye 1945 return False
23     if context.view.hovered_item:
24     menu = gtk.Menu()
25 jpye 2005 menu.connect("deactivate",self.deactivate,context)
26     menurename = gtk.MenuItem("Re_name",True)
27 jpye 2007 window = context.view.parent.parent.parent.parent
28 jpye 1945 menurename.connect("activate",self.rename,context.view.hovered_item,window)
29     menu.add(menurename)
30 jpye 2005 menudelete = gtk.MenuItem("_Delete",True)
31 jpye 1969 menudelete.connect("activate",self.delete,context.view.hovered_item,context.view)
32 jpye 1945 menu.add(menudelete)
33 jpye 2005 menu.add(gtk.SeparatorMenuItem())
34     menuinfo = gtk.MenuItem("_Info",True)
35     menuinfo.connect("activate",self.info,window,context,context.view.hovered_item)
36     menu.add(menuinfo)
37     if not hasattr(context.view.hovered_item,'blockinstance'):
38     menurename.set_sensitive(False)
39     menuinfo.set_sensitive(False)
40     menu.show_all()
41 jpye 1945 menu.popup( None, None, None, event.button, event.time)
42 jpye 2005 context.ungrab()
43     return True
44 jpye 1945
45 jpye 2005 def info(self,widget,window,context,item):
46     print window.__class__
47     bi = item.blockinstance
48     title = "Info for block '%s'" % bi.name
49     text = "Block info\n\n"
50     text += "Name:\t%s\n" % bi.name
51     text += "Type:\t%s\n" % bi.blocktype.type.getName()
52    
53     text += "\nPorts:\n"
54     for k,v in bi.ports.iteritems():
55     text += "\t%s" % v.name
56     if v.type == blockinstance.PORT_IN:
57     text += " (IN)\n"
58     elif v.type == blockinstance.PORT_OUT:
59     text += " (OUT)\n"
60    
61     if hasattr(bi,"params"):
62     text += "\nParameters:\n"
63     for k,v in bi.params.iteritems():
64     text += "\t%s = %f\n" % (v.name, v.value)
65    
66     if bi.instance:
67     text += "\nInstance exists\n"
68     else:
69     text += "\nNo instance exists\n"
70    
71     info.Info(window,text,title).run()
72    
73    
74     def deactivate(self,widget,context):
75     #print "DEACTIVATING MENU"
76     # TODO pass a signal to the HoverTool to update the hovered item
77     # according to where the mouse is currently located.
78     context.view.hovered_item = None
79    
80 jpye 1945 def rename(self,widget,item,window):
81     if hasattr(item,'blockinstance'):
82     bi = item.blockinstance
83     dia = gtk.Dialog("Rename %s '%s'"
84     % (
85     bi.blocktype.type.getName()
86     ,bi.name
87     ), window,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
88     ,(gtk.STOCK_CANCEL, 0, gtk.STOCK_OK, gtk.RESPONSE_OK)
89     )
90     dia.set_default_response(gtk.RESPONSE_OK)
91     ent = gtk.Entry()
92     ent.set_text(bi.name)
93 jpye 2004 def key_press(ent,event):
94     key = gtk.gdk.keyval_name(event.keyval)
95     if key == 'Return':
96     dia.response(gtk.RESPONSE_OK)
97     return True
98     return False
99     ent.connect("key-press-event",key_press)
100 jpye 1945 dia.vbox.add(ent)
101     dia.show_all()
102     res = dia.run()
103     if res == gtk.RESPONSE_OK:
104     bi.name = ent.get_text()
105     dia.destroy()
106    
107 jpye 1969 def delete(self,widget,item,view):
108 jpye 1945 print "DELETING OBJECT"
109     # TODO: add undo handler
110 jpye 1969 view.canvas.remove(item)
111 jpye 1945

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