Package Gnumed :: Package timelinelib :: Package wxgui :: Package components :: Module timelineview |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.wxgui.components.timelineview

      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 wx
     20
     21  from timelinelib.drawing import get_drawer
     22  from timelinelib.view.drawingarea import DrawingArea
     23  from timelinelib.wxgui.dialogs.duplicateevent import open_duplicate_event_dialog_for_event
     24  from timelinelib.wxgui.dialogs.eventeditor import open_create_event_editor
     25  from timelinelib.wxgui.dialogs.eventeditor import open_event_editor_for
     26  from timelinelib.wxgui.utils import _ask_question
     27
     28
     29 -class DrawingAreaPanel(wx.Panel):
     30
     31 -    def __init__(self, parent, status_bar_adapter, divider_line_slider,
     32                   fn_handle_db_error, config, main_frame):
     33          wx.Panel.__init__(self, parent, style=wx.NO_BORDER)
     34          self.fn_handle_db_error = fn_handle_db_error
     35          self.config = config
     36          self.main_frame = main_frame
     37          self.controller = DrawingArea(
     38              self, status_bar_adapter, config, get_drawer(),
     39              divider_line_slider, fn_handle_db_error)
     40          self.surface_bitmap = None
     41          self._create_gui()
     42
     43 -    def get_drawer(self):
     44          return self.controller.get_drawer()
     45
     46 -    def get_timeline(self):
     47          return self.controller.get_timeline()
     48
     49 -    def get_view_properties(self):
     50          return self.controller.get_view_properties()
     51
     52 -    def get_current_image(self):
     53          return self.surface_bitmap
     54
     55 -    def set_timeline(self, timeline):
     56          self.controller.set_timeline(timeline)
     57
     58 -    def show_hide_legend(self, show):
     59          self.controller.show_hide_legend(show)
     60
     61 -    def get_time_period(self):
     62          return self.controller.get_time_period()
     63
     64 -    def navigate_timeline(self, navigation_fn):
     65          self.controller.navigate_timeline(navigation_fn)
     66
     67 -    def redraw_timeline(self):
     68          self.controller.redraw_timeline()
     69
     70 -    def balloon_visibility_changed(self, visible):
     71          self.controller.balloon_visibility_changed(visible)
     72
     73 -    def redraw_surface(self, fn_draw):
     74          width, height = self.GetSizeTuple()
     75          self.surface_bitmap = wx.EmptyBitmap(width, height)
     76          memdc = wx.MemoryDC()
     77          memdc.SelectObject(self.surface_bitmap)
     78          memdc.BeginDrawing()
     79          memdc.SetBackground(wx.Brush(wx.WHITE, wx.SOLID))
     80          memdc.Clear()
     81          fn_draw(memdc)
     82          memdc.EndDrawing()
     83          del memdc
     84          self.Refresh()
     85          self.Update()
     86
     87 -    def enable_disable_menus(self):
     88          self.main_frame.enable_disable_menus()
     89
     90 -    def open_event_editor_for(self, event):
     91          open_event_editor_for(
     92              self,
     93              self.config,
     94              self.controller.get_timeline(),
     95              self.fn_handle_db_error,
     96              event)
     97
     98 -    def open_duplicate_event_dialog_for_event(self, event):
     99          open_duplicate_event_dialog_for_event(
    100              self,
    101              self.controller.get_timeline(),
    102              self.fn_handle_db_error,
    103              event)
    104
    105 -    def open_create_event_editor(self, start_time, end_time):
    106          open_create_event_editor(
    107              self,
    108              self.config,
    109              self.controller.get_timeline(),
    110              self.fn_handle_db_error,
    111              start_time,
    112              end_time)
    113
    114 -    def start_balloon_show_timer(self, milliseconds=-1, oneShot=False):
    115          self.balloon_show_timer.Start(milliseconds, oneShot)
    116
    117 -    def start_balloon_hide_timer(self, milliseconds=-1, oneShot=False):
    118          self.balloon_hide_timer.Start(milliseconds, oneShot)
    119
    120 -    def start_dragscroll_timer(self, milliseconds=-1, oneShot=False):
    121          self.dragscroll_timer.Start(milliseconds, oneShot)
    122
    123 -    def stop_dragscroll_timer(self):
    124          self.dragscroll_timer.Stop()
    125
    126 -    def set_select_period_cursor(self):
    127          self.SetCursor(wx.StockCursor(wx.CURSOR_IBEAM))
    128
    129 -    def set_size_cursor(self):
    130          self.SetCursor(wx.StockCursor(wx.CURSOR_SIZEWE))
    131
    132 -    def set_move_cursor(self):
    133          self.SetCursor(wx.StockCursor(wx.CURSOR_SIZING))
    134
    135 -    def set_default_cursor(self):
    136          self.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
    137
    138 -    def ask_question(self, question):
    139          return _ask_question(question, self)
    140
    141 -    def _create_gui(self):
    142          self.balloon_show_timer = wx.Timer(self, -1)
    143          self.balloon_hide_timer = wx.Timer(self, -1)
    144          self.dragscroll_timer = wx.Timer(self, -1)
    145          self.Bind(wx.EVT_TIMER,            self._on_balloon_show_timer, self.balloon_show_timer)
    146          self.Bind(wx.EVT_TIMER,            self._on_balloon_hide_timer, self.balloon_hide_timer)
    147          self.Bind(wx.EVT_TIMER,            self._on_dragscroll, self.dragscroll_timer)
    148          self.Bind(wx.EVT_ERASE_BACKGROUND, self._on_erase_background)
    149          self.Bind(wx.EVT_PAINT,            self._on_paint)
    150          self.Bind(wx.EVT_SIZE,             self._on_size)
    151          self.Bind(wx.EVT_LEFT_DOWN,        self._on_left_down)
    152          self.Bind(wx.EVT_RIGHT_DOWN,       self._on_right_down)
    153          self.Bind(wx.EVT_LEFT_DCLICK,      self._on_left_dclick)
    154          self.Bind(wx.EVT_MIDDLE_UP,        self._on_middle_up)
    155          self.Bind(wx.EVT_LEFT_UP,          self._on_left_up)
    156          self.Bind(wx.EVT_ENTER_WINDOW,     self._on_enter)
    157          self.Bind(wx.EVT_MOTION,           self._on_motion)
    158          self.Bind(wx.EVT_MOUSEWHEEL,       self._on_mousewheel)
    159          self.Bind(wx.EVT_KEY_DOWN,         self._on_key_down)
    160          self.Bind(wx.EVT_KEY_UP,           self._on_key_up)
    161
    162 -    def _on_balloon_show_timer(self, evt):
    163          self.controller.balloon_show_timer_fired()
    164
    165 -    def _on_balloon_hide_timer(self, evt):
    166          self.controller.balloon_hide_timer_fired()
    167
    168 -    def _on_dragscroll(self, evt):
    169          self.controller.dragscroll_timer_fired()
    170
    171 -    def _on_erase_background(self, event):
    172          # For double buffering
    173          pass
    174
    175 -    def _on_paint(self, event):
    176          dc = wx.AutoBufferedPaintDC(self)
    177          dc.BeginDrawing()
    178          if self.surface_bitmap:
    179              dc.DrawBitmap(self.surface_bitmap, 0, 0, True)
    180          else:
    181              pass # TODO: Fill with white?
    182          dc.EndDrawing()
    183
    184 -    def _on_size(self, evt):
    185          self.controller.window_resized()
    186
    187 -    def _on_left_down(self, evt):
    188          self.controller.left_mouse_down(evt.m_x, evt.m_y, evt.m_controlDown,
    189                                          evt.m_shiftDown, evt.m_altDown)
    190          evt.Skip()
    191
    192 -    def _on_right_down(self, evt):
    193          self.controller.right_mouse_down(evt.m_x, evt.m_y, evt.m_altDown)
    194
    195 -    def _on_left_dclick(self, evt):
    196          self.controller.left_mouse_dclick(evt.m_x, evt.m_y, evt.m_controlDown,
    197                                            evt.m_altDown)
    198
    199 -    def _on_middle_up(self, evt):
    200          self.controller.middle_mouse_clicked(evt.m_x)
    201
    202 -    def _on_left_up(self, evt):
    203          self.controller.left_mouse_up()
    204
    205 -    def _on_enter(self, evt):
    206          self.controller.mouse_enter(evt.m_x, evt.LeftIsDown())
    207
    208 -    def _on_motion(self, evt):
    209          self.controller.mouse_moved(evt.m_x, evt.m_y, evt.m_altDown)
    210
    211 -    def _on_mousewheel(self, evt):
    212          self.controller.mouse_wheel_moved(evt.m_wheelRotation, evt.ControlDown(), evt.ShiftDown(), evt.GetX())
    213
    214 -    def _on_key_down(self, evt):
    215          self.controller.key_down(evt.GetKeyCode(), evt.AltDown())
    216          evt.Skip()
    217
    218 -    def _on_key_up(self, evt):
    219          self.controller.key_up(evt.GetKeyCode())
    220