32
32
class DatePicker(_common.CustomProxyObjectBase):
33
33
"""Autopilot helper for the DatePicker component."""
35
@autopilot_logging.log_action(logger.info) # NOQA
35
@autopilot_logging.log_action(logger.info)
36
36
def pick_date(self, date):
37
# TODO: reduce complexity to avoid flake8 issues
38
37
"""Pick a date from the date picker.
40
38
:parameter date: The date to pick.
41
39
:type date: An object with year, month and day attributes, like
42
40
python's datetime.date.
43
:raises ubuntuuitoolkit.UiToolsException if the mode of the picker
41
:raises ToolkitException if the mode of the picker
44
42
doesn't let select a date.
44
self._assert_valid_date_mode(self.mode)
45
self._select_year(date)
46
self._select_month(date)
47
self._select_day(date)
47
if not self._is_date_picker():
48
raise _common.UiToolsException(
49
"Can't pick date. The picker mode is: {!r}.".format(self.mode))
49
def _select_year(self, date):
50
50
if 'Years' in self.mode:
51
51
self._pick_year(date.year)
52
52
self.year.wait_for(date.year)
54
def _select_month(self, date):
53
55
if 'Month' in self.mode:
54
56
# Python's date object starts at one. The model in the date picker
56
58
self._pick_month(date.month - 1)
57
59
self.month.wait_for(date.month - 1)
61
def _select_day(self, date):
58
62
if 'Day' in self.mode:
59
63
self._pick_day(date.day)
60
64
self.day.wait_for(date.day)
62
def _is_date_picker(self):
64
if 'Years' in mode or 'Months' in mode or 'Days' in mode:
67
def _assert_valid_date_mode(mode):
68
if not ('Years' in mode or 'Months' in mode or 'Days' in mode):
69
raise _common.UiToolsException(
70
"Can't pick date. The picker mode is: {!r}.".format(mode))
69
72
@autopilot_logging.log_action(logger.info)
70
73
def _pick_year(self, year):
114
117
return datetime.date(self.year, self.month + 1, self.day)
116
@autopilot_logging.log_action(logger.info) # NOQA
119
@autopilot_logging.log_action(logger.info)
117
120
def pick_time(self, time):
118
# TODO: reduce complexity to avoid flake8 issues
119
121
"""Pick a time from the date picker.
121
123
:parameter time: The time to pick.
122
124
:type time: An object with hour, minute and second attributes, like
123
125
python's datetime.time.
124
:raises ubuntuuitoolkit.UiToolsException if the mode of the picker
126
:raises ToolkitException if the mode of the picker
125
127
doesn't let select a time.
128
if not self._is_time_picker():
129
raise _common.UiToolsException(
130
"Can't pick time. The picker mode is: {!r}.".format(self.mode))
130
self._assert_valid_time_mode(self.mode)
131
131
# Workaround https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1346669
132
# By setting seconds, then minutes, then hours, erratic behavoir
132
# By setting seconds, then minutes, then hours, erratic behavior
133
133
# can be dealt with
134
self._select_seconds(time)
135
self._select_minutes(time)
136
self._select_hours(time)
138
def _select_seconds(self, time):
134
139
if 'Seconds' in self.mode:
135
140
self._pick_second(time.second)
136
141
self.seconds.wait_for(time.second)
143
def _select_minutes(self, time):
137
144
if 'Minutes' in self.mode:
138
145
self._pick_minute(time.minute)
139
146
self.minutes.wait_for(time.minute)
148
def _select_hours(self, time):
140
149
if 'Hours' in self.mode:
141
150
self._pick_hour(time.hour)
142
151
self.hours.wait_for(time.hour)
144
def _is_time_picker(self):
146
if 'Hours' in mode or 'Minutes' in mode or 'Seconds' in mode:
154
def _assert_valid_time_mode(mode):
155
if not ('Hours' in mode or 'Minutes' in mode or 'Seconds' in mode):
156
raise _common.UiToolsException(
157
"Can't pick time. The picker mode is: {!r}.".format(mode))
151
159
@autopilot_logging.log_action(logger.info)
152
160
def _pick_hour(self, hour):