Skip to content

Commit

Permalink
support forwarding notifications to the client via python + dbus rath…
Browse files Browse the repository at this point in the history
…er than relying on pynotify exclusively (it is still supported as a backup option)

Updates the distro packaging files too to add the new soft dependency ("soft" when possible, ie not rpm)

git-svn-id: https://xpra.org/svn/Xpra/trunk@323 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Dec 1, 2011
1 parent 1bd357d commit 8fd2dd0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
2 changes: 1 addition & 1 deletion debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Package: xpra
Architecture: any
Depends: ${python:Depends}, ${shlibs:Depends}, ${misc:Depends}, python-wimpiggy (=${binary:Version}), python-gtk2, xvfb, x11-xserver-utils
Recommends: python-imaging
Suggests: openssh-client, openssh-server, python-notify
Suggests: openssh-client, openssh-server, python-dbus
Description: tool to detach/reattach running X programs
Xpra gives you the functionality of GNU Screen for X applications.
.
Expand Down
1 change: 1 addition & 0 deletions scripts/xpra-0.0.7.31.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ RESTRICT_PYTHON_ABIS="3.*"

DEPEND="dev-python/pycrypto
dev-python/pygtk
dev-python/dbus-python
png? ( dev-python/imaging )
jpeg? ( dev-python/imaging )
ssh? ( net-misc/openssh )
Expand Down
6 changes: 3 additions & 3 deletions src/xpra.spec
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
%define is_suse %(test -e /etc/SuSE-release && echo 1 || echo 0)
%define include_egg 1

%define requires pygtk2, xorg-x11-server-utils, xorg-x11-server-Xvfb, python-imaging
%define requires pygtk2, xorg-x11-server-utils, xorg-x11-server-Xvfb, python-imaging, dbus-python
%if 0%{?el5}
%define requires pygtk2, xorg-x11-server-utils, xorg-x11-server-Xvfb, python-imaging, python-uuid
%define requires pygtk2, xorg-x11-server-utils, xorg-x11-server-Xvfb, python-imaging, dbus-python, python-uuid
%define include_egg 0
%endif
%if %is_suse
%define requires python-gtk, xorg-x11-server, xorg-x11-server-extra, libpng12-0
%define requires python-gtk, xorg-x11-server, xorg-x11-server-extra, libpng12-0, dbus-1-python
%endif


Expand Down
54 changes: 45 additions & 9 deletions src/xpra/xposix/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def __init__(self, client, opts):
self.setup_tray(opts.tray_icon)
self.setup_xprops(opts.pulseaudio)
self.setup_x11_bell()
self.setup_pynotify()
self.has_dbusnotify = False
self.has_pynotify = False
self.setup_dbusnotify() or self.setup_pynotify()
self.setup_clipboard_helper(ClipboardProtocolHelper)

def exit(self):
Expand Down Expand Up @@ -150,15 +152,30 @@ def setup_tray(self, tray_icon_filename):
if not self.setup_statusicon(tray_icon_filename):
log.error("failed to setup system-tray")

def setup_dbusnotify(self):
self.dbus_id = os.environ.get("DBUS_SESSION_BUS_ADDRESS", "")
try:
import dbus.glib
assert dbus.glib
bus = dbus.SessionBus()
obj = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
self.dbusnotify = dbus.Interface(obj, 'org.freedesktop.Notifications')
self.has_dbusnotify = True
log.info("using dbusnotify: %s", self.dbusnotify)
except Exception, e:
log.error("cannot import pynotify wrapper (turning notifications off) : %s", e)
return self.has_dbusnotify

def setup_pynotify(self):
self.dbus_id = os.environ.get("DBUS_SESSION_BUS_ADDRESS", "")
self.has_pynotify = False
try:
import pynotify
pynotify.init("Xpra")
self.has_pynotify = True
log.info("using pynotify: %s", pynotify)
except ImportError, e:
log.error("cannot import pynotify wrapper (turning notifications off) : %s", e)
return self.has_pynotify

def setup_x11_bell(self):
self.has_x11_bell = False
Expand Down Expand Up @@ -206,18 +223,37 @@ def system_bell(self, window, device, percent, pitch, duration, bell_class, bell
device_bell(window, device, bell_class, bell_id, percent, bell_name)

def can_notify(self):
return self.has_pynotify
return self.has_dbusnotify or self.has_pynotify

def show_notify(self, dbus_id, id, app_name, replaces_id, app_icon, summary, body, expire_timeout):
if self.dbus_id==dbus_id:
log.error("remote dbus instance is the same as our local one, "
"cannot forward notification to ourself as this would create a loop")
return
import pynotify
n = pynotify.Notification(summary, body)
n.set_urgency(pynotify.URGENCY_LOW)
n.set_timeout(expire_timeout)
n.show()
if self.has_dbusnotify:
def cbReply(*args):
log("notification reply: %s", args)
return False
def cbError(*args):
log.error("notification error: %s", args)
return False
try:
self.dbusnotify.Notify("Xpra", 0, app_icon, summary, body, [], [], expire_timeout,
reply_handler = cbReply,
error_handler = cbError)
except:
log.error("dbus notify failed", exc_info=True)
elif self.has_pynotify:
try:
import pynotify
n = pynotify.Notification(summary, body)
n.set_urgency(pynotify.URGENCY_LOW)
n.set_timeout(expire_timeout)
n.show()
except:
log.error("pynotify failed", exc_info=True)
else:
log.error("notification cannot be displayed, no backend support!")

def close_notify(self, id):
pass
Expand Down Expand Up @@ -248,7 +284,7 @@ def get_keyboard_data(command, arg):

def get_keyboard_repeat(self):
try:
from wimpiggy.lowlevel import get_key_repeat_rate
from wimpiggy.lowlevel import get_key_repeat_rate #@UnresolvedImport
delay, interval = get_key_repeat_rate()
return delay,interval
except Exception, e:
Expand Down

0 comments on commit 8fd2dd0

Please sign in to comment.