1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-24 15:12:31 +01:00

Added support for instantly enabling/disabling notifications when the preference is changed

This commit is contained in:
Adam Blackburn
2009-05-03 10:32:10 +08:00
parent c7745de68b
commit d8df1d1a36
3 changed files with 19 additions and 9 deletions

View File

@@ -141,10 +141,12 @@ class WiredProfileChooser:
class appGui(object):
""" The main wicd GUI class. """
def __init__(self, standalone=False):
def __init__(self, standalone=False, tray=None):
""" Initializes everything needed for the GUI. """
setup_dbus()
self.tray = tray
gladefile = os.path.join(wpath.share, "wicd.glade")
self.wTree = gtk.glade.XML(gladefile)
self.window = self.wTree.get_widget("window1")
@@ -305,7 +307,7 @@ class appGui(object):
def settings_dialog(self, widget, event=None):
""" Displays a general settings dialog. """
if not self.pref:
self.pref = PreferencesDialog(self.wTree)
self.pref = PreferencesDialog(self, self.wTree)
else:
self.pref.load_preferences_diag()
if self.pref.run() == 1:

View File

@@ -51,8 +51,9 @@ def setup_dbus():
class PreferencesDialog(object):
""" Class for handling the wicd preferences dialog window. """
def __init__(self, wTree):
def __init__(self, parent, wTree):
setup_dbus()
self.parent = parent
self.wTree = wTree
self.prep_settings_diag()
self.load_preferences_diag()
@@ -243,7 +244,11 @@ class PreferencesDialog(object):
else:
if os.path.exists(not_path):
os.remove(not_path)
# if this GUI was started by a tray icon,
# instantly change the notifications there
if self.parent.tray:
self.parent.tray.icon_info.use_notify = \
self.notificationscheckbox.get_active()
def set_label(self, glade_str, label):
""" Sets the label for the given widget in wicd.glade. """

View File

@@ -53,9 +53,6 @@ try:
except ImportError:
HAS_NOTIFY = False
USE_NOTIFY = os.path.exists(os.path.join(os.path.expanduser('~/.wicd'),
'USE_NOTIFICATIONS'))
# Wicd specific imports
from wicd import wpath
from wicd import misc
@@ -130,6 +127,7 @@ class TrayIcon(object):
else:
self.tr = self.StatusTrayIconGUI()
self.icon_info = self.TrayConnectionInfo(self.tr, animate)
self.tr.icon_info = self.icon_info
def is_embedded(self):
if USE_EGG:
@@ -160,6 +158,10 @@ class TrayIcon(object):
self.last_state = None
self.should_notify = True
self.use_notify = os.path.exists(os.path.join(
os.path.expanduser('~/.wicd'),
'USE_NOTIFICATIONS'))
if DBUS_AVAIL:
self.update_tray_icon()
else:
@@ -250,7 +252,8 @@ class TrayIcon(object):
if not state or not info:
[state, info] = daemon.GetConnectionStatus()
self.should_notify = (self.last_state != state) and HAS_NOTIFY and USE_NOTIFY
self.should_notify = (self.last_state != state) and \
HAS_NOTIFY and self.use_notify
self.last_state = state
@@ -599,7 +602,7 @@ class TrayIcon(object):
def toggle_wicd_gui(self):
""" Toggles the wicd GUI. """
if not self.gui_win:
self.gui_win = gui.appGui()
self.gui_win = gui.appGui(tray=self)
elif not self.gui_win.is_visible:
self.gui_win.show_win()
else: