Mercurial > MadButterfly
comparison pyink/FSM_window.py @ 1481:28ab64f8581e
Moving state
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 29 Apr 2011 01:27:47 +0800 |
parents | e11ffd5fd609 |
children | 3a671e79429a |
comparison
equal
deleted
inserted
replaced
1480:e11ffd5fd609 | 1481:28ab64f8581e |
---|---|
250 circle_node.setAttribute('cx', str(x)) | 250 circle_node.setAttribute('cx', str(x)) |
251 circle_node.setAttribute('cy', str(y)) | 251 circle_node.setAttribute('cy', str(y)) |
252 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; ' | 252 circle_node.setAttribute('style', 'stroke: #000000; stroke-width: 1; ' |
253 'fill: #ffffff') | 253 'fill: #ffffff') |
254 | 254 |
255 text_node.setAttribute('style', 'stroke: #000000; fill: #000000; font-size: 16px; font-style: normal; font-family: helvetica;') | 255 text_node.setAttribute('style', 'stroke: #000000; fill: #000000; font-size: 16px') |
256 | 256 |
257 text_content.setContent(state_name) | 257 text_content.setContent(state_name) |
258 | 258 |
259 doc = self._doc | 259 doc = self._doc |
260 spdoc = doc.spdoc | 260 spdoc = doc.spdoc |
266 | 266 |
267 def grab(self, callback): | 267 def grab(self, callback): |
268 assert not self._state_g_hdl_id | 268 assert not self._state_g_hdl_id |
269 | 269 |
270 state_g = self.state_g | 270 state_g = self.state_g |
271 state_g_hdl_id = state_g.connect('mouse-event', callback) | 271 state_g_spitem = state_g.spitem |
272 state_g_hdl_id = state_g_spitem.connect('mouse-event', callback) | |
272 self._state_g_hdl_id = state_g_hdl_id | 273 self._state_g_hdl_id = state_g_hdl_id |
273 pass | 274 pass |
274 | 275 |
275 def ungrab(self): | 276 def ungrab(self): |
276 if not self._state_g_hdl: | 277 if not self._state_g_hdl: |
383 text_content = self._text_content | 384 text_content = self._text_content |
384 circle_node = self._circle_node | 385 circle_node = self._circle_node |
385 state_name = self.state_name | 386 state_name = self.state_name |
386 r = self.r | 387 r = self.r |
387 x, y = self.xy | 388 x, y = self.xy |
388 self._update_graph(text_node, text_content, circle_node, | 389 self._update_graph(text_node, text_content, circle_node, state_name, |
389 r, x, y) | 390 r, x, y) |
390 pass | 391 pass |
391 pass | 392 pass |
392 | 393 |
393 class FSM_window(FSM_window_base): | 394 class FSM_window(FSM_window_base): |
403 _grab_hdl = None | 404 _grab_hdl = None |
404 _bg_hdl = None | 405 _bg_hdl = None |
405 | 406 |
406 _saved_x = 0 | 407 _saved_x = 0 |
407 _saved_y = 0 | 408 _saved_y = 0 |
409 | |
410 _state_mouse_event_handler = None | |
408 | 411 |
409 def __init__(self, domview_ui, close_cb, destroy_cb): | 412 def __init__(self, domview_ui, close_cb, destroy_cb): |
410 super(FSM_window, self).__init__() | 413 super(FSM_window, self).__init__() |
411 | 414 |
412 self._locker = domview_ui | 415 self._locker = domview_ui |
485 self._states[state_name] = state | 488 self._states[state_name] = state |
486 | 489 |
487 state.draw(fsm_layer) | 490 state.draw(fsm_layer) |
488 pass | 491 pass |
489 | 492 |
493 def on_state_mouse_event(self, state, evtype, buttons, x, y): | |
494 if self._state_mouse_event_handler: | |
495 self._state_mouse_event_handler(state, evtype, buttons, x, y) | |
496 pass | |
497 pass | |
498 | |
499 def _install_state_event_handler(self, state): | |
500 def mouse_event_handler(item, evtype, buttons, x, y): | |
501 self.on_state_mouse_event(state, evtype, buttons, x, y) | |
502 pass | |
503 state.grab(mouse_event_handler) | |
504 pass | |
505 | |
506 def grab_state(self, callback): | |
507 assert self._state_mouse_event_handler is None | |
508 self._state_mouse_event_handler = callback | |
509 pass | |
510 | |
511 def ungrab_state(self): | |
512 self._state_mouse_event_handler = None | |
513 pass | |
514 | |
490 def _update_view(self): | 515 def _update_view(self): |
491 self._clear_view() | 516 self._clear_view() |
517 states = self._states | |
492 | 518 |
493 domview = self._domview | 519 domview = self._domview |
494 | 520 |
495 state_names = domview.all_state_names() | 521 state_names = domview.all_state_names() |
496 for state_name in state_names: | 522 for state_name in state_names: |
497 self._draw_state_domview(state_name) | 523 self._draw_state_domview(state_name) |
524 state = states[state_name] | |
525 self._install_state_event_handler(state) | |
498 pass | 526 pass |
499 pass | 527 pass |
500 | 528 |
501 def set_svg_view(self, view): | 529 def set_svg_view(self, view): |
502 self._view_box.add(view) | 530 self._view_box.add(view) |
526 pass | 554 pass |
527 | 555 |
528 def on_move_state_toggled(self, *args): | 556 def on_move_state_toggled(self, *args): |
529 self.ungrab_bg() | 557 self.ungrab_bg() |
530 self.grab_bg(self.on_move_state_background) | 558 self.grab_bg(self.on_move_state_background) |
559 self.ungrab_state() | |
560 self.grab_state(self.handle_move_state_state) | |
531 pass | 561 pass |
532 | 562 |
533 def on_add_state_background(self, item, evtype, buttons, x, y): | 563 def on_add_state_background(self, item, evtype, buttons, x, y): |
534 import pybInkscape | 564 import pybInkscape |
535 | 565 |
540 self.show_state_editor() | 570 self.show_state_editor() |
541 pass | 571 pass |
542 pass | 572 pass |
543 | 573 |
544 def on_move_state_background(self, item, evtype, buttons, x, y): | 574 def on_move_state_background(self, item, evtype, buttons, x, y): |
575 pass | |
576 | |
577 def handle_move_state_state(self, state, evtype, buttons, x, y): | |
578 import pybInkscape | |
579 | |
580 def moving_state(item, evtype, buttons, x, y): | |
581 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_RELEASE: | |
582 self.ungrab_mouse() | |
583 pass | |
584 new_state_x = orign_state_x + start_x - x | |
585 new_state_y = orign_state_y + start_y - y | |
586 | |
587 domview = self._domview | |
588 domview.set_state_xy(state.state_name, x, y) | |
589 state.update() | |
590 state.show_selected() | |
591 pass | |
592 | |
593 if evtype == pybInkscape.PYSPItem.PYB_EVENT_BUTTON_PRESS: | |
594 start_x = x | |
595 start_y = y | |
596 orign_state_x, orign_state_y = state.xy | |
597 | |
598 state.show_selected() | |
599 | |
600 self.grab_mouse(moving_state) | |
601 pass | |
545 pass | 602 pass |
546 | 603 |
547 def on_state_apply_clicked(self, *args): | 604 def on_state_apply_clicked(self, *args): |
548 import traceback | 605 import traceback |
549 | 606 |