Package Gnumed :: Package timelinelib :: Package wxgui :: Module cursor
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.cursor

 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  """ 
20  A representation of the cursor and it's position on in the Timeline window. 
21  """ 
22 23 24 -class Cursor(object):
25
26 - def __init__(self, x=0, y=0):
27 self._start_pos = (x, y) 28 self._current_pos = (x, y) 29 self._has_moved = False
30
31 - def __repr__(self):
32 return 'Cursor from (%d, %d) at %d, %d' % (self._start_pos[0], 33 self._start_pos[1], 34 self._current_pos[0], 35 self._current_pos[1])
36 37 @property
38 - def x(self):
39 return self._current_pos[0]
40 41 @property
42 - def y(self):
43 return self._current_pos[1]
44 45 @property
46 - def pos(self):
47 return self._current_pos
48 49 @property
50 - def start(self):
51 return self._start_pos
52 53 @property
54 - def rect(self):
55 x0, y0 = self._start_pos 56 x1, y1 = self._current_pos 57 return (min(x0, x1), min(y0, y1), abs(x1 - x0), abs(y0 - y1))
58
59 - def has_moved(self):
60 return self._has_moved
61
62 - def reset_move(self):
63 self.move(*self._current_pos)
64
65 - def move(self, x, y):
66 self._has_moved = self._current_pos != (x, y) 67 self._current_pos = (x, y)
68