Fix last commit.
Use 'config_value_changed' signal from core to get config value updates instead of polling every update for StatusBar and SystemTray.
This commit is contained in:
parent
f0b6833d17
commit
80514ad829
|
@ -48,6 +48,7 @@ class Config:
|
|||
self.config = {}
|
||||
self.previous_config = {}
|
||||
self.set_functions = {}
|
||||
self._change_callback = None
|
||||
|
||||
# If defaults is not None then we need to use "defaults".
|
||||
if defaults != None:
|
||||
|
@ -121,9 +122,13 @@ class Config:
|
|||
self.config[key] = value
|
||||
# Run the set_function for this key if any
|
||||
try:
|
||||
self.set_functions[key](key, value)
|
||||
gobject.idle_add(self.set_functions[key], key, value)
|
||||
except KeyError:
|
||||
pass
|
||||
try:
|
||||
gobject.idle_add(self._change_callback, key, value)
|
||||
except:
|
||||
pass
|
||||
|
||||
def get(self, key):
|
||||
"""Get the value of 'key'. If it is an invalid key then get() will
|
||||
|
@ -145,7 +150,11 @@ class Config:
|
|||
def get_previous_config(self):
|
||||
"""Returns the config prior to the last set()"""
|
||||
return self.previous_config
|
||||
|
||||
|
||||
def register_change_callback(self, callback):
|
||||
"""Registers a callback that will be called when a value is changed"""
|
||||
self._change_callback = callback
|
||||
|
||||
def register_set_function(self, key, function, apply_now=True):
|
||||
"""Register a function to be run when a config value changes."""
|
||||
log.debug("Registering function for %s key..", key)
|
||||
|
|
|
@ -223,6 +223,7 @@ class Core(
|
|||
self.config.register_set_function("max_upload_slots_global",
|
||||
self._on_set_max_upload_slots_global)
|
||||
|
||||
self.config.register_change_callback(self._on_config_value_change)
|
||||
# Start the AlertManager
|
||||
self.alerts = AlertManager(self.session)
|
||||
|
||||
|
@ -500,7 +501,15 @@ class Core(
|
|||
log.debug("torrent_all_resumed signal emitted")
|
||||
self.signals.emit("torrent_all_resumed", torrent_id)
|
||||
|
||||
def config_value_changed(self, key, value):
|
||||
"""Emitted when a config value has changed"""
|
||||
log.debug("config_value_changed signal emitted")
|
||||
self.signals.emit("config_value_changed", key, value)
|
||||
|
||||
# Config set functions
|
||||
def _on_config_value_change(self, key, value):
|
||||
self.config_value_changed(key, value)
|
||||
|
||||
def _on_set_torrentfiles_location(self, key, value):
|
||||
try:
|
||||
old = self.config.get_previous_config()["torrentfiles_location"]
|
||||
|
|
|
@ -61,13 +61,13 @@ class SignalManager(component.Component):
|
|||
log.debug("Registering %s as a signal reciever..", uri)
|
||||
self.clients[uri] = xmlrpclib.ServerProxy(uri)
|
||||
|
||||
def emit(self, signal, data):
|
||||
def emit(self, signal, *data):
|
||||
for client in self.clients.values():
|
||||
gobject.idle_add(self._emit, client, signal, data)
|
||||
gobject.idle_add(self._emit, client, signal, *data)
|
||||
|
||||
def _emit(self, client, signal, data):
|
||||
def _emit(self, client, signal, *data):
|
||||
try:
|
||||
client.emit_signal(signal, data)
|
||||
client.emit_signal(signal, *data)
|
||||
except (socket.error, Exception), e:
|
||||
log.warning("Unable to emit signal to client %s: %s", client, e)
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ class Signals(component.Component):
|
|||
self.torrent_all_paused)
|
||||
self.receiver.connect_to_signal("torrent_all_resumed",
|
||||
self.torrent_all_resumed)
|
||||
self.receiver.connect_to_signal("config_value_changed",
|
||||
self.config_value_changed)
|
||||
|
||||
def stop(self):
|
||||
self.receiver.shutdown()
|
||||
|
@ -95,3 +97,7 @@ class Signals(component.Component):
|
|||
component.get("TorrentView").update()
|
||||
component.get("ToolBar").update_buttons("resumed")
|
||||
|
||||
def config_value_changed(self, key, value):
|
||||
log.debug("config_value_changed signal received..")
|
||||
component.get("StatusBar").config_value_changed(key, value)
|
||||
component.get("SystemTray").config_value_changed(key, value)
|
||||
|
|
|
@ -105,6 +105,11 @@ class StatusBar(component.Component):
|
|||
self.max_upload_speed = -1.0
|
||||
self.upload_rate = 0.0
|
||||
|
||||
self.config_value_changed_dict = {
|
||||
"max_connections_global": self._on_max_connections_global,
|
||||
"max_download_speed": self._on_max_download_speed,
|
||||
"max_upload_speed": self._on_max_upload_speed
|
||||
}
|
||||
# Add a HBox to the statusbar after removing the initial label widget
|
||||
self.hbox = gtk.HBox()
|
||||
self.hbox.set_spacing(5)
|
||||
|
@ -130,6 +135,14 @@ class StatusBar(component.Component):
|
|||
image=deluge.common.get_pixmap("seeding16.png"))
|
||||
self.hbox.pack_start(
|
||||
self.upload_item.get_eventbox(), expand=False, fill=False)
|
||||
|
||||
# Get some config values
|
||||
client.get_config_value(
|
||||
self._on_max_connections_global, "max_connections_global")
|
||||
client.get_config_value(
|
||||
self._on_max_download_speed, "max_download_speed")
|
||||
client.get_config_value(
|
||||
self._on_max_upload_speed, "max_upload_speed")
|
||||
|
||||
self.send_status_request()
|
||||
|
||||
|
@ -167,16 +180,17 @@ class StatusBar(component.Component):
|
|||
|
||||
def send_status_request(self):
|
||||
# Sends an async request for data from the core
|
||||
client.get_config_value(
|
||||
self._on_max_connections_global, "max_connections_global")
|
||||
client.get_num_connections(self._on_get_num_connections)
|
||||
client.get_config_value(
|
||||
self._on_max_download_speed, "max_download_speed")
|
||||
client.get_download_rate(self._on_get_download_rate)
|
||||
client.get_config_value(
|
||||
self._on_max_upload_speed, "max_upload_speed")
|
||||
client.get_upload_rate(self._on_get_upload_rate)
|
||||
|
||||
def config_value_changed(self, key, value):
|
||||
"""This is called when we received a config_value_changed signal from
|
||||
the core."""
|
||||
|
||||
if key in self.config_value_changed_dict.keys():
|
||||
self.config_value_changed_dict[key](value)
|
||||
|
||||
def _on_max_connections_global(self, max_connections):
|
||||
self.max_connections = max_connections
|
||||
|
||||
|
|
|
@ -65,7 +65,12 @@ class SystemTray(component.Component):
|
|||
self.download_rate = 0.0
|
||||
self.max_upload_speed = -1.0
|
||||
self.upload_rate = 0.0
|
||||
|
||||
|
||||
self.config_value_changed_dict = {
|
||||
"max_download_speed": self._on_max_download_speed,
|
||||
"max_upload_speed": self._on_max_upload_speed
|
||||
}
|
||||
|
||||
def enable(self):
|
||||
"""Enables the system tray icon."""
|
||||
log.debug("Enabling the system tray icon..")
|
||||
|
@ -117,6 +122,11 @@ class SystemTray(component.Component):
|
|||
# Build the bandwidth speed limit menus
|
||||
self.build_tray_bwsetsubmenu()
|
||||
|
||||
# Get some config values
|
||||
client.get_config_value(
|
||||
self._on_max_download_speed, "max_download_speed")
|
||||
client.get_config_value(
|
||||
self._on_max_upload_speed, "max_upload_speed")
|
||||
self.send_status_request()
|
||||
|
||||
def stop(self):
|
||||
|
@ -128,13 +138,16 @@ class SystemTray(component.Component):
|
|||
log.debug("Unable to hide system tray menu widgets: %s", e)
|
||||
|
||||
def send_status_request(self):
|
||||
client.get_config_value(
|
||||
self._on_max_download_speed, "max_download_speed")
|
||||
client.get_download_rate(self._on_get_download_rate)
|
||||
client.get_config_value(
|
||||
self._on_max_upload_speed, "max_upload_speed")
|
||||
client.get_upload_rate(self._on_get_upload_rate)
|
||||
|
||||
def config_value_changed(self, key, value):
|
||||
"""This is called when we received a config_value_changed signal from
|
||||
the core."""
|
||||
|
||||
if key in self.config_value_changed_dict.keys():
|
||||
self.config_value_changed_dict[key](value)
|
||||
|
||||
def _on_max_download_speed(self, max_download_speed):
|
||||
if self.max_download_speed != max_download_speed:
|
||||
self.max_download_speed = max_download_speed
|
||||
|
@ -158,8 +171,12 @@ class SystemTray(component.Component):
|
|||
|
||||
if max_download_speed == -1:
|
||||
max_download_speed = _("Unlimited")
|
||||
else:
|
||||
max_download_speed = "%s KiB/s" % (max_download_speed)
|
||||
if max_upload_speed == -1:
|
||||
max_upload_speed = _("Unlimited")
|
||||
else:
|
||||
max_upload_speed = "%s KiB/s" % (max_upload_speed)
|
||||
|
||||
msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % (
|
||||
_("Deluge Bittorrent Client"), _("Down Speed"),
|
||||
|
|
|
@ -108,13 +108,13 @@ class SignalReceiver(
|
|||
self._shutdown = False
|
||||
self.server_close()
|
||||
|
||||
def emit_signal(self, signal, data):
|
||||
def emit_signal(self, signal, *data):
|
||||
"""Exported method used by the core to emit a signal to the client"""
|
||||
try:
|
||||
if data != None:
|
||||
for callback in self.signals[signal]:
|
||||
try:
|
||||
gobject.idle_add(callback, data)
|
||||
gobject.idle_add(callback, *data)
|
||||
except:
|
||||
log.warning("Unable to call callback for signal %s",
|
||||
signal)
|
||||
|
|
|
@ -989,6 +989,9 @@ class MultiCall:
|
|||
|
||||
return MultiCallIterator(self.__server.system.multicall(marshalled_list))
|
||||
|
||||
def get_call_list(self):
|
||||
return self.__call_list
|
||||
|
||||
# --------------------------------------------------------------------
|
||||
# convenience functions
|
||||
|
||||
|
|
Loading…
Reference in New Issue