Package Gnumed :: Package timelinelib :: Package db :: Package backends :: Module tutorial |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.db.backends.tutorial

      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  from datetime import datetime
     20  from datetime import timedelta
     21
     22  from timelinelib.db.objects import Category
     23  from timelinelib.db.objects import Event
     24  from timelinelib.db.objects import TimePeriod
     25  from timelinelib.db.backends.memory import MemoryDB
     26
     27
     28 -def create_in_memory_tutorial_db():
     29      tutcreator = TutorialTimelineCreator()
     30      tutcreator.add_category(_("Welcome"), (255, 80, 80), (0, 0, 0))
     31      tutcreator.add_event(
     32          _("Welcome to Timeline"),
     33          "",
     34          timedelta(days=4))
     35      tutcreator.add_category(_("Intro"), (250, 250, 20), (0, 0, 0))
     36      tutcreator.add_event(
     37          _("Hover me!"),
     38          _("Hovering events with a triangle shows the event description."),
     39          timedelta(days=5))
     40      tutcreator.add_category(_("Features"), (100, 100, 250), (250, 250, 20))
     41      tutcreator.add_event(
     42          _("Scroll"),
     43          _("Left click somewhere on the timeline and start dragging."
     44            "\n\n"
     45            "You can also use the mouse wheel."
     46            "\n\n"
     47            "You can also middle click with the mouse to center around that point."),
     48          timedelta(days=5),
     49          timedelta(days=10))
     50      tutcreator.add_event(
     51          _("Zoom"),
     52          _("Hold down Ctrl while scrolling the mouse wheel."
     53            "\n\n"
     54            "Hold down Shift while dragging with the mouse."),
     55          timedelta(days=6),
     56          timedelta(days=11))
     57      tutcreator.add_event(
     58          _("Create event"),
     59          _("Double click somewhere on the timeline."
     60            "\n\n"
     61            "Hold down Ctrl while dragging the mouse to select a period."),
     62          timedelta(days=12),
     63          timedelta(days=18))
     64      tutcreator.add_event(
     65          _("Edit event"),
     66          _("Double click on an event."),
     67          timedelta(days=12),
     68          timedelta(days=18))
     69      tutcreator.add_event(
     70          _("Select event"),
     71          _("Click on it."
     72            "\n\n"
     73            "Hold down Ctrl while clicking events to select multiple."),
     74          timedelta(days=20),
     75          timedelta(days=25))
     76      tutcreator.add_event(
     77          _("Delete event"),
     78          _("Select events to be deleted and press the Del key."),
     79          timedelta(days=19),
     80          timedelta(days=24))
     81      tutcreator.add_event(
     82          _("Resize and move me!"),
     83          _("First select me and then drag the handles."),
     84          timedelta(days=11),
     85          timedelta(days=19))
     86      tutcreator.add_category(_("Saving"), (50, 200, 50), (0, 0, 0))
     87      tutcreator.add_event(
     88          _("Saving"),
     89          _("This timeline is stored in memory and modifications to it will not "
     90            "be persisted between sessions."
     91            "\n\n"
     92            "Choose File/New/File Timeline to create a timeline that is saved on "
     93            "disk."),
     94          timedelta(days=23))
     95      return tutcreator.get_db()
     96
     97
     98 -class TutorialTimelineCreator(object):
     99
    100 -    def __init__(self):
    101          self.db = MemoryDB()
    102          now = datetime.now()
    103          self.start = datetime(now.year, now.month, 1, 0, 0, 0)
    104          self.end = self.start + timedelta(days=30)
    105          self.db._set_displayed_period(TimePeriod(self.db.get_time_type(),
    106                                                   self.start, self.end))
    107          self.last_cat = None
    108
    109 -    def add_category(self, name, color, font_color, make_last_added_parent=False):
    110          if make_last_added_parent:
    111              parent = self.last_cat
    112          else:
    113              parent = None
    114          self.last_cat = Category(name, color, font_color, True, parent)
    115          self.db.save_category(self.last_cat)
    116
    117 -    def add_event(self, text, description, start_add, end_add=None):
    118          start = self.start + start_add
    119          end   = start
    120          if end_add is not None:
    121              end = self.start + end_add
    122          evt = Event(self.db.get_time_type(), start, end, text, self.last_cat)
    123          if description:
    124              evt.set_data("description", description)
    125          self.db.save_event(evt)
    126
    127 -    def get_db(self):
    128          return self.db
    129