Even after manual modification by the user we want to keep updating the displayed time to the newly set system time. --- pyanaconda/ui/gui/spokes/datetime_spoke.py | 56 ++++++++++++++++++++++++++++ 1 files changed, 56 insertions(+), 0 deletions(-) diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py index ee2f21b..2edde8b 100644 --- a/pyanaconda/ui/gui/spokes/datetime_spoke.py +++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py @@ -31,6 +31,7 @@ from pyanaconda.ui.gui.categories.localization import LocalizationCategory from pyanaconda import localization import datetime +import time __all__ = ["DatetimeSpoke"] @@ -102,6 +103,13 @@ class DatetimeSpoke(NormalSpoke): if self._radioButton24h.get_active(): self._set_amPm_part_sensitive(False) + self._hoursLabel = self.builder.get_object("hoursLabel") + self._minutesLabel = self.builder.get_object("minutesLabel") + + self._update_time() + self._update_time_timer_id = GLib.timeout_add_seconds(1, self._update_time) + self._start_updating_timer_id = None + self._tzmap.set_timezone("Europe/Prague") #XXX:remove before pushing! @@ -197,7 +205,45 @@ class DatetimeSpoke(NormalSpoke): return (hours + correction) % 24 + def _update_time(self): + now = time.localtime() + if self._radioButton24h.get_active(): + self._hoursLabel.set_text("%0.2d" % now.tm_hour) + else: + hours, amPm = self._to_amPm(now.tm_hour) + self._hoursLabel.set_text("%0.2d" % hours) + amPm_label = self.builder.get_object("amPmLabel") + + self._minutesLabel.set_text("%0.2d" % now.tm_min) + + #GLib's timer is driven by the return value of the function. + #It runs the fuction periodically while the returned value + #is True. + return True + + def _save_system_time(self): + #TODO: save system time here + self._update_time_timer_id = GLib.timeout_add_seconds(1, self._update_time) + + #run only once (after first 2 seconds) + return False + + def _stop_and_maybe_start_time_updating(self): + #stop time updating + GLib.source_remove(self._update_time_timer_id) + + #stop previous 2 seconds timer (see below) + if self._start_updating_timer_id: + GLib.source_remove(self._start_updating_timer_id) + + #give a user chance to change time and after 2 seconds of + #inactivity save it as system time and start time updating + self._start_updating_timer_id = GLib.timeout_add_seconds(2, + self._save_system_time) + def on_up_hours_clicked(self, *args): + self._stop_and_maybe_start_time_updating() + hours_label = self.builder.get_object("hoursLabel") hours = int(hours_label.get_text()) @@ -216,6 +262,8 @@ class DatetimeSpoke(NormalSpoke): hours_label.set_text(new_hours_str) def on_down_hours_clicked(self, *args): + self._stop_and_maybe_start_time_updating() + hours_label = self.builder.get_object("hoursLabel") hours = int(hours_label.get_text()) @@ -234,6 +282,8 @@ class DatetimeSpoke(NormalSpoke): hours_label.set_text(new_hours_str) def on_up_minutes_clicked(self, *args): + self._stop_and_maybe_start_time_updating() + minutes_label = self.builder.get_object("minutesLabel") minutes = int(minutes_label.get_text()) minutes_str = "%0.2d" % ((minutes + 1) % 60) @@ -241,12 +291,16 @@ class DatetimeSpoke(NormalSpoke): pass def on_down_minutes_clicked(self, *args): + self._stop_and_maybe_start_time_updating() + minutes_label = self.builder.get_object("minutesLabel") minutes = int(minutes_label.get_text()) minutes_str = "%0.2d" % ((minutes - 1) % 60) minutes_label.set_text(minutes_str) def on_up_ampm_clicked(self, *args): + self._stop_and_maybe_start_time_updating() + label = self.builder.get_object("amPmLabel") if label.get_text() == "AM": label.set_text("PM") @@ -254,6 +308,8 @@ class DatetimeSpoke(NormalSpoke): label.set_text("AM") def on_down_ampm_clicked(self, *args): + self._stop_and_maybe_start_time_updating() + label = self.builder.get_object("amPmLabel") if label.get_text() == "AM": label.set_text("PM") -- 1.7.4.4 _______________________________________________ Anaconda-devel-list mailing list Anaconda-devel-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/anaconda-devel-list