[gnome-clocks] First cut at Standalone Alarm view
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] First cut at Standalone Alarm view
- Date: Thu, 30 Aug 2012 01:15:36 +0000 (UTC)
commit 7562de1bccd3c532be77c7e92f6b187d348bd2fc
Author: Paolo Borelli <pborelli gnome org>
Date: Thu Aug 30 03:11:41 2012 +0200
First cut at Standalone Alarm view
Add a standalone alarm panel and show it when clicking on the alarm.
Editing can now be accessed from the Edit toolbutton when in the
standalone view. The patch includes a rework of how the toolbar is
created to make sure things are always aligned.
gnomeclocks/alarm.py | 105 ++++++++++++++++++++++++++++++++++++++------------
gnomeclocks/app.py | 76 +++++++++++++++++++++++-------------
gnomeclocks/world.py | 12 ++++--
3 files changed, 136 insertions(+), 57 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index 68e2edf..4764d09 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -175,9 +175,8 @@ class AlarmItem:
class AlarmDialog(Gtk.Dialog):
- def __init__(self, alarm_view, parent, vevent=None):
- self.vevent = vevent
- if vevent:
+ def __init__(self, alarm_view, parent, alarm=None):
+ if alarm:
Gtk.Dialog.__init__(self, _("Edit Alarm"), parent)
else:
Gtk.Dialog.__init__(self, _("New Alarm"), parent)
@@ -197,10 +196,11 @@ class AlarmDialog(Gtk.Dialog):
grid.set_border_width(6)
content_area.pack_start(grid, True, True, 0)
- if vevent:
+ if alarm:
+ vevent = alarm.get_vevent()
t = vevent.dtstart.value
h = int(t.strftime("%I"))
- m = int(t.strftime("%m"))
+ m = int(t.strftime("%M"))
p = t.strftime("%p")
name = vevent.summary.value
repeat = self.get_repeat_days_from_vevent(vevent)
@@ -308,15 +308,19 @@ class AlarmDialog(Gtk.Dialog):
class AlarmWidget():
- def __init__(self, time_given, repeat):
+ def __init__(self, view, alarm):
+ self.view = view
+ self.alarm = alarm
+ timestr = alarm.get_time_as_string()
+ repeat = alarm.get_alarm_repeat_string()
self.drawing = DigitalClockDrawing()
- t = time_given
- isDay = self.get_is_day(int(t[:2]))
+ isDay = self.get_is_day(int(timestr[:2]))
if isDay:
img = os.path.join(Dirs.get_image_dir(), "cities", "day.png")
else:
img = os.path.join(Dirs.get_image_dir(), "cities", "night.png")
- self.drawing.render(t, img, isDay, repeat)
+ self.drawing.render(timestr, img, isDay, repeat)
+ self.standalone = None
def get_is_day(self, hours):
if hours > 7 and hours < 19:
@@ -327,6 +331,11 @@ class AlarmWidget():
def get_pixbuf(self):
return self.drawing.pixbuf
+ def get_standalone_widget(self):
+ if not self.standalone:
+ self.standalone = StandaloneAlarm(self.view, self.alarm)
+ return self.standalone
+
class Alarm(Clock):
def __init__(self):
@@ -358,7 +367,6 @@ class Alarm(Clock):
for i in self.liststore:
alarm = self.liststore.get_value(i.iter, 5)
if alarm.check_expired():
- print alarm
alert = self.liststore.get_value(i.iter, 4)
alert.show()
return True
@@ -368,8 +376,8 @@ class Alarm(Clock):
win.show_clock(self)
def _on_item_activated(self, iconview, path):
- alarm = self.liststore[path][-1]
- self.open_edit_dialog(alarm.get_vevent())
+ alarm = self.liststore[path][3]
+ self.emit("show-standalone", alarm)
def _on_selection_changed(self, iconview):
self.emit("selection-changed")
@@ -396,6 +404,7 @@ class Alarm(Clock):
handler = ICSHandler()
vevents = handler.load_vevents()
for vevent in vevents:
+ t = vevent.dtstart.value
alarm = AlarmItem()
alarm.new_from_vevent(vevent)
self.add_alarm_widget(alarm)
@@ -409,9 +418,7 @@ class Alarm(Clock):
def add_alarm_widget(self, alarm):
name = alarm.get_alarm_name()
- timestr = alarm.get_time_as_string()
- repeat = alarm.get_alarm_repeat_string()
- widget = AlarmWidget(timestr, repeat)
+ widget = AlarmWidget(self, alarm)
alert = Alert("alarm-clock-elapsed", name,
self._on_notification_activated)
label = GLib.markup_escape_text(name)
@@ -440,19 +447,67 @@ class Alarm(Clock):
def open_new_dialog(self):
window = AlarmDialog(self, self.get_toplevel())
- window.connect("response", self.on_dialog_response, None)
+ window.connect("response", self.on_dialog_response)
window.show_all()
- def open_edit_dialog(self, vevent):
- window = AlarmDialog(self, self.get_toplevel(), vevent)
- window.connect("response", self.on_dialog_response, vevent)
+ def on_dialog_response(self, dialog, response):
+ if response == 1:
+ alarm = dialog.get_alarm_item()
+ self.add_alarm(alarm)
+ dialog.destroy()
+
+
+class StandaloneAlarm(Gtk.Box):
+ def __init__(self, view, alarm):
+ Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
+ self.view = view
+ self.alarm = alarm
+ self.can_edit = True
+
+ self.timebox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
+
+ self.alarm_label = Gtk.Label()
+ self.alarm_label.set_alignment(0.0, 0.5)
+ self.timebox.pack_start(self.alarm_label, True, True, 0)
+
+ self.repeat_label = Gtk.Label()
+ self.repeat_label.set_alignment(0.5, 0.5)
+ self.timebox.pack_start(self.repeat_label, True, True, 0)
+
+ self.hbox = Gtk.Box()
+ self.hbox.set_homogeneous(False)
+
+ self.hbox.pack_start(Gtk.Label(), True, True, 0)
+ self.hbox.pack_start(self.timebox, False, False, 0)
+ self.hbox.pack_start(Gtk.Label(), True, True, 0)
+
+ self.pack_start(Gtk.Label(), True, True, 0)
+ self.pack_start(self.hbox, False, False, 0)
+ self.pack_start(Gtk.Label(), True, True, 0)
+
+ self.update()
+
+ def get_name(self):
+ name = self.alarm.get_alarm_name()
+ return GLib.markup_escape_text(name)
+
+ def update(self):
+ timestr = self.alarm.get_time_as_string()
+ repeat = self.alarm.get_alarm_repeat_string()
+ self.alarm_label.set_markup(
+ "<span size='72000' color='dimgray'><b>%s</b></span>" % timestr)
+ self.repeat_label.set_markup(
+ "<span size='large' color='dimgray'><b>%s</b></span>" % repeat)
+
+ def open_edit_dialog(self):
+ window = AlarmDialog(self, self.get_toplevel(), self.alarm)
+ window.connect("response", self.on_dialog_response)
window.show_all()
- def on_dialog_response(self, dialog, response, old_vevent):
+ def on_dialog_response(self, dialog, response):
if response == 1:
- alarm = dialog.get_alarm_item()
- if old_vevent:
- self.edit_alarm(old_vevent, alarm)
- else:
- self.add_alarm(alarm)
+ old_vevent = self.alarm.get_vevent()
+ self.alarm = dialog.get_alarm_item()
+ self.view.edit_alarm(old_vevent, self.alarm)
+ self.update()
dialog.destroy()
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index cc38da2..dfab391 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -84,15 +84,15 @@ class Window(Gtk.ApplicationWindow):
self.toolbar.connect("view-clock", self._on_view_clock)
self.vbox.show_all()
self.show_all()
- self.toolbar.selection_toolbar.hide()
+ self.toolbar.show_overview_toolbar()
def show_clock(self, view):
self.toolbar.activate_view(view)
def _on_show_standalone(self, widget, d):
def show_standalone_page():
- widget, title = d.get_standalone_widget()
- self.toolbar._set_single_toolbar(title)
+ widget = d.get_standalone_widget()
+ self.toolbar.show_standalone_toolbar(widget)
self.single_evbox.add(widget)
self.single_evbox.show_all()
self.notebook.set_current_page(-1)
@@ -105,7 +105,7 @@ class Window(Gtk.ApplicationWindow):
self.single_evbox.remove(child)
view.unselect_all()
self.notebook.set_current_page(self.views.index(view))
- self.toolbar._set_overview_toolbar()
+ self.toolbar.show_overview_toolbar()
if self.single_evbox.get_children():
self.embed.spotlight(show_clock_view)
@@ -273,26 +273,24 @@ class ClocksToolbar(Gtk.Toolbar):
self.set_icon_size(Gtk.IconSize.MENU)
self.get_style_context().add_class(Gtk.STYLE_CLASS_MENUBAR)
- toolitem = Gtk.ToolItem()
- toolitem.set_expand(True)
+ self.views = views
- toolbox = Gtk.Box()
- toolitem.add(toolbox)
- self.insert(toolitem, -1)
+ sizeGroup = Gtk.SizeGroup(Gtk.SizeGroupMode.HORIZONTAL)
- self.views = views
+ leftItem = Gtk.ToolItem()
+ self.insert(leftItem, -1)
+ sizeGroup.add_widget(leftItem)
- self.newButton = Gtk.Button()
+ leftBox = Gtk.Box()
+ leftItem.add(leftBox)
+ self.newButton = Gtk.Button()
label = Gtk.Label(_("New"))
self.newButton.set_action_name("win.new")
self.newButton.get_style_context().add_class('suggested-action')
self.newButton.add(label)
self.newButton.set_size_request(64, -1)
-
- self.leftBox = box = Gtk.Box()
- box.pack_start(self.newButton, False, False, 0)
- toolbox.pack_start(box, True, True, 0)
+ leftBox.pack_start(self.newButton, False, False, 0)
self.backButton = Gtk.Button()
icon = Gio.ThemedIcon.new_with_default_fallbacks(
@@ -303,13 +301,20 @@ class ClocksToolbar(Gtk.Toolbar):
self.backButton.set_size_request(33, 33)
self.backButton.connect("clicked",
lambda w: self.emit("view-clock", self.current_view))
+ leftBox.pack_start(self.backButton, False, False, 0)
+
+ centerItem = Gtk.ToolItem()
+ centerItem.set_expand(True)
+ self.insert(centerItem, -1)
- toolbox.pack_start(Gtk.Label(""), True, True, 0)
+ centerBox = Gtk.Box()
+ centerItem.add(centerBox)
self.buttonBox = Gtk.Box()
self.buttonBox.set_homogeneous(True)
+ self.buttonBox.set_halign(Gtk.Align.CENTER)
self.buttonBox.get_style_context().add_class("linked")
- toolbox.pack_start(self.buttonBox, False, False, 0)
+ centerBox.pack_start(self.buttonBox, True, False, 0)
self.viewsButtons = {}
for view in views:
@@ -324,10 +329,16 @@ class ClocksToolbar(Gtk.Toolbar):
button.set_active(True)
self.titleLabel = Gtk.Label()
- toolbox.pack_start(self.titleLabel, False, False, 0)
- toolbox.pack_start(Gtk.Box(), False, False, 15)
+ self.titleLabel.set_halign(Gtk.Align.CENTER)
+ self.titleLabel.set_valign(Gtk.Align.CENTER)
+ centerBox.pack_start(self.titleLabel, True, False, 0)
- toolbox.pack_start(Gtk.Label(""), True, True, 0)
+ rightItem = Gtk.ToolItem()
+ sizeGroup.add_widget(rightItem)
+
+ rightBox = Gtk.Box()
+ rightItem.add(rightBox)
+ self.insert(rightItem, -1)
self.selectButton = Gtk.Button()
icon = Gio.ThemedIcon.new_with_default_fallbacks(
@@ -338,9 +349,12 @@ class ClocksToolbar(Gtk.Toolbar):
self.selectButton.set_size_request(32, 32)
self.selectButton.set_sensitive(self.current_view.can_select)
self.selectButton.connect('clicked', self._on_selection_mode, True)
- self.rightBox = box = Gtk.Box()
- box.pack_end(self.selectButton, False, False, 0)
- toolbox.pack_start(box, True, True, 0)
+ rightBox.pack_end(self.selectButton, False, False, 0)
+
+ self.editButton = Gtk.Button(_("Edit"))
+ self.editButton.set_size_request(64, 34)
+ self.editButton.connect('clicked', self._on_edit)
+ rightBox.pack_end(self.editButton, False, False, 0)
self.selection_toolbar = SelectionToolbar(embed)
self.selection_toolbar.doneButton.connect("clicked",
@@ -350,22 +364,25 @@ class ClocksToolbar(Gtk.Toolbar):
if view is not self.current_view:
self.viewsButtons[view].set_active(True)
- def _set_overview_toolbar(self):
+ def show_overview_toolbar(self):
+ self.standalone = None
+ self.selection_toolbar.hide()
self.buttonBox.show()
self.newButton.show()
self.selectButton.show()
self.backButton.hide()
self.titleLabel.hide()
+ self.editButton.hide()
- def _set_single_toolbar(self, title):
+ def show_standalone_toolbar(self, widget):
+ self.standalone = widget
self.buttonBox.hide()
self.newButton.hide()
self.selectButton.hide()
- if not self.backButton.get_parent():
- self.leftBox.pack_start(self.backButton, False, False, 0)
self.backButton.show_all()
- self.titleLabel.set_markup("<b>%s</b>" % title)
+ self.titleLabel.set_markup("<b>%s</b>" % self.standalone.get_name())
self.titleLabel.show()
+ self.editButton.set_visible(self.standalone.can_edit)
def _on_toggled(self, widget, view):
self.current_view = view
@@ -404,6 +421,9 @@ class ClocksToolbar(Gtk.Toolbar):
self.selection_toolbar.set_current_view(self.current_view)
self.current_view.set_selection_mode(selection_mode)
+ def _on_edit(self, button):
+ self.standalone.open_edit_dialog()
+
class ClocksApplication(Gtk.Application):
def __init__(self):
diff --git a/gnomeclocks/world.py b/gnomeclocks/world.py
index 2a04a18..216acaa 100644
--- a/gnomeclocks/world.py
+++ b/gnomeclocks/world.py
@@ -215,8 +215,7 @@ class DigitalClock():
if not self.standalone:
self.standalone = StandaloneClock(self.location, self.sunrise, self.sunset)
self.update()
- title = GLib.markup_escape_text(self.location.get_city_name())
- return self.standalone, title
+ return self.standalone
def get_day(self):
clock_time_day = self.get_local_time(time.time()).tm_yday
@@ -321,13 +320,13 @@ class World(Clock):
# duplicate
return
self.clocks.append(location)
+ self.storage.save_clocks(self.clocks)
self.add_clock_widget(location)
self.show_all()
- self.storage.save_clocks(self.clocks)
def add_clock_widget(self, location):
d = DigitalClock(location)
- name = d.location.get_city_name()
+ name = location.get_city_name()
label = GLib.markup_escape_text(name)
view_iter = self.liststore.append([False,
d.get_pixbuf(),
@@ -362,6 +361,8 @@ class World(Clock):
class StandaloneClock(Gtk.Box):
def __init__(self, location, sunrise, sunset):
Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL)
+ self.location = location
+ self.can_edit = False
#self.img = Gtk.Image()
#self.city_label = Gtk.Label()
#label = GLib.markup_escape_text(location.get_city_name())
@@ -426,6 +427,9 @@ class StandaloneClock(Gtk.Box):
hbox.pack_start(Gtk.Label(), True, True, 0)
self.pack_end(hbox, False, False, 30)
+ def get_name(self):
+ return GLib.markup_escape_text(self.location.get_city_name())
+
def update(self, img, text, systemClockFormat, sunrise, sunset):
size = 72000 # FIXME: (self.get_allocation().height / 300) * 72000
#if img:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]