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

# Source Code for Module Gnumed.timelinelib.wxgui.components.maincanvas.scrollbase

     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.wxgui.components.maincanvas.inputhandler import InputHandler
    20
    21
    22  # dragscroll timer interval in milliseconds
    23  DRAGSCROLL_TIMER_MSINTERVAL = 300
    24  # timeline. The scroll zone areas are found at the beginning and at the
    25  # end of the timeline.
    26  SCROLL_ZONE_WIDTH = 20
    27
    28
    29 -class ScrollViewInputHandler(InputHandler):
    30
    31 -    def __init__(self, timeline_canvas):
    32          InputHandler.__init__(self, timeline_canvas)
    33          self.timer_running = False
    34
    35 -    def mouse_moved(self, cursor, keyboard):
    36          self.last_x = cursor.x
    37          if self._in_scroll_zone(cursor.x) and not self.timer_running:
    38              self.timeline_canvas.start_dragscroll_timer(milliseconds=DRAGSCROLL_TIMER_MSINTERVAL)
    39              self.timer_running = True
    40
    41 -    def left_mouse_up(self):
    42          self.timeline_canvas.stop_dragscroll_timer()
    43
    44 -    def dragscroll_timer_fired(self):
    45          if self._in_scroll_zone(self.last_x):
    46              if self.last_x < SCROLL_ZONE_WIDTH:
    47                  direction = 1
    48              else:
    49                  direction = -1
    50              self.timeline_canvas.Scroll(direction * 0.1)
    51              self.view_scrolled()
    52
    53 -    def view_scrolled(self):
    54          raise Exception("view_scrolled not implemented in subclass.")
    55
    56 -    def _in_scroll_zone(self, x):
    57          """
    58          Return True if x is within the left hand or right hand area
    59          where timed scrolling shall start/continue.
    60          """
    61          width, _ = self.timeline_canvas.GetSizeTuple()
    62          if width - x < SCROLL_ZONE_WIDTH or x < SCROLL_ZONE_WIDTH:
    63              return True
    64          return False
    65