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

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

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

revision 2199 by jpye, Sat Jan 10 00:21:37 2009 UTC revision 2200 by grivan, Thu May 20 05:17:35 2010 UTC
# Line 1  Line 1 
1  from gaphas.tool import HandleTool  
2    from gaphas.tool import HandleTool, PlacementTool
3    from gaphas import geometry
4  from blockconnecttool import BlockConnectTool  from blockconnecttool import BlockConnectTool
5  from blockline import BlockLine  from blockline import BlockLine
6  import cairo  import cairo
# Line 18  class ConnectorTool(BlockConnectTool): Line 20  class ConnectorTool(BlockConnectTool):
20          self._handle_tool = HandleTool()          self._handle_tool = HandleTool()
21          self._handle_index_glued = 0          self._handle_index_glued = 0
22          self._handle_index_dragged = 1          self._handle_index_dragged = 1
23          self._grabbed_handle = None          self.grabbed_handle = None
24          self._grabbed_item = None          self.grabbed_item = None
25          self._new_item = None          self._new_item = None
26            self.motion_handle = None
27    
28      def on_button_press(self,context,event):      def on_button_press(self,event):        
29          if event.button != 1:          if event.button != 1:
30              return False              return False
31    
32          view = context.view          glueitem,glueport,gluepos = self.view.get_port_at_point((event.x,event.y),distance = 10,exclude = [])
33          canvas = view.canvas          
34          glueitem, glueport, gluepos = self.get_item_at_point(view, (event.x, event.y), list())          if glueport:
35          if glueport and hasattr(glueport,"point"):              self.line = self._create_line((event.x, event.y))
36              line = self._create_line(context,event.x, event.y)              self._new_item = self.line
37              canvas.get_matrix_i2c(line, calculate=True)              h_glue = self.line.handles()[self._handle_index_glued]
38              self._new_item = line              self.connect(self.line,h_glue,(event.x,event.y))
39              view.focused_item = line              self.post_connect(self.line,h_glue,None,glueport)
40              del view.selected_items              #print "Conn.Tool L40\n"
41              context.grab()              
42                h_drag = self.line.handles()[self._handle_index_dragged]
43              h_glue = line.handles()[self._handle_index_glued]              self._handle_tool.grab_handle(self.line, h_drag)
44              self.connect(view,line,h_glue, (event.x, event.y))              self.grabbed_handle = h_drag
45                self.grabbed_item = self.line
             h_drag = line.handles()[self._handle_index_dragged]  
             self._handle_tool.grab_handle(line, h_drag)  
             self._grabbed_handle = h_drag  
             self._grabbed_item = line  
46                            
47              print "STARTED NEW CONNECTOR"          return True
             return True  
48    
49      def _create_line(self, context, x, y):      def on_button_release(self,event):
50          view = context.view  
51          canvas = view.canvas          dragitem,dragport,dragpos = self.view.get_port_at_point((event.x,event.y),distance = 10,exclude = [])
52            
53            try:
54                if dragport:
55                    h_drag = self.line.handles()[self._handle_index_dragged]
56                    self.post_connect(self.line,h_drag,None,dragport)
57            finally:
58                return super(ConnectorTool, self).on_button_release(event)
59            
60            
61        def _create_line(self, (x, y)):
62            canvas = self.view.canvas
63          line = BlockLine()          line = BlockLine()
64          #line.orthogonal = True          #line.orthogonal = True
65          line.fuzziness = 5          line.fuzziness = 5
66          canvas.add(line)          canvas.add(line)
67          x, y = view.get_matrix_v2i(line).transform_point(x, y)          x, y = self.view.get_matrix_v2i(line).transform_point(x, y)
68          line.matrix.translate(x, y)          line.matrix.translate(x, y)
69          return line          return line
   

Legend:
Removed from v.2199  
changed lines
  Added in v.2200

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