Gnumed.timelinelib.wxgui.components.maincanvas.resizebydrag

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

# Source Code for Module Gnumed.timelinelib.wxgui.components.maincanvas.resizebydrag

     1  # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018  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.wxgui.components.maincanvas.scrollbase import ScrollViewInputHandler
    22
    23
    24 -class ResizeByDragInputHandler(ScrollViewInputHandler):
    25
    26 -    def __init__(self, state, timeline_canvas, event, direction):
    27          ScrollViewInputHandler.__init__(self, timeline_canvas)
    28          self._state = state
    29          self.timeline_canvas = timeline_canvas
    30          self.event = event
    31          self.direction = direction
    32          self.timer_running = False
    33          self._transaction = self.timeline_canvas.GetDb().transaction(_("Resize events"))
    34          self._state.display_status("")
    35
    36 -    def mouse_moved(self, cursor, keyboard):
    37          ScrollViewInputHandler.mouse_moved(self, cursor, keyboard)
    38          self._resize_event()
    39
    40 -    def left_mouse_up(self):
    41          ScrollViewInputHandler.left_mouse_up(self)
    42          self._state.display_status("")
    43          self._transaction.commit()
    44          self._state.edit_ends()
    45          self._state.change_to_no_op()
    46
    47 -    def view_scrolled(self):
    48          self._resize_event()
    49
    50 -    def _resize_event(self):
    51          if self.event.get_locked():
    52              return
    53          new_time = self.timeline_canvas.GetTimeAt(self.last_x)
    54          new_snapped_time = self.timeline_canvas.Snap(new_time)
    55          if self.direction == wx.LEFT:
    56              new_start = new_snapped_time
    57              new_end = self.event.get_time_period().end_time
    58              if new_start > new_end:
    59                  new_start = new_end
    60          else:
    61              new_start = self.event.get_time_period().start_time
    62              new_end = new_snapped_time
    63              if new_end < new_start:
    64                  new_end = new_start
    65          self.event.update_period(new_start, new_end)
    66          self.event.save()
    67          self.timeline_canvas.Redraw()
    68