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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2311 - (show annotations) (download) (as text)
Mon Nov 1 05:51:07 2010 UTC (13 years, 7 months ago) by jpye
File MIME type: text/x-python
File size: 2119 byte(s)
Fix outdated URL.
1
2 from gaphas.tool import HandleTool, PlacementTool
3 from gaphas import geometry
4 from blockconnecttool import BlockConnectTool
5 from blockline import BlockLine
6 import cairo
7
8 # ConnectorTool for Gaphas canvas, by John Pye, 4 Nov 2008.
9
10 class ConnectorTool(BlockConnectTool):
11 """
12 This is a port-connecting handle tool that additionally initiates the
13 creation of connector lines when the user is withing gluing distance of an
14 as-yet-unconnected Port.
15
16 handle_tool should normally be set to HandleTool()
17 """
18 def __init__(self):
19 self._handle_tool = HandleTool()
20 self._handle_index_glued = 0
21 self._handle_index_dragged = 1
22 self.grabbed_handle = None
23 self.grabbed_item = None
24 self._new_item = None
25 self.motion_handle = None
26
27 def on_button_press(self,event):
28
29 if event.button != 1:
30 return False
31
32 glueitem,glueport,gluepos = self.view.get_port_at_point((event.x,event.y),distance = 10,exclude = [])
33
34 if glueport and hasattr(glueport,"point"):
35
36 #print "Conn.Tool L36\n: "glueitem,glueport,gluepos
37 self.line = self._create_line((event.x, event.y))
38 self._new_item = self.line
39 h_glue = self.line.handles()[self._handle_index_glued]
40 self.connect(self.line,h_glue,(event.x,event.y))
41 self.post_connect(self.line,h_glue,None,glueport)
42 #print "Conn.Tool L40\n"
43
44 h_drag = self.line.handles()[self._handle_index_dragged]
45 self._handle_tool.grab_handle(self.line, h_drag)
46 self.grabbed_handle = h_drag
47 self.grabbed_item = self.line
48
49 return True
50
51 def on_button_release(self,event):
52
53 dragitem,dragport,dragpos = self.view.get_port_at_point((event.x,event.y),distance = 10,exclude = [])
54
55 try:
56 if dragport:
57 h_drag = self.line.handles()[self._handle_index_dragged]
58 self.post_connect(self.line,h_drag,None,dragport)
59 finally:
60 return super(ConnectorTool, self).on_button_release(event)
61
62
63 def _create_line(self, (x, y)):
64 canvas = self.view.canvas
65 line = BlockLine()
66 #line.orthogonal = True
67 line.fuzziness = 5
68 canvas.add(line)
69 x, y = self.view.get_matrix_v2i(line).transform_point(x, y)
70 line.matrix.translate(x, y)
71 return line

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