annotate pyink/FSM_window.py @ 1498:fc4169113259

Show popup menu for right click on a transition
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 03 May 2011 13:00:20 +0800
parents 08329d3bf452
children 9a7332e28291
rev   line source
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1 import gtk
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2 import os
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
3 import math
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
4 import data_monitor
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
5 import pybInkscape
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
6
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
7
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
8 class _dragger(object):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
9 _node = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
10 _start_x = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
11 _start_y = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
12 _state = 0
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
13
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
14 def __init__(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
15 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
16
1495
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
17 ## \brief Mouse event handler
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
18 #
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
19 # This is a placeholder for mouse vent handlers. This attribute
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
20 # of instances is switched between _mouse_event_waiting and
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
21 # _mouse_event_pressed.
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
22 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
23 def mouse_event(self, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
24 raise RuntimeError, 'should not be here'
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
25
1495
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
26 def _mouse_event_waiting(self, evtype, button, x, y):
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
27 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
28 button == 1:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
29 self._start_x = x
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
30 self._start_y = y
1495
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
31 self.mouse_event = self._mouse_event_pressed
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
32 self.start_drag()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
33 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
34 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
35
1495
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
36 def _mouse_event_pressed(self, evtype, button, x, y):
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
37 rx = x - self._start_x
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
38 ry = y - self._start_y
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
39
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
40 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
1495
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
41 self.mouse_event = self._mouse_event_waiting
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
42 self.stop_drag(rx, ry)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
43 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
44
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
45 self.update(rx, ry)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
46 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
47
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
48 def start(self):
1495
75cfacaa106e Refactoring _dragger
Thinker K.F. Li <thinker@codemud.net>
parents: 1494
diff changeset
49 self.mouse_event = self._mouse_event_waiting
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
50 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
51
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
52 def stop(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
53 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
54
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
55 def connect(self, node):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
56 self.start()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
57
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
58 def handler(item, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
59 self.mouse_event(evtype, button, x, y)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
60 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
61
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
62 self._node = node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
63 hdl_id = node.spitem.connect('mouse-event', handler)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
64 self._hdl_id = hdl_id
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
65 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
66
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
67 def disconnect(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
68 self.stop()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
69 node = self._node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
70 hdl_id = self._hdl_id
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
71 node.disconnect(hdl_id)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
72 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
73
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
74 def start_drag(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
75 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
76
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
77 def stop_drag(self, rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
78 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
79
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
80 def update(self, rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
81 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
82 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
83
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
84
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
85 class FSM_window_base(object):
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
86 _add_state_button = None
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
87 _move_state_button = None
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
88
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
89 _state_editor = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
90 _state_name = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
91 _state_radius = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
92
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
93 _error_dialog = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
94 _error_dialog_label = None
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
95
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
96 _state_menu = None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
97
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
98 def __init__(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
99 super(FSM_window_base, self).__init__()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
100
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
101 dirname = os.path.dirname(__file__)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
102 fname = os.path.join(dirname, 'FSM_window.glade')
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
103
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
104 builder = gtk.Builder()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
105 builder.add_from_file(fname)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
107 main_win = builder.get_object("FSM_main_win")
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
108 view_box = builder.get_object("view_box")
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
109 add_state_button = builder.get_object('add_state')
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
110 move_state_button = builder.get_object('move_state')
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
111
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
112 state_editor = builder.get_object("state_editor")
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
113 state_name = builder.get_object('state_name')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
114 state_radius = builder.get_object('state_radius')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
115
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
116 error_dialog = builder.get_object('error_dialog')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
117 error_dialog_label = builder.get_object('error_dialog_label')
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
118
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
119 state_menu = builder.get_object('state_menu')
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
120 transition_menu = builder.get_object('transition_menu')
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
121
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
122 builder.connect_signals(self)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
123
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
124 self._builder = builder
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
125 self._main_win = main_win
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
126 self._view_box = view_box
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
127 self._add_state_button = add_state_button
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
128 self._move_state_button = move_state_button
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
129
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
130 self._state_editor = state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
131 self._state_name = state_name
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
132 self._state_radius = state_radius
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
133
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
134 self._error_dialog = error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
135 self._error_dialog_label = error_dialog_label
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
136
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
137 self._state_menu = state_menu
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
138 self._transition_menu = transition_menu
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
139 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
140
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
141 def show_error(self, msg):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
142 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
143 error_dialog_label = self._error_dialog_label
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
144
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
145 error_dialog_label.set_text(msg)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
146 error_dialog.show()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
147 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
148
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
149 def hide_error(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
150 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
151 error_dialog.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
152 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
153
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
154 def show_state_editor(self, state_name=''):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
155 state_name_inp = self._state_name
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
156 state_radius_inp = self._state_radius
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
157 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
158
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
159 state_name_inp.set_text(state_name)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
160 state_radius_inp.set_text('30')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
161 state_editor.show()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
162 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
163
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
164 def hide_state_editor(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
165 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
166 state_editor.hide()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
167 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
168
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
169 def popup_state_menu(self):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
170 menu = self._state_menu
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
171 menu.popup(None, None, None, 0, 0)
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
172 pass
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
173
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
174 def popup_transition_menu(self):
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
175 menu = self._transition_menu
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
176 menu.popup(None, None, None, 0, 0)
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
177 pass
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
178
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
179 def show(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
180 self._main_win.show()
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
181 self._add_state_button.set_active(True)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
182 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
183
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
184 def hide(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
185 self._main_win.hide()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
186 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
187
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
188 def gtk_widget_hide(self, widget, event, *data):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
189 widget.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
190 return True
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
191
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
192 def on_start_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
193 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
194
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
195 def on_rename_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
196 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
197
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
198 def on_remove_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
199 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
200
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
201 def on_zoom_out_clicked(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
202 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
203
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
204 def on_zoom_in_clicked(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
205 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
206
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
207 def on_move_state_toggled(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
208 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
209
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
210 def on_add_state_toggled(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
211 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
212
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
213 def on_close_window_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
214 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
215
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
216 def on_FSM_main_win_destroy_event(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
217 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
218
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
219 def on_state_apply_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
220 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
221
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
222 def on_state_cancel_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
223 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
224 state_editor.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
225 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
226
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
227 def on_error_dialog_ok_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
228 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
229 error_dialog.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
230 pass
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
231
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
232 def on_add_transition_activate(self, *args):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
233 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
234
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
235 def on_del_state_activate(self, *args):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
236 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
237
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
238 def on_edit_state_activate(self, *args):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
239 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
240
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
241 def on_transition_apply_clicked(self, *args):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
242 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
243
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
244 def on_transition_cancel_clicked(self, *args):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
245 pass
1496
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
246
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
247 def on_del_transition_activate(self, *args):
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
248 pass
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
249
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
250 def on_edit_transition_activate(self, *args):
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
251 pass
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
252 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
253
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
254
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
255 class FSM_transition(object):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
256 _doc = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
257 _domview = None
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
258 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
259 _control_layer = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
260 _state = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
261 _states = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
262 trn_cond = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
263 trn_g = None
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
264 _arrow_node = None
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
265 _path_node = None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
266 _control_points = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
267
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
268 def __init__(self, trn_cond):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
269 self.trn_cond = trn_cond
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
270 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
271
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
272 def init(self, doc, domview, state, states, fsm_layer, control_layer):
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
273 self._doc = doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
274 self._domview = domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
275 self._state = state
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
276 self._states = states
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
277 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
278 self._control_layer = control_layer
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
279 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
280
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
281 @staticmethod
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
282 def _update_graph(path, arrow_node, path_node):
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
283 path_txt = 'M %f,%f C %f,%f %f,%f %f,%f' % tuple(path)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
284 path_node.setAttribute('d', path_txt)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
285 path_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; '
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
286 'fill: none')
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
287
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
288 # c0 c1 c2 c3 of cubic curve
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
289 c3 = (path[6], path[7])
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
290 c2 = (path[4], path[5])
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
291 c23_v = (c3[0] - c2[0], c3[1] - c2[1])
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
292 c23_len = math.sqrt(c23_v[0] * c23_v[0] + c23_v[1] * c23_v[1])
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
293 adir = (c23_v[0] / c23_len, c23_v[1] / c23_len) # arrow direction
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
294 odir = (-adir[1], adir[0]) # othogonal direction
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
295 arrow_pts = (c3[0], c3[1],
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
296 -adir[0] * 10 + odir[0] * 4, -adir[1] * 10 + odir[1] * 4,
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
297 -odir[0] * 8, -odir[1] * 8)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
298 arrow_txt = 'M %f,%f l %f,%f l %f,%f z' % arrow_pts
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
299 arrow_node.setAttribute('d', arrow_txt)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
300 arrow_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; '
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
301 'fill: #000000')
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
302 pass
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
303
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
304 def _draw_transition_real(self, parent, path):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
305 doc = self._doc
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
306
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
307 trn_g = doc.createElement('svg:g')
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
308
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
309 path_node = doc.createElement('svg:path')
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
310 arrow_node = doc.createElement('svg:path')
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
311 self._update_graph(path, arrow_node, path_node)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
312
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
313 trn_g.appendChild(path_node)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
314 trn_g.appendChild(arrow_node)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
315
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
316 parent.appendChild(trn_g)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
317
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
318 return trn_g, path_node, arrow_node
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
319
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
320 def _gen_path(self):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
321 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
322 target_name = self.target
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
323 target_state = states[target_name]
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
324 src_state = self._state
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
325
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
326 src_x, src_y = src_state.xy
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
327 src_r = src_state.r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
328 target_x, target_y = target_state.xy
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
329 target_r = target_state.r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
330
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
331 src_target_v = (target_x - src_x, target_y - src_y)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
332 src_target_len = \
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
333 math.sqrt(src_target_v[0] ** 2 + src_target_v[1] ** 2)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
334 distance = src_target_len - src_r - target_r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
335 distance3 = distance / 3
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
336 src_target_uv = (src_target_v[0] / src_target_len,
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
337 src_target_v[1] / src_target_len)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
338
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
339 c0x = src_x + src_target_uv[0] * src_r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
340 c0y = src_y + src_target_uv[1] * src_r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
341 c1x = c0x + src_target_uv[0] * distance3
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
342 c1y = c0y + src_target_uv[1] * distance3
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
343 c3x = target_x - src_target_uv[0] * target_r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
344 c3y = target_y - src_target_uv[1] * target_r
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
345 c2x = c3x - src_target_uv[0] * distance3
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
346 c2y = c3y - src_target_uv[1] * distance3
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
347
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
348 path = [c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y]
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
349 return path
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
350
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
351 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
352 def path(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
353 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
354 state_name = self._state.state_name
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
355 trn_cond = self.trn_cond
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
356 trn = domview.get_transition(state_name, trn_cond)
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
357 path = trn[3]
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
358
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
359 if not path:
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
360 path = self._gen_path()
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
361 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
362
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
363 return path
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
364
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
365 @property
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
366 def target(self):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
367 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
368 state_name = self._state.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
369 trn_cond = self.trn_cond
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
370 trn = domview.get_transition(state_name, trn_cond)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
371 return trn[1]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
372
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
373 @property
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
374 def state(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
375 return self._state
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
376
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
377 def draw(self, parent):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
378 path = self.path
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
379 trn_g, path_node, arrow_node = self._draw_transition_real(parent, path)
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
380 self.trn_g = trn_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
381 self._arrow_node = arrow_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
382 self._path_node = path_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
383 pass
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
384
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
385 def clear(self):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
386 trn_g = self.trn_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
387 parent = trn_g.parent()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
388 parent.removeChild(trn_g)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
389 pass
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
390
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
391 def update(self):
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
392 path = self.path
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
393 arrow_node = self._arrow_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
394 path_node = self._path_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
395 self._update_graph(path, arrow_node, path_node)
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
396 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
397
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
398 def adjust_by_ends(self):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
399 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
400
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
401 state = self._state
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
402 state_name = state.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
403 trn_cond = self.trn_cond
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
404
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
405 path = self.path
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
406
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
407 start_state = self._state
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
408 start_x, start_y = start_state.xy
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
409 start_r = start_state.r
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
410
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
411 target_name = self.target
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
412 stop_state = states[target_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
413 stop_x, stop_y = stop_state.xy
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
414 stop_r = stop_state.r
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
415
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
416 c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y = tuple(path)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
417
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
418 c0c1 = (c1x - c0x, c1y - c0y)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
419 c0c1_len = math.sqrt(c0c1[0] ** 2 + c0c1[1] ** 2)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
420 start_v = (c0c1[0] / c0c1_len, c0c1[1] / c0c1_len)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
421
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
422 c3c2 = (c2x - c3x, c2y - c3y)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
423 c3c2_len = math.sqrt(c3c2[0] ** 2 + c3c2[1] ** 2)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
424 stop_v = (c3c2[0] / c3c2_len, c3c2[1] / c3c2_len)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
425
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
426 c0x = start_v[0] * start_r + start_x
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
427 c0y = start_v[1] * start_r + start_y
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
428 c1x = start_v[0] * c0c1_len + c0x
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
429 c1y = start_v[1] * c0c1_len + c0y
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
430 c3x = stop_v[0] * stop_r + stop_x
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
431 c3y = stop_v[1] * stop_r + stop_y
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
432 c2x = stop_v[0] * c3c2_len + c3x
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
433 c2y = stop_v[1] * c3c2_len + c3y
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
434 new_path = [c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
435
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
436 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
437 domview.set_transition_path(state_name, trn_cond, new_path)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
438 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
439
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
440 def show_control_points(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
441 if not self._control_points:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
442 doc = self._doc
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
443
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
444 c1 = doc.createElement('svg:circle')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
445 c1.setAttribute('r', '3')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
446 c1.setAttribute('style', 'stroke: black; stroke-width: 1; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
447 'fill: white')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
448 l01 = doc.createElement('svg:line')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
449 l01.setAttribute('style', 'stroke: black; stroke-width: 1; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
450 'stroke-dasharray: 3 2')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
451
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
452 c2 = doc.createElement('svg:circle')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
453 c2.setAttribute('r', '3')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
454 c2.setAttribute('style', 'stroke: black; stroke-width: 1; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
455 'fill: white')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
456 l32 = doc.createElement('svg:line')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
457 l32.setAttribute('style', 'stroke: black; stroke-width: 1; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
458 'stroke-dasharray: 3 2')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
459
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
460 control_layer = self._control_layer
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
461
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
462 control_layer.appendChild(c1)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
463 control_layer.appendChild(l01)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
464 control_layer.appendChild(c2)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
465 control_layer.appendChild(l32)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
466 self._control_points = (c1, l01, c2, l32)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
467 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
468
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
469 c1, l01, c2, l32 = self._control_points
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
470 path = self.path
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
471 c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y = tuple(path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
472
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
473 c1.setAttribute('cx', str(c1x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
474 c1.setAttribute('cy', str(c1y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
475 l01.setAttribute('x1', str(c0x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
476 l01.setAttribute('y1', str(c0y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
477 l01.setAttribute('x2', str(c1x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
478 l01.setAttribute('y2', str(c1y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
479
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
480 c2.setAttribute('cx', str(c2x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
481 c2.setAttribute('cy', str(c2y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
482 l32.setAttribute('x1', str(c3x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
483 l32.setAttribute('y1', str(c3y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
484 l32.setAttribute('x2', str(c2x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
485 l32.setAttribute('y2', str(c2y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
486 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
487
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
488 def hide_control_points(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
489 if not self._control_points:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
490 return
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
491
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
492 control_layer = self._control_layer
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
493 for node in self._control_points:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
494 control_layer.removeChild(node)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
495 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
496 self._control_points = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
497 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
498
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
499 def start_hint(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
500 path_node = self._path_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
501 arrow_node = self._arrow_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
502 if path_node:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
503 path_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
504 'stroke: #404040; stroke-width: 3; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
505 'fill: none')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
506 arrow_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
507 'stroke: #404040; stroke-width: 2; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
508 'fill: #404040')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
509 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
510 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
511
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
512 def stop_hint(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
513 path_node = self._path_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
514 arrow_node = self._arrow_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
515 if path_node:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
516 path_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
517 'stroke: #000000; stroke-width: 1; ' \
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
518 'fill: none')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
519 arrow_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
520 'stroke: #000000; stroke-width: 1; ' \
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
521 'fill: #000000')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
522 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
523 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
524 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
525
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
526 class FSM_state(object):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
527 _doc = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
528 _domview = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
529 _states = None
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
530 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
531 _control_layer = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
532 state_name = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
533 state_g = None
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
534 _text_node = None
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
535 _circle_node = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
536 transitions = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
537 from_states = None # There is one or more transitions
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
538 # from these states (name).
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
539
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
540 _state_g_hdl_id = None
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
541 _selected_rect = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
542
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
543 def __init__(self, state_name):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
544 self.state_name = state_name
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
545 self.transitions = {}
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
546 self.from_states = set()
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
547 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
548
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
549 def init(self, doc, domview, states, fsm_layer, control_layer):
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
550 self._doc = doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
551 self._domview = domview
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
552 self._states = states
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
553 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
554 self._control_layer = control_layer
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
555 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
556
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
557 def _update_graph(self, text_node, text_content, circle_node,
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
558 state_name, r, x, y):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
559 circle_node.setAttribute('r', str(r))
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
560 circle_node.setAttribute('cx', str(x))
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
561 circle_node.setAttribute('cy', str(y))
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
562 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; '
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
563 'fill: #ffffff')
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
564
1497
08329d3bf452 break a long line
Thinker K.F. Li <thinker@codemud.net>
parents: 1496
diff changeset
565 text_node.setAttribute('style', 'stroke: #000000; fill: #000000; '
08329d3bf452 break a long line
Thinker K.F. Li <thinker@codemud.net>
parents: 1496
diff changeset
566 'font-size: 16px')
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
567
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
568 text_content.setContent(state_name)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
569
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
570 doc = self._doc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
571 spdoc = doc.spdoc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
572 spdoc.ensureUpToDate()
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
573 tx, ty, tw, th = text_node.getBBox()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
574 text_node.setAttribute('x', str(x - tw / 2))
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
575 text_node.setAttribute('y', str(y + th / 2))
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
576 pass
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
577
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
578 def grab(self, callback):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
579 assert not self._state_g_hdl_id
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
580
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
581 state_g = self.state_g
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
582 state_g_spitem = state_g.spitem
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
583 state_g_hdl_id = state_g_spitem.connect('mouse-event', callback)
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
584 self._state_g_hdl_id = state_g_hdl_id
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
585 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
586
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
587 def ungrab(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
588 if not self._state_g_hdl:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
589 return
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
590 state_g = self.state_g
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
591 state_g_hdl_id = self._state_g_hdl_id
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
592 state_g.disconnect(state_g_hdl_id)
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
593 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
594
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
595 def _translate_page_xy(self, x, y):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
596 doc = self._doc
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
597 root = doc.root()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
598 page_h_txt = root.getAttribute('height')
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
599 page_h = float(page_h_txt)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
600 svgx = x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
601 svgy = page_h - y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
602 return svgx, svgy
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
603
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
604 def show_selected(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
605 if not self._selected_rect:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
606 doc = self._doc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
607 rect = doc.createElement('svg:rect')
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
608 control_layer = self._control_layer
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
609 rect.setAttribute('style',
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
610 'stroke: #404040; stroke-width: 1; '
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
611 'stroke-dasharray: 6 4; fill: none')
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
612 control_layer.appendChild(rect)
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
613 self._selected_rect = rect
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
614 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
615
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
616 state_g = self.state_g
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
617 rect = self._selected_rect
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
618
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
619 px, py, pw, ph = state_g.getBBox()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
620 x, y = self._translate_page_xy(px, py)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
621 y = y - ph # px, py is left-bottom corner
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
622
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
623 rect.setAttribute('x', str(x - 2))
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
624 rect.setAttribute('y', str(y - 2))
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
625 rect.setAttribute('width', str(pw + 4))
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
626 rect.setAttribute('height', str(ph + 4))
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
627 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
628
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
629 def hide_selected(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
630 if not self._selected_rect:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
631 return
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
632
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
633 control_layer = self._control_layer
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
634 rect = self._selected_rect
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
635 control_layer.removeChild(rect)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
636 self._selected_rect = None
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
637 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
638
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
639 def _draw_state_real(self, parent, state_name, r, x, y):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
640 doc = self._doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
641
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
642 state_g = doc.createElement('svg:g')
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
643
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
644 text = doc.createElement('svg:text')
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
645 circle = doc.createElement('svg:circle')
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
646 text_content = doc.createTextNode(state_name)
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
647
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
648 text.appendChild(text_content)
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
649 state_g.appendChild(circle)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
650 state_g.appendChild(text)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
651 parent.appendChild(state_g)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
652
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
653 self._update_graph(text, text_content, circle, state_name, r, x, y)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
654
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
655 return state_g, text, text_content, circle
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
656
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
657 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
658 def r(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
659 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
660 state_name = self.state_name
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
661 r = domview.get_state_r(state_name)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
662 return r
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
663
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
664 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
665 def xy(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
666 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
667 state_name = self.state_name
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
668 xy = domview.get_state_xy(state_name)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
669 return xy
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
670
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
671 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
672 def all_transitions(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
673 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
674 state_name = self.state_name
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
675 conds = domview.all_transitions(state_name)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
676 return conds
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
677
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
678 def _load_transition_domview(self, parent, condition):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
679 domview = self._domview
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
680 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
681
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
682 trn = FSM_transition(condition)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
683 trn.init(self._doc, domview, self, states,
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
684 self._fsm_layer, self._control_layer)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
685 trn.draw(parent)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
686 self.transitions[condition] = trn
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
687 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
688
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
689 def draw(self, parent):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
690 state_name = self.state_name
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
691
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
692 r = self.r
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
693 x, y = self.xy
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
694 state_g, text_node, text_content, circle_node = \
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
695 self._draw_state_real(parent, state_name, r, x, y)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
696 self.state_g = state_g
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
697 self._text_node = text_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
698 self._text_content = text_content
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
699 self._circle_node = circle_node
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
700
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
701 for trn_cond in self.all_transitions:
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
702 self._load_transition_domview(parent, trn_cond)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
703 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
704 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
705
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
706 def clear(self):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
707 state_g = self.state_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
708 parent = state_g.parent()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
709 parent.removeChild(state_g)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
710 pass
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
711
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
712 def update(self):
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
713 text_node = self._text_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
714 text_content = self._text_content
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
715 circle_node = self._circle_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
716 state_name = self.state_name
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
717 r = self.r
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
718 x, y = self.xy
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
719 self._update_graph(text_node, text_content, circle_node, state_name,
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
720 r, x, y)
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
721 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
722
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
723 ## \brief Tell states there are transitions to them.
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
724 #
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
725 # This function is only called when loading states of a FSM from
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
726 # domview. When loading, not all states was loaded that target
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
727 # state may not in the memory. So, we call this function after
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
728 # all states being loaded. Transitions added later does need to
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
729 # call this function to notify end state.
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
730 #
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
731 def tell_target_states(self):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
732 states = self._states
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
733 transitions = self.transitions
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
734 target_state_names = [trn.target for trn in transitions.values()]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
735 target_states = [states[target_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
736 for target_name in target_state_names]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
737 state_name = self.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
738 for target_state in target_states:
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
739 target_state.from_states.add(state_name)
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
740 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
741 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
742
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
743 def adjust_transitions(self):
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
744 import itertools
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
745
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
746 states = self._states
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
747
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
748 for trn in self.transitions.values():
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
749 trn.adjust_by_ends()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
750 trn.update()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
751 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
752
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
753 state_name = self.state_name
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
754 from_states = [states[from_state_name]
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
755 for from_state_name in self.from_states]
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
756 states_transitions = [state.transitions.values()
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
757 for state in from_states]
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
758 in_state_transitions = [[trn for trn in state_transitions
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
759 if trn.target == state_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
760 for state_transitions in states_transitions]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
761 in_transitions = itertools.chain(*in_state_transitions)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
762 for trn in in_transitions:
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
763 trn.adjust_by_ends()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
764 trn.update()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
765 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
766 pass
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
767
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
768 def add_transition(self, parent, condition, target_state):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
769 domview = self._domview
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
770
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
771 state_name = self.state_name
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
772 target_name = target_state.state_name
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
773 domview.add_transition(state_name, condition, target_name)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
774
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
775 self._load_transition_domview(parent, condition)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
776
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
777 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
778 target_state = states[target_name]
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
779 target_state.from_states.add(state_name)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
780 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
781 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
782
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
783
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
784 class _FSM_move_state_mode(object):
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
785 __metaclass__ = data_monitor.data_monitor
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
786 __data_monitor_prefix__ = 'on_'
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
787
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
788 _window = None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
789 _domview = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
790 _selected_cleaner = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
791
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
792 _select_transition = None
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
793
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
794 def __init__(self, window, domview_ui):
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
795 super(_FSM_move_state_mode, self).__init__()
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
796
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
797 self._window = window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
798 self._domview = domview_ui
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
799 self._locker = domview_ui
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
800 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
801
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
802 def on_move_state_background(self, item, evtype, button, x, y):
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
803 if self._selected_cleaner is None:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
804 return
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
805
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
806 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
807 self._deselect_state()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
808 pass
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
809 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
810
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
811 def _select_state(self, state):
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
812 self._deselect_state()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
813 self._selected_cleaner = state.hide_selected
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
814 state.show_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
815 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
816
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
817 def _deselect_state(self):
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
818 if self._selected_cleaner:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
819 self._selected_cleaner()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
820 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
821 self._selected_cleaner = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
822 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
823
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
824 def _handle_move_state_state(self, state, evtype, button, x, y):
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
825 window = self._window
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
826
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
827 def moving_state(item, evtype, button, x, y):
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
828 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
829 window.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
830 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
831 new_state_x = orign_state_x + start_x - x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
832 new_state_y = orign_state_y + start_y - y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
833
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
834 domview = self._domview
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
835 domview.set_state_xy(state.state_name, x, y)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
836 state.update()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
837 state.adjust_transitions()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
838 state.show_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
839 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
840
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
841 window = self._window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
842
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
843 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
844 button == 1:
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
845 start_x = x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
846 start_y = y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
847 orign_state_x, orign_state_y = state.xy
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
848
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
849 self._select_state(state)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
850 window.grab_mouse(moving_state)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
851 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
852
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
853 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
854 button == 1:
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
855 window.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
856 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
857 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
858
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
859 ## \brief Install event handler for control points of a transitions.
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
860 #
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
861 def _install_trn_cps_mouse(self, trn):
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
862 c1, l01, c2, l32 = trn._control_points
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
863 path = trn.path
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
864 c0x, c0y, c1x, c1y, c2x, c2y, c3x, c3y = tuple(path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
865
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
866 state_src = trn.state
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
867 target_name = trn.target
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
868 states = trn._states
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
869 state_target = states[target_name]
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
870 domview = self._domview
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
871 window = self._window
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
872
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
873 def c1_update(rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
874 nc1x = c1x + rx
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
875 nc1y = c1y + ry
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
876 cx, cy = state_src.xy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
877 r = state_src.r
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
878
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
879 cv = nc1x - cx, nc1y - cy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
880 cv_len = math.sqrt(cv[0] ** 2 + cv[1] ** 2)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
881 nc0x = cx + cv[0] * r / cv_len
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
882 nc0y = cy + cv[1] * r / cv_len
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
883
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
884 path = list(trn.path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
885 path[:4] = [nc0x, nc0y, nc1x, nc1y]
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
886
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
887 state_name = state_src.state_name
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
888 cond = trn.trn_cond
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
889 domview.set_transition_path(state_name, cond, path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
890
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
891 trn.show_control_points()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
892 trn.update()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
893 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
894
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
895 def c1_start():
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
896 def relay_event(item, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
897 c1_dragger.mouse_event(evtype, button, x, y)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
898 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
899
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
900 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
901 window.grab_bg(relay_event)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
902 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
903
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
904 def c1_stop(rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
905 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
906 window.grab_bg(self.on_move_state_background)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
907 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
908
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
909 def c2_update(rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
910 nc2x = c2x + rx
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
911 nc2y = c2y + ry
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
912 cx, cy = state_target.xy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
913 r = state_target.r
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
914
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
915 cv = nc2x - cx, nc2y - cy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
916 cv_len = math.sqrt(cv[0] ** 2 + cv[1] ** 2)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
917 nc3x = cx + cv[0] * r / cv_len
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
918 nc3y = cy + cv[1] * r / cv_len
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
919
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
920 path = list(trn.path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
921 path[4:] = [nc2x, nc2y, nc3x, nc3y]
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
922
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
923 state_name = state_src.state_name
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
924 cond = trn.trn_cond
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
925 domview.set_transition_path(state_name, cond, path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
926
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
927 trn.show_control_points()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
928 trn.update()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
929 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
930
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
931 def c2_start():
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
932 def relay_event(item, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
933 c2_dragger.mouse_event(evtype, button, x, y)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
934 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
935
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
936 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
937 window.grab_bg(relay_event)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
938 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
939
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
940 def c2_stop(rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
941 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
942 window.grab_bg(self.on_move_state_background)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
943 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
944
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
945 c1_dragger = _dragger()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
946 c1_dragger.update = c1_update
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
947 c1_dragger.start_drag = c1_start
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
948 c1_dragger.stop_drag = c1_stop
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
949 c1_dragger.connect(c1)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
950
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
951 c2_dragger = _dragger()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
952 c2_dragger.update = c2_update
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
953 c2_dragger.start_drag = c2_start
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
954 c2_dragger.stop_drag = c2_stop
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
955 c2_dragger.connect(c2)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
956 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
957
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
958 ## \brief A transition was selected.
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
959 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
960 def _select_transition(self, trn):
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
961 def deselect():
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
962 trn.hide_control_points()
1493
b0e113605382 Add comment
Thinker K.F. Li <thinker@codemud.net>
parents: 1492
diff changeset
963 del self._hint_transition # enable _hint_transition
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
964 pass
1493
b0e113605382 Add comment
Thinker K.F. Li <thinker@codemud.net>
parents: 1492
diff changeset
965
b0e113605382 Add comment
Thinker K.F. Li <thinker@codemud.net>
parents: 1492
diff changeset
966 self._hint_transition = lambda *args: None # disable _hint_transition
b0e113605382 Add comment
Thinker K.F. Li <thinker@codemud.net>
parents: 1492
diff changeset
967
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
968 self._deselect_state()
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
969 self._selected_cleaner = deselect
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
970 trn.show_control_points()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
971
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
972 trn.stop_hint()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
973 window = self._window
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
974 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
975
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
976 self._install_trn_cps_mouse(trn)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
977 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
978
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
979 ## \brief Hint for mouse over a transition.
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
980 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
981 def _hint_transition(self, trn):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
982 def stop_hint(*args):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
983 trn.stop_hint()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
984 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
985 window.grab_bg(self.on_move_state_background)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
986 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
987
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
988 trn.start_hint()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
989
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
990 window = self._window
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
991 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
992 window.grab_bg(stop_hint)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
993 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
994
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
995 def on_del_transition_activate(self, *args):
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
996 pass
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
997
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
998 def on_edit_transition_activate(self, *args):
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
999 pass
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1000
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1001 def _show_transition_menu(self, trn):
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1002 self._select_transition = trn
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1003
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1004 window = self._window
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1005 window.popup_transition_menu()
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1006 pass
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1007
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1008 ## \brief Handle mouse events when selecting no transition.
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1009 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1010 def _handle_transitoin_mouse_events(self, trn, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1011 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1012 button == 1:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1013 self._select_transition(trn)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1014 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_ENTER:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1015 self._hint_transition(trn)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1016 pass
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1017 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1018 button == 3:
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1019 self._show_transition_menu(trn)
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1020 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1021 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1022
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1023 def activate(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1024 window = self._window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1025 window._emit_leave_mode()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1026 window._clear_leave_mode_cb()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1027 window.ungrab_all()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1028
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1029 window.grab_bg(self.on_move_state_background)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1030 window.grab_state(self._handle_move_state_state)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1031 window.grab_transition(self._handle_transitoin_mouse_events)
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1032 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1033
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1034 def deactivate(self):
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1035 self._deselect_state()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1036 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1037 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1038
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1039
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1040 class _FSM_add_state_mode(object):
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1041 __metaclass__ = data_monitor.data_monitor
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1042 __data_monitor_prefix__ = 'on_'
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1043
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1044 _window = None
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1045 _domview = None
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1046
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1047 _saved_x = 0
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1048 _saved_y = 0
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1049
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1050 _select_state = None
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1051 _candidate_state = None
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1052
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1053 def __init__(self, window, domview_ui):
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1054 super(_FSM_add_state_mode, self).__init__()
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1055
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1056 self._window = window
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1057 self._domview = domview_ui
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1058 self._locker = domview_ui
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1059 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1060
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1061 def handle_new_state(self):
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1062 import traceback
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1063
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1064 domview = self._domview
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1065 window = self._window
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1066 x, y = window._translate_xy(self._saved_x, self._saved_y)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1067
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1068 state_name = window._state_name.get_text()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1069 r_txt = window._state_radius.get_text()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1070 try:
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1071 r = float(r_txt)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1072 except ValueError:
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1073 traceback.print_exc()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1074 window.show_error('Invalid value: "%s" is not a valid value '
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1075 'for radius.' % (r_txt))
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1076 return
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1077
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1078 try:
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1079 domview.add_state(state_name)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1080 except:
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1081 traceback.print_exc()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1082 window.show_error('Invalid state name: "%s" is existing' %
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1083 (state_name))
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1084 return
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1085 domview.set_state_xy(state_name, x, y)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1086 domview.set_state_r(state_name, r)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1087
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1088 window._load_new_state_incr(state_name)
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1089
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1090 window.hide_state_editor()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1091 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1092
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1093 def on_add_state_background(self, item, evtype, button, x, y):
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1094 window = self._window
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1095
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1096 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1097 button == 1:
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1098 self._saved_x = x
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1099 self._saved_y = y
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1100 window.show_state_editor()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1101 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1102 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1103
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1104 def _stop_select_target(self):
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1105 self.deactivate()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1106 self.activate()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1107 pass
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1108
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1109 def _handle_select_transition_target(self, state, evtype, button, x, y):
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1110 if self._candidate_state != state and self._select_state != state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1111 if self._candidate_state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1112 self._candidate_state.hide_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1113 pass
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1114 self._candidate_state = state
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1115 state.show_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1116 pass
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1117
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1118 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1119 return
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1120 if button != 1:
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1121 return
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1122
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1123 if state == self._select_state:
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1124 self._stop_select_target()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1125 return
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1126
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1127 window = self._window
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1128 fsm_layer = window._fsm_layer
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1129
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1130 target_state = state
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1131 src_state = self._select_state
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1132 cond = ''
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1133 src_state.add_transition(fsm_layer, cond, target_state)
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1134
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1135 self._stop_select_target()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1136 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1137
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1138 def _handle_add_transition(self, *args):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1139 def restore_bg(item, evtype, *args):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1140 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS:
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1141 if self._candidate_state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1142 self._candidate_state.hide_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1143 self._candidate_state = None
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1144 pass
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1145 return
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1146 self._stop_select_target()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1147 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1148
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1149 window = self._window
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1150 window.ungrab_bg()
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1151 window.grab_bg(restore_bg)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1152
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1153 window.ungrab_state()
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1154 window.grab_state(self._handle_select_transition_target)
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1155 self._select_state.show_selected()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1156 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1157
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1158 def _handle_state_mouse_events(self, state, evtype, button, x, y):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1159 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1160 button == 3:
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1161 self._select_state = state
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1162
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1163 window = self._window
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1164 window.popup_state_menu()
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1165 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1166 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1167
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1168 def activate(self):
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1169 window = self._window
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1170
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1171 window._emit_leave_mode()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1172 window.ungrab_all()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1173
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1174 window.grab_bg(self.on_add_state_background)
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1175 window.grab_state(self._handle_state_mouse_events)
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1176 window.grab_add_transition(self._handle_add_transition)
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1177 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1178
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1179 def deactivate(self):
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1180 if self._select_state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1181 self._select_state.hide_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1182 pass
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1183 if self._candidate_state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1184 self._candidate_state.hide_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1185 self._candidate_state = None
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1186 pass
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1187 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1188 pass
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1189
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1190 class FSM_window(FSM_window_base):
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1191 __metaclass__ = data_monitor.data_monitor
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1192 __data_monitor_prefix__ = 'on_'
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1193
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1194 _background = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1195 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1196 _control_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1197 width = 1024
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1198 height = 768
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1199
1489
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1200 _grab_mouse_hdl = None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1201 _bg_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1202
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1203 _leave_mode_cb = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1204 _move_state_mode = None
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1205 _add_state_mode = None
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1206 _state_mouse_event_handler = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1207 _add_transition_cb = None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1208 _transition_mouse_event_handler = None
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1209
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1210 def __init__(self, domview_ui, close_cb, destroy_cb):
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1211 super(FSM_window, self).__init__()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1212
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1213 self._locker = domview_ui
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1214
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1215 self._domview = domview_ui
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1216 self._states = {}
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1217
1457
416a18409603 Show an empty document in SVG viewer widget
Thinker K.F. Li <thinker@codemud.net>
parents: 1456
diff changeset
1218 self._close_cb = close_cb # callback to close editor window (hide)
416a18409603 Show an empty document in SVG viewer widget
Thinker K.F. Li <thinker@codemud.net>
parents: 1456
diff changeset
1219 self._destroy_cb = destroy_cb # callback to destroy editor window
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1220
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1221 self._move_state_mode = _FSM_move_state_mode(self, domview_ui)
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1222 self._add_state_mode = _FSM_add_state_mode(self, domview_ui)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1223 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1224
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1225 def _init_layers(self):
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1226 doc = self._doc()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1227 root = self._root()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1228
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1229 root.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1230
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1231 background = doc.createElement('svg:rect')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1232 background.setAttribute('x', '0')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1233 background.setAttribute('y', '0')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1234 background.setAttribute('width', str(self.width))
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1235 background.setAttribute('height', str(self.height))
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1236 background.setAttribute('style', 'fill: #ffffff')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1237 root.appendChild(background)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1238 self._background = background
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1239
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1240 fsm_layer = doc.createElement('svg:g')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1241 fsm_layer.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1242 root.appendChild(fsm_layer)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1243 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1244
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1245 control_layer = doc.createElement('svg:g')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1246 control_layer.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1247 root.appendChild(control_layer)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1248 self._control_layer = control_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1249 pass
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1250
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1251 def _doc(self):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1252 view_widget = self._view_widget
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1253 view = view_widget.view
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1254 doc = view.doc().rdoc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1255 return doc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1256
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1257 def _root(self):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1258 doc = self._doc()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1259 root = doc.root()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1260 return root
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1261
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1262 def _translate_xy(self, x, y):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1263 return x, y
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1264
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1265 def _clear_view(self):
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1266 if not self._background:
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1267 self._init_layers()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1268 return
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1269
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1270 children = [child for child in self._fsm_layer.childList()] + \
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1271 [child for child in self._control_layer.childList()]
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1272 for child in children:
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1273 parent = child.parent()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1274 parent.removeChild(child)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1275 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1276
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1277 self._states = {}
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1278 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1279
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1280 def _draw_state_domview(self, state_name):
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1281 domview = self._domview
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1282 doc = self._doc()
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1283 fsm_layer = self._fsm_layer
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1284 states = self._states
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1285
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1286 state = FSM_state(state_name)
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1287 state.init(doc, domview, states, self._fsm_layer, self._control_layer)
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1288 self._states[state_name] = state
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1289
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1290 state.draw(fsm_layer)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1291 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1292
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1293 def _set_leave_mode_cb(self, callback):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1294 self._leave_mode_cb = callback
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1295 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1296
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1297 def _clear_leave_mode_cb(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1298 self._leave_mode_cb = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1299 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1300
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1301 def _emit_leave_mode(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1302 if self._leave_mode_cb:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1303 self._leave_mode_cb()
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
1304 self._leave_mode_cb = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1305 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1306 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1307
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1308 def ungrab_all(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1309 self.ungrab_bg()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1310 self.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1311 self.ungrab_state()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1312 self.ungrab_add_transition()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1313 self.ungrab_transition()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1314 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1315
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1316 def on_state_mouse_event(self, state, evtype, button, x, y):
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1317 if self._state_mouse_event_handler:
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1318 self._state_mouse_event_handler(state, evtype, button, x, y)
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1319 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1320 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1321
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1322 def _install_state_event_handler(self, state):
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1323 def mouse_event_handler(item, evtype, button, x, y):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1324 self.on_state_mouse_event(state, evtype, button, x, y)
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1325 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1326 state.grab(mouse_event_handler)
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1327 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1328
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1329 def on_transition_mouse_event(self, trn, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1330 if self._transition_mouse_event_handler:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1331 self._transition_mouse_event_handler(trn, evtype, button, x, y)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1332 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1333 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1334
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1335 def _install_transition_event_handler(self, trn):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1336 def mouse_event_handler(item, evtype, button, x, y):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1337 self.on_transition_mouse_event(trn, evtype, button, x, y)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1338 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1339 trn_g = trn.trn_g
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1340 trn_g.spitem.connect('mouse-event', mouse_event_handler)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1341 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1342
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1343 def grab_transition(self, callback):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1344 assert self._transition_mouse_event_handler is None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1345 self._transition_mouse_event_handler = callback
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1346 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1347
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1348 def ungrab_transition(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1349 self._transition_mouse_event_handler = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1350 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1351
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1352 def grab_state(self, callback):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1353 assert self._state_mouse_event_handler is None
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1354 self._state_mouse_event_handler = callback
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1355 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1356
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1357 def ungrab_state(self):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1358 self._state_mouse_event_handler = None
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1359 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1360
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1361 def grab_add_transition(self, callback):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1362 assert self._add_transition_cb is None
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1363 self._add_transition_cb = callback
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1364 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1365
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1366 def ungrab_add_transition(self):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1367 self._add_transition_cb = None
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1368 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1369
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1370 def _load_new_state(self, state_name):
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1371 states = self._states
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1372
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1373 self._draw_state_domview(state_name)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1374 state = states[state_name]
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1375 self._install_state_event_handler(state)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1376
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1377 for trn in state.transitions.values():
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1378 self._install_transition_event_handler(trn)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1379 pass
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1380 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1381
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1382 ## \brief Load new state incrementally.
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1383 #
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1384 def _load_new_state_incr(self, state_name):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1385 self._load_new_state(state_name)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1386 states = self._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1387 state = states[state_name]
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1388 state.tell_target_states()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1389 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1390
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
1391 def _rebuild_from_states(self):
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1392 states = self._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1393 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1394 state_names = domview.all_state_names()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1395 for state_name in state_names:
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1396 state = states[state_name]
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1397 state.tell_target_states()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1398 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1399 pass
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1400
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1401 def _update_view(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1402 self._clear_view()
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1403 states = self._states
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1404
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1405 domview = self._domview
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1406
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1407 state_names = domview.all_state_names()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1408 for state_name in state_names:
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1409 self._load_new_state(state_name)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1410 pass
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
1411 self._rebuild_from_states()
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1412 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1413
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1414 def set_svg_view(self, view):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1415 self._view_box.add(view)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1416 self._view_widget = view
1479
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
1417
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
1418 root = self._root()
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
1419 root.setAttribute('width', '1024')
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
1420 root.setAttribute('height', '768')
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
1421 view.setResize(True, 800, 600)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1422 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1423
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1424 def on_close_window_activate(self, *args):
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
1425 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1426 self._close_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1427 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1428
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1429 def on_FSM_main_win_destroy_event(self, *args):
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
1430 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1431 self._destroy_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1432 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1433
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1434 def on_FSM_main_win_delete_event(self, *args):
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
1435 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1436 self._destroy_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1437 pass
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1438
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1439 def on_add_state_toggled(self, *args):
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1440 mode = self._add_state_mode
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1441 mode.activate()
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1442 self._set_leave_mode_cb(lambda: mode.deactivate())
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1443 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1444
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1445 def on_move_state_toggled(self, *args):
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1446 mode = self._move_state_mode
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1447 mode.activate()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1448 self._set_leave_mode_cb(lambda: mode.deactivate())
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1449 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1450
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1451 def on_state_apply_clicked(self, *args):
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1452 self._add_state_mode.handle_new_state()
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1453 pass
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1454
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1455 def on_add_transition_activate(self, *args):
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1456 if self._add_transition_cb:
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1457 self._add_transition_cb(*args)
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1458 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1459 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1460
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1461 def _install_test_data(self):
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1462 self._init_layers()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1463
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1464 domview = self._domview
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1465
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1466 view = self._view_widget.view
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1467 doc = view.doc()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1468 rdoc = doc.rdoc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1469 root_node = doc.root().repr
1479
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
1470
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1471 line_node = rdoc.createElement('svg:line')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1472 line_node.setAttribute('x1', '10')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1473 line_node.setAttribute('y1', '10')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1474 line_node.setAttribute('x2', '100')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1475 line_node.setAttribute('y2', '100')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1476 line_node.setAttribute('style', 'stroke: #000000; stroke-width:2')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1477
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1478 root_node.appendChild(line_node)
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1479
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1480 def show_msg(*args, **kws):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1481 print 'mouse_event'
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1482 print args
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1483 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1484 print 'before connect'
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1485 hdl_id = line_node.spitem.connect('mouse-event', show_msg)
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1486 print hdl_id
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1487
1471
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1488 state1 = 'state 1'
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1489 domview.add_state(state1)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1490 domview.set_state_r(state1, 50)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1491 domview.set_state_xy(state1, 200, 100)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1492 state2 = 'state 2'
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1493 domview.add_state(state2)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1494 domview.set_state_r(state2, 30)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1495 domview.set_state_xy(state2, 300, 100)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1496 domview.add_transition(state1, 'event1', state2)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1497 domview.set_transition_path(state1, 'event1', (200, 150,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1498 240, 180,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1499 260, 180,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
1500 300, 130))
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1501 pass
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1502
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1503 def show(self):
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1504 self._install_test_data()
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1505 self._install_test_data = lambda: None
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1506 self._update_view()
1486
471805e582cc Leave current mode when closing a FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents: 1485
diff changeset
1507 self._add_state_mode.activate()
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1508 super(FSM_window, self).show()
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
1509 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1510
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1511 def grab_mouse(self, callback):
1489
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1512 assert self._grab_mouse_hdl is None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1513
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1514 root = self._root()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1515 root.setAttribute('inkscape:groupmode', '')
1489
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1516 self._grab_mouse_hdl = root.spitem.connect('mouse-event', callback)
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1517 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1518
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1519 def ungrab_mouse(self):
1489
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1520 if not self._grab_mouse_hdl:
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1521 return
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1522
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1523 root = self._root()
1489
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1524 root.spitem.disconnect(self._grab_mouse_hdl)
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1525 self._grab_mouse_hdl = None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1526 root.setAttribute('inkscape:groupmode', 'layer')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1527 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1528
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1529 def grab_bg(self, callback):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1530 assert self._bg_hdl is None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1531 assert self._background
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1532
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1533 background = self._background
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1534 bg_hdl = background.spitem.connect('mouse-event', callback)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1535 self._bg_hdl = bg_hdl
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1536 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1537
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1538 def ungrab_bg(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1539 if not self._bg_hdl:
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1540 return
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1541
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1542 background = self._background
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1543 bg_hdl = self._bg_hdl
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1544 background.spitem.disconnect(bg_hdl)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1545 self._bg_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1546 pass
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1547 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1548
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1549 if __name__ == '__main__':
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1550 win = FSM_window()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1551 win._main_win.connect('destroy', gtk.main_quit)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1552 win.show()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1553 gtk.main()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1554 pass