コード例 #1
0
ファイル: gui.py プロジェクト: dochench/xpra
class OSX_Notifier(NotifierBase):

    def __init__(self, closed_cb=None, action_cb=None):
        super().__init__(closed_cb, action_cb)
        self.gtk_notifier = None
        self.gtk_notifications = set()
        self.notifications = {}
        self.notification_center = NSUserNotificationCenter.defaultUserNotificationCenter()
        assert self.notification_center

    def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon,
                    summary, body, actions, hints, expire_timeout, icon):
        GTK_NOTIFIER = envbool("XPRA_OSX_GTK_NOTIFIER", True)
        if actions and GTK_NOTIFIER:
            #try to use GTK notifier if we have actions buttons to handle:
            try:
                from xpra.gtk_common.gtk_notifier import GTK_Notifier
            except ImportError as e:
                log("cannot use GTK notifier for handling actions: %s", e)
            else:
                self.gtk_notifier = GTK_Notifier(self.closed_cb, self.action_cb)
                self.gtk_notifier.show_notify(dbus_id, tray, nid, app_name, replaces_nid, app_icon,
                                              summary, body, actions, hints, expire_timeout, icon)
                self.gtk_notifications.add(nid)
                return
        GLib.idle_add(self.do_show_notify, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon)

    def do_show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon,
                       summary, body, actions, hints, expire_timeout, icon):
        notification = NSUserNotification.alloc().init()
        notification.setTitle_(summary)
        notification.setInformativeText_(body)
        notification.setIdentifier_("%s" % nid)
        #enable sound:
        notification.setSoundName_(NSUserNotificationDefaultSoundName)
        notifylog("do_show_notify(..) nid=%s, %s(%s)", nid, self.notification_center.deliverNotification_, notification)
        self.notifications[nid] = notification
        self.notification_center.deliverNotification_(notification)

    def close_notify(self, nid):
        try:
            self.gtk_notifications.remove(nid)
        except KeyError:
            notification = self.notifications.get(nid)
            notifylog("close_notify(..) notification[%i]=%s", nid, notification)
            if notification:
                GLib.idle_add(self.notification_center.removeDeliveredNotification_, notification)
        else:
            self.gtk_notifier.close_notify(nid)

    def cleanup(self):
        NotifierBase.cleanup(self)
        GLib.idle_add(self.notification_center.removeAllDeliveredNotifications)
コード例 #2
0
ファイル: win32_notifier.py プロジェクト: gitmirrors2/xpra
 def get_gtk_notifier(self):
     if self.gtk_notifier is None:
         try:
             self.gtk_notifier = GTK_Notifier(self.closed_cb, self.action_cb)
         except:
             log("failed to load GTK Notifier fallback", exc_info=True)
     return self.gtk_notifier
コード例 #3
0
ファイル: gui.py プロジェクト: dochench/xpra
 def show_notify(self, dbus_id, tray, nid, app_name, replaces_nid, app_icon,
                 summary, body, actions, hints, expire_timeout, icon):
     GTK_NOTIFIER = envbool("XPRA_OSX_GTK_NOTIFIER", True)
     if actions and GTK_NOTIFIER:
         #try to use GTK notifier if we have actions buttons to handle:
         try:
             from xpra.gtk_common.gtk_notifier import GTK_Notifier
         except ImportError as e:
             log("cannot use GTK notifier for handling actions: %s", e)
         else:
             self.gtk_notifier = GTK_Notifier(self.closed_cb, self.action_cb)
             self.gtk_notifier.show_notify(dbus_id, tray, nid, app_name, replaces_nid, app_icon,
                                           summary, body, actions, hints, expire_timeout, icon)
             self.gtk_notifications.add(nid)
             return
     GLib.idle_add(self.do_show_notify, dbus_id, tray, nid, app_name, replaces_nid, app_icon, summary, body, actions, hints, expire_timeout, icon)