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

# Source Code for Module Gnumed.timelinelib.wxgui.dialogs.milestone.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.canvas.data import TimePeriod
    20  from timelinelib.canvas.data.milestone import Milestone
    21  from timelinelib.wxgui.framework import Controller
    22  from timelinelib.wxgui.utils import display_error_message
    23
    24
    25 -class DateTimeError(Exception):
    26      pass
    27
    28
    29 -class EditMilestoneDialogController(Controller):
    30
    31 -    def on_init(self, db, milestone):
    32          self._db = db
    33          self._time_type = db.time_type
    34          if milestone is None:
    35              now = self._time_type.now()
    36              self._milestone = Milestone().update(now, now, "")
    37              self._milestone.set_description("")
    38          else:
    39              self._milestone = milestone
    40          self._populate_view()
    41
    42 -    def get_milestone(self):
    43          return self._milestone
    44
    45 -    def on_ok_clicked(self, evt):
    46          try:
    47              self._update_milestone()
    48              self.view.Close()
    49          except DateTimeError:
    50              pass
    51
    52 -    def _populate_view(self):
    53          self.view.SetTime(self._milestone.get_time())
    54          self.view.SetColor(self._milestone.get_default_color())
    55          self.view.SetDescription(self._milestone.get_description())
    56          label = self._milestone.get_text()
    57          self.view.SetLable(label)
    58          self.view.SetCategory(self._milestone.get_category())
    59
    60 -    def _update_milestone(self):
    61          self._set_milestone_description()
    62          self._milestone.set_text(self.view.GetLabel())
    63          self._milestone.set_default_color(self.view.GetColour()[:3])
    64          self._set_milestone_time_period()
    65          self._milestone.set_category(self.view.GetCategory())
    66          self._save_milestone_to_db()
    67
    68 -    def _set_milestone_description(self):
    69          if self.view.GetDescription() == "":
    70              self._milestone.set_description(None)
    71          else:
    72              self._milestone.set_description(self.view.GetDescription())
    73
    74 -    def _set_milestone_time_period(self):
    75          try:
    76              t = self.view.GetTime()
    77              if t is None:
    78                  raise DateTimeError()
    79              self._milestone.set_time_period(TimePeriod(t, t))
    80          except:
    81              display_error_message(_("You can't save a milestone with an invalid date/time"))
    82              raise(DateTimeError())
    83
    84 -    def _save_milestone_to_db(self):
    85          self._db.save_event(self._milestone)
    86