Gnumed.timelinelib.canvas.drawing.graphobject

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

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

      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  Contains the GraphObject class.
     20  Tests are defined :doc:`Here <unit_canvas_drawing_graphobject>`.
     21  """
     22
     23  import operator
     24
     25
     26 -class GraphObject(object):
     27      """
     28      Contains metric and color information and a list of child
     29      graphical objects.
     30      When a Graphical object is translated to another position
     31      all of its children are also translated.
     32      The purpose is to be able to define a graphical object
     33      position relative to it's parent.
     34      """
     35
     36 -    def __init__(self, x=0, y=0, w=0, h=0, text=''):
     37          self._childs = []
     38          self._rect = (x, y, w, h)
     39          self._text = text
     40          self._brush_color = (0, 0, 0)
     41          self._pen_color = (0, 0, 0)
     42
     43 -    def translate(self, x, y):
     44          """
     45          Translate this object to a new position and translate
     46          all of it's child the same amount.
     47          """
     48          self._rect = tuple(map(operator.add, self._rect, (x, y, 0, 0)))
     49          for child in self.childs:
     50              child.translate(x, y)
     51
     52      @property
     53 -    def childs(self):
     54          """Getter and Setter property."""
     55          return self._childs
     56
     57      @childs.setter
     58 -    def childs(self, childs):
     59          """ """
     60          self._childs = childs
     61
     62      @property
     63 -    def first_child(self):
     64          """Getter property."""
     65          return self._childs[0]
     66
     67 -    def add_child(self, child):
     68          """Add a new child to the list of childs."""
     69          self._childs.append(child)
     70
     71      @property
     72 -    def text(self):
     73          """Getter property."""
     74          return self._text
     75
     76      @property
     77 -    def point(self):
     78          """Getter property."""
     79          return self.rect[:2]
     80
     81      @property
     82 -    def rect(self):
     83          """Getter property."""
     84          return self._rect
     85
     86      @property
     87 -    def width(self):
     88          """Getter property."""
     89          return self._rect[2]
     90
     91      @property
     92 -    def height(self):
     93          """Getter property."""
     94          return self._rect[3]
     95
     96      @property
     97 -    def brush_color(self):
     98          """Getter and Setter property."""
     99          return self._brush_color
    100
    101      @brush_color.setter
    102 -    def brush_color(self, brush_color):
    103          self._brush_color = brush_color
    104
    105      @property
    106 -    def pen_color(self):
    107          """Getter and Setter property."""
    108          return self._pen_color
    109
    110      @pen_color.setter
    111 -    def pen_color(self, pen_color):
    112          self._pen_color = pen_color
    113