annotate pyink/FSM_window.py @ 1525:701a568f6949

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