Package Gnumed :: Package timelinelib :: Package wxgui :: Package dialogs :: Module playframe
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.wxgui.dialogs.playframe

  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  import datetime 
 20   
 21  import wx 
 22   
 23  from timelinelib.drawing.drawers.default import DefaultDrawingAlgorithm 
 24  from timelinelib.play.playcontroller import PlayController 
 25   
 26   
27 -class PlayFrame(wx.Dialog):
28
29 - def __init__(self, timeline, config):
30 wx.Dialog.__init__(self, None, style=wx.DEFAULT_FRAME_STYLE) 31 self.close_button = wx.Button(self, wx.ID_ANY, label=_("Close")) 32 self.drawing_area = DrawingArea(self) 33 self.Bind(wx.EVT_BUTTON, self.on_close_clicked, self.close_button) 34 35 vbox = wx.BoxSizer(wx.VERTICAL) 36 vbox.Add(self.drawing_area) 37 vbox.Add(self.close_button) 38 self.SetSizerAndFit(vbox) 39 40 drawing_algorithm = DefaultDrawingAlgorithm() 41 self.controller = PlayController( 42 self, timeline, drawing_algorithm, config) 43 self.controller.start_movie()
44
45 - def start_timer(self, interval_in_ms):
46 self.timer = OurTimer(self.controller.tick) 47 self.timer.Start(interval_in_ms)
48
49 - def stop_timer(self):
50 self.timer.Stop()
51
52 - def redraw_drawing_area(self, fn):
53 self.drawing_area.redraw_surface(fn)
54
55 - def on_close_clicked(self, e):
56 self.controller.on_close_clicked()
57
58 - def close(self):
59 self.EndModal(wx.ID_OK)
60
61 - def get_view_period_length(self):
62 return datetime.timedelta(days=10)
63 64
65 -class OurTimer(wx.Timer):
66
67 - def __init__(self, fn):
68 wx.Timer.__init__(self) 69 self.tick_function = fn
70
71 - def Notify(self):
72 self.tick_function()
73 74
75 -class DrawingArea(wx.Panel):
76
77 - def __init__(self, parent):
78 wx.Panel.__init__(self, parent, size=(600, 400)) 79 self.surface_bitmap = None 80 self._create_gui()
81
82 - def _create_gui(self):
83 self.Bind(wx.EVT_PAINT, self._on_paint)
84
85 - def redraw_surface(self, fn_draw):
86 width, height = self.GetSizeTuple() 87 self.surface_bitmap = wx.EmptyBitmap(width, height) 88 memdc = wx.MemoryDC() 89 memdc.SelectObject(self.surface_bitmap) 90 memdc.BeginDrawing() 91 memdc.SetBackground(wx.Brush(wx.WHITE, wx.SOLID)) 92 memdc.Clear() 93 fn_draw(memdc) 94 memdc.EndDrawing() 95 del memdc 96 self.Refresh() 97 self.Update()
98
99 - def _on_paint(self, event):
100 dc = wx.AutoBufferedPaintDC(self) 101 dc.BeginDrawing() 102 if self.surface_bitmap: 103 dc.DrawBitmap(self.surface_bitmap, 0, 0, True) 104 else: 105 pass # TODO: Fill with white? 106 dc.EndDrawing()
107