Extend API for activities notifications

Add a new method, called notify_user, to the base
Activity class.

This method can be used by activity developers to
send notifications to the new notification front
end. ie.,

    self.notify_user('New High Score!',
                     'Your score is over 8999')
master
Sam Parkinson 10 years ago committed by Martin Abente Lahaye
parent f92f0efe06
commit cbf325d994

@ -82,6 +82,7 @@ from sugar3.graphics.window import Window
from sugar3.graphics.alert import Alert from sugar3.graphics.alert import Alert
from sugar3.graphics.icon import Icon from sugar3.graphics.icon import Icon
from sugar3.datastore import datastore from sugar3.datastore import datastore
from sugar3.bundle.activitybundle import ActivityBundle
from gi.repository import SugarExt from gi.repository import SugarExt
_ = lambda msg: gettext.dgettext('sugar-toolkit-gtk3', msg) _ = lambda msg: gettext.dgettext('sugar-toolkit-gtk3', msg)
@ -94,6 +95,10 @@ J_DBUS_SERVICE = 'org.laptop.Journal'
J_DBUS_PATH = '/org/laptop/Journal' J_DBUS_PATH = '/org/laptop/Journal'
J_DBUS_INTERFACE = 'org.laptop.Journal' J_DBUS_INTERFACE = 'org.laptop.Journal'
N_BUS_NAME = 'org.freedesktop.Notifications'
N_OBJ_PATH = '/org/freedesktop/Notifications'
N_IFACE_NAME = 'org.freedesktop.Notifications'
CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties' CONN_INTERFACE_ACTIVITY_PROPERTIES = 'org.laptop.Telepathy.ActivityProperties'
PREVIEW_SIZE = style.zoom(300), style.zoom(225) PREVIEW_SIZE = style.zoom(300), style.zoom(225)
@ -633,6 +638,21 @@ class Activity(Window, Gtk.Container):
""" """
raise NotImplementedError raise NotImplementedError
def notify_user(self, summary, body):
"""
Display a notification with the given summary and body.
The notification will go under the activities icon in the frame.
"""
bundle = ActivityBundle(get_bundle_path())
icon = bundle.get_icon()
bus = dbus.SessionBus()
notify_obj = bus.get_object(N_BUS_NAME, N_OBJ_PATH)
notifications = dbus.Interface(notify_obj, N_IFACE_NAME)
notifications.Notify(self.get_id(), 0, '', summary, body, [],
{'x-sugar-icon-file-name': icon}, -1)
def __save_cb(self): def __save_cb(self):
logging.debug('Activity.__save_cb') logging.debug('Activity.__save_cb')
self._updating_jobject = False self._updating_jobject = False

Loading…
Cancel
Save