Package Gnumed :: Package timelinelib :: Package dataimport :: Module tutorial |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.dataimport.tutorial

      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.calendar.gregorian.gregorian import GregorianDateTime
     20  from timelinelib.calendar.gregorian.time import GregorianDelta
     21  from timelinelib.calendar.num.time import NumDelta
     22  from timelinelib.canvas.data.db import MemoryDB
     23  from timelinelib.canvas.data import TimePeriod
     24
     25
     26 -class TutorialTimelineCreator(object):
     27
     28 -    def __init__(self):
     29          self.db = MemoryDB()
     30          self.db.time_type = self.get_time_type()
     31          self.start, self.end = self.get_start_end()
     32          self.db.set_displayed_period(TimePeriod(self.start, self.end))
     33          self.last_cat = None
     34
     35 -    def add_category(self, name, color, font_color, make_last_added_parent=False):
     36          if make_last_added_parent:
     37              parent = self.last_cat
     38          else:
     39              parent = None
     40          self.prev_cat = self.last_cat
     41          self.last_cat = self.db.new_category().update(
     42              name=name,
     43              color=color,
     44              font_color=font_color,
     45              parent=parent
     46          ).save()
     47
     48 -    def add_milestone(self, time_add, text, label):
     49          start, end = self._calc_start_end(time_add, time_add)
     50          self.db.new_milestone(
     51              description=text
     52          ).update(start, start, label).save()
     53
     54 -    def add_era(self, start_add, end_add, name):
     55          start, end = self._calc_start_end(start_add, end_add)
     56          self.db.new_era(
     57          ).update(start, end, name, color=(250, 250, 230)).save()
     58
     59 -    def add_event(self, text, description, start_add, end_add=None, hyperlink=None):
     60          start, end = self._calc_start_end(start_add, end_add)
     61          event = self.db.new_event().update(start, end, text, self.last_cat)
     62          if description:
     63              event.set_data("description", description)
     64          if hyperlink:
     65              event.set_hyperlink(hyperlink)
     66          event.set_default_color((200, 200, 200))
     67          event.save()
     68
     69 -    def add_container(self, text, description, start_add, end_add=None):
     70          start, end = self._calc_start_end(start_add, end_add)
     71          return self.db.new_container(
     72          ).update(start, end, text, self.prev_cat).save()
     73
     74 -    def add_subevent(self, container, text, description, start_add, end_add=None, hyperlink=None):
     75          start, end = self._calc_start_end(start_add, end_add)
     76          event = self.db.new_subevent(
     77              container=container,
     78              time_period=TimePeriod(start, end)
     79          ).update(start, end, text, self.last_cat)
     80          if description:
     81              event.set_data("description", description)
     82          if hyperlink:
     83              event.set_hyperlink(hyperlink)
     84          event.save()
     85
     86 -    def get_db(self):
     87          self.db.clear_transactions()
     88          return self.db
     89
     90 -    def _calc_start_end(self, start_add, end_add=None):
     91          start = self.start + self.get_delta(start_add)
     92          end = start
     93          if end_add is not None:
     94              end = self.start + self.get_delta(end_add)
     95          return (start, end)
     96
     97
     98 -class GregorianTutorialTimelineCreator(TutorialTimelineCreator):
     99
    100 -    def get_time_type(self):
    101          from timelinelib.calendar.gregorian.timetype import GregorianTimeType
    102          return GregorianTimeType()
    103
    104 -    def get_start_end(self):
    105          now = GregorianDateTime.from_time(self.db.time_type.now())
    106          start = GregorianDateTime(
    107              now.year,
    108              now.month,
    109              1,
    110              0,
    111              0,
    112              0
    113          ).to_time()
    114          end = start + self.get_delta(30)
    115          return (start, end)
    116
    117 -    def get_delta(self, value):
    118          return GregorianDelta.from_days(value)
    119
    120
    121 -class NumericTutorialTimelineCreator(TutorialTimelineCreator):
    122
    123 -    def get_time_type(self):
    124          from timelinelib.calendar.num.timetype import NumTimeType
    125          return NumTimeType()
    126
    127 -    def get_start_end(self):
    128          start = self.db.time_type.now()
    129          end = start + self.get_delta(30)
    130          return (start, end)
    131
    132 -    def get_delta(self, value):
    133          return NumDelta(value)
    134
    135
    136 -def create_in_memory_gregorian_tutorial_db():
    137      return create_in_memory_tutorial_db(GregorianTutorialTimelineCreator())
    138
    139
    140 -def create_in_memory_numeric_tutorial_db():
    141      return create_in_memory_tutorial_db(NumericTutorialTimelineCreator())
    142
    143
    144 -def create_in_memory_tutorial_db(tutcreator):
    145      tutcreator.add_milestone(
    146          1,
    147          _("Start"),
    148          "<",
    149      )
    150      tutcreator.add_milestone(
    151          29,
    152          _("End"),
    153          ">",
    154      )
    155      tutcreator.add_era(
    156          20, 28,
    157          _("Example era"),
    158      )
    159      tutcreator.add_category(
    160          _("Welcome"), (255, 80, 80), (0, 0, 0)
    161      )
    162      tutcreator.add_event(
    163          _("Welcome to Timeline"), "",  4
    164      )
    165      tutcreator.add_category(
    166          _("Intro"), (250, 250, 20), (0, 0, 0)
    167      )
    168      tutcreator.add_event(
    169          _("This event has hyperlinks"),
    170          _("Right-click for context menu where the hyperlinks can be accessed."),
    171          11,
    172          19,
    173          "https://sourceforge.net/projects/thetimelineproj/;http://thetimelineproj.sourceforge.net/"
    174      )
    175      tutcreator.add_event(
    176          _("Hover me!"),
    177          _("Hovering events with a triangle shows the event description."),
    178          5
    179      )
    180      tutcreator.add_category(
    181          _("Features"), (100, 100, 250), (250, 250, 20)
    182      )
    183      tutcreator.add_event(
    184          _("Scroll"),
    185          _("Left click somewhere on the timeline and start dragging."
    186            "\n\n"
    187            "You can also use the mouse wheel."
    188            "\n\n"
    189            "You can also middle click with the mouse to center around that point."),
    190          5,
    191          10
    192      )
    193      container = tutcreator.add_container(
    194          _("Container"),
    195          _("?"),
    196          5,
    197          10
    198      )
    199      tutcreator.add_subevent(
    200          container,
    201          _("Resize me"),
    202          _("Container Subevent 1\nClick on the event to get the resize handles"),
    203          5,
    204          10
    205      )
    206      tutcreator.add_subevent(
    207          container,
    208          _("Drag me"),
    209          _("Container Subevent 2\n\n"
    210            "Click on the event to get the drag handle and drag it.\n\n"
    211            "To drag the whole container, click on it while holding down the Alt key. "
    212            "Keep the Alt key down and find the drag point at the center of the container and drag it."),
    213          12,
    214          18
    215      )
    216      tutcreator.add_subevent(
    217          container,
    218          _("View Container demo video"),
    219          _("Container Subevent 3\n\n"
    220            "Select hyperlink to show demo video.\n\n"
    221            "Right-click in the event and select 'Goto URL' in the popup menu and select the first (and only) link"),
    222          19,
    223          24,
    224          "http://www.youtube.com/watch?v=dBwEQ3vqB_I"
    225      )
    226      tutcreator.add_event(
    227          _("Zoom"),
    228          _("Hold down Ctrl while scrolling the mouse wheel."
    229            "\n\n"
    230            "Hold down Shift while dragging with the mouse."),
    231          6,
    232          11
    233      )
    234      tutcreator.add_event(
    235          _("Create event"),
    236          _("Double click somewhere on the timeline."
    237            "\n\n"
    238            "Hold down Ctrl while dragging the mouse to select a period."),
    239          12,
    240          18
    241      )
    242      tutcreator.add_event(
    243          _("Edit event"),
    244          _("Double click on an event."),
    245          12,
    246          18
    247      )
    248      tutcreator.add_event(
    249          _("Select event"),
    250          _("Click on it."
    251            "\n\n"
    252            "Hold down Ctrl while clicking events to select multiple."),
    253          20,
    254          25
    255      )
    256      tutcreator.add_event(
    257          _("Delete event"),
    258          _("Select events to be deleted and press the Del key."),
    259          19,
    260          24
    261      )
    262      tutcreator.add_event(
    263          _("Resize and move me!"),
    264          _("First select me and then drag the handles."),
    265          11,
    266          19
    267      )
    268      tutcreator.add_category(
    269          _("Saving"), (50, 200, 50), (0, 0, 0)
    270      )
    271      tutcreator.add_event(
    272          _("Saving"),
    273          _("This timeline is stored in memory and modifications to it will not "
    274            "be persisted between sessions."
    275            "\n\n"
    276            "Choose File/New/File Timeline to create a timeline that is saved on "
    277            "disk."),
    278          23
    279      )
    280      return tutcreator.get_db()
    281