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

Source Code for Module Gnumed.timelinelib.view.resize

 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.db.objects import PeriodTooLongError 
22  from timelinelib.view.scrollbase import ScrollViewInputHandler 
23   
24   
25 -class ResizeByDragInputHandler(ScrollViewInputHandler):
26
27 - def __init__(self, controller, status_bar, event, direction):
28 ScrollViewInputHandler.__init__(self, controller) 29 self.controller = controller 30 self.status_bar = status_bar 31 self.event = event 32 self.direction = direction 33 self.timer_running = False
34
35 - def mouse_moved(self, x, y, alt_down=False):
36 ScrollViewInputHandler.mouse_moved(self, x, y, alt_down) 37 self._resize_event()
38
39 - def left_mouse_up(self):
40 ScrollViewInputHandler.left_mouse_up(self) 41 self._clear_status_text() 42 self.controller.change_input_handler_to_no_op()
43
44 - def view_scrolled(self):
45 self._resize_event()
46
47 - def _resize_event(self):
48 if self.event.locked: 49 return 50 new_time = self.controller.get_time(self.last_x) 51 new_snapped_time = self.controller.get_drawer().snap(new_time) 52 if self.direction == wx.LEFT: 53 new_start = new_snapped_time 54 new_end = self.event.time_period.end_time 55 if new_start > new_end: 56 new_start = new_end 57 else: 58 new_start = self.event.time_period.start_time 59 new_end = new_snapped_time 60 if new_end < new_start: 61 new_end = new_start 62 try: 63 self.event.update_period(new_start, new_end) 64 except PeriodTooLongError: 65 self.status_bar.set_text(_("Period is too long")) 66 else: 67 self._clear_status_text() 68 if self.event.is_container(): 69 self._adjust_container_edges() 70 self.controller.redraw_timeline()
71
72 - def _adjust_container_edges(self):
73 self.event.strategy._set_time_period()
74
75 - def _clear_status_text(self):
76 self.status_bar.set_text("")
77