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

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

 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.canvas.data import TimePeriod 
20  from timelinelib.wxgui.components.maincanvas.scrollbase import ScrollViewInputHandler 
21   
22   
23 -class SelectPeriodByDragInputHandler(ScrollViewInputHandler):
24
25 - def __init__(self, state, timeline_canvas, initial_time):
26 ScrollViewInputHandler.__init__(self, timeline_canvas) 27 self._state = state 28 self.timeline_canvas = timeline_canvas 29 self.initial_time = initial_time 30 self.last_valid_time = initial_time 31 self.current_time = initial_time
32
33 - def mouse_moved(self, cursor, keyboard):
34 ScrollViewInputHandler.mouse_moved(self, cursor, keyboard) 35 self._move_current_time()
36
37 - def view_scrolled(self):
38 self._move_current_time()
39
40 - def _move_current_time(self):
41 try: 42 self.current_time = self.timeline_canvas.GetTimeAt(self.last_x) 43 period = self.get_current_period() 44 self.last_valid_time = self.current_time 45 except ValueError: 46 period = self.get_last_valid_period() 47 self.timeline_canvas.SetPeriodSelection(period)
48
49 - def get_last_valid_period(self):
50 return self._get_period(self.initial_time, self.last_valid_time)
51
52 - def get_current_period(self):
53 return self._get_period(self.initial_time, self.current_time)
54
55 - def _get_period(self, t1, t2):
56 if t1 > t2: 57 start = t2 58 end = t1 59 else: 60 start = t1 61 end = t2 62 return TimePeriod( 63 self.timeline_canvas.Snap(start), 64 self.timeline_canvas.Snap(end))
65
66 - def left_mouse_up(self):
67 ScrollViewInputHandler.left_mouse_up(self) 68 self._end_action()
69
70 - def _end_action(self):
71 self.end_action() 72 self._remove_selection() 73 self._state.change_to_no_op() 74 self._state.edit_ends()
75
76 - def _remove_selection(self):
77 self.timeline_canvas.SetPeriodSelection(None)
78
79 - def end_action(self):
80 raise Exception("end_action not implemented in subclass.")
81