/[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 2004 - (show annotations) (download) (as text)
Wed Apr 15 08:59:46 2009 UTC (10 years, 2 months ago) by jpye
Original Path: trunk/pygtk/canvas/contextmenutool.py
File MIME type: text/x-python
File size: 1946 byte(s)
Add steps to converge rankine_regen (still problematic). 
Fixed 'rename' tool in canvas model so that Enter key works. 
Added Export as SVG support in blocklist.py.
In PyGTK GUI, "Fixed variables" dialog now includes the values (no units yet).
Graphviz view of system now attempts to show unconverged relations (ongoing).
1 from gaphas.tool import Tool
2 import pygtk
3 pygtk.require('2.0')
4 import gtk
5
6 class ContextMenuTool(Tool):
7 """
8 Context menu for blocks and connectors on the canvas, intended to be
9 the main mouse-based way by which interaction with blocks occurs (blocks
10 renamed, parameters specified, values examined, etc).
11 Code for performing these tasks should not be here; this should just
12 hook into the appropriate code in the Application layer.
13 """
14 def __init__(self):
15 pass
16
17 def on_button_press(self, context, event):
18 if event.button != 3:
19 return False
20 if context.view.hovered_item:
21 menu = gtk.Menu()
22 menurename = gtk.MenuItem("Re_name",True);
23 window = context.view.parent.parent.parent.parent
24 print window.__class__
25 menurename.connect("activate",self.rename,context.view.hovered_item,window)
26 menu.add(menurename)
27 menudelete = gtk.MenuItem("_Delete",True);
28 menudelete.connect("activate",self.delete,context.view.hovered_item,context.view)
29 menu.add(menudelete)
30 menu.show_all()
31 menu.popup( None, None, None, event.button, event.time)
32
33 def rename(self,widget,item,window):
34 if hasattr(item,'blockinstance'):
35 bi = item.blockinstance
36 dia = gtk.Dialog("Rename %s '%s'"
37 % (
38 bi.blocktype.type.getName()
39 ,bi.name
40 ), window,gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT
41 ,(gtk.STOCK_CANCEL, 0, gtk.STOCK_OK, gtk.RESPONSE_OK)
42 )
43 dia.set_default_response(gtk.RESPONSE_OK)
44 ent = gtk.Entry()
45 ent.set_text(bi.name)
46 def key_press(ent,event):
47 key = gtk.gdk.keyval_name(event.keyval)
48 if key == 'Return':
49 dia.response(gtk.RESPONSE_OK)
50 return True
51 return False
52 ent.connect("key-press-event",key_press)
53 dia.vbox.add(ent)
54 dia.show_all()
55 res = dia.run()
56 if res == gtk.RESPONSE_OK:
57 bi.name = ent.get_text()
58 dia.destroy()
59
60 def delete(self,widget,item,view):
61 print "DELETING OBJECT"
62 # TODO: add undo handler
63 view.canvas.remove(item)
64

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