[clocks] New design for alarms dialog
- From: Seif Lotfy <seiflotfy src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [clocks] New design for alarms dialog
- Date: Fri, 3 Aug 2012 19:12:15 +0000 (UTC)
commit 6f6efe92696a6bf43aafcc87408b95c4233a35fc
Author: Eslam Mostafa <cseslam gmail com>
Date: Thu Aug 2 22:00:28 2012 +0200
New design for alarms dialog
Signed-off-by: Seif Lotfy <seif lotfy com>
alarm.py | 24 ++++++++++---
clocks.py | 6 ++--
widgets.py | 109 ++++++++++++++++++++++++++++++++++-------------------------
3 files changed, 84 insertions(+), 55 deletions(-)
---
diff --git a/alarm.py b/alarm.py
index 9f09b74..9472d2f 100644
--- a/alarm.py
+++ b/alarm.py
@@ -1,12 +1,13 @@
import datetime, vobject, time
class AlarmItem:
- def __init__(self, name, time, repeat, h, m):
+ def __init__(self, name, time, repeat, h, m, p):
self.name = name
self.time = time
self.repeat = repeat
self.h = h
self.m = m
+ self.p = p
def set_alarm_time(self, time):
self.time = time
@@ -29,10 +30,21 @@ class AlarmItem:
def get_vobject(self):
alarm = vobject.newFromBehavior('vevent')
alarm.add('summary').value = self.name
- alarm.add('dtstart').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h, self.m))
- if self.h == 23:
- alarm.add('dtend').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h, 59))
- else:
- alarm.add('dtend').value = datetime.datetime.combine(datetime.date.today(), datetime.time(self.h+1, self.m))
+ if self.p == 'AM':
+ print self.h
+ if self.h == 12:
+ self.h = 0
+ h_end = self.h+1
+ m_end = self.m
+ elif self.p == 'PM':
+ self.h += 12
+ h_end = self.h+1
+ m_end = self.m
+ if self.h == 24:
+ self.h = 23
+ h_end = 23
+ 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)
return alarm
diff --git a/clocks.py b/clocks.py
index 27535d1..d8826f7 100644
--- a/clocks.py
+++ b/clocks.py
@@ -191,8 +191,8 @@ class Alarm (Clock):
alarms = ah.load_alarms()
for alarm in alarms:
name = alarm.summary.value
- trigger = alarm.dtstart.value
- d = AlarmWidget(trigger)
+ time = alarm.dtstart.value
+ d = AlarmWidget(time)
view_iter = self.liststore.append([d.drawing.pixbuf, "<b>" + name + "</b>", d])
d.set_iter(self.liststore, view_iter)
self.show_all()
@@ -200,7 +200,7 @@ class Alarm (Clock):
def add_alarm(self, alarm):
ah = AlarmsHandler()
ah.add_alarm(alarm.get_vobject())
- d = AlarmWidget(datetime.utcfromtimestamp(alarm.time))
+ d = AlarmWidget(datetime.utcfromtimestamp(alarm.time))
view_iter = self.liststore.append([d.drawing.pixbuf, "<b>" + alarm.get_alarm_name() + "</b>", d])
d.set_iter(self.liststore, view_iter)
self.show_all()
diff --git a/widgets.py b/widgets.py
index 4089889..fcc43f3 100644
--- a/widgets.py
+++ b/widgets.py
@@ -169,14 +169,13 @@ class DigitalClock ():
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, time_given):
- t = time_given.strftime("%I:%M %p")
- self.drawing = DigitalClockDrawing ()
+ def __init__(self, t_given):
+ self.drawing = DigitalClockDrawing ()
+ t = t_given.strftime("%I:%M %p")
isDay = self.get_is_day(t)
if isDay == True:
img = "data/cities/day.png"
@@ -186,9 +185,9 @@ class AlarmWidget():
def get_is_day(self, t):
if t[6:8] == 'AM':
- return True
+ return True
else:
- return False
+ return False
def set_iter (self, list_store, view_iter):
self.view_iter = view_iter
@@ -350,7 +349,7 @@ class NewAlarmDialog (Gtk.Dialog):
self.set_modal(True)
self.repeat_days = []
- table1 = Gtk.Table(4, 5, False)
+ table1 = Gtk.Table(4, 6, False)
table1.set_row_spacings(9)
table1.set_col_spacings(9)
content_area = self.get_content_area ()
@@ -362,29 +361,44 @@ class NewAlarmDialog (Gtk.Dialog):
self.connect("response", self.on_response)
table1.set_border_width (5)
- hour = Gtk.Label ("Hours")
- hour.set_alignment(1.0, 0.5)
- minute = Gtk.Label ("Minutes")
- minute.set_alignment(1.0, 0.5)
-
- houradjust = Gtk.Adjustment(0, 0, 24, 1, 1, 0)
+ 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")
+ time_label.set_alignment(1.0, 0.5)
+ points = Gtk.Label (":")
+ points.set_alignment(0.5, 0.5)
+
+ houradjust = Gtk.Adjustment(h, 0, 12, 1, 1, 0)
self.hourselect = hourselect = Gtk.SpinButton()
hourselect.connect('value-changed', self._on_hours_changed)
hourselect.set_adjustment(houradjust)
hourbox = Gtk.Box(True, 0)
- hourbox.pack_start (hourselect, True, True, 0)
+ hourbox.pack_start (hourselect, False, True, 0)
- minuteadjust = Gtk.Adjustment(0, 0, 60, 1, 1, 0)
+ minuteadjust = Gtk.Adjustment(m, 0, 59, 1, 1, 0)
self.minuteselect = minuteselect = Gtk.SpinButton()
minuteselect.connect('value-changed', self._on_minutes_changed)
minuteselect.set_adjustment(minuteadjust)
minutebox = Gtk.Box(True, 0)
- minutebox.pack_start (minuteselect, True, 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 (hour, 0, 1, 0, 1)
+ table1.attach (time_label, 0, 1, 0, 1)
table1.attach (hourbox, 1, 2, 0, 1)
- table1.attach (minute, 2, 3, 0, 1)
+ table1.attach (points, 2, 3, 0, 1)
table1.attach (minutebox, 3, 4, 0, 1)
+ table1.attach (ampm, 4, 5, 0, 1)
name = Gtk.Label ("Name")
name.set_alignment(1.0, 0.5)
@@ -400,21 +414,21 @@ class NewAlarmDialog (Gtk.Dialog):
self.entry = entry = Gtk.Entry ()
entry.set_text("New Alarm")
entry.set_editable (True)
- table1.attach(entry, 1, 4, 1, 2)
+ table1.attach(entry, 1, 5, 1, 2)
- buttond1 = Gtk.ToggleButton(label="Sun")
+ buttond1 = Gtk.ToggleButton(label="Mon")
buttond1.connect("clicked", self.on_d1_clicked)
- buttond2 = Gtk.ToggleButton(label="Mon")
+ buttond2 = Gtk.ToggleButton(label="Tue")
buttond2.connect("clicked", self.on_d2_clicked)
- buttond3 = Gtk.ToggleButton(label="Tue")
+ buttond3 = Gtk.ToggleButton(label="Wed")
buttond3.connect("clicked", self.on_d3_clicked)
- buttond4 = Gtk.ToggleButton(label="Wed")
+ buttond4 = Gtk.ToggleButton(label="Thu")
buttond4.connect("clicked", self.on_d4_clicked)
- buttond5 = Gtk.ToggleButton(label="Thu")
+ buttond5 = Gtk.ToggleButton(label="Fri")
buttond5.connect("clicked", self.on_d5_clicked)
- buttond6 = Gtk.ToggleButton(label="Fri")
+ buttond6 = Gtk.ToggleButton(label="Sat")
buttond6.connect("clicked", self.on_d6_clicked)
- buttond7 = Gtk.ToggleButton(label="Sat")
+ buttond7 = Gtk.ToggleButton(label="Sun")
buttond7.connect("clicked", self.on_d7_clicked)
# create a box and put them all in it
@@ -427,7 +441,7 @@ 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, 4, 2, 3)
+ table1.attach(box, 1, 5, 2, 3)
soundbox = Gtk.ComboBox ()
#table1.attach(soundbox, 1, 3, 3, 4)
@@ -439,7 +453,12 @@ 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
- new_alarm = AlarmItem(name, time, repeat, self.hourselect.get_value_as_int(), self.minuteselect.get_value_as_int())
+ 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)
self.emit('add-alarm', new_alarm)
self.destroy ()
else:
@@ -452,61 +471,59 @@ class NewAlarmDialog (Gtk.Dialog):
self.check_save_button_status()
def check_save_button_status(self):
- if self.hourselect.get_value_as_int() != 0 or self.minuteselect.get_value_as_int() != 0:
- if len(self.repeat_days) != 0:
- self.save.set_sensitive(True)
- else:
- self.save.set_sensitive(False)
+ if len(self.repeat_days) != 0:
+ self.save.set_sensitive(True)
else:
self.save.set_sensitive(False)
+
def on_d1_clicked(self, btn):
if btn.get_active() == True:
- self.repeat_days.append('SU')
+ self.repeat_days.append('MO')
if btn.get_active() == False:
- self.repeat_days.remove('SU')
+ self.repeat_days.remove('MO')
self.check_save_button_status()
def on_d2_clicked(self, btn):
if btn.get_active() == True:
- self.repeat_days.append('MO')
- else:
- self.repeat_days.remove('MO')
- self.check_save_button_status()
-
- def on_d3_clicked(self, btn):
- if btn.get_active() == True:
self.repeat_days.append('TU')
else:
self.repeat_days.remove('TU')
self.check_save_button_status()
- def on_d4_clicked(self, btn):
+ def on_d3_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('WE')
else:
self.repeat_days.remove('WE')
self.check_save_button_status()
- def on_d5_clicked(self, btn):
+ def on_d4_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('TH')
else:
self.repeat_days.remove('TH')
self.check_save_button_status()
- def on_d6_clicked(self, btn):
+ def on_d5_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('FR')
else:
self.repeat_days.remove('FR')
self.check_save_button_status()
- def on_d7_clicked(self, btn):
+ def on_d6_clicked(self, btn):
if btn.get_active() == True:
self.repeat_days.append('SA')
else:
self.repeat_days.remove('SA')
self.check_save_button_status()
+
+ def on_d7_clicked(self, btn):
+ if btn.get_active() == True:
+ self.repeat_days.append('SU')
+ else:
+ self.repeat_days.remove('SU')
+ self.check_save_button_status()
"""
if text.startswith("0"):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]