class StartTime(object): def __init__(self, parent, input_values, # Temporary workaround for bug #332 filename, id_): self.box = wx.BoxSizer(wx.HORIZONTAL) self.slabel = wx.StaticText(parent, label='Start time:') self.box.Add(self.slabel, flag=wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, border=4) self.startw = HourCtrl(parent) self.startw.set_values(input_values['start_hour'], input_values['start_minute']) self.box.Add(self.startw.get_main_panel()) def get_main_window(self): return self.box def get_first_column_width(self): return self.slabel.GetSizeTuple()[0] def set_first_column_width(self, width): sminh = self.slabel.GetMinHeight() self.slabel.SetMinSize((width, sminh)) def get_values(self, values): return {'start_relative_time': self.startw.get_relative_time(), 'start_hour': self.startw.get_hour(), 'start_minute': self.startw.get_minute()}
class _Alarm(object): def __init__( self, parent, mode, input_values, # Temporary workaround for bug #332 filename, id_): widgets = { 0: (('No alarm', None), ('Alarm advance:', self._create_alarm_advance_widget), ('Alarm date:', self._create_alarm_date_widget)), 1: (('No alarm', None), ('Alarm advance:', self._create_alarm_advance_widget), ('Sample alarm:', self._create_alarm_date_widget)), 2: (('No alarm', None), ('Alarm advance:', self._create_alarm_advance_widget), ('Alarm time:', self._create_alarm_time_widget)) } type_values = { 0: (self._get_values_none, self._get_values_duration, self._get_values_date), 1: (self._get_values_none, self._get_values_duration, self._get_values_date), 2: (self._get_values_none, self._get_values_duration, self._get_values_time) } self.type_values = type_values[mode] self.input_values = input_values self.alarmchoicew = WidgetChoiceCtrl(parent, widgets[mode], self.input_values['alarm_type'], 4) self.alarmchoicew.force_update() def get_main_window(self): return self.alarmchoicew.get_main_panel() def _create_alarm_advance_widget(self): self.alarmw = TimeSpanCtrl(self.alarmchoicew.get_main_panel(), 0, 999) self.alarmw.set_values(self.input_values['alarm_relative_number'], self.input_values['alarm_relative_unit']) return self.alarmw.get_main_panel() def _create_alarm_date_widget(self): self.alarmw = DateHourCtrl(self.alarmchoicew.get_main_panel()) self.alarmw.set_values(self.input_values['alarm_year'], self.input_values['alarm_month'], self.input_values['alarm_day'], self.input_values['alarm_hour'], self.input_values['alarm_minute']) # Temporary workaround for bug #332 wxgui_api.Bug332Workaround(self.alarmw.datectrl, self.alarmchoicew.choicectrl, self.alarmw.hourctrl.hourctrl) return self.alarmw.get_main_panel() def _create_alarm_time_widget(self): self.alarmw = HourCtrl(self.alarmchoicew.get_main_panel()) self.alarmw.set_values(self.input_values['alarm_hour'], self.input_values['alarm_minute']) return self.alarmw.get_main_panel() def get_first_column_width(self): return self.alarmchoicew.get_choice_width() def set_first_column_width(self, width): self.alarmchoicew.set_choice_min_width(width) def get_values(self, in_values): alarmtype = self.alarmchoicew.get_selection() values = {'alarm_type': alarmtype} values.update(self.type_values[alarmtype](in_values)) return values def _get_values_none(self, in_values): return { 'alarm_unix_time': None, 'alarm_relative_time': None, 'alarm_previous_day': False, 'alarm_relative_number': None, 'alarm_relative_unit': None, 'alarm_hour': None, 'alarm_minute': None } def _get_values_duration(self, in_values): start = in_values.get('start_unix_time') ralarm = self.alarmw.get_time_span() try: alarm = start - ralarm except TypeError: alarm = None return { 'alarm_unix_time': alarm, 'alarm_relative_time': ralarm, 'alarm_previous_day': False, 'alarm_relative_number': self.alarmw.get_number(), 'alarm_relative_unit': self.alarmw.get_unit(), 'alarm_hour': None, 'alarm_minute': None } def _get_values_time(self, in_values): rstart = in_values['start_relative_time'] alarmrt = self.alarmw.get_relative_time() # If time is set later than start, interpret it as referring to the # previous day if alarmrt <= rstart: ralarm = rstart - alarmrt palarm = False else: ralarm = 86400 - alarmrt + rstart palarm = True return { 'alarm_unix_time': None, 'alarm_relative_time': ralarm, 'alarm_previous_day': palarm, 'alarm_relative_number': None, 'alarm_relative_unit': None, 'alarm_hour': self.alarmw.get_hour(), 'alarm_minute': self.alarmw.get_minute() } def _get_values_date(self, in_values): start = in_values['start_unix_time'] utcoffset = in_values['utc_offset'] alarm = self.alarmw.get_unix_time() - utcoffset return { 'alarm_unix_time': alarm, 'alarm_relative_time': start - alarm, 'alarm_previous_day': False, 'alarm_relative_number': None, 'alarm_relative_unit': None, 'alarm_hour': None, 'alarm_minute': None }
class _End(object): def __init__( self, parent, mode, input_values, # Temporary workaround for bug #332 filename, id_): widgets = { 0: (('No duration', None), ('Duration:', self._create_duration_widget), ('End date:', self._create_end_date_widget)), 1: (('End date:', self._create_end_date_widget), ('Duration:', self._create_duration_widget)), 2: (('No duration', None), ('Duration:', self._create_duration_widget), ('Sample end:', self._create_end_date_widget)), 3: (('Sample end:', self._create_end_date_widget), ('Duration:', self._create_duration_widget)), 4: (('No duration', None), ('Duration:', self._create_duration_widget), ('End time:', self._create_end_time_widget)) } type_values = { 0: (self._get_values_none, self._get_values_duration, self._get_values_date), 1: (self._get_values_date, self._get_values_duration), 2: (self._get_values_none, self._get_values_duration, self._get_values_date), 3: (self._get_values_date, self._get_values_duration), 4: (self._get_values_none, self._get_values_duration, self._get_values_time) } self.type_values = type_values[mode] self.input_values = input_values self.endchoicew = WidgetChoiceCtrl(parent, widgets[mode], self.input_values['end_type'], 4) self.endchoicew.force_update() def get_main_window(self): return self.endchoicew.get_main_panel() def _create_duration_widget(self): self.endw = TimeSpanCtrl(self.endchoicew.get_main_panel(), 1, 999) self.endw.set_values(self.input_values['end_relative_number'], self.input_values['end_relative_unit']) return self.endw.get_main_panel() def _create_end_date_widget(self): self.endw = DateHourCtrl(self.endchoicew.get_main_panel()) self.endw.set_values(self.input_values['end_year'], self.input_values['end_month'], self.input_values['end_day'], self.input_values['end_hour'], self.input_values['end_minute']) # Temporary workaround for bug #332 wxgui_api.Bug332Workaround(self.endw.datectrl, self.endchoicew.choicectrl, self.endw.hourctrl.hourctrl) return self.endw.get_main_panel() def _create_end_time_widget(self): self.endw = HourCtrl(self.endchoicew.get_main_panel()) self.endw.set_values(self.input_values['end_hour'], self.input_values['end_minute']) return self.endw.get_main_panel() def get_first_column_width(self): return self.endchoicew.get_choice_width() def set_first_column_width(self, width): self.endchoicew.set_choice_min_width(width) def get_values(self, in_values): endtype = self.endchoicew.get_selection() values = {'end_type': endtype} values.update(self.type_values[endtype](in_values)) return values def _get_values_none(self, in_values): return { 'end_unix_time': None, 'end_relative_time': None, 'end_next_day': False, 'end_relative_number': None, 'end_relative_unit': None, 'end_hour': None, 'end_minute': None } def _get_values_duration(self, in_values): start = in_values.get('start_unix_time') rend = self.endw.get_time_span() try: end = start + rend except TypeError: end = None return { 'end_unix_time': end, 'end_relative_time': rend, 'end_next_day': False, 'end_relative_number': self.endw.get_number(), 'end_relative_unit': self.endw.get_unit(), 'end_hour': None, 'end_minute': None } def _get_values_time(self, in_values): rstart = in_values['start_relative_time'] endrt = self.endw.get_relative_time() # If time is set earlier than or equal to start, interpret it as # referring to the following day if endrt > rstart: rend = endrt - rstart fend = False else: rend = 86400 - rstart + endrt fend = True return { 'end_unix_time': None, 'end_relative_time': rend, 'end_next_day': fend, 'end_relative_number': None, 'end_relative_unit': None, 'end_hour': self.endw.get_hour(), 'end_minute': self.endw.get_minute() } def _get_values_date(self, in_values): start = in_values['start_unix_time'] utcoffset = in_values['utc_offset'] end = self.endw.get_unix_time() - utcoffset return { 'end_unix_time': end, 'end_relative_time': end - start, 'end_next_day': False, 'end_relative_number': None, 'end_relative_unit': None, 'end_hour': None, 'end_minute': None }
class _Alarm(object): def __init__(self, parent, mode, input_values, # Temporary workaround for bug #332 filename, id_): widgets = {0: (('No alarm', None), ('Alarm advance:', self._create_alarm_advance_widget), ('Alarm date:', self._create_alarm_date_widget)), 1: (('No alarm', None), ('Alarm advance:', self._create_alarm_advance_widget), ('Sample alarm:', self._create_alarm_date_widget)), 2: (('No alarm', None), ('Alarm advance:', self._create_alarm_advance_widget), ('Alarm time:', self._create_alarm_time_widget))} type_values = {0: (self._get_values_none, self._get_values_duration, self._get_values_date), 1: (self._get_values_none, self._get_values_duration, self._get_values_date), 2: (self._get_values_none, self._get_values_duration, self._get_values_time)} self.type_values = type_values[mode] self.input_values = input_values self.alarmchoicew = WidgetChoiceCtrl(parent, widgets[mode], self.input_values['alarm_type'], 4) self.alarmchoicew.force_update() def get_main_window(self): return self.alarmchoicew.get_main_panel() def _create_alarm_advance_widget(self): self.alarmw = TimeSpanCtrl(self.alarmchoicew.get_main_panel(), 0, 999) self.alarmw.set_values(self.input_values['alarm_relative_number'], self.input_values['alarm_relative_unit']) return self.alarmw.get_main_panel() def _create_alarm_date_widget(self): self.alarmw = DateHourCtrl(self.alarmchoicew.get_main_panel()) self.alarmw.set_values(self.input_values['alarm_year'], self.input_values['alarm_month'], self.input_values['alarm_day'], self.input_values['alarm_hour'], self.input_values['alarm_minute']) # Temporary workaround for bug #332 wxgui_api.Bug332Workaround(self.alarmw.datectrl, self.alarmchoicew.choicectrl, self.alarmw.hourctrl.hourctrl) return self.alarmw.get_main_panel() def _create_alarm_time_widget(self): self.alarmw = HourCtrl(self.alarmchoicew.get_main_panel()) self.alarmw.set_values(self.input_values['alarm_hour'], self.input_values['alarm_minute']) return self.alarmw.get_main_panel() def get_first_column_width(self): return self.alarmchoicew.get_choice_width() def set_first_column_width(self, width): self.alarmchoicew.set_choice_min_width(width) def get_values(self, in_values): alarmtype = self.alarmchoicew.get_selection() values = {'alarm_type': alarmtype} values.update(self.type_values[alarmtype](in_values)) return values def _get_values_none(self, in_values): return {'alarm_unix_time': None, 'alarm_relative_time': None, 'alarm_previous_day': False, 'alarm_relative_number': None, 'alarm_relative_unit': None, 'alarm_hour': None, 'alarm_minute': None} def _get_values_duration(self, in_values): start = in_values.get('start_unix_time') ralarm = self.alarmw.get_time_span() try: alarm = start - ralarm except TypeError: alarm = None return {'alarm_unix_time': alarm, 'alarm_relative_time': ralarm, 'alarm_previous_day': False, 'alarm_relative_number': self.alarmw.get_number(), 'alarm_relative_unit': self.alarmw.get_unit(), 'alarm_hour': None, 'alarm_minute': None} def _get_values_time(self, in_values): rstart = in_values['start_relative_time'] alarmrt = self.alarmw.get_relative_time() # If time is set later than start, interpret it as referring to the # previous day if alarmrt <= rstart: ralarm = rstart - alarmrt palarm = False else: ralarm = 86400 - alarmrt + rstart palarm = True return {'alarm_unix_time': None, 'alarm_relative_time': ralarm, 'alarm_previous_day': palarm, 'alarm_relative_number': None, 'alarm_relative_unit': None, 'alarm_hour': self.alarmw.get_hour(), 'alarm_minute': self.alarmw.get_minute()} def _get_values_date(self, in_values): start = in_values['start_unix_time'] utcoffset = in_values['utc_offset'] alarm = self.alarmw.get_unix_time() - utcoffset return {'alarm_unix_time': alarm, 'alarm_relative_time': start - alarm, 'alarm_previous_day': False, 'alarm_relative_number': None, 'alarm_relative_unit': None, 'alarm_hour': None, 'alarm_minute': None}
class _End(object): def __init__(self, parent, mode, input_values, # Temporary workaround for bug #332 filename, id_): widgets = {0: (('No duration', None), ('Duration:', self._create_duration_widget), ('End date:', self._create_end_date_widget)), 1: (('End date:', self._create_end_date_widget), ('Duration:', self._create_duration_widget)), 2: (('No duration', None), ('Duration:', self._create_duration_widget), ('Sample end:', self._create_end_date_widget)), 3: (('Sample end:', self._create_end_date_widget), ('Duration:', self._create_duration_widget)), 4: (('No duration', None), ('Duration:', self._create_duration_widget), ('End time:', self._create_end_time_widget))} type_values = {0: (self._get_values_none, self._get_values_duration, self._get_values_date), 1: (self._get_values_date, self._get_values_duration), 2: (self._get_values_none, self._get_values_duration, self._get_values_date), 3: (self._get_values_date, self._get_values_duration), 4: (self._get_values_none, self._get_values_duration, self._get_values_time)} self.type_values = type_values[mode] self.input_values = input_values self.endchoicew = WidgetChoiceCtrl(parent, widgets[mode], self.input_values['end_type'], 4) self.endchoicew.force_update() def get_main_window(self): return self.endchoicew.get_main_panel() def _create_duration_widget(self): self.endw = TimeSpanCtrl(self.endchoicew.get_main_panel(), 1, 999) self.endw.set_values(self.input_values['end_relative_number'], self.input_values['end_relative_unit']) return self.endw.get_main_panel() def _create_end_date_widget(self): self.endw = DateHourCtrl(self.endchoicew.get_main_panel()) self.endw.set_values(self.input_values['end_year'], self.input_values['end_month'], self.input_values['end_day'], self.input_values['end_hour'], self.input_values['end_minute']) # Temporary workaround for bug #332 wxgui_api.Bug332Workaround(self.endw.datectrl, self.endchoicew.choicectrl, self.endw.hourctrl.hourctrl) return self.endw.get_main_panel() def _create_end_time_widget(self): self.endw = HourCtrl(self.endchoicew.get_main_panel()) self.endw.set_values(self.input_values['end_hour'], self.input_values['end_minute']) return self.endw.get_main_panel() def get_first_column_width(self): return self.endchoicew.get_choice_width() def set_first_column_width(self, width): self.endchoicew.set_choice_min_width(width) def get_values(self, in_values): endtype = self.endchoicew.get_selection() values = {'end_type': endtype} values.update(self.type_values[endtype](in_values)) return values def _get_values_none(self, in_values): return {'end_unix_time': None, 'end_relative_time': None, 'end_next_day': False, 'end_relative_number': None, 'end_relative_unit': None, 'end_hour': None, 'end_minute': None} def _get_values_duration(self, in_values): start = in_values.get('start_unix_time') rend = self.endw.get_time_span() try: end = start + rend except TypeError: end = None return {'end_unix_time': end, 'end_relative_time': rend, 'end_next_day': False, 'end_relative_number': self.endw.get_number(), 'end_relative_unit': self.endw.get_unit(), 'end_hour': None, 'end_minute': None} def _get_values_time(self, in_values): rstart = in_values['start_relative_time'] endrt = self.endw.get_relative_time() # If time is set earlier than or equal to start, interpret it as # referring to the following day if endrt > rstart: rend = endrt - rstart fend = False else: rend = 86400 - rstart + endrt fend = True return {'end_unix_time': None, 'end_relative_time': rend, 'end_next_day': fend, 'end_relative_number': None, 'end_relative_unit': None, 'end_hour': self.endw.get_hour(), 'end_minute': self.endw.get_minute()} def _get_values_date(self, in_values): start = in_values['start_unix_time'] utcoffset = in_values['utc_offset'] end = self.endw.get_unix_time() - utcoffset return {'end_unix_time': end, 'end_relative_time': end - start, 'end_next_day': False, 'end_relative_number': None, 'end_relative_unit': None, 'end_hour': None, 'end_minute': None}