Package Gnumed :: Package timelinelib :: Package view :: Module noop
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.view.noop

  1  # Copyright (C) 2009, 2010, 2011  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  import wx 
 20   
 21  from timelinelib.view.inputhandler import InputHandler 
 22   
 23   
 24  # Used by Sizer and Mover classes to detect when to go into action 
 25  HIT_REGION_PX_WITH = 5 
 26   
 27   
28 -class NoOpInputHandler(InputHandler):
29
30 - def __init__(self, drawing_area, drawing_area_view):
31 self.drawing_area = drawing_area 32 self.drawing_area_view = drawing_area_view 33 self.drawer = drawing_area.drawing_algorithm 34 self.view_properties = drawing_area.view_properties 35 self.show_timer_running = False 36 self.hide_timer_running = False 37 self.last_hovered_event = None 38 self.last_hovered_balloon_event = None
39
40 - def left_mouse_down(self, x, y, ctrl_down, shift_down, alt_down=False):
41 self._toggle_balloon_stickyness(x, y) 42 event = self.drawing_area.event_at(x, y, alt_down) 43 time_at_x = self.drawing_area.get_time(x) 44 if self._hit_resize_handle(x, y, alt_down) is not None: 45 direction = self._hit_resize_handle(x, y, alt_down) 46 self.drawing_area.change_input_handler_to_resize_by_drag(event, direction) 47 return 48 if self._hit_move_handle(x, y, alt_down) and not event.ends_today: 49 self.drawing_area.change_input_handler_to_move_by_drag(event, time_at_x) 50 return 51 if (event is None and ctrl_down == False and shift_down == False): 52 self.drawing_area._toggle_event_selection(x, y, ctrl_down) 53 self.drawing_area.change_input_handler_to_scroll_by_drag(time_at_x) 54 return 55 if (event is None and ctrl_down == True): 56 self.drawing_area._toggle_event_selection(x, y, ctrl_down) 57 self.drawing_area.change_input_handler_to_create_period_event_by_drag(time_at_x) 58 return 59 if (event is None and shift_down == True): 60 self.drawing_area._toggle_event_selection(x, y, ctrl_down) 61 self.drawing_area.change_input_handler_to_zoom_by_drag(time_at_x) 62 return 63 self.drawing_area._toggle_event_selection(x, y, ctrl_down, alt_down)
64
65 - def _toggle_balloon_stickyness(self, x, y):
66 event_with_balloon = self.drawer.balloon_at(x, y) 67 if event_with_balloon: 68 stick = not self.view_properties.event_has_sticky_balloon(event_with_balloon) 69 self.view_properties.set_event_has_sticky_balloon(event_with_balloon, has_sticky=stick) 70 if stick: 71 self.drawing_area._redraw_timeline() 72 else: 73 if self.view_properties.show_balloons_on_hover: 74 self.drawing_area._redraw_balloons(event_with_balloon) 75 else: 76 self.drawing_area._redraw_balloons(None)
77
78 - def mouse_moved(self, x, y, alt_down=False):
79 self.last_hovered_event = self.drawing_area.event_at(x, y, alt_down) 80 self.last_hovered_balloon_event = self.drawer.balloon_at(x, y) 81 self._start_balloon_timers() 82 self.drawing_area._display_eventinfo_in_statusbar(x, y, alt_down) 83 if self._hit_resize_handle(x, y, alt_down) is not None: 84 self.drawing_area_view.set_size_cursor() 85 elif self._hit_move_handle(x, y, alt_down) and not self.last_hovered_event.ends_today: 86 self.drawing_area_view.set_move_cursor() 87 else: 88 self.drawing_area_view.set_default_cursor()
89
90 - def _start_balloon_timers(self):
91 if self._balloons_disabled(): 92 return 93 if self._current_event_selected(): 94 return 95 if self.show_timer_running: 96 return 97 if self.hide_timer_running: 98 return 99 if self._should_start_balloon_show_timer(): 100 self.drawing_area_view.start_balloon_show_timer(milliseconds=500, oneShot=True) 101 self.show_timer_running = True 102 elif self._should_start_balloon_hide_timer(): 103 self.drawing_area_view.start_balloon_hide_timer(milliseconds=100, oneShot=True) 104 self.hide_timer_running = True
105
106 - def _balloons_disabled(self):
107 return not self.view_properties.show_balloons_on_hover
108
109 - def _current_event_selected(self):
110 return (self.last_hovered_event is not None and 111 self.drawing_area.is_selected(self.last_hovered_event))
112
114 return (self._mouse_is_over_event() and 115 not self._mouse_is_over_balloon() and 116 not self._balloon_shown_for_event(self.last_hovered_event))
117
119 return (self._balloon_is_shown() and 120 not self._mouse_is_over_event() and 121 not self._balloon_shown_for_event(self.last_hovered_balloon_event))
122
123 - def _mouse_is_over_event(self):
124 return self.last_hovered_event is not None
125
126 - def _mouse_is_over_balloon(self):
127 return self.last_hovered_balloon_event is not None
128
129 - def _balloon_is_shown(self):
130 return self.view_properties.hovered_event is not None
131
132 - def _balloon_shown_for_event(self, event):
133 return self.view_properties.hovered_event == event
134
135 - def balloon_show_timer_fired(self):
136 self.show_timer_running = False 137 self.drawing_area._redraw_balloons(self.last_hovered_event)
138
139 - def balloon_hide_timer_fired(self):
140 self.hide_timer_running = False 141 hevt = self.view_properties.hovered_event 142 # If there is no balloon visible we don't have to do anything 143 if hevt is None: 144 return 145 cevt = self.last_hovered_event 146 bevt = self.last_hovered_balloon_event 147 # If the visible balloon doesn't belong to the event pointed to 148 # we remove the ballloon. 149 if hevt != cevt and hevt != bevt: 150 self.drawing_area._redraw_balloons(None)
151
152 - def _hit_move_handle(self, x, y, alt_down=False):
153 event_and_rect = self.drawing_area.event_with_rect_at(x, y, alt_down) 154 if event_and_rect is None: 155 return False 156 event, rect = event_and_rect 157 if event.locked: 158 return None 159 if not self.drawing_area.is_selected(event): 160 return False 161 center = rect.X + rect.Width / 2 162 if abs(x - center) <= HIT_REGION_PX_WITH: 163 return True 164 return False
165
166 - def _hit_resize_handle(self, x, y, alt_down=False):
167 event_and_rect = self.drawing_area.event_with_rect_at(x, y, alt_down) 168 if event_and_rect == None: 169 return None 170 event, rect = event_and_rect 171 if event.locked: 172 return None 173 if not self.drawing_area.is_selected(event): 174 return None 175 if abs(x - rect.X) < HIT_REGION_PX_WITH: 176 return wx.LEFT 177 elif abs(rect.X + rect.Width - x) < HIT_REGION_PX_WITH: 178 return wx.RIGHT 179 return None
180