[clocks] Alarms sensitivity to system clock format



commit 2dab977d3a48325d33a9f5d40310a36c310e23b2
Author: Eslam Mostafa <cseslam gmail com>
Date:   Fri Aug 3 06:25:48 2012 +0200

    Alarms sensitivity to system clock format
    
    Signed-off-by: Seif Lotfy <seif lotfy com>

 alarm.py   |    3 +
 widgets.py |  125 ++++++++++++++++++++++++++++++++++++++++--------------------
 2 files changed, 86 insertions(+), 42 deletions(-)
---
diff --git a/alarm.py b/alarm.py
index 9472d2f..c6d3985 100644
--- a/alarm.py
+++ b/alarm.py
@@ -44,6 +44,9 @@ class AlarmItem:
                 self.h = 23
                 h_end = 23
                 m_end = 59
+        else:
+            h_end = self.h
+            m_end = 59
         alarm.add('dtstart').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h, self.m))                      
         alarm.add('dtend').value = datetime.datetime.combine(datetime.date.today(), datetime.time(h_end, m_end))
         alarm.add('rrule').value = 'FREQ=WEEKLY;BYDAY=%s' % ','.join(self.repeat)        
diff --git a/widgets.py b/widgets.py
index fcc43f3..0284d65 100644
--- a/widgets.py
+++ b/widgets.py
@@ -132,9 +132,9 @@ class DigitalClock ():
         return text
 
     def get_system_clock_format(self):
-      settings = Gio.Settings.new('org.gnome.desktop.interface')
-      systemClockFormat = settings.get_string('clock-format')
-      return systemClockFormat
+        settings = Gio.Settings.new('org.gnome.desktop.interface')
+        systemClockFormat = settings.get_string('clock-format')
+        return systemClockFormat
     
     def get_image(self):
         local_time = self.get_local_time ()
@@ -151,37 +151,47 @@ class DigitalClock ():
             return False
 
     def update(self):
-      t = self.get_local_time_text ()
-      systemClockFormat = self.get_system_clock_format ()
-      if systemClockFormat == '12h':
-        t = time.strftime("%I:%M %p", self.get_local_time ())
-      else:
-        t = time.strftime("%H:%M", self.get_local_time ()) #Convert to 24h
-      if not t == self._last_time:
-        img = self.get_image ()
-        self.drawing.render(t, img, self.get_is_day ())
-        if self.view_iter and self.list_store:
-          self.list_store.set_value(self.view_iter, 0, self.drawing.pixbuf)
-        self.standalone.update (img, t, systemClockFormat)
-      self._last_time = t
-      return True
+        t = self.get_local_time_text ()
+        systemClockFormat = self.get_system_clock_format ()
+        if systemClockFormat == '12h':
+            t = time.strftime("%I:%M %p", self.get_local_time ())
+        else:
+            t = time.strftime("%H:%M", self.get_local_time ()) #Convert to 24h
+        if not t == self._last_time:
+            img = self.get_image ()
+            self.drawing.render(t, img, self.get_is_day ())
+            if self.view_iter and self.list_store:
+                self.list_store.set_value(self.view_iter, 0, self.drawing.pixbuf)
+            self.standalone.update (img, t, systemClockFormat)
+        self._last_time = t
+        return True
 
     def set_iter (self, list_store, view_iter):
         self.view_iter = view_iter
         self.list_store = list_store
+        
     def get_standalone_widget (self):
         return self.standalone
 
 class AlarmWidget():
     def __init__(self, t_given):                          
         self.drawing = DigitalClockDrawing ()        
-        t = t_given.strftime("%I:%M %p")        
+        clockformat = self.get_system_clock_format()
+        if clockformat == '12h':
+            t = t_given.strftime("%I:%M %p")        
+        else:
+            t = t_given.strftime("%H:%M")        
         isDay = self.get_is_day(t)
         if isDay == True:
             img = "data/cities/day.png"
         else:
             img = "data/cities/night.png"
         self.drawing.render(t, img, isDay)
+    
+    def get_system_clock_format(self):
+        settings = Gio.Settings.new('org.gnome.desktop.interface')
+        systemClockFormat = settings.get_string('clock-format')
+        return systemClockFormat
         
     def get_is_day(self, t):
         if t[6:8] == 'AM':
@@ -349,7 +359,11 @@ class NewAlarmDialog (Gtk.Dialog):
         self.set_modal(True)
         self.repeat_days = []
 
-        table1 = Gtk.Table(4, 6, False) 
+        self.cf = cf = self.get_system_clock_format()
+        if cf == "12h":
+            table1 = Gtk.Table(4, 6, False) 
+        else:
+            table1 = Gtk.Table(4, 5, False) 
         table1.set_row_spacings(9)
         table1.set_col_spacings(9)
         content_area = self.get_content_area ()        
@@ -363,8 +377,6 @@ class NewAlarmDialog (Gtk.Dialog):
         
         t = time.localtime()        
         h = t.tm_hour
-        if h > 12:
-             h = h-12
         m = t.tm_min
         p = time.strftime("%p", t)        
         time_label = Gtk.Label ("Time")
@@ -372,7 +384,10 @@ class NewAlarmDialog (Gtk.Dialog):
         points = Gtk.Label (":")
         points.set_alignment(0.5, 0.5)
 
-        houradjust = Gtk.Adjustment(h, 0, 12, 1, 1, 0)
+        if cf == "12h":
+            houradjust = Gtk.Adjustment(h, 0, 12, 1, 1, 0)
+        else:
+            houradjust = Gtk.Adjustment(h, 0, 23, 1, 1, 0)
         self.hourselect = hourselect = Gtk.SpinButton()
         hourselect.connect('value-changed', self._on_hours_changed)
         hourselect.set_adjustment(houradjust)        
@@ -386,20 +401,27 @@ class NewAlarmDialog (Gtk.Dialog):
         minutebox = Gtk.Box(True, 0)        
         minutebox.pack_start (minuteselect, False, True, 0)
         
-        self.ampm = ampm = Gtk.ComboBoxText()             
-        ampm.append_text("AM")
-        ampm.append_text("PM")
-        if p == 'AM':
-            ampm.set_active(0)
-        else:
-            ampm.set_active(1)
-    
-        table1.attach (time_label, 0, 1, 0, 1)
-        table1.attach (hourbox, 1, 2, 0, 1)
-        table1.attach (points, 2, 3, 0, 1)
-        table1.attach (minutebox, 3, 4, 0, 1)  
-        table1.attach (ampm, 4, 5, 0, 1)  
         
+        if cf == "12h":
+            self.ampm = ampm = Gtk.ComboBoxText()             
+            ampm.append_text("AM")
+            ampm.append_text("PM")
+            if p == 'AM':
+                ampm.set_active(0)
+            else:
+                ampm.set_active(1)    
+            
+            table1.attach (time_label, 0, 1, 0, 1)
+            table1.attach (hourbox, 1, 2, 0, 1)
+            table1.attach (points, 2, 3, 0, 1)
+            table1.attach (minutebox, 3, 4, 0, 1)  
+            table1.attach (ampm, 4, 5, 0, 1)  
+        else:
+            table1.attach (time_label, 0, 1, 0, 1)
+            table1.attach (hourbox, 1, 2, 0, 1)
+            table1.attach (points, 2, 3, 0, 1)
+            table1.attach (minutebox, 3, 4, 0, 1)              
+            
         name = Gtk.Label ("Name")
         name.set_alignment(1.0, 0.5)
         repeat = Gtk.Label ("Repeat Every")
@@ -414,7 +436,10 @@ class NewAlarmDialog (Gtk.Dialog):
         self.entry = entry = Gtk.Entry ()
         entry.set_text("New Alarm")
         entry.set_editable (True)
-        table1.attach(entry, 1, 5, 1, 2) 
+        if cf == "12h":
+            table1.attach(entry, 1, 5, 1, 2) 
+        else:
+            table1.attach(entry, 1, 4, 1, 2) 
         
         buttond1 = Gtk.ToggleButton(label="Mon")
         buttond1.connect("clicked", self.on_d1_clicked)
@@ -441,10 +466,18 @@ class NewAlarmDialog (Gtk.Dialog):
         box.pack_start (buttond5, True, True, 0)
         box.pack_start (buttond6, True, True, 0)
         box.pack_start (buttond7, True, True, 0)
-        table1.attach(box, 1, 5, 2, 3) 
+        if cf == "12h":
+            table1.attach(box, 1, 5, 2, 3) 
+        else:
+            table1.attach(box, 1, 4, 2, 3) 
        
         soundbox = Gtk.ComboBox ()
         #table1.attach(soundbox, 1, 3, 3, 4)
+        
+    def get_system_clock_format(self):
+        settings = Gio.Settings.new('org.gnome.desktop.interface')
+        systemClockFormat = settings.get_string('clock-format')
+        return systemClockFormat
       
     def on_response(self, widget, id):
         if id == 0:
@@ -453,12 +486,15 @@ class NewAlarmDialog (Gtk.Dialog):
             name = self.entry.get_text()  #Perfect
             time = self.hourselect.get_value_as_int() * 60 * 60 + self.minuteselect.get_value_as_int() * 60            
             repeat = self.repeat_days
-            r = self.ampm.get_active()
-            if r == 0:
-                p = 'AM'
+            if self.cf == "12h":
+                r = self.ampm.get_active()
+                if r == 0:
+                    p = 'AM'
+                else:
+                    p = 'PM'
+                new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int(), p)            
             else:
-                p = 'PM'
-            new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int(), p)            
+                new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int(), None)            
             self.emit('add-alarm', new_alarm)
             self.destroy ()
         else:
@@ -536,3 +572,8 @@ def get_image(self, local_time):
     else:
         return "data/cities/night.png"
 """
+
+class ClocksHome(Gtk.Box):
+    def __init__(self):
+        Gt.Box.__init__(self)
+        self.set_orientation(Gtk.Orientation.VERTICAL)



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