1
0
mirror of https://github.com/gryf/wicd.git synced 2025-12-22 14:07:59 +01:00

More tweaking of how the GUI updates the status bar. Should be more efficient now.

This commit is contained in:
Dan O'Reilly
2009-02-04 19:13:06 -05:00
parent 22e134b78e
commit 70c93746dd
3 changed files with 44 additions and 28 deletions

View File

@@ -38,6 +38,7 @@ from wicd import misc
from wicd import wpath
from wicd import dbusmanager
from wicd import prefs
from wicd import netentry
from wicd.misc import noneToString
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
from wicd.prefs import PreferencesDialog
@@ -67,6 +68,7 @@ def setup_dbus(force=True):
else:
return False
prefs.setup_dbus()
netentry.setup_dbus()
bus = dbusmanager.get_bus()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
daemon = dbus_ifaces['daemon']
@@ -91,7 +93,7 @@ class WiredProfileChooser:
""" Initializes and runs the wired profile chooser. """
# Import and init WiredNetworkEntry to steal some of the
# functions and widgets it uses.
wired_net_entry = WiredNetworkEntry(dbusmanager.get_dbus_ifaces())
wired_net_entry = WiredNetworkEntry()
dialog = gtk.Dialog(title = language['wired_network_found'],
flags = gtk.DIALOG_MODAL,
@@ -213,14 +215,17 @@ class appGui(object):
'ConnectResultsSent', 'org.wicd.daemon')
bus.add_signal_receiver(lambda: setup_dbus(force=False),
"DaemonStarting", "org.wicd.daemon")
bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged',
'org.wicd.daemon')
if standalone:
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
"org.wicd.daemon")
try:
gobject.timeout_add_seconds(2, self.update_statusbar)
except:
gobject.timeout_add(2000, self.update_statusbar)
if hasattr(gobject, "timeout_add_seconds"):
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
else:
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
self._do_statusbar_update(*daemon.GetConnectionStatus())
self.refresh_clicked()
def handle_connection_results(self, results):
@@ -349,17 +354,16 @@ class appGui(object):
return True
def update_statusbar(self):
""" Updates the status bar
Queries the daemon for network connection information and
updates the GUI status bar based on the results.
"""
""" Triggers a status update in wicd-monitor. """
if not self.is_visible or self.refreshing:
return True
daemon.UpdateState()
[state, info] = daemon.GetConnectionStatus()
return True
def _do_statusbar_update(self, state, info):
if not self.is_visible or self.refreshing:
return True
if state == misc.WIRED:
return self.set_wired_state(info)
@@ -485,7 +489,7 @@ class appGui(object):
if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface():
printLine = True # In this case we print a separator.
wirednet = WiredNetworkEntry(dbusmanager.get_dbus_ifaces())
wirednet = WiredNetworkEntry()
self.network_list.pack_start(wirednet, False, False)
wirednet.connect_button.connect("button-press-event", self.connect,
"wired", 0, wirednet)
@@ -499,7 +503,6 @@ class appGui(object):
instruct_label = self.wTree.get_widget("label_instructions")
if num_networks > 0:
instruct_label.show()
dbus_ifaces = dbusmanager.get_dbus_ifaces()
for x in range(0, num_networks):
if printLine:
sep = gtk.HSeparator()
@@ -508,7 +511,7 @@ class appGui(object):
sep.show()
else:
printLine = True
tempnet = WirelessNetworkEntry(x, dbus_ifaces)
tempnet = WirelessNetworkEntry(x)
self.network_list.pack_start(tempnet, False, False)
tempnet.connect_button.connect("button-press-event",
self.connect, "wireless", x,
@@ -676,6 +679,9 @@ class appGui(object):
"""
self.window.hide()
gobject.source_remove(self.update_cb)
bus.remove_signal_receiver(self._do_statusbar_update, 'StatusChanged',
'org.wicd.daemon')
[width, height] = self.window.get_size()
try:
daemon.WriteWindowSize(width, height, "main")
@@ -702,6 +708,12 @@ class appGui(object):
daemon.SetGUIOpen(True)
self.wait_for_events(0.1)
gobject.idle_add(self.refresh_clicked)
bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged',
'org.wicd.daemon')
if hasattr(gobject, "timeout_add_seconds"):
self.update_cb = gobject.timeout_add_seconds(2, self.update_statusbar)
else:
self.update_cb = gobject.timeout_add(2000, self.update_statusbar)
if __name__ == '__main__':

View File

@@ -311,10 +311,10 @@ def err_handle(error):
def add_poll_callback():
global monitor, to_time, update_callback
try:
if hasattr(gobject, "timeout_add_seconds"):
update_callback = gobject.timeout_add_seconds(to_time,
monitor.update_connection_status)
except:
else:
update_callback = gobject.timeout_add(to_time * 1000,
monitor.update_connection_status)

View File

@@ -20,6 +20,7 @@ import os
import misc
import wpath
import dbusmanager
from misc import noneToString, stringToNone, noneToBlankString, to_bool
from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input
@@ -30,6 +31,12 @@ daemon = None
wired = None
wireless = None
def setup_dbus():
global daemon, wireless, wired
daemon = dbusmanager.get_interface('daemon')
wireless = dbusmanager.get_interface('wireless')
wired = dbusmanager.get_interface('wired')
class AdvancedSettingsDialog(gtk.Dialog):
def __init__(self):
""" Build the base advanced settings dialog.
@@ -466,17 +473,14 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
class NetworkEntry(gtk.HBox):
def __init__(self, dbus_ifaces):
def __init__(self):
""" Base network entry class.
Provides gtk objects used by both the WiredNetworkEntry and
WirelessNetworkEntry classes.
"""
global daemon, wired, wireless
daemon = dbus_ifaces["daemon"]
wired = dbus_ifaces["wired"]
wireless = dbus_ifaces["wireless"]
setup_dbus()
gtk.HBox.__init__(self, False, 2)
self.image = gtk.Image()
self.pack_start(self.image, False, False)
@@ -533,9 +537,9 @@ class NetworkEntry(gtk.HBox):
class WiredNetworkEntry(NetworkEntry):
def __init__(self, dbus_ifaces):
def __init__(self):
""" Load the wired network entry. """
NetworkEntry.__init__(self, dbus_ifaces)
NetworkEntry.__init__(self)
# Center the picture and pad it a bit
self.image.set_padding(0, 0)
self.image.set_alignment(.5, .5)
@@ -718,9 +722,9 @@ class WiredNetworkEntry(NetworkEntry):
class WirelessNetworkEntry(NetworkEntry):
def __init__(self, networkID, dbus_ifaces):
def __init__(self, networkID):
""" Build the wireless network entry. """
NetworkEntry.__init__(self, dbus_ifaces)
NetworkEntry.__init__(self)
self.networkID = networkID
self.image.set_padding(0, 0)