/[ascend]/trunk/pygtk/canvas/blocklist.py
ViewVC logotype

Diff of /trunk/pygtk/canvas/blocklist.py

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

revision 1938 by jpye, Thu Oct 30 02:12:24 2008 UTC revision 1939 by jpye, Thu Oct 30 02:38:43 2008 UTC
# Line 103  import os, os.path, re Line 103  import os, os.path, re
103  import cairo  import cairo
104  from gaphas import GtkView, View  from gaphas import GtkView, View
105  from gaphas.tool import HoverTool, PlacementTool, HandleTool, ToolChain  from gaphas.tool import HoverTool, PlacementTool, HandleTool, ToolChain
106  from gaphas.tool import ItemTool, RubberbandTool  from gaphas.tool import Tool, ItemTool, RubberbandTool
107  from port import *  from port import *
108    
 def factory(view, cls):  
     """  
     Simple canvas item factory.  
     """  
     def wrapper():  
         item = cls()  
         view.canvas.add(item)  
         return item  
     return wrapper  
   
109  gtk.gdk.threads_init()  gtk.gdk.threads_init()
110    
111  class BlockIconView(gtk.IconView):  class BlockIconView(gtk.IconView):
# Line 155  class BlockIconView(gtk.IconView): Line 145  class BlockIconView(gtk.IconView):
145              self.app.set_placement_tool(b)              self.app.set_placement_tool(b)
146              self.app.status.push(0,"Selected '%s'..." % b.type.getName())              self.app.status.push(0,"Selected '%s'..." % b.type.getName())
147    
148    class ContextMenuTool(Tool):
149        """
150        Context menu for blocks and connectors on the canvas, intended to be
151        the main mouse-based way by which interaction with blocks occurs (blocks
152        renamed, parameters specified, values examined, etc).
153        Code for performing these tasks should not be here; this should just
154        hook into the appropriate code in the Application layer.
155        """
156        def __init__(self):
157            pass
158        def on_button_press(self, context, event):
159            if event.button != 3:
160                return False
161            if context.view.hovered_item:
162                menu = gtk.Menu()
163                menurename = gtk.MenuItem("Re_name",True);
164                menurename.connect("activate",self.rename)
165                menu.add(menurename)
166                menu.show_all()    
167                menu.popup( None, None, None, event.button, event.time)
168    
169        def rename(self,widget):
170            print "RENAMING OBJECT"
171    
172    def BlockToolChain():
173        """
174        The default tool chain build from HoverTool, ItemTool and HandleTool.
175        """
176        chain = ToolChain()
177        chain.append(HoverTool())
178        chain.append(PortConnectingHandleTool())
179        chain.append(ContextMenuTool())
180        chain.append(ItemTool())
181        chain.append(RubberbandTool())
182        return chain
183    
184  class app(gtk.Window):  class app(gtk.Window):
185      def __init__(self):      def __init__(self):
186          self.status = gtk.Statusbar()          self.status = gtk.Statusbar()
# Line 177  class app(gtk.Window): Line 203  class app(gtk.Window):
203    
204          # the 'view' widget implemented by Gaphas          # the 'view' widget implemented by Gaphas
205          self.view = GtkView()          self.view = GtkView()
206          self.view.tool =  DefaultExampleTool()          self.view.tool =  BlockToolChain()
207    
208          # table containing scrollbars and main canvas          # table containing scrollbars and main canvas
209          t = gtk.Table(2,2)          t = gtk.Table(2,2)

Legend:
Removed from v.1938  
changed lines
  Added in v.1939

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