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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2007 - (show annotations) (download) (as text)
Mon Apr 27 06:09:29 2009 UTC (10 years, 2 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 from gaphas.tool import Tool
2 import pygtk
3 pygtk.require('2.0')
4 import gtk
5 import info
6 import blockinstance
7
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 context.ungrab()
22 return False
23 if context.view.hovered_item:
24 menu = gtk.Menu()
25 menu.connect("deactivate",self.deactivate,context)
26 menurename = gtk.MenuItem("Re_name",True)
27 window = context.view.parent.parent.parent.parent
28 menurename.connect("activate",self.rename,context.view.hovered_item,window)
29 menu.add(menurename)
30 menudelete = gtk.MenuItem("_Delete",True)
31 menudelete.connect("activate",self.delete,context.view.hovered_item,context.view)
32 menu.add(menudelete)
33 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 menu.popup( None, None, None, event.button, event.time)
42 context.ungrab()
43 return True
44
45 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 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 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 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 def delete(self,widget,item,view):
108 print "DELETING OBJECT"
109 # TODO: add undo handler
110 view.canvas.remove(item)
111

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