comparison pyink/FSM_window.py @ 1480:e11ffd5fd609

functions for showing selected control for state
author Thinker K.F. Li <thinker@codemud.net>
date Thu, 28 Apr 2011 01:11:15 +0800
parents 92a8497d0361
children 28ab64f8581e
comparison
equal deleted inserted replaced
1479:92a8497d0361 1480:e11ffd5fd609
226 state_name = None 226 state_name = None
227 state_g = None 227 state_g = None
228 _text_node = None 228 _text_node = None
229 _circle_node = None 229 _circle_node = None
230 transitions = None 230 transitions = None
231
232 _state_g_hdl_id = None
233 _selected_rect = None
231 234
232 def __init__(self, state_name): 235 def __init__(self, state_name):
233 self.state_name = state_name 236 self.state_name = state_name
234 self.transitions = {} 237 self.transitions = {}
235 pass 238 pass
239 self._domview = domview 242 self._domview = domview
240 self._fsm_layer = fsm_layer 243 self._fsm_layer = fsm_layer
241 self._control_layer = control_layer 244 self._control_layer = control_layer
242 pass 245 pass
243 246
244 @staticmethod 247 def _update_graph(self, text_node, text_content, circle_node,
245 def _update_graph(text_node, text_content, circle_node,
246 state_name, r, x, y): 248 state_name, r, x, y):
247 circle_node.setAttribute('r', str(r)) 249 circle_node.setAttribute('r', str(r))
248 circle_node.setAttribute('cx', str(x)) 250 circle_node.setAttribute('cx', str(x))
249 circle_node.setAttribute('cy', str(y)) 251 circle_node.setAttribute('cy', str(y))
250 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; ' 252 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; '
251 'fill: #ffffff') 253 'fill: #ffffff')
252 254
253 text_node.setAttribute('font-size', '16') 255 text_node.setAttribute('style', 'stroke: #000000; fill: #000000; font-size: 16px; font-style: normal; font-family: helvetica;')
254 text_node.setAttribute('style', 'stroke: #000000; fill: #000000')
255 256
256 text_content.setContent(state_name) 257 text_content.setContent(state_name)
257 258
259 doc = self._doc
260 spdoc = doc.spdoc
261 spdoc.ensureUpToDate()
258 tx, ty, tw, th = text_node.getBBox() 262 tx, ty, tw, th = text_node.getBBox()
259 text_node.setAttribute('x', str(x - tw / 2)) 263 text_node.setAttribute('x', str(x - tw / 2))
260 text_node.setAttribute('y', str(y + th / 2)) 264 text_node.setAttribute('y', str(y + th / 2))
265 pass
266
267 def grab(self, callback):
268 assert not self._state_g_hdl_id
269
270 state_g = self.state_g
271 state_g_hdl_id = state_g.connect('mouse-event', callback)
272 self._state_g_hdl_id = state_g_hdl_id
273 pass
274
275 def ungrab(self):
276 if not self._state_g_hdl:
277 return
278 state_g = self.state_g
279 state_g_hdl_id = self._state_g_hdl_id
280 state_g.disconnect(state_g_hdl_id)
281 pass
282
283 def show_selected(self):
284 if not self._selected_rect:
285 doc = self._doc
286 rect = doc.createElement('svg:rect')
287 control_layer = self._control_layer
288 rect.setAttribute('style',
289 'stroke: #404040; stroke-width: 1; '
290 'stroke-dasharray: 5 3; fill: none')
291 control_layer.appendChild(rect)
292 self._selected_rect = rect
293 pass
294
295 state_g = self.state_g
296 rect = self._selected_rect
297
298 x, y, w, h = state_g.getBBox()
299 rect.setAttribute('x', str(x - 2))
300 rect.setAttribute('y', str(y - 2))
301 rect.setAttribute('width', str(w + 4))
302 rect.setAttribute('height', str(h + 4))
303 pass
304
305 def hide_selected(self):
306 if not self._selected_rect:
307 return
308
309 state_g = self.state_g
310 rect = self._selected_rect
311 state_g.removeChild(rect)
261 pass 312 pass
262 313
263 def _draw_state_real(self, parent, state_name, r, x, y): 314 def _draw_state_real(self, parent, state_name, r, x, y):
264 doc = self._doc 315 doc = self._doc
265 316