Gnumed.timelinelib.dataimport.tutorial

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