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

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

      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  """
     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):
     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 use_fast_draw(self, value):
     43          self.fast_draw = value
     44
     45 -    def event_is_period(self, time_period):
     46          """
     47          Return True if the event time_period will make the event appear
     48          below the center line, as a period event.
     49          """
     50          return None
     51
     52 -    def snap(self, time, snap_region=10):
     53          """Snap time to minor strip if within snap_region pixels."""
     54          return time
     55
     56 -    def snap_selection(self, period_selection):
     57          """
     58          Return a tuple where the selection has been stretched to fit to minor
     59          strip.
     60
     61          period_selection: (start, end)
     62          Return: (new_start, new_end)
     63          """
     64          return period_selection
     65
     66 -    def event_at(self, x, y):
     67          """
     68          Return the event at pixel coordinate (x, y) or None if no event there.
     69          """
     70          return None
     71
     72 -    def event_with_rect_at(self, x, y):
     73          """
     74          Return the event at pixel coordinate (x, y) and its rect in a tuple
     75          (event, rect) or None if no event there.
     76          """
     77          return None
     78
     79 -    def event_rect_at(self, event):
     80          """
     81          Return the rect for the given event or None if no event isn't found.
     82          """
     83          return None
     84
     85 -    def is_balloon_at(self, event, x, y):
     86          """
     87          Return True if a balloon for event is drawn at (x, y), otherwise False.
     88          """
     89
     90 -    def get_closest_overlapping_event(self, event_to_move, up=True):
     91          raise NotImplementedError()
     92
     93
     94 -class Strip(object):
     95      """
     96      An interface for strips.
     97
     98      The different strips are implemented in subclasses below.
     99
    100      The timeline is divided in major and minor strips. The minor strip might
    101      for example be days, and the major strip months. Major strips are divided
    102      with a solid line and minor strips with dotted lines. Typically maximum
    103      three major strips should be shown and the rest will be minor strips.
    104      """
    105
    106 -    def label(self, time, major=False):
    107          """
    108          Return the label for this strip at the given time when used as major or
    109          minor strip.
    110          """
    111
    112 -    def start(self, time):
    113          """
    114          Return the start time for this strip and the given time.
    115
    116          For example, if the time is 2008-08-31 and the strip is month, the
    117          start would be 2008-08-01.
    118          """
    119
    120 -    def increment(self, time):
    121          """
    122          Increment the given time so that it points to the start of the next
    123          strip.
    124          """
    125
    126 -    def get_font(self, time_period):
    127          """
    128          Return the preferred font for this strip
    129          """
    130