[X2Go-Commits] [pyhoca-gui] 07/10: Introduce stdout_NotifierPopup fallback class for situations where no desktop notification service is running.
git-admin at x2go.org
git-admin at x2go.org
Tue Jul 23 21:53:29 CEST 2019
This is an automated email from the git hooks/post-receive script.
x2go pushed a commit to branch master
in repository pyhoca-gui.
commit bebe2356a8b4542bc91dcff18e733cc74059848b
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date: Tue Jul 23 21:15:57 2019 +0200
Introduce stdout_NotifierPopup fallback class for situations where no desktop notification service is running.
---
debian/changelog | 2 +
pyhoca/wxgui/frontend.py | 6 ++-
pyhoca/wxgui/notify.py | 110 +++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 117 insertions(+), 1 deletion(-)
diff --git a/debian/changelog b/debian/changelog
index 1a02b1c..3c19d30 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -26,6 +26,8 @@ pyhoca-gui (0.5.0.9-0x2go1) UNRELEASED; urgency=medium
- Reduce 'Gtk-Critical: gtk_box_gadget_distribute: assertion 'size >= 0'
failed in GtkRadioButton' error message. Unfortunately, some of them
left when entering profile manager.
+ - Introduce stdout_NotifierPopup fallback class for situations where no
+ desktop notification service is running.
* debian/control:
+ Drop python-notify alternative dependency, rely on the GTK-3 Notify
GObject.
diff --git a/pyhoca/wxgui/frontend.py b/pyhoca/wxgui/frontend.py
index 8059182..46edfb8 100644
--- a/pyhoca/wxgui/frontend.py
+++ b/pyhoca/wxgui/frontend.py
@@ -323,7 +323,11 @@ class PyHocaGUI(wx.App, x2go.X2GoClient):
self.taskbar.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.taskbar.CreateSessionManagerPopupMenu)
if x2go.X2GOCLIENT_OS in ('Linux', 'Mac'):
- self.notifier = notify.libnotify_NotifierPopup(self)
+ if notify.notification_service_available():
+ self.notifier = notify.libnotify_NotifierPopup(self)
+ else:
+ self._pyhoca_logger('no desktop notification service running, using stdout notifier', loglevel=x2go.log.loglevel_WARN, )
+ self.notifier = notify.stdout_NotifierPopup(self)
if x2go.X2GOCLIENT_OS in ('Windows'):
self.notifier = notify.showballoon_NotifierPopup(self.about)
diff --git a/pyhoca/wxgui/notify.py b/pyhoca/wxgui/notify.py
index 56bd2bf..7431915 100644
--- a/pyhoca/wxgui/notify.py
+++ b/pyhoca/wxgui/notify.py
@@ -38,6 +38,116 @@ import x2go.utils as utils
class NotSupportedException(exceptions.StandardError): pass
class PyHocaNotificationException(exceptions.StandardError): pass
+def notification_service_available():
+ return _Notify.get_server_info()[0]
+
+class stdout_NotifierPopup(object):
+ """\
+ L{PyHocaGUI} stdout notifications, used when no desktop notification service is available.
+
+ """
+ title = {}
+ text = {}
+ icon = {}
+ timeout = {}
+
+ def __init__(self, _PyHocaGUI):
+ """\
+ Notifier popup (constructor).
+
+ @param _PyHocaGUI: main application instance
+ @type _PyHocaGUI: C{obj}
+
+ """
+ self._PyHocaGUI = _PyHocaGUI
+ self._pyhoca_logger = self._PyHocaGUI._pyhoca_logger
+
+ def prepare(self, context, title=None, text=None, icon=None, timeout=None):
+ """\
+ Prepare a notification that gets sent to stdout later (by the L{send()} method).
+
+ Use C{context} as a unique identifier. When sending the notification later, C{context}
+ will unequivocally map to the notification content that shall get sent.
+
+ @param context: a unique identifier for this notification preparation
+ @type context: C{str}
+ @param title: notification title
+ @type title: C{str}
+ @param text: notification text
+ @type text: C{str}
+ @param icon: icon name for an icon that appears with the notification
+ @type icon: C{str}
+ @param timeout: let notification disappear after C{<timeout>} milliseconds
+ @type timeout: C{int}
+
+ """
+ if title is not None:
+ self.title[context] = title
+ if text is not None:
+ self.text[context] = text
+ if icon is not None:
+ self.icon[context] = icon
+ if timeout is not None:
+ self.timeout[context] = timeout
+
+ def send(self, title=None, text=None, context=None, icon=None, timeout=8000):
+ """\
+ Send notifications directly to stdout (or use a prepared notification).
+
+ @param title: notification title
+ @type title: C{str}
+ @param text: notification text
+ @type text: C{str}
+ @param context: an identifier that refers to a prepared notification
+ @type context: C{str}
+ @param icon: icon name for an icon that appears with the notification
+ @type icon: C{str}
+ @param timeout: let notification disappear after C{<timeout>} milliseconds
+ @type timeout: C{int}
+
+ @raise PyHocaNotificationException: if notification failed
+
+ """
+ if context is not None:
+ try:
+ title = self.title[context]
+ del self.title[context]
+ except KeyError:
+ pass
+ try:
+ text = self.text[context]
+ del self.text[context]
+ except KeyError:
+ pass
+ try:
+ icon = self.icon[context]
+ del self.icon[context]
+ except KeyError:
+ pass
+ try:
+ timeout = self.timeout[context]
+ del self.timeout[context]
+ except KeyError:
+ pass
+
+ if title and text:
+ self._pyhoca_logger('[%s] %s' % (title.encode(utils.get_encoding()), text.encode(utils.get_encoding())), loglevel=log.loglevel_NOTICE)
+
+ def Close(self):
+ """\
+ Provide a C{Close()} method which does nothing.
+
+ """
+ pass
+
+ def Destroy(self):
+ """\
+ Provide a C{Destroy()} method which does nothing.
+
+ """
+ pass
+
+
class libnotify_NotifierPopup(object):
"""\
L{PyHocaGUI} notification utilizing C{libnotify}, used on Linux/Unix OS.
--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/pyhoca-gui.git
More information about the x2go-commits
mailing list