Display Timeline Example¶
This example shows how to display a timeline in an aplication
- It contains two files
- display_example.py (Contains the main program)
- timelineadaptor.py (Code needed to access the Timeline library)
display_example.py¶
"""
This example displays the tutorial timeline in a wx.Frame window
using a TimelineCanvas object.
"""
import timelineadaptor
import wx
from timelinelib.canvas import TimelineCanvas
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, size=(800, 400))
canvas = TimelineCanvas(self)
self._display_example_timeline(canvas)
def _display_example_timeline(self, canvas):
# The way to populate the canvas is to use a database object from timelinelib
# and call its display_in_canvas method.
# The following code opens the tutorial timeline
from timelinelib.db import db_open
path_to_timeline_file = ":tutorial:"
db = db_open(path_to_timeline_file)
db.display_in_canvas(canvas)
if __name__ == "__main__":
app = wx.App()
frame = MainFrame()
frame.Show()
app.MainLoop()
timelineadaptor.py¶
def make_sure_timelinelib_can_be_imported():
"""
If you have the timelinelib installed in another place than is pointed
out here you have to update the sys.path.insert line.
The os.path must point to the 'source' directory of the Timeline installation.
"""
import os
import sys
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "..", "..", "source"))
def install_gettext_in_builtin_namespace():
def _(message):
return message
import builtins
if not "_" in builtins.__dict__:
builtins.__dict__["_"] = _
make_sure_timelinelib_can_be_imported()
install_gettext_in_builtin_namespace()