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:
42
wicd/gui.py
42
wicd/gui.py
@@ -38,6 +38,7 @@ from wicd import misc
|
|||||||
from wicd import wpath
|
from wicd import wpath
|
||||||
from wicd import dbusmanager
|
from wicd import dbusmanager
|
||||||
from wicd import prefs
|
from wicd import prefs
|
||||||
|
from wicd import netentry
|
||||||
from wicd.misc import noneToString
|
from wicd.misc import noneToString
|
||||||
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
|
from wicd.netentry import WiredNetworkEntry, WirelessNetworkEntry
|
||||||
from wicd.prefs import PreferencesDialog
|
from wicd.prefs import PreferencesDialog
|
||||||
@@ -67,6 +68,7 @@ def setup_dbus(force=True):
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
prefs.setup_dbus()
|
prefs.setup_dbus()
|
||||||
|
netentry.setup_dbus()
|
||||||
bus = dbusmanager.get_bus()
|
bus = dbusmanager.get_bus()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
||||||
daemon = dbus_ifaces['daemon']
|
daemon = dbus_ifaces['daemon']
|
||||||
@@ -91,7 +93,7 @@ class WiredProfileChooser:
|
|||||||
""" Initializes and runs the wired profile chooser. """
|
""" Initializes and runs the wired profile chooser. """
|
||||||
# Import and init WiredNetworkEntry to steal some of the
|
# Import and init WiredNetworkEntry to steal some of the
|
||||||
# functions and widgets it uses.
|
# 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'],
|
dialog = gtk.Dialog(title = language['wired_network_found'],
|
||||||
flags = gtk.DIALOG_MODAL,
|
flags = gtk.DIALOG_MODAL,
|
||||||
@@ -213,14 +215,17 @@ class appGui(object):
|
|||||||
'ConnectResultsSent', 'org.wicd.daemon')
|
'ConnectResultsSent', 'org.wicd.daemon')
|
||||||
bus.add_signal_receiver(lambda: setup_dbus(force=False),
|
bus.add_signal_receiver(lambda: setup_dbus(force=False),
|
||||||
"DaemonStarting", "org.wicd.daemon")
|
"DaemonStarting", "org.wicd.daemon")
|
||||||
|
bus.add_signal_receiver(self._do_statusbar_update, 'StatusChanged',
|
||||||
|
'org.wicd.daemon')
|
||||||
if standalone:
|
if standalone:
|
||||||
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
bus.add_signal_receiver(handle_no_dbus, "DaemonClosing",
|
||||||
"org.wicd.daemon")
|
"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()
|
self.refresh_clicked()
|
||||||
|
|
||||||
def handle_connection_results(self, results):
|
def handle_connection_results(self, results):
|
||||||
@@ -349,17 +354,16 @@ class appGui(object):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def update_statusbar(self):
|
def update_statusbar(self):
|
||||||
""" Updates the status bar
|
""" Triggers a status update in wicd-monitor. """
|
||||||
|
|
||||||
Queries the daemon for network connection information and
|
|
||||||
updates the GUI status bar based on the results.
|
|
||||||
|
|
||||||
"""
|
|
||||||
if not self.is_visible or self.refreshing:
|
if not self.is_visible or self.refreshing:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
daemon.UpdateState()
|
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:
|
if state == misc.WIRED:
|
||||||
return self.set_wired_state(info)
|
return self.set_wired_state(info)
|
||||||
@@ -485,7 +489,7 @@ class appGui(object):
|
|||||||
|
|
||||||
if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface():
|
if wired.CheckPluggedIn() or daemon.GetAlwaysShowWiredInterface():
|
||||||
printLine = True # In this case we print a separator.
|
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)
|
self.network_list.pack_start(wirednet, False, False)
|
||||||
wirednet.connect_button.connect("button-press-event", self.connect,
|
wirednet.connect_button.connect("button-press-event", self.connect,
|
||||||
"wired", 0, wirednet)
|
"wired", 0, wirednet)
|
||||||
@@ -499,7 +503,6 @@ class appGui(object):
|
|||||||
instruct_label = self.wTree.get_widget("label_instructions")
|
instruct_label = self.wTree.get_widget("label_instructions")
|
||||||
if num_networks > 0:
|
if num_networks > 0:
|
||||||
instruct_label.show()
|
instruct_label.show()
|
||||||
dbus_ifaces = dbusmanager.get_dbus_ifaces()
|
|
||||||
for x in range(0, num_networks):
|
for x in range(0, num_networks):
|
||||||
if printLine:
|
if printLine:
|
||||||
sep = gtk.HSeparator()
|
sep = gtk.HSeparator()
|
||||||
@@ -508,7 +511,7 @@ class appGui(object):
|
|||||||
sep.show()
|
sep.show()
|
||||||
else:
|
else:
|
||||||
printLine = True
|
printLine = True
|
||||||
tempnet = WirelessNetworkEntry(x, dbus_ifaces)
|
tempnet = WirelessNetworkEntry(x)
|
||||||
self.network_list.pack_start(tempnet, False, False)
|
self.network_list.pack_start(tempnet, False, False)
|
||||||
tempnet.connect_button.connect("button-press-event",
|
tempnet.connect_button.connect("button-press-event",
|
||||||
self.connect, "wireless", x,
|
self.connect, "wireless", x,
|
||||||
@@ -676,6 +679,9 @@ class appGui(object):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
self.window.hide()
|
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()
|
[width, height] = self.window.get_size()
|
||||||
try:
|
try:
|
||||||
daemon.WriteWindowSize(width, height, "main")
|
daemon.WriteWindowSize(width, height, "main")
|
||||||
@@ -702,6 +708,12 @@ class appGui(object):
|
|||||||
daemon.SetGUIOpen(True)
|
daemon.SetGUIOpen(True)
|
||||||
self.wait_for_events(0.1)
|
self.wait_for_events(0.1)
|
||||||
gobject.idle_add(self.refresh_clicked)
|
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__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
@@ -311,10 +311,10 @@ def err_handle(error):
|
|||||||
def add_poll_callback():
|
def add_poll_callback():
|
||||||
global monitor, to_time, update_callback
|
global monitor, to_time, update_callback
|
||||||
|
|
||||||
try:
|
if hasattr(gobject, "timeout_add_seconds"):
|
||||||
update_callback = gobject.timeout_add_seconds(to_time,
|
update_callback = gobject.timeout_add_seconds(to_time,
|
||||||
monitor.update_connection_status)
|
monitor.update_connection_status)
|
||||||
except:
|
else:
|
||||||
update_callback = gobject.timeout_add(to_time * 1000,
|
update_callback = gobject.timeout_add(to_time * 1000,
|
||||||
monitor.update_connection_status)
|
monitor.update_connection_status)
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import os
|
|||||||
|
|
||||||
import misc
|
import misc
|
||||||
import wpath
|
import wpath
|
||||||
|
import dbusmanager
|
||||||
from misc import noneToString, stringToNone, noneToBlankString, to_bool
|
from misc import noneToString, stringToNone, noneToBlankString, to_bool
|
||||||
from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input
|
from guiutil import error, SmallLabel, LabelEntry, GreyLabel, LeftAlignedLabel, string_input
|
||||||
|
|
||||||
@@ -30,6 +31,12 @@ daemon = None
|
|||||||
wired = None
|
wired = None
|
||||||
wireless = 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):
|
class AdvancedSettingsDialog(gtk.Dialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
""" Build the base advanced settings dialog.
|
""" Build the base advanced settings dialog.
|
||||||
@@ -466,17 +473,14 @@ class WirelessSettingsDialog(AdvancedSettingsDialog):
|
|||||||
|
|
||||||
|
|
||||||
class NetworkEntry(gtk.HBox):
|
class NetworkEntry(gtk.HBox):
|
||||||
def __init__(self, dbus_ifaces):
|
def __init__(self):
|
||||||
""" Base network entry class.
|
""" Base network entry class.
|
||||||
|
|
||||||
Provides gtk objects used by both the WiredNetworkEntry and
|
Provides gtk objects used by both the WiredNetworkEntry and
|
||||||
WirelessNetworkEntry classes.
|
WirelessNetworkEntry classes.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
global daemon, wired, wireless
|
setup_dbus()
|
||||||
daemon = dbus_ifaces["daemon"]
|
|
||||||
wired = dbus_ifaces["wired"]
|
|
||||||
wireless = dbus_ifaces["wireless"]
|
|
||||||
gtk.HBox.__init__(self, False, 2)
|
gtk.HBox.__init__(self, False, 2)
|
||||||
self.image = gtk.Image()
|
self.image = gtk.Image()
|
||||||
self.pack_start(self.image, False, False)
|
self.pack_start(self.image, False, False)
|
||||||
@@ -533,9 +537,9 @@ class NetworkEntry(gtk.HBox):
|
|||||||
|
|
||||||
|
|
||||||
class WiredNetworkEntry(NetworkEntry):
|
class WiredNetworkEntry(NetworkEntry):
|
||||||
def __init__(self, dbus_ifaces):
|
def __init__(self):
|
||||||
""" Load the wired network entry. """
|
""" Load the wired network entry. """
|
||||||
NetworkEntry.__init__(self, dbus_ifaces)
|
NetworkEntry.__init__(self)
|
||||||
# Center the picture and pad it a bit
|
# Center the picture and pad it a bit
|
||||||
self.image.set_padding(0, 0)
|
self.image.set_padding(0, 0)
|
||||||
self.image.set_alignment(.5, .5)
|
self.image.set_alignment(.5, .5)
|
||||||
@@ -718,9 +722,9 @@ class WiredNetworkEntry(NetworkEntry):
|
|||||||
|
|
||||||
|
|
||||||
class WirelessNetworkEntry(NetworkEntry):
|
class WirelessNetworkEntry(NetworkEntry):
|
||||||
def __init__(self, networkID, dbus_ifaces):
|
def __init__(self, networkID):
|
||||||
""" Build the wireless network entry. """
|
""" Build the wireless network entry. """
|
||||||
NetworkEntry.__init__(self, dbus_ifaces)
|
NetworkEntry.__init__(self)
|
||||||
|
|
||||||
self.networkID = networkID
|
self.networkID = networkID
|
||||||
self.image.set_padding(0, 0)
|
self.image.set_padding(0, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user