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

# Source Code for Module Gnumed.timelinelib.view.periodbase

     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  from timelinelib.db.objects import TimePeriod
    20  from timelinelib.view.scrollbase import ScrollViewInputHandler
    21
    22
    23 -class SelectPeriodByDragInputHandler(ScrollViewInputHandler):
    24
    25 -    def __init__(self, controller, initial_time):
    26          ScrollViewInputHandler.__init__(self, controller)
    27          self.controller = controller
    28          self.initial_time = initial_time
    29          self.last_valid_time = initial_time
    30          self.current_time = initial_time
    31
    32 -    def mouse_moved(self, x, y, alt_down=False):
    33          ScrollViewInputHandler.mouse_moved(self, x, y, alt_down)
    34          self._move_current_time()
    35
    36 -    def view_scrolled(self):
    37          self._move_current_time()
    38
    39 -    def _move_current_time(self):
    40          self.current_time = self.controller.get_time(self.last_x)
    41          try:
    42              period = self.get_current_period()
    43              self.last_valid_time = self.current_time
    44          except ValueError:
    45              period = self.get_last_valid_period()
    46          self.controller.view_properties.period_selection = (period.start_time, period.end_time)
    47          self.controller._redraw_timeline()
    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.controller.get_timeline().get_time_type(),
    64              self.controller.get_drawer().snap(start),
    65              self.controller.get_drawer().snap(end))
    66
    67 -    def left_mouse_up(self):
    68          ScrollViewInputHandler.left_mouse_up(self)
    69          self._end_action()
    70
    71 -    def _end_action(self):
    72          self.end_action()
    73          self._remove_selection()
    74          self.controller.change_input_handler_to_no_op()
    75
    76 -    def _remove_selection(self):
    77          self.controller.view_properties.period_selection = None
    78          self.controller.redraw_timeline()
    79
    80 -    def end_action(self):
    81          raise Exception("end_action not implemented in subclass.")
    82