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

# Source Code for Module Gnumed.timelinelib.wxgui.dialogs.editcontainer.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 EditContainerDialogController(Controller):
    23
    24      """
    25      This controller is responsible for two things:
    26
    27      1. Creating a new container
    28      2. Updating properties of an existing container
    29
    30      When creating a new container the result is NOT stored in the database.
    31      This happens later when the first event added to the container is saved to
    32      the database.
    33
    34      The reason for this behavior is that we don't want to have empty containers
    35      in the database. When updating the properties of an existing container the
    36      changes are stored in the timeline database.
    37      """
    38
    39 -    def on_init(self, db, container):
    40          self.view.PopulateCategories()
    41          self._create_container(db, container)
    42          self._populate_view()
    43
    44 -    def on_ok_clicked(self, event):
    45          if self._validate():
    46              self._populate_container()
    47              if self._is_updating:
    48                  self._container.save()
    49              self.view.EndModalOk()
    50
    51 -    def get_container(self):
    52          return self._container
    53
    54 -    def _create_container(self, db, container):
    55          if container is None:
    56              self._is_updating = False
    57              self._container = db.new_container(text="", category=None)
    58          else:
    59              self._is_updating = True
    60              self._container = container
    61
    62 -    def _populate_view(self):
    63          self.view.SetName(self._container.get_text())
    64          self.view.SetCategory(self._container.get_category())
    65
    66 -    def _validate(self):
    67          if self.view.GetName() == "":
    68              self.view.DisplayInvalidName(
    69                  _("Field '%s' can't be empty.") % _("Name")
    70              )
    71              return False
    72          return True
    73
    74 -    def _populate_container(self):
    75          self._container.text = self.view.GetName()
    76          self._container.category = self.view.GetCategory()
    77