[gnome-clocks] Rework timer notification



commit a886fc3f35d93287744d5a56d3d91e92e9f78e9c
Author: Paolo Borelli <pborelli gnome org>
Date:   Thu Aug 23 20:51:33 2012 +0200

    Rework timer notification
    
    Make sure that the timer page is shown when clicking on the notification

 gnomeclocks/app.py    |    9 +++++++++
 gnomeclocks/clocks.py |   10 ++++++++--
 gnomeclocks/utils.py  |   15 ++++++++++-----
 3 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/gnomeclocks/app.py b/gnomeclocks/app.py
index dfb6a89..500f56a 100644
--- a/gnomeclocks/app.py
+++ b/gnomeclocks/app.py
@@ -78,6 +78,9 @@ class Window(Gtk.ApplicationWindow):
         self.show_all()
         self.toolbar.selection_toolbar.hide()
 
+    def show_clock(self, view):
+        self.toolbar.activate_view(view)
+
     def _on_show_clock(self, widget, d):
         self.toolbar._set_single_toolbar()
         self.notebook.set_current_page(-1)
@@ -299,14 +302,20 @@ class ClocksToolbar(Gtk.Toolbar):
 
     def set_clocks(self, views):
         self.views = views
+        self.viewsButtons = {}
         for view in views:
             button = ClockButton(view.label)
             self.buttonBox.pack_start(button, False, False, 0)
             button.connect('toggled', self._on_toggled, view)
+            self.viewsButtons[view] = button
             if view == views[0]:
                 self.current_view = view
                 button.set_active(True)
 
+    def activate_view(self, view):
+        if view is not self.current_view:
+            self.viewsButtons[view].set_active(True)
+
     def _set_overview_toolbar(self):
         self.buttonBox.show()
         self.newButton.show()
diff --git a/gnomeclocks/clocks.py b/gnomeclocks/clocks.py
index 17e3308..9af2467 100644
--- a/gnomeclocks/clocks.py
+++ b/gnomeclocks/clocks.py
@@ -394,7 +394,6 @@ class Timer(Clock):
         self.state = Timer.State.STOPPED
         self.g_id = 0
 
-        self.alert = Alert()
         self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
         box = Gtk.Box()
         self.add(box)
@@ -412,6 +411,13 @@ class Timer(Clock):
         self.timer_screen = TimerScreen(self)
         self.show_timer_welcome_screen()
 
+        self.alert = Alert("complete", "Ta Da !",
+                           self._on_notification_activated)
+
+    def _on_notification_activated(self, notif, action, data):
+        win = self.get_toplevel()
+        win.show_clock(self)
+
     def show_timer_welcome_screen(self):
         self.timerbox.pack_start(self.timer_welcome_screen, True, True, 0)
         self.timer_welcome_screen.update_start_button_status()
@@ -465,7 +471,7 @@ class Timer(Clock):
         self.timer_screen.timerLabel.set_markup(TIMER_LABEL_MARKUP %
                                                 (hours, minutes, seconds))
         if hours == 00 and minutes == 00 and seconds == 00:
-            self.alert.do_alert("Ta Da !", "complete")
+            self.alert.show()
             self.state = Timer.State.STOPPED
             self.timerbox.remove(self.timer_screen)
             self.show_timer_welcome_screen()
diff --git a/gnomeclocks/utils.py b/gnomeclocks/utils.py
index eb6962d..c092b61 100644
--- a/gnomeclocks/utils.py
+++ b/gnomeclocks/utils.py
@@ -62,14 +62,19 @@ class SystemSettings:
 
 
 class Alert:
-    def __init__(self):
+    def __init__(self, soundid, msg, callback):
         self.canberra = pycanberra.Canberra()
+        self.soundid = soundid
 
-    def do_alert(self, msg, eventid):
+        self.notification = None
         if Notify.init("GNOME Clocks"):
-            Alert = Notify.Notification.new("Clocks", msg, 'test')
-            Alert.show()
+            self.notification = Notify.Notification.new("Clocks", msg, 'clocks')
+            # the special "default" action should not display a button
+            self.notification.add_action("default", "Show", callback, None, None)
         else:
             print "Error: Could not trigger Alert"
 
-        self.canberra.play(1, pycanberra.CA_PROP_EVENT_ID, eventid, None)
+    def show(self):
+        self.canberra.play(1, pycanberra.CA_PROP_EVENT_ID, self.soundid, None)
+        if self.notification:
+            self.notification.show()



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