annotate pyink/FSM_window.py @ 1510:47b02e97bdee

Delete states and transitions
author Thinker K.F. Li <thinker@codemud.net>
date Tue, 10 May 2011 01:14:55 +0800
parents 4a2402ac34dd
children 4c349b214877
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')
1499
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
115 state_entry_action = builder.get_object('state_entry_action')
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
116
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
117 error_dialog = builder.get_object('error_dialog')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
118 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
119
1499
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
120 transition_editor = builder.get_object('transition_editor')
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
121 transition_cond = builder.get_object('transition_cond')
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
122 transition_action = builder.get_object('transition_action')
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
123
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
124 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
125 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
126
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
127 builder.connect_signals(self)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
128
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
129 self._builder = builder
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
130 self._main_win = main_win
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
131 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
132 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
133 self._move_state_button = move_state_button
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
134
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
135 self._state_editor = state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
136 self._state_name = state_name
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
137 self._state_radius = state_radius
1499
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
138 self._state_entry_action = state_entry_action
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
139
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
140 self._transition_editor = transition_editor
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
141 self._transition_cond = transition_cond
9a7332e28291 Get objects from builder for state and transition editors
Thinker K.F. Li <thinker@codemud.net>
parents: 1498
diff changeset
142 self._transition_action = transition_action
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
143
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
144 self._error_dialog = error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
145 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
146
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
147 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
148 self._transition_menu = transition_menu
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
149 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
150
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
151 def show_error(self, msg):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
152 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
153 error_dialog_label = self._error_dialog_label
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
154
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
155 error_dialog_label.set_text(msg)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
156 error_dialog.show()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
157 pass
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 def hide_error(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
160 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
161 error_dialog.hide()
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
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
164 def show_state_editor(self, state_name='', radius=30, entry_action=''):
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
165 state_name_inp = self._state_name
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
166 state_radius_inp = self._state_radius
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
167 state_entry_action = self._state_entry_action
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
168 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
169
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
170 state_name_inp.set_text(state_name)
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
171 state_radius_inp.set_text(str(radius))
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
172 state_entry_action.set_text(entry_action or '')
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
173 state_editor.show()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
174 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
175
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
176 def hide_state_editor(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
177 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
178 state_editor.hide()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
179 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
180
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
181 def show_transition_editor(self, cond='', action=''):
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
182 transition_cond = self._transition_cond
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
183 transition_action = self._transition_action
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
184 transition_editor = self._transition_editor
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
185
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
186 transition_cond.set_text(cond)
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
187 transition_action.set_text(action)
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
188 transition_editor.show()
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
189 pass
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
190
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
191 def hide_transition_editor(self):
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
192 transition_editor = self._transition_editor
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
193 transition_editor.hide()
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
194 pass
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
195
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
196 def popup_state_menu(self):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
197 menu = self._state_menu
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
198 menu.popup(None, None, None, 0, 0)
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
199 pass
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
200
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
201 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
202 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
203 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
204 pass
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
205
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
206 def show(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
207 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
208 self._add_state_button.set_active(True)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
209 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
210
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
211 def hide(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
212 self._main_win.hide()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
213 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
214
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
215 def gtk_widget_hide(self, widget, event, *data):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
216 widget.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
217 return True
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
218
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
219 def on_start_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
220 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
221
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
222 def on_rename_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
223 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
224
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
225 def on_remove_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
226 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
227
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
228 def on_zoom_out_clicked(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
229 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
230
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
231 def on_zoom_in_clicked(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
232 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
233
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
234 def on_move_state_toggled(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
235 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
236
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
237 def on_add_state_toggled(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
238 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
239
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
240 def on_close_window_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
241 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
242
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
243 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
244 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
245
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
246 def on_state_apply_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
247 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
248
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
249 def on_state_cancel_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
250 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
251 state_editor.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
252 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
253
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
254 def on_error_dialog_ok_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
255 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
256 error_dialog.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
257 pass
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
258
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
259 def on_add_transition_activate(self, *args):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
260 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
261
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
262 def on_del_state_activate(self, *args):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
263 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
264
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
265 def on_edit_state_activate(self, *args):
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
266 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
267
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
268 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
269 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
270
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
271 def on_transition_cancel_clicked(self, *args):
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
272 transition_editor = self._transition_editor
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
273 transition_editor.hide()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
274 pass
1496
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
275
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
276 def on_del_transition_activate(self, *args):
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
277 pass
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
278
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
279 def on_edit_transition_activate(self, *args):
042587afed2e Add popup menu for transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1495
diff changeset
280 pass
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
281 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
282
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
283
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
284 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
285 _doc = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
286 _domview = None
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
287 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
288 _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
289 _state = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
290 _states = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
291 trn_cond = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
292 trn_g = None
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
293 _arrow_node = None
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
294 _path_node = None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
295 _control_points = None
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
296 _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
297
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
298 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
299 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
300 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
301
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
302 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
303 self._doc = doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
304 self._domview = domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
305 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
306 self._states = states
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
307 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
308 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
309 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
310
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
311 def _translate_page_xy(self, x, y):
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
312 return x, y
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
313
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
314 @staticmethod
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
315 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
316 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
317 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
318 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
319 'fill: none')
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
320
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
321 # 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
322 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
323 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
324 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
325 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
326 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
327 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
328 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
329 -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
330 -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
331 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
332 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
333 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
334 'fill: #000000')
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
335 pass
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
336
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
337 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
338 doc = self._doc
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
339
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
340 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
341
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
342 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
343 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
344 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
345
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
346 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
347 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
348
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
349 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
350
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
351 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
352
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
353 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
354 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
355 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
356 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
357 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
358
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
359 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
360 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
361 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
362 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
363
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
364 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
365 src_target_len = \
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
366 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
367 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
368 distance3 = distance / 3
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
369 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
370 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
371
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
372 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
373 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
374 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
375 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
376 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
377 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
378 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
379 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
380
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
381 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
382 return path
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
383
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
384 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
385 def path(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
386 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
387 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
388 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
389 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
390 path = trn[3]
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
391
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
392 if not path:
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
393 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
394 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
395
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
396 return path
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
397
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
398 @property
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
399 def target(self):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
400 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
401 state_name = self._state.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
402 trn_cond = self.trn_cond
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
403 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
404 return trn[1]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
405
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
406 @property
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
407 def state(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
408 return self._state
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
409
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
410 @property
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
411 def action(self):
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
412 domview = self._domview
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
413 state_name = self._state.state_name
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
414 trn_cond = self.trn_cond
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
415 trn = domview.get_transition(state_name, trn_cond)
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
416 return trn[2]
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
417
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
418 def draw(self):
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
419 path = self.path
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
420 fsm_layer = self._fsm_layer
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
421 trn_g, path_node, arrow_node = \
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
422 self._draw_transition_real(fsm_layer, path)
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
423 self.trn_g = trn_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
424 self._arrow_node = arrow_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
425 self._path_node = path_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
426 pass
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
427
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
428 def clear(self):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
429 trn_g = self.trn_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
430 parent = trn_g.parent()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
431 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
432 pass
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
433
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
434 def update(self):
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
435 path = self.path
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
436 arrow_node = self._arrow_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
437 path_node = self._path_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
438 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
439 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
440
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
441 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
442 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
443
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
444 state = self._state
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
445 state_name = state.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
446 trn_cond = self.trn_cond
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
447
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
448 path = self.path
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
449
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
450 start_state = self._state
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
451 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
452 start_r = start_state.r
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
453
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
454 target_name = self.target
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
455 stop_state = states[target_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
456 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
457 stop_r = stop_state.r
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
458
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
459 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
460
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
461 c0c1 = (c1x - c0x, c1y - c0y)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
462 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
463 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
464
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
465 c3c2 = (c2x - c3x, c2y - c3y)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
466 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
467 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
468
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
469 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
470 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
471 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
472 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
473 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
474 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
475 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
476 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
477 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
478
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
479 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
480 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
481 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
482
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
483 def show_control_points(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
484 if not self._control_points:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
485 doc = self._doc
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
486
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
487 c1 = doc.createElement('svg:circle')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
488 c1.setAttribute('r', '3')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
489 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
490 'fill: white')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
491 l01 = doc.createElement('svg:line')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
492 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
493 'stroke-dasharray: 3 2')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
494
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
495 c2 = doc.createElement('svg:circle')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
496 c2.setAttribute('r', '3')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
497 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
498 'fill: white')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
499 l32 = doc.createElement('svg:line')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
500 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
501 'stroke-dasharray: 3 2')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
502
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
503 control_layer = self._control_layer
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
504
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
505 control_layer.appendChild(c1)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
506 control_layer.appendChild(l01)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
507 control_layer.appendChild(c2)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
508 control_layer.appendChild(l32)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
509 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
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 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
513 path = self.path
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
514 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
515
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
516 c1.setAttribute('cx', str(c1x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
517 c1.setAttribute('cy', str(c1y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
518 l01.setAttribute('x1', str(c0x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
519 l01.setAttribute('y1', str(c0y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
520 l01.setAttribute('x2', str(c1x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
521 l01.setAttribute('y2', str(c1y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
522
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
523 c2.setAttribute('cx', str(c2x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
524 c2.setAttribute('cy', str(c2y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
525 l32.setAttribute('x1', str(c3x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
526 l32.setAttribute('y1', str(c3y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
527 l32.setAttribute('x2', str(c2x))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
528 l32.setAttribute('y2', str(c2y))
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
529 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
530
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
531 def hide_control_points(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
532 if not self._control_points:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
533 return
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
534
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
535 control_layer = self._control_layer
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
536 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
537 control_layer.removeChild(node)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
538 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
539 self._control_points = None
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
540 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
541
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
542 def start_hint(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
543 path_node = self._path_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
544 arrow_node = self._arrow_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
545 if path_node:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
546 path_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
547 'stroke: #404040; stroke-width: 3; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
548 'fill: none')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
549 arrow_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
550 'stroke: #404040; stroke-width: 2; '
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
551 'fill: #404040')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
552 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
553 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
554
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
555 def stop_hint(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
556 path_node = self._path_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
557 arrow_node = self._arrow_node
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
558 if path_node:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
559 path_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
560 'stroke: #000000; stroke-width: 1; ' \
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
561 'fill: none')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
562 arrow_node.setAttribute('style',
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
563 'stroke: #000000; stroke-width: 1; ' \
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
564 'fill: #000000')
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
565 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
566 pass
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
567
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
568 def show_selected(self):
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
569 if not self._selected_rect:
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
570 doc = self._doc
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
571 rect = doc.createElement('svg:rect')
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
572 control_layer = self._control_layer
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
573 rect.setAttribute('style',
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
574 'stroke: #404040; stroke-width: 1; '
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
575 'stroke-dasharray: 6 4; fill: none')
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
576 control_layer.appendChild(rect)
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
577 self._selected_rect = rect
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
578 pass
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
579
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
580 trn_g = self.trn_g
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
581 rect = self._selected_rect
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
582
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
583 px, py, pw, ph = trn_g.getBBox()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
584 x, y = self._translate_page_xy(px, py)
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
585 y = y - ph # px, py is left-bottom corner
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
586
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
587 rect.setAttribute('x', str(x - 2))
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
588 rect.setAttribute('y', str(y - 2))
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
589 rect.setAttribute('width', str(pw + 4))
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
590 rect.setAttribute('height', str(ph + 4))
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
591 pass
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
592
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
593 def hide_selected(self):
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
594 if not self._selected_rect:
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
595 return
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
596
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
597 control_layer = self._control_layer
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
598 rect = self._selected_rect
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
599 control_layer.removeChild(rect)
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
600 self._selected_rect = None
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
601 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
602 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
603
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
604 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
605 _doc = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
606 _domview = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
607 _states = None
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
608 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
609 _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
610 state_name = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
611 state_g = None
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
612 _text_node = None
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
613 _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
614 transitions = None
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
615 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
616 # from these states (name).
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
617
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
618 _state_g_hdl_id = None
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
619 _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
620
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
621 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
622 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
623 self.transitions = {}
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
624 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
625 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
626
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
627 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
628 self._doc = doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
629 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
630 self._states = states
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
631 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
632 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
633 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
634
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
635 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
636 state_name, r, x, y):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
637 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
638 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
639 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
640 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
641 'fill: #ffffff')
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
642
1497
08329d3bf452 break a long line
Thinker K.F. Li <thinker@codemud.net>
parents: 1496
diff changeset
643 text_node.setAttribute('style', 'stroke: #000000; fill: #000000; '
08329d3bf452 break a long line
Thinker K.F. Li <thinker@codemud.net>
parents: 1496
diff changeset
644 'font-size: 16px')
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
645
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
646 text_content.setContent(state_name)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
647
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
648 doc = self._doc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
649 spdoc = doc.spdoc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
650 spdoc.ensureUpToDate()
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
651 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
652 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
653 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
654 pass
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
655
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
656 def grab(self, callback):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
657 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
658
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
659 state_g = self.state_g
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
660 state_g_spitem = state_g.spitem
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
661 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
662 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
663 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
664
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
665 def ungrab(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
666 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
667 return
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
668 state_g = self.state_g
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
669 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
670 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
671 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
672
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
673 def _translate_page_xy(self, x, y):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
674 doc = self._doc
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
675 root = doc.root()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
676 page_h_txt = root.getAttribute('height')
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
677 page_h = float(page_h_txt)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
678 svgx = x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
679 svgy = page_h - y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
680 return svgx, svgy
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
681
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
682 def show_selected(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
683 if not self._selected_rect:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
684 doc = self._doc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
685 rect = doc.createElement('svg:rect')
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
686 control_layer = self._control_layer
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
687 rect.setAttribute('style',
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
688 'stroke: #404040; stroke-width: 1; '
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
689 '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
690 control_layer.appendChild(rect)
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
691 self._selected_rect = rect
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
692 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
693
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
694 state_g = self.state_g
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
695 rect = self._selected_rect
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
696
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
697 px, py, pw, ph = state_g.getBBox()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
698 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
699 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
700
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
701 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
702 rect.setAttribute('y', str(y - 2))
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
703 rect.setAttribute('width', str(pw + 4))
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
704 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
705 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
706
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
707 def hide_selected(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
708 if not self._selected_rect:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
709 return
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
710
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
711 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
712 rect = self._selected_rect
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
713 control_layer.removeChild(rect)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
714 self._selected_rect = None
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
715 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
716
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
717 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
718 doc = self._doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
719
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
720 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
721
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
722 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
723 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
724 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
725
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
726 text.appendChild(text_content)
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
727 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
728 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
729 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
730
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
731 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
732
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
733 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
734
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
735 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
736 def r(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
737 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
738 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
739 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
740 return r
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
741
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
742 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
743 def xy(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
744 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
745 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
746 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
747 return xy
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
748
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
749 @property
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
750 def entry_action(self):
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
751 domview = self._domview
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
752 state_name = self.state_name
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
753 entry_action = domview.get_state_entry_action(state_name)
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
754 return entry_action
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
755
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
756 @property
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
757 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
758 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
759 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
760 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
761 return conds
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
762
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
763 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
764 domview = self._domview
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
765 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
766
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
767 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
768 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
769 self._fsm_layer, self._control_layer)
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
770 trn.draw()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
771 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
772 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
773
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
774 def draw(self):
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
775 state_name = self.state_name
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
776 fsm_layer = self._fsm_layer
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
777
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
778 r = self.r
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
779 x, y = self.xy
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
780 state_g, text_node, text_content, circle_node = \
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
781 self._draw_state_real(fsm_layer, 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
782 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
783 self._text_node = text_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
784 self._text_content = text_content
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
785 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
786
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
787 for trn_cond in self.all_transitions:
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
788 self._load_transition_domview(fsm_layer, trn_cond)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
789 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
790 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
791
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
792 def clear(self):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
793 state_g = self.state_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
794 parent = state_g.parent()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
795 parent.removeChild(state_g)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
796 pass
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
797
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
798 def update(self):
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
799 text_node = self._text_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
800 text_content = self._text_content
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
801 circle_node = self._circle_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
802 state_name = self.state_name
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
803 r = self.r
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
804 x, y = self.xy
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
805 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
806 r, x, y)
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
807 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
808
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
809 ## \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
810 #
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
811 # 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
812 # 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
813 # 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
814 # 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
815 # 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
816 #
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
817 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
818 states = self._states
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
819 transitions = self.transitions
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
820 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
821 target_states = [states[target_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
822 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
823 state_name = self.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
824 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
825 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
826 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
827 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
828
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
829 def rm_target_from_states(self):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
830 state_name = self.state_name
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
831
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
832 transitions = self.transitions.values()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
833 target_names = [trn.target for trn in transitions]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
834
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
835 states = self._states
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
836 for target_name in target_names:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
837 target_state = states[target_name]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
838 target_state.from_states.remove(state_name)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
839 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
840 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
841
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
842 def adjust_transitions(self):
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
843 import itertools
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
844
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
845 states = self._states
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
846
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
847 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
848 trn.adjust_by_ends()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
849 trn.update()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
850 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
851
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
852 state_name = self.state_name
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
853 from_states = [states[from_state_name]
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
854 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
855 states_transitions = [state.transitions.values()
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
856 for state in from_states]
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
857 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
858 if trn.target == state_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
859 for state_transitions in states_transitions]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
860 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
861 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
862 trn.adjust_by_ends()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
863 trn.update()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
864 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
865 pass
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
866
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
867 def add_transition(self, parent, condition):
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
868 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
869
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
870 transitions = self.transitions
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
871 trn = transitions[condition]
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
872 target_name = trn.target
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
873
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
874 state_name = self.state_name
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
875 states = self._states
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
876 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
877 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
878 pass
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
879
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
880 ## \brief Remove state from from_states of a given target.
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
881 #
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
882 # The state was removed only when there is no transition targeted
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
883 # on given target state.
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
884 #
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
885 def _rm_from_states_for_target(self, target_name):
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
886 transitions = self.transitions
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
887 same_targets = [trn.target for trn in transitions.values()
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
888 if trn.target == target_name]
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
889 same_target_cnt = len(same_targets)
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
890 if same_target_cnt == 0:
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
891 states = self._states
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
892 target_state = states[target_name]
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
893 state_name = self.state_name
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
894 target_state.from_states.remove(state_name)
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
895 pass
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
896 pass
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
897
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
898 def rm_transition(self, condition):
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
899 transitions = self.transitions
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
900 trn = transitions[condition]
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
901 target_name = trn.target
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
902 del transitions[condition]
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
903 trn.clear()
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
904
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
905 self._rm_from_states_for_target(target_name)
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
906 pass
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
907
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
908 def start_hint(self):
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
909 circle_node = self._circle_node
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
910 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 3; '
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
911 'fill: #ffffff')
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
912 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
913
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
914 def stop_hint(self):
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
915 circle_node = self._circle_node
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
916 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; '
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
917 'fill: #ffffff')
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
918 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
919 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
920
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
921
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
922 class _select_manager(object):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
923 selected_state = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
924 selected_transition = None
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
925 controlled_transition = None
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
926
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
927 def deselect(self):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
928 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
929
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
930 def select_state(self, state):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
931 self.deselect()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
932
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
933 self.selected_state = state
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
934 state.show_selected()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
935
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
936 def hide():
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
937 state.hide_selected()
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
938 self.reset()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
939 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
940 self.deselect = hide
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
941 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
942
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
943 def select_transition(self, transition):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
944 self.deselect()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
945
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
946 self.selected_transition = transition
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
947 transition.show_selected()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
948
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
949 def hide():
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
950 transition.hide_selected()
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
951 self.reset()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
952 pass
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
953 self.deselect = hide
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
954 pass
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
955
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
956 def control_transition(self, transition):
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
957 self.deselect()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
958
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
959 self.controlled_transition = transition
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
960 transition.show_control_points()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
961
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
962 def hide():
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
963 transition.hide_control_points()
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
964 self.reset()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
965 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
966 self.deselect = hide
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
967 pass
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
968
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
969 def reset(self):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
970 try:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
971 del self.deselect
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
972 except AttributeError:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
973 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
974 self.selected_state = None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
975 self.selected_transition = None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
976 self.controlled_transition = None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
977 pass
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
978 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
979
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
980
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
981 class _FSM_popup(object):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
982 _window = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
983 _domview = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
984
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
985 _menu_state = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
986 _menu_transition = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
987
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
988 _candidate_target = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
989
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
990 _select = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
991
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
992 def __init__(self, window, domview_ui, select_man):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
993 super(_FSM_popup, self).__init__()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
994 self._window = window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
995 self._domview = domview_ui
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
996 self._select = select_man
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
997 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
998
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
999 def _show_state_menu(self, state):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1000 self._menu_state = state
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1001 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1002 window.popup_state_menu()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1003 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1004
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1005 def _show_transition_menu(self, trn):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1006 self._menu_transition = trn
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1007 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1008 window.popup_transition_menu()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1009 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1010
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1011 ## \brief Handle mouse events for state objects.
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1012 #
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1013 # This method must be called by mode object to handle mouse events
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1014 # that is not handled by them.
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1015 #
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1016 def _handle_state_mouse_events(self, state, evtype, button, x, y):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1017 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1018 button == 3:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1019 self._show_state_menu(state)
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1020 self._select.select_state(state)
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1021 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_ENTER:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1022 state.start_hint()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1023 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_LEAVE:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1024 state.stop_hint()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1025 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1026 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1027
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1028 ## \brief Handle mouse events for transition objects.
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1029 #
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1030 # This method must be called by mode object to handle mouse events
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1031 # that is not handled by them.
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1032 #
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1033 def _handle_transition_mouse_events(self, trn, evtype, button, x, y):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1034 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS and \
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1035 button == 3:
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1036 self._select.select_transition(trn)
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1037 self._show_transition_menu(trn)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1038 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_ENTER:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1039 trn.start_hint()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1040 elif evtype == pybInkscape.PYSPItem.PYB_EVENT_MOUSE_LEAVE:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1041 trn.stop_hint()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1042 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1043 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1044
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1045 def _handle_select_transition_target(self, state, evtype, button, x, y):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1046 if self._candidate_target != state and self._menu_state != state:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1047 if self._candidate_target:
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1048 self._candidate_target.stop_hint()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1049 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1050 self._candidate_target = state
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1051 state.start_hint()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1052 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1053
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1054 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1055 return
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1056 if button != 1:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1057 return
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1058
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1059 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1060
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1061 if state == self._menu_state:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1062 window.pop_grabs()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1063 return
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1064
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1065 fsm_layer = window._fsm_layer
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1066
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1067 target_state = state
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1068 target_name = target_state.state_name
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1069 src_state = self._menu_state
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1070 src_name = src_state.state_name
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1071 cond = ''
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1072
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1073 domview = self._domview
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1074 try:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1075 domview.add_transition(src_name, cond, target_name)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1076 except:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1077 import traceback
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1078 traceback.print_exc()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1079 window.show_error('invalid condition: %s' % (cond))
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1080 else:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1081 src_state.add_transition(fsm_layer, cond)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1082
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1083 trn = src_state.transitions[cond]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1084 window._install_transition_event_handler(trn)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1085 pass
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1086
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1087 window.pop_grabs()
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1088
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1089 target_state.stop_hint()
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1090 select = self._select
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1091 select.deselect()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1092 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1093
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1094 def _handle_add_transition(self, *args):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1095 def restore_bg(item, evtype, *args):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1096 if evtype != pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1097 if self._candidate_target:
1507
bebf73ee38c8 Fix issue of stopping hint when pointer leaving a target state
Thinker K.F. Li <thinker@codemud.net>
parents: 1506
diff changeset
1098 self._candidate_target.stop_hint()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1099 self._candidate_target = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1100 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1101 return
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1102 self._select.deselect()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1103 window.pop_grabs()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1104 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1105
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1106 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1107 window.push_grabs()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1108 window.ungrab_bg()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1109 window.grab_bg(restore_bg)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1110
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1111 window.ungrab_state()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1112 window.grab_state(self._handle_select_transition_target)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1113 self._select.select_state(self._menu_state)
1507
bebf73ee38c8 Fix issue of stopping hint when pointer leaving a target state
Thinker K.F. Li <thinker@codemud.net>
parents: 1506
diff changeset
1114 self._menu_state.stop_hint()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1115 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1116
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1117 def _handle_edit_transition(self, *args):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1118 trn = self._select.selected_transition
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1119
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1120 cond = trn.trn_cond
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1121 action = trn.action or ''
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1122
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1123 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1124 window.show_transition_editor(cond, action)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1125 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1126
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1127 def _handle_transition_apply(self, *args):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1128 trn = self._select.selected_transition
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1129 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1130 domview = self._domview
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1131 transition_cond = window._transition_cond
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1132 transition_action = window._transition_action
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1133
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1134 trn_cond = trn.trn_cond
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1135 trn_action = trn.action
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1136 trn_state = trn.state
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1137 trn_state_name = trn_state.state_name
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1138
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1139 new_cond = transition_cond.get_text()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1140 new_action = transition_action.get_text()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1141
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1142 if new_action != trn_action:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1143 domview.set_transition_action(trn_state_name, trn_cond, new_action)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1144 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1145
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1146 if new_cond != trn_cond:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1147 trn_state.rm_transition(trn_cond)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1148
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1149 domview.chg_transition_cond(trn_state_name, trn_cond, new_cond)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1150
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1151 fsm_layer = window._fsm_layer
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1152 trn_state.add_transition(fsm_layer, new_cond)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1153
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1154 transitions = trn_state.transitions
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1155 new_trn = transitions[new_cond]
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1156 window._install_transition_event_handler(new_trn)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1157 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1158
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1159 window.hide_transition_editor()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1160 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1161
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1162 def _handle_edit_state(self, *args):
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1163 select = self._select
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1164 state = select.selected_state
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1165 name = state.state_name
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1166 r = state.r
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1167 entry_action = state.entry_action
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1168
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1169 window = self._window
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1170 window.show_state_editor(name, r, entry_action)
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1171 pass
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1172
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1173 def _handle_state_change(self):
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1174 window = self._window
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1175 domview = self._domview
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1176 select = self._select
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1177
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1178 state_name_txt = window._state_name
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1179 state_radius_txt = window._state_radius
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1180 state_entry_action_txt = window._state_entry_action
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1181
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1182 state_name = state_name_txt.get_text()
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1183 state_radius = state_radius_txt.get_text()
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1184 state_entry_action = state_entry_action_txt.get_text()
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1185
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1186 state_radius_f = float(state_radius)
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1187
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1188 state = select.selected_state
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1189 old_state_name = state.state_name
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1190 if old_state_name != state_name:
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1191 domview.rename_state(old_state_name, state_name)
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1192 state.state_name = state_name
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1193 pass
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1194
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1195 domview.set_state_r(state_name, state_radius_f)
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1196 domview.set_state_entry_action(state_name, state_entry_action)
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1197
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1198 state.update()
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1199
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1200 window.hide_state_editor()
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1201 select.deselect()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1202 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1203
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1204 def _handle_del_state(self, *args):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1205 window = self._window
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1206 select = self._select
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1207 domview = self._domview
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1208
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1209 state = select.selected_state
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1210 state_name = state.state_name
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1211
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1212 select.deselect()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1213
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1214 states = window._states
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1215 del states[state_name]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1216
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1217 state.clear()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1218
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1219 # Remove out transitions
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1220 transitions = state.transitions
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1221 for trn in transitions.values():
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1222 trn.clear()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1223 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1224
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1225 state.rm_target_from_states()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1226
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1227 # Remove in-transition
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1228 src_state_names = state.from_states
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1229 for src_state_name in src_state_names:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1230 src_state = states[src_state_name]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1231 in_cond_trns = [(in_cond, in_trn)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1232 for in_cond, in_trn in \
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1233 src_state.transitions.items()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1234 if in_trn.target == state_name]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1235 for in_cond, in_trn in in_cond_trns:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1236 in_trn.clear()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1237 del src_state.transitions[in_cond]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1238 domview.rm_transition(src_state_name, in_cond)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1239 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1240 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1241
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1242 domview.rm_state(state_name)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1243 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1244
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1245 def _handle_del_transition(self, *args):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1246 window = self._window
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1247 select = self._select
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1248 domview = self._domview
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1249
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1250 trn = select.selected_transition
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1251 trn.clear()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1252 trn_cond = trn.trn_cond
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1253
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1254 trn_state = trn.state
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1255 trn_state_name = trn_state.state_name
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1256 trn_target_name = trn.target
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1257 target_names = [trn.target for trn in trn_state.transitions.values()]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1258
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1259 # the transition must live until getting all info.
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1260 domview.rm_transition(trn_state_name, trn_cond)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1261
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1262 if trn_target_name not in target_names:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1263 trn_target_state = window._states[trn_target_name]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1264 trn_target_state.from_states.remove(trn_state_name)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1265 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1266
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1267 del trn_state.transitions[trn_cond]
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1268 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1269
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1270 def popup_install_handler(self):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1271 window = self._window
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1272
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1273 window.grab_add_transition(self._handle_add_transition)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1274 window.grab_edit_transition(self._handle_edit_transition)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1275 window.grab_edit_state(self._handle_edit_state)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1276 window.grab_transition_apply(self._handle_transition_apply)
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1277 window.grab_state_apply(self._handle_state_change)
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1278 window.grab_del_state(self._handle_del_state)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1279 window.grab_del_transition(self._handle_del_transition)
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1280 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1281 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1282
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1283
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1284 class _FSM_move_state_mode(object):
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1285 __metaclass__ = data_monitor.data_monitor
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1286 __data_monitor_prefix__ = 'on_'
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1287
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1288 _popup = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1289
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1290 _window = None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1291 _domview = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1292
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1293 _select = None
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1294
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1295 _on_deactivate = None
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1296
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1297 def __init__(self, window, domview_ui, select_man):
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1298 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
1299
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1300 self._window = window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1301 self._domview = domview_ui
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1302 self._locker = domview_ui
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1303
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1304 self._popup = _FSM_popup(window, domview_ui, select_man)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1305 self._select = select_man
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1306
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1307 self._on_deactivate = []
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1308 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1309
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1310 def _handle_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
1311 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE:
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1312 self._select.deselect()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1313 pass
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
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1316 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
1317 window = self._window
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1318
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1319 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
1320 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
1321 window.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1322 pass
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1323 new_state_x = orign_state_x + x - start_x
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1324 new_state_y = orign_state_y + y - start_y
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1325
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1326 domview = self._domview
1505
7b8e67b2391b Hint for user overing a state object
Thinker K.F. Li <thinker@codemud.net>
parents: 1504
diff changeset
1327 domview.set_state_xy(state.state_name, new_state_x, new_state_y)
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1328 state.update()
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1329 state.adjust_transitions()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1330 state.show_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1331 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1332
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1333 window = self._window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1334
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1335 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
1336 button == 1:
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1337 start_x = x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1338 start_y = y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1339 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
1340
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1341 self._select.select_state(state)
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1342 window.grab_mouse(moving_state)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1343 pass
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1344 elif 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
1345 button == 1:
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1346 window.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1347 pass
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1348 else:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1349 self._popup._handle_state_mouse_events(state, evtype, button, x, y)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1350 pass
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1351 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1352
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1353 ## \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
1354 #
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1355 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
1356 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
1357 path = trn.path
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1358 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
1359
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1360 state_src = trn.state
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1361 target_name = trn.target
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1362 states = trn._states
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1363 state_target = states[target_name]
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1364 domview = self._domview
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1365 window = self._window
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1366 select = self._select
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1367
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1368 def c1_update(rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1369 nc1x = c1x + rx
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1370 nc1y = c1y + ry
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1371 cx, cy = state_src.xy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1372 r = state_src.r
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1373
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1374 cv = nc1x - cx, nc1y - cy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1375 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
1376 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
1377 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
1378
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1379 path = list(trn.path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1380 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
1381
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1382 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
1383 cond = trn.trn_cond
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1384 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
1385
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1386 trn.update()
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1387 trn.show_control_points()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1388 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1389
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1390 def c1_start():
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1391 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
1392 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
1393 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1394
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1395 window.push_grabs()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1396 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1397 window.grab_bg(relay_event)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1398 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1399
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1400 def c1_stop(rx, ry):
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1401 window.pop_grabs()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1402 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1403
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1404 def c2_update(rx, ry):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1405 nc2x = c2x + rx
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1406 nc2y = c2y + ry
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1407 cx, cy = state_target.xy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1408 r = state_target.r
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1409
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1410 cv = nc2x - cx, nc2y - cy
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1411 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
1412 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
1413 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
1414
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1415 path = list(trn.path)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1416 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
1417
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1418 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
1419 cond = trn.trn_cond
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1420 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
1421
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1422 trn.update()
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1423 trn.show_control_points()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1424 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1425
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1426 def c2_start():
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1427 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
1428 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
1429 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1430
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1431 window.push_grabs()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1432 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1433 window.grab_bg(relay_event)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1434 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1435
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1436 def c2_stop(rx, ry):
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1437 window.pop_grabs()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1438 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1439
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1440 c1_dragger = _dragger()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1441 c1_dragger.update = c1_update
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1442 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
1443 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
1444 c1_dragger.connect(c1)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1445
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1446 c2_dragger = _dragger()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1447 c2_dragger.update = c2_update
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1448 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
1449 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
1450 c2_dragger.connect(c2)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1451 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1452
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1453 ## \brief A transition was selected.
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1454 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1455 def _select_transition(self, trn):
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1456 def handle_bg(item, evtype, button, x, y):
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1457 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS:
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1458 window.pop_grabs()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1459 window.ungrab_bg()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1460
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1461 self._on_deactivate.pop()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1462 self._on_deactivate.pop()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1463
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1464 select.deselect()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1465 del self._hint_transition
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1466 pass
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1467 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1468
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1469 select = self._select
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1470 select.control_transition(trn)
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1471
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1472 self._hint_transition = lambda trn: None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1473 trn.stop_hint()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1474 window = self._window
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1475 window.push_grabs()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1476 window.ungrab_bg()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1477 window.grab_bg(handle_bg)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1478
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1479 self._install_trn_cps_mouse(trn)
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1480 self._on_deactivate.append(window.pop_grabs)
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1481 def del_hint_transition():
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1482 del self._hint_transition
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1483 pass
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1484 self._on_deactivate.append(del_hint_transition)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1485 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1486
1494
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1487 ## \brief Hint for mouse over a transition.
ac390af12152 Add comment and rename methods
Thinker K.F. Li <thinker@codemud.net>
parents: 1493
diff changeset
1488 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1489 def _hint_transition(self, trn):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1490 def stop_hint(*args):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1491 trn.stop_hint()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1492 window.ungrab_bg()
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1493 window.grab_bg(self._handle_move_state_background)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1494 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1495
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1496 trn.start_hint()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1497
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1498 window = self._window
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1499 window.ungrab_bg()
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1500 window.grab_bg(stop_hint)
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1501 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1502
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1503 def _handle_del_transition(self, *args):
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1504 pass
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1505
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1506 ## \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
1507 #
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1508 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
1509 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
1510 button == 1:
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1511 self._select_transition(trn)
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1512 else:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1513 self._popup._handle_transition_mouse_events(trn, evtype, button,
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1514 x, y)
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1515 pass
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1516 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1517
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1518 def activate(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1519 window = self._window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1520 window._emit_leave_mode()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1521 window._clear_leave_mode_cb()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1522 window.ungrab_all()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1523
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1524 window.ungrab_bg()
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1525 window.grab_bg(self._handle_move_state_background)
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1526 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
1527 window.grab_transition(self._handle_transitoin_mouse_events)
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1528
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1529 self._popup.popup_install_handler()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1530 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1531
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1532 def deactivate(self):
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1533 self._select.deselect()
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1534 while self._on_deactivate:
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1535 deactivate = self._on_deactivate.pop()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1536 deactivate()
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1537 pass
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1538 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1539 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1540
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1541
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1542 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
1543 __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
1544 __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
1545
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1546 _window = None
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1547 _domview = None
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1548
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
1549 _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
1550 _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
1551
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1552 _select_state = None
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1553 _candidate_state = None
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1554
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1555 _popup = None
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1556 _select = None
1498
fc4169113259 Show popup menu for right click on a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1497
diff changeset
1557
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1558 def __init__(self, window, domview_ui, select_man):
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
1559 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
1560
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1561 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
1562 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
1563 self._locker = domview_ui
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1564
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1565 self._select = select_man
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1566 self._popup = _FSM_popup(window, domview_ui, select_man)
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
1567 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
1568
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1569 def _handle_add_new_state(self):
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
1570 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
1571
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1572 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
1573 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
1574 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
1575
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1576 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
1577 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
1578 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
1579 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
1580 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
1581 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
1582 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
1583 '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
1584 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
1585
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1586 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
1587 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
1588 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
1589 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
1590 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
1591 (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
1592 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
1593 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
1594 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
1595
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1596 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
1597
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1598 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
1599 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
1600
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1601 def _handle_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
1602 window = self._window
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1603 select = self._select
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
1604
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1605 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
1606 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
1607 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
1608 self._saved_y = y
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1609 select.deselect()
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
1610 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
1611 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
1612 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
1613
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1614 ## \brief Dispatching state apply event to _FSM_popup or this class.
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1615 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1616 # When user change properties of a state, this event is deliveried to
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1617 # _FSM_popup. Otherwise, dispatch the event to this class.
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1618 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1619 def _handle_state_apply(self):
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1620 select = self._select
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1621 if select.selected_state:
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1622 # selected the state while user request to edit a state.
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1623 popup = self._popup
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1624 popup._handle_state_change()
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1625 else:
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1626 # deselected while user click on bg to add a new state.
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1627 self._handle_add_new_state()
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1628 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1629 pass
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1630
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
1631 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
1632 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
1633
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1634 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
1635 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
1636
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1637 window.grab_bg(self._handle_add_state_background)
1508
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1638
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1639 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1640 # Install event handlers for _FSM_popup
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1641 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1642 window.grab_state(self._popup._handle_state_mouse_events)
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1643 window.grab_transition(self._popup._handle_transition_mouse_events)
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1644 self._popup.popup_install_handler()
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1645
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1646 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1647 # Workaround to make state apply events dispatched to right
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1648 # place according history of user actions.
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1649 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1650 # see _handle_state_apply()
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1651 #
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1652 window.ungrab_state_apply()
62001d2c89f6 Make _FSM_add_state_mode to use _FSM_popup
Thinker K.F. Li <thinker@codemud.net>
parents: 1507
diff changeset
1653 window.grab_state_apply(self._handle_state_apply)
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
1654 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
1655
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1656 def deactivate(self):
1491
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1657 if self._select_state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1658 self._select_state.hide_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1659 pass
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1660 if self._candidate_state:
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1661 self._candidate_state.hide_selected()
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1662 self._candidate_state = None
06c101bba830 Hint user to select transition target
Thinker K.F. Li <thinker@codemud.net>
parents: 1490
diff changeset
1663 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
1664 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
1665 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
1666
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1667 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
1668 __metaclass__ = data_monitor.data_monitor
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1669 __data_monitor_prefix__ = 'on_'
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1670
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1671 _background = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1672 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1673 _control_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1674 width = 1024
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1675 height = 768
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1676
1489
1e607ce4bf7d Rename FSM_window._grab_hdl to _grab_mouse_hdl
Thinker K.F. Li <thinker@codemud.net>
parents: 1488
diff changeset
1677 _grab_mouse_hdl = None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1678 _bg_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1679
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1680 _bg_mouse_event_cb = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1681 _leave_mode_cb = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1682 _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
1683 _add_state_mode = None
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1684 _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
1685 _add_transition_cb = None
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1686 _edit_transition_cb = None
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1687 _transition_apply_cb = None
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1688 _transition_mouse_event_handler = None
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1689 _edit_state_cb = None
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1690 _state_apply_cb = None
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1691 _del_state_cb = None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1692 _del_transition_cb = None
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1693
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1694 _grab_stack = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1695
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1696 _select = None
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1697
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1698 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
1699 super(FSM_window, self).__init__()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1700
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1701 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
1702
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
1703 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
1704 self._states = {}
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
1705
1457
416a18409603 Show an empty document in SVG viewer widget
Thinker K.F. Li <thinker@codemud.net>
parents: 1456
diff changeset
1706 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
1707 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
1708
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1709 _select = _select_manager()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1710 self._select = _select
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1711
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1712 self._move_state_mode = _FSM_move_state_mode(self, domview_ui, _select)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1713 self._add_state_mode = _FSM_add_state_mode(self, domview_ui, _select)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1714
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1715 self._grab_stack = []
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1716 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
1717
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1718 def _init_layers(self):
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1719 doc = self._doc()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1720 root = self._root()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1721
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1722 root.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1723
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1724 background = doc.createElement('svg:rect')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1725 background.setAttribute('x', '0')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1726 background.setAttribute('y', '0')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1727 background.setAttribute('width', str(self.width))
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1728 background.setAttribute('height', str(self.height))
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1729 background.setAttribute('style', 'fill: #ffffff')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1730 root.appendChild(background)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1731 self._background = background
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1732
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1733 fsm_layer = doc.createElement('svg:g')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1734 fsm_layer.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1735 root.appendChild(fsm_layer)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1736 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1737
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1738 control_layer = doc.createElement('svg:g')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1739 control_layer.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1740 root.appendChild(control_layer)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1741 self._control_layer = control_layer
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1742
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1743 bg_hdl = background.spitem.connect('mouse-event',
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1744 self.on_bg_mouse_events)
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1745 self._bg_hdl = bg_hdl
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1746 pass
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1747
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1748 def _doc(self):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1749 view_widget = self._view_widget
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1750 view = view_widget.view
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1751 doc = view.doc().rdoc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1752 return doc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1753
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1754 def _root(self):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1755 doc = self._doc()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1756 root = doc.root()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1757 return root
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1758
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1759 def _translate_xy(self, x, y):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1760 return x, y
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1761
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1762 def _clear_view(self):
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1763 if not self._background:
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1764 self._init_layers()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1765 return
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1766
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1767 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
1768 [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
1769 for child in children:
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1770 parent = child.parent()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1771 parent.removeChild(child)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1772 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1773
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
1774 self._states = {}
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1775 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1776
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1777 def _make_state_domview(self, state_name):
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
1778 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
1779 doc = self._doc()
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
1780 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
1781 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
1782
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1783 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
1784 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
1785 self._states[state_name] = state
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1786
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1787 return state
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
1788
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1789 def _set_leave_mode_cb(self, callback):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1790 self._leave_mode_cb = callback
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1791 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1792
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1793 def _clear_leave_mode_cb(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1794 self._leave_mode_cb = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1795 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1796
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1797 def _emit_leave_mode(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1798 if self._leave_mode_cb:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1799 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
1800 self._leave_mode_cb = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1801 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1802 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1803
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1804 def ungrab_all(self):
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1805 self.ungrab_bg()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1806 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
1807 self.ungrab_add_transition()
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1808 self.ungrab_transition()
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1809 self.ungrab_edit_transition()
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1810 self.ungrab_edit_state()
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1811 self.ungrab_transition_apply()
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1812 self.ungrab_state_apply()
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1813 self.ungrab_del_state()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1814 self.ungrab_del_transition()
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1815 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
1816
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1817 def save_grabs(self):
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1818 save = (self._bg_mouse_event_cb,
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1819 self._state_mouse_event_handler,
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1820 self._transition_mouse_event_handler,
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1821 self._add_transition_cb,
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1822 self._edit_transition_cb,
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1823 self._transition_apply_cb,
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1824 self._edit_state_cb,
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1825 self._state_apply_cb,
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1826 self._del_state_cb,
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1827 self._del_transition_cb)
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1828 return save
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1829
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1830 def restore_grabs(self, save):
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1831 self._bg_mouse_event_cb, \
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1832 self._state_mouse_event_handler, \
1503
4d582306df85 Manage control points of transitions by _select_manager
Thinker K.F. Li <thinker@codemud.net>
parents: 1502
diff changeset
1833 self._transition_mouse_event_handler, \
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1834 self._add_transition_cb, \
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1835 self._edit_transition_cb, \
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1836 self._transition_apply_cb, \
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1837 self._edit_state_cb, \
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1838 self._state_apply_cb, \
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1839 self._del_state_cb, \
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1840 self._del_transition_cb \
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1841 = save
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1842 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1843
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1844 ## \brief Push current setting of grab handles into the stack.
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1845 #
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1846 def push_grabs(self):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1847 save = self.save_grabs()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1848 self._grab_stack.append(save)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1849 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1850
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1851 ## \brief Restore setting of grab handles from the stack.
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
1852 #
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1853 def pop_grabs(self):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1854 save = self._grab_stack.pop()
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1855 self.restore_grabs(save)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1856 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1857
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1858 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
1859 if self._state_mouse_event_handler:
1488
757c5626d15d Show context menu for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1487
diff changeset
1860 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
1861 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1862 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1863
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1864 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
1865 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
1866 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
1867 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1868 state.grab(mouse_event_handler)
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1869 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1870
1492
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1871 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
1872 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
1873 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
1874 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1875 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1876
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1877 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
1878 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
1879 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
1880 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1881 trn_g = trn.trn_g
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1882 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
1883 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1884
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1885 def grab_transition(self, callback):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1886 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
1887 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
1888 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1889
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1890 def ungrab_transition(self):
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1891 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
1892 pass
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1893
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1894 def grab_state(self, callback):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1895 assert self._state_mouse_event_handler is None
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1896 self._state_mouse_event_handler = callback
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1897 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1898
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1899 def ungrab_state(self):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1900 self._state_mouse_event_handler = None
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1901 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
1902
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1903 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
1904 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
1905 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
1906 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1907
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1908 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
1909 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
1910 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
1911
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1912 def grab_edit_transition(self, callback):
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1913 assert self._edit_transition_cb is None
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1914 self._edit_transition_cb = callback
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1915 pass
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1916
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1917 def ungrab_edit_transition(self):
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1918 self._edit_transition_cb = None
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1919 pass
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
1920
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1921 def grab_transition_apply(self, callback):
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1922 assert self._transition_apply_cb is None
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1923 self._transition_apply_cb = callback
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1924 pass
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1925
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1926 def ungrab_transition_apply(self):
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1927 self._transition_apply_cb = None
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1928 pass
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
1929
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1930 def grab_edit_state(self, callback):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1931 assert self._edit_state_cb is None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1932 self._edit_state_cb = callback
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1933 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1934
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1935 def ungrab_edit_state(self):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1936 self._edit_state_cb = None
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1937 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
1938
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1939 def grab_state_apply(self, callback):
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1940 assert self._state_apply_cb is None
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1941 self._state_apply_cb = callback
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1942 pass
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1943
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1944 def ungrab_state_apply(self):
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1945 self._state_apply_cb = None
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1946 pass
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
1947
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1948 def grab_del_state(self, callback):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1949 assert self._del_state_cb is None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1950 self._del_state_cb = callback
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1951 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1952
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1953 def ungrab_del_state(self):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1954 self._del_state_cb = None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1955 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1956
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1957 def grab_del_transition(self, callback):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1958 assert self._del_transition_cb is None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1959 self._del_transition_cb = callback
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1960 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1961
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1962 def ungrab_del_transition(self):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1963 self._del_transition_cb = None
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1964 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1965
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1966 def _draw_new_state(self, 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
1967 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
1968
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
1969 state = states[state_name]
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1970 state.draw()
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
1971 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
1972
6616530c4180 Show hint when mouse over a transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1491
diff changeset
1973 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
1974 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
1975 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
1976 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1977
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1978 def _load_new_state(self, state_name):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1979 state = self._make_state_domview(state_name)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1980 self._draw_new_state(state_name)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1981 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1982
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1983 ## \brief Load new state incrementally.
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1984 #
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1985 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
1986 self._load_new_state(state_name)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1987 states = self._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1988 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
1989 state.tell_target_states()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1990 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1991
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
1992 def _rebuild_from_states(self):
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1993 states = self._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1994 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1995 state_names = domview.all_state_names()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1996 for state_name in state_names:
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
1997 state = states[state_name]
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
1998 self._draw_new_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
1999 state.tell_target_states()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
2000 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
2001 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
2002
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2003 def _update_view(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2004 self._clear_view()
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
2005 states = self._states
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2006
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2007 domview = self._domview
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2008
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2009 state_names = domview.all_state_names()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2010 for state_name in state_names:
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2011 self._make_state_domview(state_name)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2012 pass
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
2013 self._rebuild_from_states()
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2014 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2015
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2016 def set_svg_view(self, view):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2017 self._view_box.add(view)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2018 self._view_widget = view
1479
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
2019
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
2020 root = self._root()
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
2021 root.setAttribute('width', '1024')
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
2022 root.setAttribute('height', '768')
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
2023 view.setResize(True, 800, 600)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2024 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2025
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2026 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
2027 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2028 self._close_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2029 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2030
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2031 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
2032 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2033 self._destroy_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2034 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2035
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2036 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
2037 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2038 self._destroy_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2039 pass
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
2040
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
2041 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
2042 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
2043 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
2044 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
2045 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2046
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2047 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
2048 mode = self._move_state_mode
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
2049 mode.activate()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
2050 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
2051 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2052
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2053 def on_state_apply_clicked(self, *args):
1506
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
2054 if self._state_apply_cb:
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
2055 self._state_apply_cb()
f185a9d23a30 _FSM_popup handles edit state
Thinker K.F. Li <thinker@codemud.net>
parents: 1505
diff changeset
2056 pass
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2057 pass
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2058
1490
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
2059 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
2060 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
2061 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
2062 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
2063 pass
3f107ceee9c1 User can add transitions for states by popup menu
Thinker K.F. Li <thinker@codemud.net>
parents: 1489
diff changeset
2064
1500
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
2065 def on_edit_transition_activate(self, *args):
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
2066 if self._edit_transition_cb:
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
2067 self._edit_transition_cb(*args)
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
2068 pass
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
2069 pass
65249f15138e Show transition editor when user click on "Edit" menu item
Thinker K.F. Li <thinker@codemud.net>
parents: 1499
diff changeset
2070
1501
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
2071 def on_transition_apply_clicked(self, *args):
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
2072 if self._transition_apply_cb:
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
2073 self._transition_apply_cb(*args)
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
2074 pass
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
2075 pass
4a57650bb926 Apply changes returned from transition editor
Thinker K.F. Li <thinker@codemud.net>
parents: 1500
diff changeset
2076
1502
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
2077 def on_edit_state_activate(self, *args):
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
2078 if self._edit_state_cb:
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
2079 self._edit_state_cb(*args)
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
2080 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
2081 pass
376a8cb7312e Refactor popup menu and selection of states and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1501
diff changeset
2082
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2083 def on_del_state_activate(self, *args):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2084 if self._del_state_cb:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2085 self._del_state_cb(*args)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2086 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2087 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2088
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2089 def on_del_transition_activate(self, *args):
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2090 if self._del_transition_cb:
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2091 self._del_transition_cb(*args)
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2092 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2093 pass
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2094
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2095 def _install_test_data(self):
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
2096 self._init_layers()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
2097
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
2098 domview = self._domview
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2099
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2100 view = self._view_widget.view
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2101 doc = view.doc()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2102 rdoc = doc.rdoc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2103 root_node = doc.root().repr
1479
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
2104
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2105 line_node = rdoc.createElement('svg:line')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2106 line_node.setAttribute('x1', '10')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2107 line_node.setAttribute('y1', '10')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2108 line_node.setAttribute('x2', '100')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2109 line_node.setAttribute('y2', '100')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2110 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
2111
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2112 root_node.appendChild(line_node)
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2113
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2114 def show_msg(*args, **kws):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2115 print 'mouse_event'
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2116 print args
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2117 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2118 print 'before connect'
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2119 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
2120 print hdl_id
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
2121
1471
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2122 state1 = 'state 1'
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2123 domview.add_state(state1)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2124 domview.set_state_r(state1, 50)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2125 domview.set_state_xy(state1, 200, 100)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2126 state2 = 'state 2'
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2127 domview.add_state(state2)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2128 domview.set_state_r(state2, 30)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2129 domview.set_state_xy(state2, 300, 100)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2130 domview.add_transition(state1, 'event1', state2)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2131 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
2132 240, 180,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2133 260, 180,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
2134 300, 130))
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
2135 pass
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2136
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2137 def show(self):
1509
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2138 if _install_test_data_flag:
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2139 self._install_test_data()
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2140 self._install_test_data = lambda: None
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2141 pass
1510
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2142
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2143 #
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2144 # Crash if without line.
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2145 # This line remove selection infor to prevent select manager to
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2146 # deselect an object selected in previous session. It would crash
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2147 # if we don't reset it and domview of previous session were
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2148 # removed.
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2149 #
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2150 self._select.reset()
47b02e97bdee Delete states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1509
diff changeset
2151
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2152 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
2153 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
2154 super(FSM_window, self).show()
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
2155 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2156
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2157 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
2158 assert self._grab_mouse_hdl is None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2159
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2160 root = self._root()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2161 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
2162 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
2163 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2164
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2165 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
2166 if not self._grab_mouse_hdl:
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2167 return
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2168
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2169 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
2170 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
2171 self._grab_mouse_hdl = None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2172 root.setAttribute('inkscape:groupmode', 'layer')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2173 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2174
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2175 def on_bg_mouse_events(self, item, evtype, button, x, y):
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2176 if not self._bg_mouse_event_cb:
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2177 return
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2178
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2179 self._bg_mouse_event_cb(item, evtype, button, x, y)
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2180 pass
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2181
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2182 def grab_bg(self, callback):
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2183 assert self._bg_mouse_event_cb is None
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2184
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2185 self._bg_mouse_event_cb = callback
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2186 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2187
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2188 def ungrab_bg(self):
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2189 if not self._bg_mouse_event_cb:
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2190 return
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2191
1504
d5b677831671 Make grab_bg() stackable
Thinker K.F. Li <thinker@codemud.net>
parents: 1503
diff changeset
2192 self._bg_mouse_event_cb = None
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
2193 pass
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2194 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2195
1509
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2196 _install_test_data_flag = False
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2197
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2198 if __name__ == '__main__':
1509
4a2402ac34dd Stop install test data for normal execution
Thinker K.F. Li <thinker@codemud.net>
parents: 1508
diff changeset
2199 _install_test_data_flag = True
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2200 win = FSM_window()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2201 win._main_win.connect('destroy', gtk.main_quit)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2202 win.show()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2203 gtk.main()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
2204 pass