/[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 1944 by jpye, Tue Nov 4 09:16:21 2008 UTC revision 1945 by jpye, Thu Nov 6 08:54:02 2008 UTC
# Line 1  Line 1 
1    #!/usr/bin/env python
2  from __future__ import with_statement  from __future__ import with_statement
3  import os, sys  import os, sys
4    
# Line 6  os.environ['ASCENDLIBRARY'] = "../../mod Line 7  os.environ['ASCENDLIBRARY'] = "../../mod
7  os.environ['LD_LIBRARY_PATH'] = "../.."  os.environ['LD_LIBRARY_PATH'] = "../.."
8  sys.path.append("..")  sys.path.append("..")
9    
   
10  if sys.platform.startswith("win"):  if sys.platform.startswith("win"):
11      # Fetchs gtk2 path from registry      # Fetchs gtk2 path from registry
12      import _winreg      import _winreg
# Line 42  M = L.getModules() Line 42  M = L.getModules()
42    
43  blocktypes = set()  blocktypes = set()
44    
 class Block:  
     def __init__(self, typedesc, notesdb):  
         self.type = typedesc  
         self.notesdb = notesdb  
   
         nn = notesdb.getTypeRefinedNotesLang(self.type,ascpy.SymChar("inline"))  
   
         self.inputs = []  
         self.outputs = []  
         for n in nn:  
             t = n.getText()  
             if t[0:min(len(t),3)]=="in:":  
                 self.inputs += [n]  
             elif t[0:min(len(t),4)]=="out:":  
                 self.outputs += [n]  
   
     def get_icon(self, width, height):  
         return gtk.gdk.pixbuf_new_from_file_at_size("defaultblock.svg",width,height)  
   
   
45  for m in M:  for m in M:
46      T = L.getModuleTypes(m)      T = L.getModuleTypes(m)
47      for t in T:      for t in T:
# Line 76  for m in M: Line 56  for m in M:
56    
57  blocks = []  blocks = []
58    
59    from blocktype import *
60    
61  print "block types:"  print "block types:"
62  if not blocktypes:  if not blocktypes:
63      print "NONE FOUND"      print "NONE FOUND"
64  for t in blocktypes:  for t in blocktypes:
65    
66      b = Block(t,D)      b = BlockType(t,D)
67    
68      blocks += [b]      blocks += [b]
69    
# Line 91  import gtk Line 73  import gtk
73  import os, os.path, re  import os, os.path, re
74    
75  import cairo  import cairo
 from gaphas import GtkView, View  
 from gaphas.tool import HoverTool, PlacementTool, HandleTool, ToolChain  
 from gaphas.tool import Tool, ItemTool, RubberbandTool  
 from gaphas.item import Line  
 from port import *  
76    
77  gtk.gdk.threads_init()  gtk.gdk.threads_init()
78    
79  class BlockIconView(gtk.IconView):  class BlockIconView(gtk.IconView):
80      """      """
81      IconView containing the palette of Block available for use in the      IconView containing the palette of BlockTypes available for use in the
82      canvas. The list of blocks is supplied currently as an initialisation      canvas. The list of blocks is supplied currently as an initialisation
83      parameter, but it is intended that this would be dynamic in a final system.      parameter, but it is intended that this would be dynamic in a final system.
84    
# Line 141  class BlockIconView(gtk.IconView): Line 118  class BlockIconView(gtk.IconView):
118      def item_activated(self,iconview, path):      def item_activated(self,iconview, path):
119          self.app.set_placement_tool(self.otank[path])          self.app.set_placement_tool(self.otank[path])
120    
121  class ContextMenuTool(Tool):  from gaphas import GtkView, View
122      """  from gaphas.tool import HoverTool, PlacementTool, HandleTool, ToolChain
123      Context menu for blocks and connectors on the canvas, intended to be  from gaphas.tool import Tool, ItemTool, RubberbandTool
124      the main mouse-based way by which interaction with blocks occurs (blocks  from gaphas.item import Line
125      renamed, parameters specified, values examined, etc).  from blockitem import *
126      Code for performing these tasks should not be here; this should just  from contextmenutool import *
     hook into the appropriate code in the Application layer.  
     """  
     def __init__(self):  
         pass  
   
     def on_button_press(self, context, event):  
         if event.button != 3:  
             return False  
         if context.view.hovered_item:  
             menu = gtk.Menu()  
             menurename = gtk.MenuItem("Re_name",True);  
             menurename.connect("activate",self.rename,context.view.hovered_item)  
             menu.add(menurename)  
             menudelete = gtk.MenuItem("_Delete",True);  
             menudelete.connect("activate",self.delete,context.view)  
             menu.add(menudelete)  
             menu.show_all()      
             menu.popup( None, None, None, event.button, event.time)  
   
     def rename(self,widget):  
         print "RENAMING OBJECT"  
   
     def delete(self,widget,view):  
         print "DELETING OBJECT"  
         # TODO: add undo handler  
         view.canvas.remove(view.hovered_item)  
   
127  from connectortool import *  from connectortool import *
128    from portconnectinghandletool import *
129    from blockcanvas import *
130    from panzoom import *
131    from blockinstance import *
132    
133  def BlockToolChain():  def BlockToolChain():
134      """      """
# Line 250  class app(gtk.Window): Line 204  class app(gtk.Window):
204          # a message about the found blocks          # a message about the found blocks
205          self.status.push(0, "Found %d block types." % (len(blocks)))          self.status.push(0, "Found %d block types." % (len(blocks)))
206                                    
207      def set_placement_tool(self,block):      def set_placement_tool(self,blocktype):
208          # TODO: add undo handler          # TODO: add undo handler
209          label = block.type.getName()          label = blocktype.type.getName()
210          def my_block_factory():          def my_block_factory():
211              def wrapper():              def wrapper():
212                  b = DefaultBlock(label,inputs=len(block.inputs),outputs=len(block.outputs))                  b = BlockInstance(blocktype)
213                  self.view.canvas.add(b)                  bi = DefaultBlockItem(b)
214                  return b                  self.view.canvas.add(bi)
215                    return bi
216              return wrapper              return wrapper
217          self.view.tool.grab(PlacementTool(my_block_factory(), HandleTool(), 2))          self.view.tool.grab(PlacementTool(my_block_factory(), HandleTool(), 2))
218          self.status.push(0,"Selected '%s'..." % block.type.getName())          self.status.push(0,"Selected '%s'..." % blocktype.type.getName())
219    
220      def set_connector_tool(self):      def set_connector_tool(self):
221          def my_line_factory():          def my_line_factory():

Legend:
Removed from v.1944  
changed lines
  Added in v.1945

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