mirror of
https://github.com/gryf/wicd.git
synced 2026-01-08 06:44:20 +01:00
Initial notification support
This commit is contained in:
@@ -43,6 +43,17 @@ import pango
|
|||||||
import atexit
|
import atexit
|
||||||
from dbus import DBusException
|
from dbus import DBusException
|
||||||
|
|
||||||
|
HAS_NOTIFY = True
|
||||||
|
try:
|
||||||
|
import pygtk
|
||||||
|
pygtk.require('2.0')
|
||||||
|
import pynotify
|
||||||
|
if not pynotify.init("Wicd"):
|
||||||
|
HAS_NOTIFY = False
|
||||||
|
except ImportError:
|
||||||
|
HAS_NOTIFY = False
|
||||||
|
|
||||||
|
|
||||||
# Wicd specific imports
|
# Wicd specific imports
|
||||||
from wicd import wpath
|
from wicd import wpath
|
||||||
from wicd import misc
|
from wicd import misc
|
||||||
@@ -63,6 +74,8 @@ if not hasattr(gtk, "StatusIcon"):
|
|||||||
print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
|
print 'Unable to load tray icon: Missing both egg.trayicon and gtk.StatusIcon modules.'
|
||||||
ICON_AVAIL = False
|
ICON_AVAIL = False
|
||||||
|
|
||||||
|
print "Has notifications support", HAS_NOTIFY
|
||||||
|
|
||||||
misc.RenameProcess("wicd-client")
|
misc.RenameProcess("wicd-client")
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -118,7 +131,7 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
def is_embedded(self):
|
def is_embedded(self):
|
||||||
if USE_EGG:
|
if USE_EGG:
|
||||||
raise NotImplementedError
|
raise NotImplementedError()
|
||||||
else:
|
else:
|
||||||
return self.tr.is_embedded()
|
return self.tr.is_embedded()
|
||||||
|
|
||||||
@@ -138,12 +151,30 @@ class TrayIcon(object):
|
|||||||
self.max_snd_gain = 10000
|
self.max_snd_gain = 10000
|
||||||
self.max_rcv_gain = 10000
|
self.max_rcv_gain = 10000
|
||||||
self.animate = animate
|
self.animate = animate
|
||||||
|
|
||||||
|
# keep track of the last state to provide appropriate
|
||||||
|
# notifications
|
||||||
|
self._last_bubble = None
|
||||||
|
self.last_state = None
|
||||||
|
self.should_notify = True
|
||||||
|
|
||||||
if DBUS_AVAIL:
|
if DBUS_AVAIL:
|
||||||
self.update_tray_icon()
|
self.update_tray_icon()
|
||||||
else:
|
else:
|
||||||
handle_no_dbus()
|
handle_no_dbus()
|
||||||
self.set_not_connected_state()
|
self.set_not_connected_state()
|
||||||
|
|
||||||
|
def _show_notification(self, status_string):
|
||||||
|
if self.should_notify:
|
||||||
|
if not self._last_bubble:
|
||||||
|
self._last_bubble = pynotify.Notification("Network status", status_string)
|
||||||
|
self._last_bubble.show()
|
||||||
|
else:
|
||||||
|
self._last_bubble.update("Network status", status_string)
|
||||||
|
self._last_bubble.show()
|
||||||
|
|
||||||
|
self.should_notify = False
|
||||||
|
|
||||||
@catchdbus
|
@catchdbus
|
||||||
def wired_profile_chooser(self):
|
def wired_profile_chooser(self):
|
||||||
""" Launch the wired profile chooser. """
|
""" Launch the wired profile chooser. """
|
||||||
@@ -154,8 +185,10 @@ class TrayIcon(object):
|
|||||||
""" Sets the icon info for a wired state. """
|
""" Sets the icon info for a wired state. """
|
||||||
wired_ip = info[0]
|
wired_ip = info[0]
|
||||||
self.tr.set_from_file(os.path.join(wpath.images, "wired.png"))
|
self.tr.set_from_file(os.path.join(wpath.images, "wired.png"))
|
||||||
self.tr.set_tooltip(language['connected_to_wired'].replace('$A',
|
status_string = language['connected_to_wired'].replace('$A',
|
||||||
wired_ip))
|
wired_ip)
|
||||||
|
self.tr.set_tooltip(status_string)
|
||||||
|
self._show_notification(status_string)
|
||||||
|
|
||||||
@catchdbus
|
@catchdbus
|
||||||
def set_wireless_state(self, info):
|
def set_wireless_state(self, info):
|
||||||
@@ -169,12 +202,14 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
if wireless.GetWirelessProperty(cur_net_id, "encryption"):
|
if wireless.GetWirelessProperty(cur_net_id, "encryption"):
|
||||||
lock = "-lock"
|
lock = "-lock"
|
||||||
|
status_string = (language['connected_to_wireless']
|
||||||
self.tr.set_tooltip(language['connected_to_wireless']
|
|
||||||
.replace('$A', self.network)
|
.replace('$A', self.network)
|
||||||
.replace('$B', sig_string)
|
.replace('$B', sig_string)
|
||||||
.replace('$C', str(wireless_ip)))
|
.replace('$C', str(wireless_ip)))
|
||||||
|
self.tr.set_tooltip(status_string)
|
||||||
self.set_signal_image(int(strength), lock)
|
self.set_signal_image(int(strength), lock)
|
||||||
|
self._show_notification(status_string)
|
||||||
|
|
||||||
|
|
||||||
def set_connecting_state(self, info):
|
def set_connecting_state(self, info):
|
||||||
""" Sets the icon info for a connecting state. """
|
""" Sets the icon info for a connecting state. """
|
||||||
@@ -182,9 +217,11 @@ class TrayIcon(object):
|
|||||||
cur_network = language['wired_network']
|
cur_network = language['wired_network']
|
||||||
else:
|
else:
|
||||||
cur_network = info[1]
|
cur_network = info[1]
|
||||||
self.tr.set_tooltip(language['connecting'] + " to " +
|
status_string = language['connecting'] + " to " + \
|
||||||
cur_network + "...")
|
cur_network + "..."
|
||||||
|
self.tr.set_tooltip(status_string)
|
||||||
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
|
self.tr.set_from_file(os.path.join(wpath.images, "no-signal.png"))
|
||||||
|
self._show_notification(status_string)
|
||||||
|
|
||||||
@catchdbus
|
@catchdbus
|
||||||
def set_not_connected_state(self, info=None):
|
def set_not_connected_state(self, info=None):
|
||||||
@@ -198,6 +235,7 @@ class TrayIcon(object):
|
|||||||
else:
|
else:
|
||||||
status = language['not_connected']
|
status = language['not_connected']
|
||||||
self.tr.set_tooltip(status)
|
self.tr.set_tooltip(status)
|
||||||
|
self._show_notification(status)
|
||||||
|
|
||||||
@catchdbus
|
@catchdbus
|
||||||
def update_tray_icon(self, state=None, info=None):
|
def update_tray_icon(self, state=None, info=None):
|
||||||
@@ -206,6 +244,12 @@ class TrayIcon(object):
|
|||||||
|
|
||||||
if not state or not info:
|
if not state or not info:
|
||||||
[state, info] = daemon.GetConnectionStatus()
|
[state, info] = daemon.GetConnectionStatus()
|
||||||
|
|
||||||
|
self._show_notification('hello!')
|
||||||
|
|
||||||
|
self.should_notify = (self.last_state != state) and HAS_NOTIFY
|
||||||
|
|
||||||
|
self.last_state = state
|
||||||
|
|
||||||
if state == misc.WIRED:
|
if state == misc.WIRED:
|
||||||
self.set_wired_state(info)
|
self.set_wired_state(info)
|
||||||
|
|||||||
Reference in New Issue
Block a user