[PATCH] Update both time and date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This one will be also squashed with the 2/2 and 3/3.

---
 pyanaconda/ui/gui/spokes/datetime_spoke.py |   60 ++++++++++++++++------------
 1 files changed, 34 insertions(+), 26 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/datetime_spoke.py b/pyanaconda/ui/gui/spokes/datetime_spoke.py
index 0582d92..3425c26 100644
--- a/pyanaconda/ui/gui/spokes/datetime_spoke.py
+++ b/pyanaconda/ui/gui/spokes/datetime_spoke.py
@@ -31,7 +31,6 @@ from pyanaconda.ui.gui.categories.localization import LocalizationCategory
 
 from pyanaconda import localization
 import datetime
-import time
 
 __all__ = ["DatetimeSpoke"]
 
@@ -113,7 +112,7 @@ class DatetimeSpoke(NormalSpoke):
         return _("Something selected")
 
     def apply(self):
-        GLib.source_remove(self._update_time_timer_id)
+        GLib.source_remove(self._update_datetime_timer_id)
 
     @property
     def completed(self):
@@ -121,8 +120,9 @@ class DatetimeSpoke(NormalSpoke):
         return True
 
     def refresh(self):
-        self._update_time()
-        self._update_time_timer_id = GLib.timeout_add_seconds(1, self._update_time)
+        self._update_datetime()
+        self._update_datetime_timer_id = GLib.timeout_add_seconds(1,
+                                                    self._update_datetime)
         self._start_updating_timer_id = None
 
     def add_to_store(self, store, item):
@@ -197,16 +197,21 @@ class DatetimeSpoke(NormalSpoke):
 
         return (hours + correction) % 24
 
-    def _update_time(self):
-        now = time.localtime()
+    def _update_datetime(self):
+        now = datetime.datetime.now()
         if self._radioButton24h.get_active():
-            self._hoursLabel.set_text("%0.2d" % now.tm_hour)
+            self._hoursLabel.set_text("%0.2d" % now.hour)
         else:
-            hours, amPm = self._to_amPm(now.tm_hour)
+            hours, amPm = self._to_amPm(now.hour)
             self._hoursLabel.set_text("%0.2d" % hours)
             amPm_label = self.builder.get_object("amPmLabel")
 
-        self._minutesLabel.set_text("%0.2d" % now.tm_min)
+        self._minutesLabel.set_text("%0.2d" % now.minute)
+
+        self._set_combo_selection(self._dayCombo, now.day)
+        self._set_combo_selection(self._monthCombo,
+                            datetime.date(2000, now.month, 1).strftime('%B'))
+        self._set_combo_selection(self._yearCombo, now.year)
 
         #GLib's timer is driven by the return value of the function.
         #It runs the fuction periodically while the returned value
@@ -215,14 +220,15 @@ class DatetimeSpoke(NormalSpoke):
 
     def _save_system_time(self):
         #TODO: save system time here
-        self._update_time_timer_id = GLib.timeout_add_seconds(1, self._update_time)
+        self._update_datetime_timer_id = GLib.timeout_add_seconds(1,
+                                                        self._update_datetime)
 
         #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)
+        GLib.source_remove(self._update_datetime_timer_id)
 
         #stop previous 2 seconds timer (see below)
         if self._start_updating_timer_id:
@@ -233,6 +239,21 @@ class DatetimeSpoke(NormalSpoke):
         self._start_updating_timer_id = GLib.timeout_add_seconds(2,
                                                     self._save_system_time)
 
+    def _set_combo_selection(self, combo, item):
+        model = combo.get_model()
+        if not model:
+            return False
+
+        itr = model.get_iter_first()
+        while itr:
+            if model[itr][0] == item:
+                combo.set_active_iter(itr)
+                return True
+
+            itr = model.iter_next(itr)
+
+        return False
+
     def on_up_hours_clicked(self, *args):
         self._stop_and_maybe_start_time_updating()
 
@@ -351,21 +372,8 @@ class DatetimeSpoke(NormalSpoke):
         else:
             region, city = fields
 
-        itr = self._regionsStore.get_iter_first()
-        while itr:
-            if self._regionsStore[itr][0] == region:
-                self._regionCombo.set_active_iter(itr)
-                break
-
-            itr = self._regionsStore.iter_next(itr)
-
-        itr = self._citiesSort.get_iter_first()
-        while itr:
-            if self._citiesSort[itr][0] == city:
-                self._cityCombo.set_active_iter(itr)
-                break
-
-            itr = self._citiesSort.iter_next(itr)
+        self._set_combo_selection(self._regionCombo, region)
+        self._set_combo_selection(self._cityCombo, city)
 
     def on_timeformat_changed(self, button24h, *args):
         hours_label = self.builder.get_object("hoursLabel")
-- 
1.7.4.4

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux