Gnumed.timelinelib.canvas.drawing.interface

Package Gnumed :: Package timelinelib :: Package canvas :: Package drawing :: Module interface |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.canvas.drawing.interface

      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  Defines the interface that drawers should adhere to.
     21  """
     22
     23
     24 -class Drawer(object):
     25      """
     26      Draw timeline onto a device context and provide information about drawing.
     27      """
     28
     29 -    def draw(self, dc, timeline, view_properties, config, fast_draw=False):
     30          """
     31          Draw a representation of a timeline.
     32
     33          The dc is used to do the actual drawing. The timeline is used to get
     34          the events to visualize. The view properties contains information like
     35          which events are selected in the view we are drawing for and what
     36          period is currently displayed.
     37
     38          When the dc is temporarily stored in a class variable such as self.dc,
     39          this class variable must be deleted before the draw method ends.
     40          """
     41
     42 -    def event_is_period(self, time_period):
     43          """
     44          Return True if the event time_period will make the event appear
     45          below the center line, as a period event.
     46          """
     47          return None
     48
     49 -    def snap(self, time, snap_region=10):
     50          """Snap time to minor strip if within snap_region pixels."""
     51          return time
     52
     53 -    def snap_selection(self, period_selection):
     54          """
     55          Return a tuple where the selection has been stretched to fit to minor
     56          strip.
     57
     58          period_selection: (start, end)
     59          Return: (new_start, new_end)
     60          """
     61          return period_selection
     62
     63 -    def event_at(self, x, y):
     64          """
     65          Return the event at pixel coordinate (x, y) or None if no event there.
     66          """
     67          return None
     68
     69 -    def event_with_rect_at(self, x, y):
     70          """
     71          Return the event at pixel coordinate (x, y) and its rect in a tuple
     72          (event, rect) or None if no event there.
     73          """
     74          return None
     75
     76 -    def event_rect_at(self, event):
     77          """
     78          Return the rect for the given event or None if no event isn't found.
     79          """
     80          return None
     81
     82 -    def is_balloon_at(self, event, x, y):
     83          """
     84          Return True if a balloon for event is drawn at (x, y), otherwise False.
     85          """
     86
     87 -    def get_closest_overlapping_event(self, event_to_move, up=True):
     88          raise NotImplementedError()
     89
     90
     91 -class Strip(object):
     92      """
     93      An interface for strips.
     94
     95      The different strips are implemented in subclasses below.
     96
     97      The timeline is divided in major and minor strips. The minor strip might
     98      for example be days, and the major strip months. Major strips are divided
     99      with a solid line and minor strips with dotted lines. Typically maximum
    100      three major strips should be shown and the rest will be minor strips.
    101      """
    102
    103 -    def label(self, time, major=False):
    104          """
    105          Return the label for this strip at the given time when used as major or
    106          minor strip.
    107          """
    108
    109 -    def start(self, time):
    110          """
    111          Return the start time for this strip and the given time.
    112
    113          For example, if the time is 2008-08-31 and the strip is month, the
    114          start would be 2008-08-01.
    115          """
    116
    117 -    def increment(self, time):
    118          """
    119          Increment the given time so that it points to the start of the next
    120          strip.
    121          """
    122
    123 -    def is_day(self):
    124          return False
    125