Center At Cursor Example¶
This example shows how to scroll the timeline to move the clicked date to the center of the screen.
- It contains three files
- center_at_cursor_example.py (Contains the main program)
- canvas.py (User defined Canvas class)
- timelineadaptor.py (Code needed to access the Timeline library)
center_at_cursor_example.py¶
"""
This example displays the tutorial timeline in a wx.Frame window
using a TimelineCanvas object.
By clicking with the cursor on a date in the timeline, the timeline will be scrolled
to a position where the selected date is in the center of the timeline.
"""
import wx
import timelineadaptor
from timelinelib.db import db_open
from canvas import Canvas
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, size=(800, 400))
self._display_example_timeline()
def _display_example_timeline(self):
path_to_timeline_file = ":tutorial:"
db_open(path_to_timeline_file).display_in_canvas(Canvas(self))
if __name__ == "__main__":
app = wx.App()
frame = MainFrame()
frame.Show()
app.MainLoop()
canvas.py¶
"""
The user defined Canvas class inherited from TimelineCanvas.
"""
import wx
from timelinelib.canvas import TimelineCanvas
class Canvas(TimelineCanvas):
def __init__(self, parent):
self._parent = parent
TimelineCanvas.__init__(self, parent)
self.Bind(wx.EVT_LEFT_DOWN, self._on_left_down)
def _on_left_down(self, evt):
self.CenterAtCursor(evt)
timelineadaptor.py¶
def make_sure_timelinelib_can_be_imported():
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()