[gnome-clocks] Rework the AlarmItem class
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Rework the AlarmItem class
- Date: Sun, 19 Aug 2012 16:40:11 +0000 (UTC)
commit 636422afeeadf2aff744462c791e47cda96769a8
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Aug 19 18:26:37 2012 +0200
Rework the AlarmItem class
The class should always use its internal datetime object to keep track
of the alarm, not manually fiddle with hours and minutes. This solves
many problems related to am/pm etc.
However I am pretty sure things are still not working, for instance we
do not propagate from the alarm edit dialog any info about the date
gnomeclocks/alarm.py | 68 +++++++++++-------------------------------------
gnomeclocks/clocks.py | 9 ++----
2 files changed, 19 insertions(+), 58 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index 84f9624..6e3147a 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -16,10 +16,11 @@
#
# Author: Seif Lotfy <seif lotfy collabora co uk>
-import datetime
-import vobject
import os
+from datetime import datetime
+import vobject
+from utils import SystemSettings
class ICSHandler():
def __init__(self):
@@ -71,53 +72,29 @@ class AlarmItem:
self.repeat = repeat
self.vevent = None
self.uid = None
- self.h = h
- self.m = m
- self.p = p
+ if h and m:
+ if p:
+ self.time = datetime.strptime("%02i:%02i %s" % (h, m, p), "%I:%M %p")
+ else:
+ self.time = datetime.strptime("%02i:%02i" % (h, m), "%H:%M")
+ else:
+ self.time = None
def new_from_vevent(self, vevent):
self.vevent = vevent
self.name = vevent.summary.value
self.time = vevent.dtstart.value
- self.h = int(self.time.strftime("%H"))
- self.m = int(self.time.strftime("%M"))
- self.p = self.time.strftime("%p")
self.uid = vevent.uid.value
if vevent.rrule.value == 'FREQ=DAILY;':
self.repeat = ['FR', 'MO', 'SA', 'SU', 'TH', 'TU', 'WE']
else:
self.repeat = vevent.rrule.value[19:].split(',')
- def set_alarm_time(self, h, m, p):
- self.h = h
- self.m = m
- self.p = p
-
- def get_alarm_time(self):
- time = {}
- time['h'] = self.h
- time['m'] = self.m
- time['p'] = self.p
- return self.time
-
- def get_time_12h_as_string(self):
- if self.p == 'AM' or self.p == 'PM':
- if self.h == 12 or self.h == 0:
- h = 12
- else:
- h = self.h - 12
- else:
- h = self.h
- return "%2i:%02i %s" % (h, self.m, self.p)
-
- def get_time_24h_as_string(self):
- if self.p == 'AM' or self.p == 'PM':
- h = self.h + 12
- if h == 24:
- h = 12
+ def get_time_as_string(self):
+ if SystemSettings.get_clock_format() == "12h":
+ return self.time.strftime("%I:%M %p")
else:
- h = self.h
- return "%2i:%02i" % (h, self.m)
+ return self.time.strftime("%H:%M")
def set_alarm_name(self, name):
self.name = name
@@ -166,21 +143,8 @@ class AlarmItem:
def get_vevent(self):
self.vevent = vevent = vobject.newFromBehavior('vevent')
vevent.add('summary').value = self.name
- h = self.h
- m = self.m
- if self.p == "PM":
- h = self.h + 12
- if h == 24:
- h = 12
- elif self.p == "AM":
- if h == 12:
- h = 0
- vevent.add('dtstart').value =\
- datetime.datetime.combine(datetime.date.today(),
- datetime.time(h, m))
- vevent.add('dtend').value =\
- datetime.datetime.combine(datetime.date.today(),
- datetime.time(h, m))
+ vevent.add('dtstart').value = self.time
+ vevent.add('dtend').value = self.time
if len(self.repeat) == 0:
vevent.add('rrule').value = 'FREQ=DAILY;'
else:
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index f2aa9fd..6752b7e 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -222,8 +222,8 @@ class Alarm(Clock):
items = iconview.get_selected_items()
if items:
path = iconview.get_selected_items()[0]
- vevent = self.liststore[path][-1]
- self.open_edit_dialog(vevent)
+ alarm = self.liststore[path][-1]
+ self.open_edit_dialog(alarm)
def load_alarms(self):
handler = ICSHandler()
@@ -262,10 +262,7 @@ class Alarm(Clock):
def add_alarm_widget(self, alarm):
name = alarm.get_alarm_name()
- if SystemSettings.get_clock_format() == "12h":
- timestr = alarm.get_time_12h_as_string()
- else:
- timestr = alarm.get_time_24h_as_string()
+ timestr = alarm.get_time_as_string()
repeat = alarm.get_alarm_repeat_string()
widget = AlarmWidget(timestr, repeat)
view_iter = self.liststore.append([widget.drawing.pixbuf,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]