annotate pyink/FSM_window.py @ 1487:3aba29609607

Rename state modes
author Thinker K.F. Li <thinker@codemud.net>
date Sat, 30 Apr 2011 11:18:44 +0800
parents 471805e582cc
children 757c5626d15d
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
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
3 import data_monitor
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
4
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
5 class FSM_window_base(object):
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
6 _state_editor = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
7 _state_name = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
8 _state_radius = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
9
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
10 _error_dialog = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
11 _error_dialog_label = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
12
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
13 def __init__(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
14 super(FSM_window_base, self).__init__()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
15
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
16 dirname = os.path.dirname(__file__)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
17 fname = os.path.join(dirname, 'FSM_window.glade')
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
18
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
19 builder = gtk.Builder()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
20 builder.add_from_file(fname)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
21
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
22 main_win = builder.get_object("FSM_main_win")
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
23 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
24 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
25 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
26
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
27 state_editor = builder.get_object("state_editor")
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
28 state_name = builder.get_object('state_name')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
29 state_radius = builder.get_object('state_radius')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
30
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
31 error_dialog = builder.get_object('error_dialog')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
32 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
33
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
34 builder.connect_signals(self)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
35
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
36 self._builder = builder
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
37 self._main_win = main_win
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
38 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
39 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
40 self._move_state_button = move_state_button
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
41
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
42 self._state_editor = state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
43 self._state_name = state_name
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
44 self._state_radius = state_radius
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
45
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
46 self._error_dialog = error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
47 self._error_dialog_label = error_dialog_label
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
48 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
49
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
50 def show_error(self, msg):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
51 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
52 error_dialog_label = self._error_dialog_label
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
53
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
54 error_dialog_label.set_text(msg)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
55 error_dialog.show()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
56 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
57
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
58 def hide_error(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
59 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
60 error_dialog.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
61 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
62
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
63 def show_state_editor(self, state_name=''):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
64 state_name_inp = self._state_name
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
65 state_radius_inp = self._state_radius
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
66 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
67
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
68 state_name_inp.set_text(state_name)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
69 state_radius_inp.set_text('30')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
70 state_editor.show()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
71 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
72
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
73 def hide_state_editor(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
74 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
75 state_editor.hide()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
76 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
77
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
78 def show(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
79 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
80 self._add_state_button.set_active(True)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
81 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
82
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
83 def hide(self):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
84 self._main_win.hide()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
85 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
86
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
87 def gtk_widget_hide(self, widget, event, *data):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
88 widget.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
89 return True
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
90
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
91 def on_start_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
92 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
93
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
94 def on_rename_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
95 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
96
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
97 def on_remove_state_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
98 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
99
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
100 def on_zoom_out_clicked(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
101 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
102
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
103 def on_zoom_in_clicked(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
104 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
105
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
106 def on_move_state_toggled(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
107 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
108
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
109 def on_add_state_toggled(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
110 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
111
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
112 def on_close_window_activate(self, *args):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
113 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
114
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
115 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
116 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
117
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
118 def on_state_apply_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
119 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
120
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
121 def on_state_cancel_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
122 state_editor = self._state_editor
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
123 state_editor.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
124 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
125
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
126 def on_error_dialog_ok_clicked(self, *args):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
127 error_dialog = self._error_dialog
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
128 error_dialog.hide()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
129 pass
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
130 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
131
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
132 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
133 _doc = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
134 _domview = None
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
135 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
136 _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
137 _state = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
138 trn_cond = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
139 trn_g = None
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
140 _arrow_node = None
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
141 _path_node = None
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
142
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
143 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
144 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
145 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
146
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
147 def init(self, doc, domview, state, 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
148 self._doc = doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
149 self._domview = domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
150 self._state = state
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
151 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
152 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
153 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
154
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
155 @staticmethod
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
156 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
157 import math
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
158
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
159 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
160 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
161 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
162 'fill: none')
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
163
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
164 # 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 -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
173 -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
174 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
175 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
176 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
177 'fill: #000000')
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
178 pass
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
179
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
180 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
181 doc = self._doc
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
182
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
183 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
184
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
185 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
186 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
187 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
188
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
189 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
190 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
191
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
192 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
193
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
194 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
195
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
196 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
197 def path(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
198 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
199 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
200 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
201 trn = domview.get_transition(state_name, trn_cond)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
202 return trn[3]
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
203
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
204 @property
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
205 def target(self):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
206 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
207 state_name = self._state.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
208 trn_cond = self.trn_cond
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
209 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
210 return trn[1]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
211
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
212 def draw(self, parent):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
213 path = self.path
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
214 trn_g, arrow_node, path_node = self._draw_transition_real(parent, path)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
215 self.trn_g = trn_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
216 self._arrow_node = arrow_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
217 self._path_node = path_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
218 pass
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
219
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
220 def clear(self):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
221 trn_g = self.trn_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
222 parent = trn_g.parent()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
223 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
224 pass
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
225
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
226 def update(self):
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
227 path = self.path
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
228 arrow_node = self._arrow_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
229 path_node = self._path_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
230 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
231 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
232
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
233 def adjust_by_ends(self, states):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
234 import math
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
235
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
236 state = self._state
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
237 state_name = state.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
238 trn_cond = self.trn_cond
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
239
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
240 path = self.path
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
241
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
242 start_state = self._state
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
243 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
244 start_r = start_state.r
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
245
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
246 target_name = self.target
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
247 stop_state = states[target_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
248 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
249 stop_r = stop_state.r
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
250
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
251 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
252
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
253 c0c1 = (c1x - c0x, c1y - c0y)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
254 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
255 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
256
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
257 c3c2 = (c2x - c3x, c2y - c3y)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
258 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
259 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
260
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
261 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
262 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
263 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
264 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
265 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
266 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
267 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
268 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
269 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
270
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
271 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
272 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
273 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
274 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
275
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
276 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
277 _doc = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
278 _domview = None
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
279 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
280 _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
281 state_name = None
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
282 state_g = None
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
283 _text_node = None
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
284 _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
285 transitions = None
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
286 from_states = None
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
287
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
288 _state_g_hdl_id = None
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
289 _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
290
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
291 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
292 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
293 self.transitions = {}
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
294 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
295 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
296
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
297 def init(self, doc, domview, 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
298 self._doc = doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
299 self._domview = domview
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
300 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
301 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
302 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
303
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
304 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
305 state_name, r, x, y):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
306 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
307 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
308 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
309 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
310 'fill: #ffffff')
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
311
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
312 text_node.setAttribute('style', 'stroke: #000000; fill: #000000; font-size: 16px')
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
313
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
314 text_content.setContent(state_name)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
315
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
316 doc = self._doc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
317 spdoc = doc.spdoc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
318 spdoc.ensureUpToDate()
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
319 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
320 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
321 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
322 pass
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
323
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
324 def grab(self, callback):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
325 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
326
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
327 state_g = self.state_g
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
328 state_g_spitem = state_g.spitem
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
329 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
330 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
331 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
332
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
333 def ungrab(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
334 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
335 return
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
336 state_g = self.state_g
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
337 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
338 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
339 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
340
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
341 def _translate_page_xy(self, x, y):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
342 doc = self._doc
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
343 root = doc.root()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
344 page_h_txt = root.getAttribute('height')
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
345 page_h = float(page_h_txt)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
346 svgx = x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
347 svgy = page_h - y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
348 return svgx, svgy
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
349
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
350 def show_selected(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
351 if not self._selected_rect:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
352 doc = self._doc
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
353 rect = doc.createElement('svg:rect')
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
354 control_layer = self._control_layer
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
355 rect.setAttribute('style',
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
356 'stroke: #404040; stroke-width: 1; '
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
357 '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
358 control_layer.appendChild(rect)
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
359 self._selected_rect = rect
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
360 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
361
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
362 state_g = self.state_g
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
363 rect = self._selected_rect
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
364
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
365 px, py, pw, ph = state_g.getBBox()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
366 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
367 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
368
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
369 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
370 rect.setAttribute('y', str(y - 2))
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
371 rect.setAttribute('width', str(pw + 4))
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
372 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
373 pass
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
374
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
375 def hide_selected(self):
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
376 if not self._selected_rect:
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
377 return
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
378
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
379 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
380 rect = self._selected_rect
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
381 control_layer.removeChild(rect)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
382 self._selected_rect = None
1480
e11ffd5fd609 functions for showing selected control for state
Thinker K.F. Li <thinker@codemud.net>
parents: 1479
diff changeset
383 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
384
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
385 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
386 doc = self._doc
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
387
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
388 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
389
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
390 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
391 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
392 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
393
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
394 text.appendChild(text_content)
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
395 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
396 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
397 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
398
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
399 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
400
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
401 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
402
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
403 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
404 def r(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
405 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
406 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
407 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
408 return r
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
409
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
410 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
411 def xy(self):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
412 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
413 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
414 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
415 return xy
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
416
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
417 @property
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
418 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
419 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
420 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
421 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
422 return conds
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
423
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
424 def draw(self, parent):
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
425 domview = self._domview
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
426 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
427
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
428 r = self.r
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
429 x, y = self.xy
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
430 state_g, text_node, text_content, circle_node = \
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
431 self._draw_state_real(parent, state_name, r, x, y)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
432 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
433 self._text_node = text_node
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
434 self._text_content = text_content
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
435 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
436
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
437 for trn_cond in self.all_transitions:
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
438 trn = FSM_transition(trn_cond)
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
439 trn.init(self._doc, domview, self,
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
440 self._fsm_layer, self._control_layer)
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
441 trn.draw(parent)
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
442 self.transitions[trn_cond] = trn
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
443 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
444 pass
1473
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
445
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
446 def clear(self):
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
447 state_g = self.state_g
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
448 parent = state_g.parent()
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
449 parent.removeChild(state_g)
e807ad5aeb91 Extract update_graph for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1472
diff changeset
450 pass
1474
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
451
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
452 def update(self):
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
453 text_node = self._text_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
454 text_content = self._text_content
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
455 circle_node = self._circle_node
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
456 state_name = self.state_name
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
457 r = self.r
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
458 x, y = self.xy
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
459 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
460 r, x, y)
697ebfa9dc47 Update state and transition from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1473
diff changeset
461 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
462
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
463 def tell_target_states(self, states):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
464 transitions = self.transitions
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
465 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
466 target_states = [states[target_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
467 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
468 state_name = self.state_name
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
469 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
470 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
471 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
472 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
473
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
474 def adjust_transitions(self, states):
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
475 import itertools
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
476
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
477 for trn in self.transitions.values():
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
478 trn.adjust_by_ends(states)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
479 trn.update()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
480 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
481
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
482 state_name = self.state_name
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
483 from_states = [states[from_state_name]
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
484 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
485 states_transitions = [state.transitions.values()
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
486 for state in from_states]
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
487 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
488 if trn.target == state_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
489 for state_transitions in states_transitions]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
490 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
491 for trn in in_transitions:
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
492 trn.adjust_by_ends(states)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
493 trn.update()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
494 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
495 pass
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
496 pass
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
497
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
498
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
499 class _FSM_move_state_mode(object):
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
500 __metaclass__ = data_monitor.data_monitor
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
501 __data_monitor_prefix__ = 'on_'
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
502
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
503 _window = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
504 _selected_state = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
505
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
506 def __init__(self, window, domview_ui):
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
507 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
508
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
509 self._window = window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
510 self._domview = domview_ui
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
511 self._locker = domview_ui
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
512 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
513
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
514 def on_move_state_background(self, item, evtype, buttons, x, y):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
515 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
516
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
517 def _select_state(self, state):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
518 if self._selected_state:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
519 self._selected_state.hide_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
520 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
521 self._selected_state = state
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
522 state.show_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
523 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
524
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
525 def _clear_select(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
526 if self._selected_state:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
527 self._selected_state.hide_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
528 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
529 self._selected_state = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
530 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
531
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
532 def handle_move_state_state(self, state, evtype, buttons, x, y):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
533 import pybInkscape
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
534
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
535 window = self._window
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
536 states = window._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
537
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
538 def moving_state(item, evtype, buttons, x, y):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
539 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
540 window.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
541 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
542 new_state_x = orign_state_x + start_x - x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
543 new_state_y = orign_state_y + start_y - y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
544
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
545 domview = self._domview
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
546 domview.set_state_xy(state.state_name, x, y)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
547 state.update()
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
548 state.adjust_transitions(states)
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
549 state.show_selected()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
550 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
551
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
552 window = self._window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
553
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
554 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
555 start_x = x
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
556 start_y = y
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
557 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
558
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
559 self._select_state(state)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
560 window.grab_mouse(moving_state)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
561 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
562
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
563 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
564 window.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
565 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
566 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
567
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
568 def activate(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
569 window = self._window
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
570 window._emit_leave_mode()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
571 window._clear_leave_mode_cb()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
572 window.ungrab_all()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
573
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
574 window.grab_bg(self.on_move_state_background)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
575 window.grab_state(self.handle_move_state_state)
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
576 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
577
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
578 def deactivate(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
579 if self._selected_state:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
580 self._clear_select()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
581 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
582 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
583 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
584
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
585
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
586 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
587 __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
588 __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
589
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
590 _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
591 _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
592
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
593 def __init__(self, window, domview_ui):
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
594 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
595
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
596 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
597 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
598 self._locker = domview_ui
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
599 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
600
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
601 def handle_new_state(self):
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
602 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
603
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
604 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
605 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
606 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
607
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
608 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
609 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
610 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
611 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
612 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
613 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
614 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
615 '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
616 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
617
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
618 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
619 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
620 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
621 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
622 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
623 (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
624 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
625 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
626 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
627
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
628 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
629
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
630 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
631 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
632
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
633 def on_add_state_background(self, item, evtype, buttons, 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
634 import pybInkscape
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
635
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
636 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
637
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
638 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE and \
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
639 buttons == 1:
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
640 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
641 self._saved_y = y
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
642 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
643 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
644 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
645
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
646 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
647 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
648
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
649 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
650 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
651
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
652 window.grab_bg(self.on_add_state_background)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
653 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
654
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
655 def deactivate(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
656 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
657 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
658
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
659 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
660 __metaclass__ = data_monitor.data_monitor
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
661 __data_monitor_prefix__ = 'on_'
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
662
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
663 _background = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
664 _fsm_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
665 _control_layer = None
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
666 width = 1024
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
667 height = 768
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
668
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
669 _grab_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
670 _bg_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
671
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
672 _leave_mode_cb = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
673 _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
674 _add_state_mode = None
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
675 _state_mouse_event_handler = None
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
676
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
677 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
678 super(FSM_window, self).__init__()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
679
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
680 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
681
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
682 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
683 self._states = {}
1458
59b90d7fcf57 Lock UI event handlers for FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1457
diff changeset
684
1457
416a18409603 Show an empty document in SVG viewer widget
Thinker K.F. Li <thinker@codemud.net>
parents: 1456
diff changeset
685 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
686 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
687
1487
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
688 self._move_state_mode = _FSM_move_state_mode(self, domview_ui)
3aba29609607 Rename state modes
Thinker K.F. Li <thinker@codemud.net>
parents: 1486
diff changeset
689 self._add_state_mode = _FSM_add_state_mode(self, domview_ui)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
690 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
691
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
692 def _init_layers(self):
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
693 doc = self._doc()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
694 root = self._root()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
695
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
696 root.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
697
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
698 background = doc.createElement('svg:rect')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
699 background.setAttribute('x', '0')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
700 background.setAttribute('y', '0')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
701 background.setAttribute('width', str(self.width))
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
702 background.setAttribute('height', str(self.height))
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
703 background.setAttribute('style', 'fill: #ffffff')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
704 root.appendChild(background)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
705 self._background = background
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
706
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
707 fsm_layer = doc.createElement('svg:g')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
708 fsm_layer.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
709 root.appendChild(fsm_layer)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
710 self._fsm_layer = fsm_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
711
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
712 control_layer = doc.createElement('svg:g')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
713 control_layer.setAttribute('inkscape:groupmode', 'layer')
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
714 root.appendChild(control_layer)
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
715 self._control_layer = control_layer
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
716 pass
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
717
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
718 def _doc(self):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
719 view_widget = self._view_widget
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
720 view = view_widget.view
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
721 doc = view.doc().rdoc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
722 return doc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
723
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
724 def _root(self):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
725 doc = self._doc()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
726 root = doc.root()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
727 return root
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
728
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
729 def _translate_xy(self, x, y):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
730 return x, y
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
731
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
732 def _clear_view(self):
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
733 if not self._background:
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
734 self._init_layers()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
735 return
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
736
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
737 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
738 [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
739 for child in children:
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
740 parent = child.parent()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
741 parent.removeChild(child)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
742 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
743
1472
7cb7abb5063b Refactory drawing functions into classes for state and transition
Thinker K.F. Li <thinker@codemud.net>
parents: 1471
diff changeset
744 self._states = {}
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
745 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
746
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
747 def _draw_state_domview(self, state_name):
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
748 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
749 doc = self._doc()
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
750 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
751
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
752 state = FSM_state(state_name)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
753 state.init(doc, domview, self._fsm_layer, self._control_layer)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
754 self._states[state_name] = state
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
755
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
756 state.draw(fsm_layer)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
757 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
758
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
759 def _set_leave_mode_cb(self, callback):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
760 self._leave_mode_cb = callback
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
761 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
762
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
763 def _clear_leave_mode_cb(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
764 self._leave_mode_cb = None
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
765 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
766
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
767 def _emit_leave_mode(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
768 if self._leave_mode_cb:
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
769 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
770 self._leave_mode_cb = None
1482
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
771 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
772 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
773
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
774 def ungrab_all(self):
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
775 self.ungrab_bg()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
776 self.ungrab_mouse()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
777 self.ungrab_state()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
778 pass
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
779
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
780 def on_state_mouse_event(self, state, evtype, buttons, x, y):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
781 if self._state_mouse_event_handler:
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
782 self._state_mouse_event_handler(state, evtype, buttons, x, y)
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
783 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
784 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
785
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
786 def _install_state_event_handler(self, state):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
787 def mouse_event_handler(item, evtype, buttons, x, y):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
788 self.on_state_mouse_event(state, evtype, buttons, x, y)
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
789 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
790 state.grab(mouse_event_handler)
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
791 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
792
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
793 def grab_state(self, callback):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
794 assert self._state_mouse_event_handler is None
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
795 self._state_mouse_event_handler = callback
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
796 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
797
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
798 def ungrab_state(self):
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
799 self._state_mouse_event_handler = None
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
800 pass
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
801
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
802 def _load_new_state(self, state_name):
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
803 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
804
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
805 self._draw_state_domview(state_name)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
806 state = states[state_name]
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
807 self._install_state_event_handler(state)
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
808 pass
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
809
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
810 ## \brief Load new state incrementally.
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
811 #
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
812 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
813 self._load_new_state(state_name)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
814 states = self._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
815 state = states[state_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
816 state.tell_target_states(states)
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
817 pass
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
818
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
819 def _rebuild_from_states(self):
1484
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
820 states = self._states
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
821 domview = self._domview
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
822 state_names = domview.all_state_names()
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
823 for state_name in state_names:
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
824 state = states[state_name]
aa4137f3141e Transition will follow the moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1483
diff changeset
825 state.tell_target_states(states)
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
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
828
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
829 def _update_view(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
830 self._clear_view()
1481
28ab64f8581e Moving state
Thinker K.F. Li <thinker@codemud.net>
parents: 1480
diff changeset
831 states = self._states
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
832
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
833 domview = self._domview
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
834
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
835 state_names = domview.all_state_names()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
836 for state_name in state_names:
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
837 self._load_new_state(state_name)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
838 pass
1485
20cf6ea263c6 Rename from_srcs to from_states
Thinker K.F. Li <thinker@codemud.net>
parents: 1484
diff changeset
839 self._rebuild_from_states()
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
840 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
841
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
842 def set_svg_view(self, view):
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
843 self._view_box.add(view)
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
844 self._view_widget = view
1479
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
845
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
846 root = self._root()
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
847 root.setAttribute('width', '1024')
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
848 root.setAttribute('height', '768')
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
849 view.setResize(True, 800, 600)
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
850 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
851
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
852 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
853 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
854 self._close_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
855 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
856
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
857 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
858 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
859 self._destroy_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
860 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
861
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
862 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
863 self._emit_leave_mode()
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
864 self._destroy_cb()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
865 pass
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
866
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
867 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
868 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
869 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
870 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
871 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
872
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
873 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
874 mode = self._move_state_mode
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
875 mode.activate()
3a671e79429a Hide/show selection for states
Thinker K.F. Li <thinker@codemud.net>
parents: 1481
diff changeset
876 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
877 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
878
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
879 def on_state_apply_clicked(self, *args):
1483
9df6ed043b87 Move code for add state mode to FSM_add_state_mode class
Thinker K.F. Li <thinker@codemud.net>
parents: 1482
diff changeset
880 self._add_state_mode.handle_new_state()
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
881 pass
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
882
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
883 def _install_test_data(self):
1476
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
884 self._init_layers()
eddec4543761 Install layers for FSM_window.
Thinker K.F. Li <thinker@codemud.net>
parents: 1475
diff changeset
885
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
886 domview = self._domview
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
887
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
888 view = self._view_widget.view
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
889 doc = view.doc()
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
890 rdoc = doc.rdoc
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
891 root_node = doc.root().repr
1479
92a8497d0361 Make FSM editor scrollable
Thinker K.F. Li <thinker@codemud.net>
parents: 1478
diff changeset
892
1469
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
893 line_node = rdoc.createElement('svg:line')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
894 line_node.setAttribute('x1', '10')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
895 line_node.setAttribute('y1', '10')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
896 line_node.setAttribute('x2', '100')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
897 line_node.setAttribute('y2', '100')
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
898 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
899
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
900 root_node.appendChild(line_node)
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
901
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
902 def show_msg(*args, **kws):
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
903 print 'mouse_event'
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
904 print args
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
905 pass
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
906 print 'before connect'
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
907 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
908 print hdl_id
c1e70540541c Drawing functions for states and transitions
Thinker K.F. Li <thinker@codemud.net>
parents: 1467
diff changeset
909
1471
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
910 state1 = 'state 1'
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
911 domview.add_state(state1)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
912 domview.set_state_r(state1, 50)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
913 domview.set_state_xy(state1, 200, 100)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
914 state2 = 'state 2'
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
915 domview.add_state(state2)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
916 domview.set_state_r(state2, 30)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
917 domview.set_state_xy(state2, 300, 100)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
918 domview.add_transition(state1, 'event1', state2)
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
919 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
920 240, 180,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
921 260, 180,
055845649807 Update FSM_window from domview
Thinker K.F. Li <thinker@codemud.net>
parents: 1469
diff changeset
922 300, 130))
1467
6927debad4ee Fix issue and a simple testcase for FSM
Thinker K.F. Li <thinker@codemud.net>
parents: 1458
diff changeset
923 pass
1475
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
924
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
925 def show(self):
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
926 self._install_test_data()
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
927 self._install_test_data = lambda: None
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
928 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
929 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
930 super(FSM_window, self).show()
8c6078c17f2d Install test data when show FSM_window
Thinker K.F. Li <thinker@codemud.net>
parents: 1474
diff changeset
931 pass
1478
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
932
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
933 def grab_mouse(self, callback):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
934 assert self._grab_hdl is None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
935
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
936 root = self._root()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
937 root.setAttribute('inkscape:groupmode', '')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
938 self._grab_hdl = root.spitem.connect('mouse-event', callback)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
939 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
940
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
941 def ungrab_mouse(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
942 if not self._grab_hdl:
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
943 return
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
944
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
945 root = self._root()
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
946 root.spitem.disconnect(self._grab_hdl)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
947 self._grab_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
948 root.setAttribute('inkscape:groupmode', 'layer')
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
949 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
950
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
951 def grab_bg(self, callback):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
952 assert self._bg_hdl is None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
953 assert self._background
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
954
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
955 background = self._background
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
956 bg_hdl = background.spitem.connect('mouse-event', callback)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
957 self._bg_hdl = bg_hdl
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
958 pass
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
959
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
960 def ungrab_bg(self):
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
961 if not self._bg_hdl:
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
962 return
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
963
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
964 background = self._background
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
965 bg_hdl = self._bg_hdl
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
966 background.spitem.disconnect(bg_hdl)
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
967 self._bg_hdl = None
6fe773e62b2a Add state to FSM.
Thinker K.F. Li <thinker@codemud.net>
parents: 1476
diff changeset
968 pass
1456
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
969 pass
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
970
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
971 if __name__ == '__main__':
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
972 win = FSM_window()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
973 win._main_win.connect('destroy', gtk.main_quit)
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
974 win.show()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
975 gtk.main()
894a4bf35fe6 Start implement FSM editor window
Thinker K.F. Li <thinker@codemud.net>
parents:
diff changeset
976 pass