Gnumed.timelinelib.wxgui.dialogs.changenowdate.controller

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

# Source Code for Module Gnumed.timelinelib.wxgui.dialogs.changenowdate.controller

     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  from timelinelib.wxgui.framework import Controller
    20
    21
    22 -class ChangeNowDateDialogController(Controller):
    23
    24 -    def on_init(self, db, handle_new_time_fn):
    25          self.db = db
    26          self.handle_new_time_fn = handle_new_time_fn
    27          self._set_initial_values()
    28
    29 -    def on_show_time_changed(self, event):
    30          self.view.ShowTime(self.view.IsShowTimeChecked())
    31
    32 -    def on_time_changed(self):
    33          try:
    34              self.db.set_saved_now(self._get_timepicker_time())
    35              self._trigger_new_time_callback()
    36          except ValueError:
    37              pass
    38
    39 -    def _set_initial_values(self):
    40          self.view.SetNowValue(self.db.get_saved_now())
    41          self.view.ShowTime(self.view.IsShowTimeChecked())
    42          self.view.FocusTimePicker()
    43          self._trigger_new_time_callback()
    44
    45 -    def _trigger_new_time_callback(self):
    46          self.handle_new_time_fn(self.db.get_saved_now())
    47
    48 -    def _get_timepicker_time(self):
    49          time = self.view.GetNowValue()
    50          if time is None:
    51              raise ValueError()
    52          return time
    53