Gnumed.timelinelib.wxgui.dialogs.timeeditor

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

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

     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.wxgui.utils import BORDER
    22  from timelinelib.wxgui.utils import _display_error_message
    23  from timelinelib.wxgui.utils import time_picker_for
    24  from timelinelib.utils import ex_msg
    25
    26
    27 -class TimeEditorDialog(wx.Dialog):
    28
    29 -    def __init__(self, parent, config, time_type, time, title):
    30          wx.Dialog.__init__(self, parent, title=title)
    31          self.time_type = time_type
    32          self.config = config
    33          self._create_gui()
    34          self.time_picker.set_value(time)
    35          if self._should_display_show_time_checkbox():
    36              self.time_picker.show_time(self.checkbox.IsChecked())
    37          self.time_picker.SetFocus()
    38
    39 -    def _create_gui(self):
    40          self._create_show_time_checkbox()
    41          self._create_time_picker()
    42          self._create_buttons()
    43          self._layout_components()
    44
    45 -    def _create_show_time_checkbox(self):
    46          if self._should_display_show_time_checkbox():
    47              self.checkbox = wx.CheckBox(self, label=_("Show time"))
    48              self.checkbox.SetValue(False)
    49              self.Bind(wx.EVT_CHECKBOX, self._show_time_checkbox_on_checked, self.checkbox)
    50
    51 -    def _show_time_checkbox_on_checked(self, e):
    52          self.time_picker.show_time(e.IsChecked())
    53
    54 -    def _create_time_picker(self):
    55          self.time_picker = time_picker_for(self.time_type)(self, config=self.config)
    56
    57 -    def _create_buttons(self):
    58          self.button_box = self.CreateStdDialogButtonSizer(wx.OK|wx.CANCEL)
    59          self.Bind(wx.EVT_BUTTON, self._ok_button_on_click, id=wx.ID_OK)
    60
    61 -    def _ok_button_on_click(self, e):
    62          try:
    63              self.time = self.time_picker.get_value()
    64          except ValueError, ex:
    65              _display_error_message(ex_msg(ex))
    66          else:
    67              self.EndModal(wx.ID_OK)
    68
    69 -    def _layout_components(self):
    70          vbox = wx.BoxSizer(wx.VERTICAL)
    71          if self._should_display_show_time_checkbox():
    72              vbox.Add(self.checkbox, flag=wx.LEFT|wx.TOP|wx.RIGHT,
    73                       border=BORDER, proportion=1)
    74          if self._should_display_show_time_checkbox():
    75              flag = wx.EXPAND|wx.RIGHT|wx.BOTTOM|wx.LEFT
    76          else:
    77              flag = wx.EXPAND|wx.RIGHT|wx.TOP|wx.BOTTOM|wx.LEFT
    78          vbox.Add(self.time_picker, flag=flag,
    79                   border=BORDER, proportion=1)
    80          vbox.Add(self.button_box, flag=wx.ALL|wx.EXPAND, border=BORDER)
    81          self.SetSizerAndFit(vbox)
    82
    83 -    def _should_display_show_time_checkbox(self):
    84          return self.time_type.is_date_time_type()
    85