Package Gnumed :: Package timelinelib :: Package wxgui :: Package components :: Package maincanvas :: Module noop
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.components.maincanvas.noop

  1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  Rickard Lindberg, Roger Lindberg 
  2  # 
  3  # This file is part of Timeline. 
  4  # 
  5  # Timeline is free software: you can redistribute it and/or modify 
  6  # it under the terms of the GNU General Public License as published by 
  7  # the Free Software Foundation, either version 3 of the License, or 
  8  # (at your option) any later version. 
  9  # 
 10  # Timeline is distributed in the hope that it will be useful, 
 11  # but WITHOUT ANY WARRANTY; without even the implied warranty of 
 12  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 13  # GNU General Public License for more details. 
 14  # 
 15  # You should have received a copy of the GNU General Public License 
 16  # along with Timeline.  If not, see <http://www.gnu.org/licenses/>. 
 17   
 18   
 19  from timelinelib.wxgui.components.maincanvas.inputhandler import InputHandler 
 20  from timelinelib.general.methodcontainer import MethodContainer 
 21  from timelinelib.wxgui.keyboard import Keyboard 
 22   
 23   
 24  """ 
 25  A NoOpInputHandler gets messages about the start of a user input, such as a 
 26  mouse move action, and delegates the workload to fulfill the user action, to 
 27  another event handler 
 28  """ 
 29   
 30   
31 -class NoOpInputHandler(InputHandler):
32
33 - def __init__(self, state, timeline_canvas):
34 InputHandler.__init__(self, timeline_canvas) 35 self._state = state
36
37 - def left_mouse_down(self, cursor, keyboard):
38 39 def toggle_balloon_stickyness(): 40 event_with_balloon = self._canvas.GetBalloonAt(cursor) 41 if event_with_balloon: 42 self._canvas.toggle_balloon_stickyness(event_with_balloon)
43 44 def event_at_cursor(): 45 return self._canvas.GetEventAt(cursor, keyboard.alt)
46 47 toggle_balloon_stickyness() 48 event = event_at_cursor() 49 if event: 50 self._left_mouse_down_on_event(self._state, event, cursor, keyboard) 51 else: 52 self._left_mouse_down_on_timeline(self._state, cursor, keyboard) 53
54 - def _left_mouse_down_on_event(self, state, event, cursor, keyboard):
55 56 def hit_resize_handle(): 57 return self._canvas.hit_resize_handle(cursor, keyboard)
58 59 def is_resize_command(): 60 return hit_resize_handle() is not None 61 62 def hit_move_handle(): 63 return self._canvas.hit_move_handle(cursor, keyboard) 64 65 def is_move_command(): 66 if event.get_ends_today(): 67 return False 68 else: 69 return hit_move_handle() 70 71 def start_event_action(action_method, action_arg): 72 if state.ok_to_edit(): 73 try: 74 action_method(event, action_arg) 75 except: 76 state.edit_ends() 77 raise 78 79 def resize_event(): 80 start_event_action(state.change_to_resize_by_drag, hit_resize_handle()) 81 82 def move_event(): 83 start_event_action(state.change_to_move_by_drag, self._canvas.GetTimeAt(cursor.x)) 84 85 def toggle_event_selection(): 86 self._canvas.toggle_event_selection(cursor, keyboard) 87 88 methods = MethodContainer( 89 [ 90 (is_resize_command(), resize_event), 91 (is_move_command(), move_event) 92 ], 93 default_method=toggle_event_selection) 94 methods.select(True)() 95
96 - def _left_mouse_down_on_timeline(self, state, cursor, keyboard):
97 98 def scroll(): 99 state.change_to_scroll_by_drag(cursor)
100 101 def create_event(): 102 self._canvas.ClearSelectedEvents() 103 state.change_to_create_period_event_by_drag(cursor) 104 105 def zoom(): 106 self._canvas.ClearSelectedEvents() 107 state.change_to_zoom_by_drag(cursor) 108 109 def select(): 110 state.change_to_select(cursor) 111 112 methods = MethodContainer( 113 [ 114 (Keyboard.NONE, scroll), 115 (Keyboard.SHIFT, zoom), 116 (Keyboard.CTRL, create_event), 117 (Keyboard.SHIFT | Keyboard.CTRL, select), 118 ]) 119 methods.select(keyboard.keys_combination)() 120