Package Gnumed :: Package timelinelib :: Package calendar :: Package num :: Module periodpicker |
[frames] | no frames]

# Source Code for Module Gnumed.timelinelib.calendar.num.periodpicker

      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.calendar.num.timetype import NumTimeType
     20  from timelinelib.canvas.data import TimePeriod
     21  from timelinelib.wxgui.framework import Controller
     22  from timelinelib.wxgui.framework import Panel
     23
     24
     25 -class NumPeriodPicker(Panel):
     26
     27      """
     28      <BoxSizerVertical>
     29          <BoxSizerHorizontal>
     30              <TimePicker
     31                  name="start_time"
     32                  time_type="$(time_type)"
     33                  config="$(config)"
     34              />
     35              <Spacer />
     36              <StaticText
     37                  label="$(to_label)"
     38                  name="to_label"
     39                  align="ALIGN_CENTER_VERTICAL"
     40              />
     41              <Spacer />
     42              <TimePicker
     43                  name="end_time"
     44                  time_type="$(time_type)"
     45                  config="$(config)"
     46              />
     47          </BoxSizerHorizontal>
     48          <Spacer />
     49          <BoxSizerHorizontal>
     50              <CheckBox
     51                  name="period_checkbox"
     52                  event_EVT_CHECKBOX="on_period_checkbox_changed"
     53                  label="$(period_checkbox_text)" />
     54          </BoxSizerHorizontal>
     55      </BoxSizerVertical>
     56      """
     57
     58 -    def __init__(self, parent, config, name=None):
     59          Panel.__init__(self, NumPeriodPickerController, parent, {
     60              "time_type": NumTimeType(),
     61              "config": config,
     62              "to_label": _("to"),
     63              "period_checkbox_text": _("Period"),
     64          })
     65
     66 -    def GetValue(self):
     67          return self.controller.get_value()
     68
     69 -    def SetValue(self, time_period):
     70          self.controller.set_value(time_period)
     71
     72 -    def GetStartValue(self):
     73          return self.start_time.get_value()
     74
     75 -    def SetStartValue(self, time):
     76          self.start_time.set_value(time)
     77
     78 -    def GetEndValue(self):
     79          return self.end_time.get_value()
     80
     81 -    def SetEndValue(self, time):
     82          self.end_time.set_value(time)
     83
     84 -    def GetShowPeriod(self):
     85          return self.period_checkbox.GetValue()
     86
     87 -    def SetShowPeriod(self, show):
     88          self.period_checkbox.SetValue(show)
     89          self.to_label.Show(show)
     90          self.end_time.Show(show)
     91          self.Layout()
     92
     93 -    def GetShowTime(self):
     94          return False
     95
     96 -    def SetShowTime(self, show):
     97          pass
     98
     99 -    def DisableTime(self):
    100          pass
    101
    102
    103 -class NumPeriodPickerController(Controller):
    104
    105 -    def get_value(self):
    106          return TimePeriod(self._get_start(), self._get_end())
    107
    108 -    def set_value(self, time_period):
    109          self.view.SetStartValue(time_period.get_start_time())
    110          self.view.SetEndValue(time_period.get_end_time())
    111          self.view.SetShowPeriod(time_period.is_period())
    112
    113 -    def on_period_checkbox_changed(self, event):
    114          self.view.SetShowPeriod(event.IsChecked())
    115
    116 -    def _get_start(self):
    117          return self.view.GetStartValue()
    118
    119 -    def _get_end(self):
    120          if self.view.GetShowPeriod():
    121              return self.view.GetEndValue()
    122          else:
    123              return self._get_start()
    124