Mouse Move Example¶
This example shows how to display status information of the timeline depending on the mouse position.
- It contains three files
- mouse_move_example.py (Contains the main program)
- canvas.py (User defined Canvas class)
- timelineadaptor.py (Code needed to access the Timeline library)
mouse_move_example.py¶
"""
This example displays the tutorial timeline in a wx.Frame window
using a user defined Canvas object that inherits from TimelineCanvas.
Hoovering the mouse over the timeline displays event information in the
status bar and also displays event balloon information if present.
"""
import wx
import timelineadaptor
from canvas import Canvas
from timelinelib.db import db_open
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, size=(800, 400))
self.statusbar = self.CreateStatusBar(1)
self._display_example_timeline()
def _display_example_timeline(self):
# 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
path_to_timeline_file = ":tutorial:"
db = db_open(path_to_timeline_file)
db.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_MOTION, self._on_motion)
def _on_motion(self, evt):
self.DisplayBalloons(evt)
self._parent.SetStatusText(self.GetTimelineInfoText(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()