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

# Source Code for Module Gnumed.timelinelib.wxgui.dialogs.containereditor

      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.editors.container import ContainerEditor
     22  from timelinelib.wxgui.components.categorychoice import CategoryChoice
     23  from timelinelib.wxgui.utils import BORDER
     24  from timelinelib.wxgui.utils import _display_error_message
     25  from timelinelib.wxgui.utils import _set_focus_and_select
     26  import timelinelib.wxgui.utils as gui_utils
     27
     28
     29 -class StaticContainerEditorDialog(wx.Dialog):
     30
     31 -    def __init__(self, parent, title, db):
     32          wx.Dialog.__init__(self, parent, title=title, name="container_editor",
     33                             style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
     34          self.db = db
     35          self._create_gui()
     36
     37 -    def _create_gui(self):
     38          sizer = wx.BoxSizer(wx.VERTICAL)
     39          self._create_propeties_groupbox(sizer)
     40          self._create_buttons(sizer)
     41          self.SetSizerAndFit(sizer)
     42          self.txt_name.SetFocus()
     43
     44 -    def _create_propeties_groupbox(self, sizer):
     45          groupbox = wx.StaticBox(self, wx.ID_ANY, _("Container Properties"))
     46          box = wx.StaticBoxSizer(groupbox, wx.VERTICAL)
     47          self._create_properties_groupbox_content(box)
     48          sizer.Add(box, flag=wx.EXPAND|wx.ALL, border=BORDER, proportion=1)
     49
     50 -    def _create_properties_groupbox_content(self, sizer):
     51          grid = wx.FlexGridSizer(4, 2, BORDER, BORDER)
     52          grid.AddGrowableCol(1)
     53          self._create_name_textctrl(grid)
     54          self._create_categories_listbox(grid)
     55          sizer.Add(grid, flag=wx.ALL|wx.EXPAND, border=BORDER)
     56
     57 -    def _create_name_textctrl(self, grid):
     58          self.txt_name = wx.TextCtrl(self, wx.ID_ANY, name="name")
     59          label = wx.StaticText(self, label=_("Name:"))
     60          grid.Add(label, flag=wx.ALIGN_CENTER_VERTICAL)
     61          grid.Add(self.txt_name, flag=wx.EXPAND)
     62
     63 -    def _create_categories_listbox(self, grid):
     64          self.lst_category = CategoryChoice(self, self.db)
     65          label = wx.StaticText(self, label=_("Category:"))
     66          grid.Add(label, flag=wx.ALIGN_CENTER_VERTICAL)
     67          grid.Add(self.lst_category)
     68
     69 -    def _create_buttons(self, properties_box):
     70          button_box = self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL)
     71          properties_box.Add(button_box, flag=wx.EXPAND|wx.ALL, border=BORDER)
     72
     73
     74 -class ContainerEditorControllerApi(object):
     75
     76 -    def __init__(self, db, container):
     77          self._bind_events()
     78          self.controller = ContainerEditor(self, db, container)
     79
     80 -    def set_name(self, name):
     81          self.txt_name.SetValue(name)
     82
     83 -    def get_name(self):
     84          return self.txt_name.GetValue().strip()
     85
     86 -    def set_category(self, category):
     87          self.lst_category.select(category)
     88
     89 -    def get_category(self):
     90          return self.lst_category.get()
     91
     92 -    def display_invalid_name(self, message):
     93          _display_error_message(message, self)
     94          _set_focus_and_select(self.txt_name)
     95
     96 -    def display_db_exception(self, e):
     97          gui_utils.handle_db_error_in_dialog(self, e)
     98
     99 -    def close(self):
    100          self.EndModal(wx.ID_OK)
    101
    102 -    def _bind_events(self):
    103          self.Bind(wx.EVT_BUTTON, self._btn_ok_on_click, id=wx.ID_OK)
    104          self.Bind(wx.EVT_CHOICE, self.lst_category.on_choice, self.lst_category)
    105
    106 -    def _btn_ok_on_click(self, evt):
    107          self.controller.save()
    108
    109
    110 -class ContainerEditorDialog(StaticContainerEditorDialog,
    111                              ContainerEditorControllerApi):
    112      """
    113      This dialog is used for two purposes, editing an existing container
    114      event and creating a new container event (container==None).
    115      The 'business logic' is handled by the controller.
    116      """
    117 -    def __init__(self, parent, title, db, container=None):
    118          StaticContainerEditorDialog.__init__(self, parent, title, db)
    119          ContainerEditorControllerApi.__init__(self, db, container)
    120
    121      #
    122      # Parent API
    123      #
    124 -    def get_edited_container(self):
    125          return self.controller.get_container()
    126