[gnome-clocks] Move the alert in the AlarmItem object
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-clocks] Move the alert in the AlarmItem object
- Date: Sun, 18 Nov 2012 14:45:12 +0000 (UTC)
commit 677f15211e0368e0d421d16733f7dfd0fc053ba6
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Nov 18 15:43:21 2012 +0100
Move the alert in the AlarmItem object
It does not belong to the Thumbnail object, which is just a view.
I do not like much the hack we do to get ahold of the toplevel window
and show the alarm page, but it was already a hack before, so it is at
least not worse...
gnomeclocks/alarm.py | 34 ++++++++++++++--------------------
1 files changed, 14 insertions(+), 20 deletions(-)
---
diff --git a/gnomeclocks/alarm.py b/gnomeclocks/alarm.py
index 988b99d..1435708 100644
--- a/gnomeclocks/alarm.py
+++ b/gnomeclocks/alarm.py
@@ -21,7 +21,7 @@ import errno
import time
import json
from datetime import datetime, timedelta
-from gi.repository import GLib, GObject, Gtk, GdkPixbuf
+from gi.repository import GLib, Gio, GObject, Gtk, GdkPixbuf
from clocks import Clock
from utils import Dirs, SystemSettings, LocalizedWeekdays, Alert
from widgets import DigitalClockDrawing, SelectableIconView, ContentView
@@ -72,6 +72,8 @@ class AlarmItem:
def __init__(self, name=None, hour=None, minute=None, days=EVERY_DAY):
self.update(name=name, hour=hour, minute=minute, days=days)
+ self.alert = Alert("alarm-clock-elapsed", name,
+ self._on_notification_activated)
def update(self, name=None, hour=None, minute=None, days=EVERY_DAY):
self.name = name
@@ -109,11 +111,17 @@ class AlarmItem:
self.snooze_time = start_time + timedelta(minutes=9)
self.is_snoozing = False
+ def _on_notification_activated(self, notif, action, data):
+ app = Gio.Application.get_default()
+ app.win.show_clock(app.win.alarm)
+
def snooze(self):
self.is_snoozing = True
+ self.alert.stop()
def stop(self):
self._reset_snooze(self.time)
+ self.alert.stop()
def get_time_as_string(self):
if SystemSettings.get_clock_format() == "12h":
@@ -142,6 +150,7 @@ class AlarmItem:
def check_expired(self):
t = datetime.now()
if t > self.time:
+ self.alert.show()
self._reset_snooze(self.time)
self._update_expiration_time()
return True
@@ -288,10 +297,9 @@ class AlarmDialog(Gtk.Dialog):
class AlarmThumbnail():
- def __init__(self, view, alarm, alert):
+ def __init__(self, view, alarm):
self.view = view
self.alarm = alarm
- self.alert = alert
timestr = alarm.get_time_as_string()
repeat = alarm.get_alarm_repeat_string()
self.drawing = DigitalClockDrawing()
@@ -309,23 +317,19 @@ class AlarmThumbnail():
def get_pixbuf(self):
return self.drawing.pixbuf
- def get_alert(self):
- return self.alert
-
def get_standalone_widget(self):
if not self.standalone:
- self.standalone = StandaloneAlarm(self.view, self.alarm, self.alert)
+ self.standalone = StandaloneAlarm(self.view, self.alarm)
return self.standalone
class StandaloneAlarm(Gtk.EventBox):
- def __init__(self, view, alarm, alert):
+ def __init__(self, view, alarm):
Gtk.EventBox.__init__(self)
self.get_style_context().add_class('view')
self.get_style_context().add_class('content-view')
self.view = view
self.alarm = alarm
- self.alert = alert
self.can_edit = True
self.vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
@@ -384,11 +388,9 @@ class StandaloneAlarm(Gtk.EventBox):
def _on_stop_clicked(self, button):
self.alarm.stop()
- self.alert.stop()
def _on_snooze_clicked(self, button):
self.alarm.snooze()
- self.alert.stop()
def get_name(self):
name = self.alarm.name
@@ -449,17 +451,11 @@ class Alarm(Clock):
for i in self.liststore:
thumb = self.liststore.get_value(i.iter, 3)
if thumb.get_alarm().check_expired():
- alert = thumb.get_alert()
- alert.show()
standalone = thumb.get_standalone_widget()
standalone.set_ringing(True)
self.emit("show-standalone", thumb)
return True
- def _on_notification_activated(self, notif, action, data):
- win = self.get_toplevel()
- win.show_clock(self)
-
def _on_item_activated(self, iconview, path):
thumb = self.liststore[path][3]
self.emit("show-standalone", thumb)
@@ -494,9 +490,7 @@ class Alarm(Clock):
self.show_all()
def add_alarm_thumbnail(self, alarm):
- alert = Alert("alarm-clock-elapsed", alarm.name,
- self._on_notification_activated)
- thumb = AlarmThumbnail(self, alarm, alert)
+ thumb = AlarmThumbnail(self, alarm)
label = GLib.markup_escape_text(alarm.name)
view_iter = self.liststore.append([False,
thumb.get_pixbuf(),
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]