Package Gnumed :: Package timelinelib :: Package calendar :: Package gregorian :: Package timepicker :: Module period
[frames] | no frames]

Source Code for Module Gnumed.timelinelib.calendar.gregorian.timepicker.period

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