Implemented passing a copy of an event instead of it's arguments to event handlers. Necessary changes to the event handlers on deluge's code were made, plugins still need to be ported to this new style.
This commit is contained in:
parent
0f36a65aaf
commit
67ea05921c
|
@ -1,4 +1,5 @@
|
||||||
=== Deluge 1.3.0 (In Development) ===
|
=== Deluge 1.3.0 (In Development) ===
|
||||||
|
|
||||||
==== Core ====
|
==== Core ====
|
||||||
* Implement #1063 option to delete torrent file copy on torrent removal - patch from Ghent
|
* Implement #1063 option to delete torrent file copy on torrent removal - patch from Ghent
|
||||||
* Implement #457 progress bars for folders
|
* Implement #457 progress bars for folders
|
||||||
|
@ -8,6 +9,7 @@
|
||||||
* #1247: Fix deluge-gtk from hanging on shutdown
|
* #1247: Fix deluge-gtk from hanging on shutdown
|
||||||
* #995: Rewrote tracker_icons
|
* #995: Rewrote tracker_icons
|
||||||
* Make the distinction between adding to the session new unmanaged torrents and torrents loaded from state. This will break backwards compatability.
|
* Make the distinction between adding to the session new unmanaged torrents and torrents loaded from state. This will break backwards compatability.
|
||||||
|
* Pass a copy of an event instead of passing the event arguments to the event handlers. This will break backwards compatability.
|
||||||
|
|
||||||
==== GtkUI ====
|
==== GtkUI ====
|
||||||
* Fix uncaught exception when closing deluge in classic mode
|
* Fix uncaught exception when closing deluge in classic mode
|
||||||
|
|
|
@ -53,7 +53,7 @@ class EventManager(component.Component):
|
||||||
if event.name in self.handlers:
|
if event.name in self.handlers:
|
||||||
for handler in self.handlers[event.name]:
|
for handler in self.handlers[event.name]:
|
||||||
#log.debug("Running handler %s for event %s with args: %s", event.name, handler, event.args)
|
#log.debug("Running handler %s for event %s with args: %s", event.name, handler, event.args)
|
||||||
handler(*event.args)
|
handler(event.copy())
|
||||||
|
|
||||||
def register_event_handler(self, event, handler):
|
def register_event_handler(self, event, handler):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -485,7 +485,8 @@ class RPCServer(component.Component):
|
||||||
# Find sessions interested in this event
|
# Find sessions interested in this event
|
||||||
for session_id, interest in self.factory.interested_events.iteritems():
|
for session_id, interest in self.factory.interested_events.iteritems():
|
||||||
if event.name in interest:
|
if event.name in interest:
|
||||||
log.debug("Emit Event: %s %s", event.name, event.args)
|
log.debug("Emit Event: %s %s", event.name, zip(event.__slots__,
|
||||||
|
event.args))
|
||||||
# This session is interested so send a RPC_EVENT
|
# This session is interested so send a RPC_EVENT
|
||||||
self.factory.session_protocols[session_id].sendData(
|
self.factory.session_protocols[session_id].sendData(
|
||||||
(RPC_EVENT, event.name, event.args)
|
(RPC_EVENT, event.name, event.args)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# event.py
|
# event.py
|
||||||
#
|
#
|
||||||
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
|
||||||
|
# Copyright (C) 2010 Pedro Algarvio <pedro@algarvio.me>
|
||||||
#
|
#
|
||||||
# Deluge is free software.
|
# Deluge is free software.
|
||||||
#
|
#
|
||||||
|
@ -47,6 +48,8 @@ class DelugeEventMetaClass(type):
|
||||||
"""
|
"""
|
||||||
This metaclass simply keeps a list of all events classes created.
|
This metaclass simply keeps a list of all events classes created.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
def __init__(cls, name, bases, dct):
|
def __init__(cls, name, bases, dct):
|
||||||
super(DelugeEventMetaClass, cls).__init__(name, bases, dct)
|
super(DelugeEventMetaClass, cls).__init__(name, bases, dct)
|
||||||
if name != "DelugeEvent":
|
if name != "DelugeEvent":
|
||||||
|
@ -62,23 +65,26 @@ class DelugeEvent(object):
|
||||||
:type args: list
|
:type args: list
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ()
|
||||||
__metaclass__ = DelugeEventMetaClass
|
__metaclass__ = DelugeEventMetaClass
|
||||||
|
|
||||||
def _get_name(self):
|
def _get_name(self):
|
||||||
return self.__class__.__name__
|
return self.__class__.__name__
|
||||||
|
name = property(fget=_get_name)
|
||||||
|
|
||||||
def _get_args(self):
|
def _get_args(self):
|
||||||
if not hasattr(self, "_args"):
|
return [getattr(self, arg) for arg in self.__slots__]
|
||||||
return []
|
|
||||||
return self._args
|
|
||||||
|
|
||||||
name = property(fget=_get_name)
|
|
||||||
args = property(fget=_get_args)
|
args = property(fget=_get_args)
|
||||||
|
|
||||||
|
def copy(self):
|
||||||
|
return self.__class__(*self.args)
|
||||||
|
|
||||||
class TorrentAddedEvent(DelugeEvent):
|
class TorrentAddedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a new torrent is successfully added to the session.
|
Emitted when a new torrent is successfully added to the session.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id', 'from_state')
|
||||||
|
|
||||||
def __init__(self, torrent_id, from_state):
|
def __init__(self, torrent_id, from_state):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id of the torrent that was added
|
:param torrent_id: the torrent_id of the torrent that was added
|
||||||
|
@ -86,34 +92,41 @@ class TorrentAddedEvent(DelugeEvent):
|
||||||
:param from_state: was the torrent loaded from state? Or is it a new torrent.
|
:param from_state: was the torrent loaded from state? Or is it a new torrent.
|
||||||
:type from_state: bool
|
:type from_state: bool
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id, from_state]
|
self.torrent_id = torrent_id
|
||||||
|
self.from_state = from_state
|
||||||
|
|
||||||
class TorrentRemovedEvent(DelugeEvent):
|
class TorrentRemovedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a torrent has been removed from the session.
|
Emitted when a torrent has been removed from the session.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id',)
|
||||||
|
|
||||||
def __init__(self, torrent_id):
|
def __init__(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
:type torrent_id: string
|
:type torrent_id: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id]
|
self.torrent_id = torrent_id
|
||||||
|
|
||||||
class PreTorrentRemovedEvent(DelugeEvent):
|
class PreTorrentRemovedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a torrent is about to be removed from the session.
|
Emitted when a torrent is about to be removed from the session.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id',)
|
||||||
|
|
||||||
def __init__(self, torrent_id):
|
def __init__(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
:type torrent_id: string
|
:type torrent_id: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id]
|
self.torrent_id = torrent_id
|
||||||
|
|
||||||
class TorrentStateChangedEvent(DelugeEvent):
|
class TorrentStateChangedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a torrent changes state.
|
Emitted when a torrent changes state.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id', 'state')
|
||||||
|
|
||||||
def __init__(self, torrent_id, state):
|
def __init__(self, torrent_id, state):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
|
@ -121,18 +134,20 @@ class TorrentStateChangedEvent(DelugeEvent):
|
||||||
:param state: the new state
|
:param state: the new state
|
||||||
:type state: string
|
:type state: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id, state]
|
self.torrent_id = torrent_id
|
||||||
|
self.state = state
|
||||||
|
|
||||||
class TorrentQueueChangedEvent(DelugeEvent):
|
class TorrentQueueChangedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when the queue order has changed.
|
Emitted when the queue order has changed.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
class TorrentFolderRenamedEvent(DelugeEvent):
|
class TorrentFolderRenamedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a folder within a torrent has been renamed.
|
Emitted when a folder within a torrent has been renamed.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id', 'old', 'new')
|
||||||
|
|
||||||
def __init__(self, torrent_id, old, new):
|
def __init__(self, torrent_id, old, new):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
|
@ -142,44 +157,54 @@ class TorrentFolderRenamedEvent(DelugeEvent):
|
||||||
:param new: the new folder name
|
:param new: the new folder name
|
||||||
:type new: string
|
:type new: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id, old, new]
|
self.torrent_id = torrent_id
|
||||||
|
self.old = old
|
||||||
|
self.new = new
|
||||||
|
|
||||||
class TorrentFileRenamedEvent(DelugeEvent):
|
class TorrentFileRenamedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a file within a torrent has been renamed.
|
Emitted when a file within a torrent has been renamed.
|
||||||
"""
|
"""
|
||||||
def __init__(self, torrent_id, index, name):
|
__slots__ = ('torrent_id', 'index', 'filename')
|
||||||
|
|
||||||
|
def __init__(self, torrent_id, index, filename):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
:type torrent_id: string
|
:type torrent_id: string
|
||||||
:param index: the index of the file
|
:param index: the index of the file
|
||||||
:type index: int
|
:type index: int
|
||||||
:param name: the new filename
|
:param filename: the new filename
|
||||||
:type name: string
|
:type filename: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id, index, name]
|
self.torrent_id = torrent_id
|
||||||
|
self.index = index
|
||||||
|
self.filename = filename
|
||||||
|
|
||||||
class TorrentFinishedEvent(DelugeEvent):
|
class TorrentFinishedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a torrent finishes downloading.
|
Emitted when a torrent finishes downloading.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id',)
|
||||||
|
|
||||||
def __init__(self, torrent_id):
|
def __init__(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
:type torrent_id: string
|
:type torrent_id: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id]
|
self.torrent_id = torrent_id
|
||||||
|
|
||||||
class TorrentResumedEvent(DelugeEvent):
|
class TorrentResumedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a torrent resumes from a paused state.
|
Emitted when a torrent resumes from a paused state.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id',)
|
||||||
|
|
||||||
def __init__(self, torrent_id):
|
def __init__(self, torrent_id):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
:type torrent_id: string
|
:type torrent_id: string
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id]
|
self.torrent_id = torrent_id
|
||||||
|
|
||||||
class TorrentFileCompletedEvent(DelugeEvent):
|
class TorrentFileCompletedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
|
@ -188,6 +213,8 @@ class TorrentFileCompletedEvent(DelugeEvent):
|
||||||
This will only work with libtorrent 0.15 or greater.
|
This will only work with libtorrent 0.15 or greater.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('torrent_id', 'index')
|
||||||
|
|
||||||
def __init__(self, torrent_id, index):
|
def __init__(self, torrent_id, index):
|
||||||
"""
|
"""
|
||||||
:param torrent_id: the torrent_id
|
:param torrent_id: the torrent_id
|
||||||
|
@ -195,68 +222,75 @@ class TorrentFileCompletedEvent(DelugeEvent):
|
||||||
:param index: the file index
|
:param index: the file index
|
||||||
:type index: int
|
:type index: int
|
||||||
"""
|
"""
|
||||||
self._args = [torrent_id, index]
|
self.torrent_id = torrent_id
|
||||||
|
self.index = index
|
||||||
|
|
||||||
class NewVersionAvailableEvent(DelugeEvent):
|
class NewVersionAvailableEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a more recent version of Deluge is available.
|
Emitted when a more recent version of Deluge is available.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('new_release',)
|
||||||
|
|
||||||
def __init__(self, new_release):
|
def __init__(self, new_release):
|
||||||
"""
|
"""
|
||||||
:param new_release: the new version that is available
|
:param new_release: the new version that is available
|
||||||
:type new_release: string
|
:type new_release: string
|
||||||
"""
|
"""
|
||||||
self._args = [new_release]
|
self.new_release = new_release
|
||||||
|
|
||||||
class SessionStartedEvent(DelugeEvent):
|
class SessionStartedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a session has started. This typically only happens once when
|
Emitted when a session has started. This typically only happens once when
|
||||||
the daemon is initially started.
|
the daemon is initially started.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
class SessionPausedEvent(DelugeEvent):
|
class SessionPausedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when the session has been paused.
|
Emitted when the session has been paused.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
class SessionResumedEvent(DelugeEvent):
|
class SessionResumedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when the session has been resumed.
|
Emitted when the session has been resumed.
|
||||||
"""
|
"""
|
||||||
pass
|
|
||||||
|
|
||||||
class ConfigValueChangedEvent(DelugeEvent):
|
class ConfigValueChangedEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a config value changes in the Core.
|
Emitted when a config value changes in the Core.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('key', 'value')
|
||||||
|
|
||||||
def __init__(self, key, value):
|
def __init__(self, key, value):
|
||||||
"""
|
"""
|
||||||
:param key: the key that changed
|
:param key: the key that changed
|
||||||
:type key: string
|
:type key: string
|
||||||
:param value: the new value of the `:param:key`
|
:param value: the new value of the `:param:key`
|
||||||
"""
|
"""
|
||||||
self._args = [key, value]
|
self.key = key
|
||||||
|
self.value = value
|
||||||
|
|
||||||
class PluginEnabledEvent(DelugeEvent):
|
class PluginEnabledEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a plugin is enabled in the Core.
|
Emitted when a plugin is enabled in the Core.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('name',)
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
"""
|
"""
|
||||||
:param name: the plugin name
|
:param name: the plugin name
|
||||||
:type name: string
|
:type name: string
|
||||||
"""
|
"""
|
||||||
self._args = [name]
|
self.name = name
|
||||||
|
|
||||||
class PluginDisabledEvent(DelugeEvent):
|
class PluginDisabledEvent(DelugeEvent):
|
||||||
"""
|
"""
|
||||||
Emitted when a plugin is disabled in the Core.
|
Emitted when a plugin is disabled in the Core.
|
||||||
"""
|
"""
|
||||||
|
__slots__ = ('name',)
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
"""
|
"""
|
||||||
:param name: the plugin name
|
:param name: the plugin name
|
||||||
:type name: string
|
:type name: string
|
||||||
"""
|
"""
|
||||||
self._args = [name]
|
self.name = name
|
||||||
|
|
|
@ -45,6 +45,7 @@ import zlib
|
||||||
import deluge.common
|
import deluge.common
|
||||||
import deluge.component as component
|
import deluge.component as component
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
from deluge.event import known_events
|
||||||
|
|
||||||
if deluge.common.windows_check():
|
if deluge.common.windows_check():
|
||||||
import win32api
|
import win32api
|
||||||
|
@ -163,13 +164,14 @@ class DelugeRPCProtocol(Protocol):
|
||||||
message_type = request[0]
|
message_type = request[0]
|
||||||
|
|
||||||
if message_type == RPC_EVENT:
|
if message_type == RPC_EVENT:
|
||||||
event = request[1]
|
event_name = request[1]
|
||||||
#log.debug("Received RPCEvent: %s", event)
|
#log.debug("Received RPCEvent: %s", event)
|
||||||
# A RPCEvent was received from the daemon so run any handlers
|
# A RPCEvent was received from the daemon so run any handlers
|
||||||
# associated with it.
|
# associated with it.
|
||||||
if event in self.factory.event_handlers:
|
if event_name in self.factory.event_handlers:
|
||||||
for handler in self.factory.event_handlers[event]:
|
event = known_events[event_name](*request[2])
|
||||||
reactor.callLater(0, handler, *request[2])
|
for handler in self.factory.event_handlers[event_name]:
|
||||||
|
reactor.callLater(0, handler, event.copy())
|
||||||
continue
|
continue
|
||||||
|
|
||||||
request_id = request[1]
|
request_id = request[1]
|
||||||
|
|
|
@ -61,53 +61,53 @@ class EventLog(component.Component):
|
||||||
client.register_event_handler("PluginEnabledEvent", self.on_plugin_enabled_event)
|
client.register_event_handler("PluginEnabledEvent", self.on_plugin_enabled_event)
|
||||||
client.register_event_handler("PluginDisabledEvent", self.on_plugin_disabled_event)
|
client.register_event_handler("PluginDisabledEvent", self.on_plugin_disabled_event)
|
||||||
|
|
||||||
def on_torrent_added_event(self, torrent_id, from_state):
|
def on_torrent_added_event(self, event):
|
||||||
def on_torrent_status(status):
|
def on_torrent_status(status):
|
||||||
self.console.write(self.prefix + "TorrentAdded(from_state=%s): {!info!}%s (%s)" % (
|
self.console.write(self.prefix + "TorrentAdded(from_state=%s): {!info!}%s (%s)" % (
|
||||||
from_state, status["name"], torrent_id)
|
event.from_state, status["name"], event.torrent_id)
|
||||||
)
|
)
|
||||||
client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
|
client.core.get_torrent_status(event.torrent_id, ["name"]).addCallback(on_torrent_status)
|
||||||
|
|
||||||
def on_torrent_removed_event(self, torrent_id):
|
def on_torrent_removed_event(self, event):
|
||||||
self.console.write(self.prefix + "TorrentRemoved: {!info!}%s (%s)" %
|
self.console.write(self.prefix + "TorrentRemoved: {!info!}%s (%s)" %
|
||||||
(self.console.get_torrent_name(torrent_id), torrent_id))
|
(self.console.get_torrent_name(event.torrent_id), event.torrent_id))
|
||||||
|
|
||||||
def on_torrent_state_changed_event(self, torrent_id, state):
|
def on_torrent_state_changed_event(self, event):
|
||||||
# Modify the state string color
|
# Modify the state string color
|
||||||
if state in colors.state_color:
|
if event.state in colors.state_color:
|
||||||
state = colors.state_color[state] + state
|
state = colors.state_color[event.state] + event.state
|
||||||
|
|
||||||
self.console.write(self.prefix + "TorrentStateChanged: %s {!info!}%s (%s)" %
|
self.console.write(self.prefix + "TorrentStateChanged: %s {!info!}%s (%s)" %
|
||||||
(state, self.console.get_torrent_name(torrent_id), torrent_id))
|
(state, self.console.get_torrent_name(event.torrent_id), event.torrent_id))
|
||||||
|
|
||||||
def on_torrent_paused_event(self, torrent_id):
|
def on_torrent_paused_event(self, event):
|
||||||
self.console.write(self.prefix + "TorrentPaused: {!info!}%s (%s)" %
|
self.console.write(self.prefix + "TorrentPaused: {!info!}%s (%s)" %
|
||||||
(self.console.get_torrent_name(torrent_id), torrent_id))
|
(self.console.get_torrent_name(event.torrent_id), event.torrent_id))
|
||||||
|
|
||||||
def on_torrent_finished_event(self, torrent_id):
|
def on_torrent_finished_event(self, event):
|
||||||
self.console.write(self.prefix + "TorrentFinished: {!info!}%s (%s)" %
|
self.console.write(self.prefix + "TorrentFinished: {!info!}%s (%s)" %
|
||||||
(self.console.get_torrent_name(torrent_id), torrent_id))
|
(self.console.get_torrent_name(event.torrent_id), event.torrent_id))
|
||||||
|
|
||||||
def on_new_version_available_event(self, version):
|
def on_new_version_available_event(self, event):
|
||||||
self.console.write(self.prefix + "NewVersionAvailable: {!info!}%s" %
|
self.console.write(self.prefix + "NewVersionAvailable: {!info!}%s" %
|
||||||
(version))
|
(event.new_release))
|
||||||
|
|
||||||
def on_session_paused_event(self):
|
def on_session_paused_event(self, event):
|
||||||
self.console.write(self.prefix + "SessionPaused")
|
self.console.write(self.prefix + "SessionPaused")
|
||||||
|
|
||||||
def on_session_resumed_event(self):
|
def on_session_resumed_event(self, event):
|
||||||
self.console.write(self.prefix + "SessionResumed")
|
self.console.write(self.prefix + "SessionResumed")
|
||||||
|
|
||||||
def on_config_value_changed_event(self, key, value):
|
def on_config_value_changed_event(self, event):
|
||||||
color = "{!white,black,bold!}"
|
color = "{!white,black,bold!}"
|
||||||
if type(value) in colors.type_color:
|
if type(event.value) in colors.type_color:
|
||||||
color = colors.type_color[type(value)]
|
color = colors.type_color[type(event.value)]
|
||||||
|
|
||||||
self.console.write(self.prefix + "ConfigValueChanged: {!input!}%s: %s%s" %
|
self.console.write(self.prefix + "ConfigValueChanged: {!input!}%s: %s%s" %
|
||||||
(key, color, value))
|
(event.key, color, event.value))
|
||||||
|
|
||||||
def on_plugin_enabled_event(self, name):
|
def on_plugin_enabled_event(self, event):
|
||||||
self.console.write(self.prefix + "PluginEnabled: {!info!}%s" % name)
|
self.console.write(self.prefix + "PluginEnabled: {!info!}%s" % event.name)
|
||||||
|
|
||||||
def on_plugin_disabled_event(self, name):
|
def on_plugin_disabled_event(self, event):
|
||||||
self.console.write(self.prefix + "PluginDisabled: {!info!}%s" % name)
|
self.console.write(self.prefix + "PluginDisabled: {!info!}%s" % event.name)
|
||||||
|
|
|
@ -439,14 +439,14 @@ class ConsoleUI(component.Component):
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def on_torrent_added_event(self, torrent_id, from_state):
|
def on_torrent_added_event(self, event):
|
||||||
def on_torrent_status(status):
|
def on_torrent_status(status):
|
||||||
self.torrents.append((torrent_id, status["name"]))
|
self.torrents.append((event.torrent_id, status["name"]))
|
||||||
client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
|
client.core.get_torrent_status(event.torrent_id, ["name"]).addCallback(on_torrent_status)
|
||||||
|
|
||||||
def on_torrent_removed_event(self, torrent_id):
|
def on_torrent_removed_event(self, event):
|
||||||
for index, (tid, name) in enumerate(self.torrents):
|
for index, (tid, name) in enumerate(self.torrents):
|
||||||
if torrent_id == tid:
|
if event.torrent_id == tid:
|
||||||
del self.torrents[index]
|
del self.torrents[index]
|
||||||
|
|
||||||
def on_client_disconnect(self):
|
def on_client_disconnect(self):
|
||||||
|
|
|
@ -43,8 +43,8 @@ class CoreConfig(component.Component):
|
||||||
log.debug("CoreConfig init..")
|
log.debug("CoreConfig init..")
|
||||||
component.Component.__init__(self, "CoreConfig")
|
component.Component.__init__(self, "CoreConfig")
|
||||||
self.config = {}
|
self.config = {}
|
||||||
def on_configvaluechanged_event(key, value):
|
def on_configvaluechanged_event(event):
|
||||||
self.config[key] = value
|
self.config[event.key] = event.value
|
||||||
client.register_event_handler("ConfigValueChangedEvent", on_configvaluechanged_event)
|
client.register_event_handler("ConfigValueChangedEvent", on_configvaluechanged_event)
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
|
|
|
@ -602,34 +602,34 @@ class FilesTab(Tab):
|
||||||
def _on_filename_editing_canceled(self, renderer):
|
def _on_filename_editing_canceled(self, renderer):
|
||||||
self._editing_index = None
|
self._editing_index = None
|
||||||
|
|
||||||
def _on_torrentfilerenamed_event(self, torrent_id, index, name):
|
def _on_torrentfilerenamed_event(self, event):
|
||||||
log.debug("index: %s name: %s", index, name)
|
log.debug("index: %s name: %s", event.index, event.filename)
|
||||||
|
|
||||||
if torrent_id not in self.files_list:
|
if event.torrent_id not in self.files_list:
|
||||||
return
|
return
|
||||||
|
|
||||||
old_name = self.files_list[torrent_id][index]["path"]
|
old_name = self.files_list[event.torrent_id][event.index]["path"]
|
||||||
self.files_list[torrent_id][index]["path"] = name
|
self.files_list[event.torrent_id][event.index]["path"] = event.filename
|
||||||
|
|
||||||
# We need to update the filename displayed if we're currently viewing
|
# We need to update the filename displayed if we're currently viewing
|
||||||
# this torrents files.
|
# this torrents files.
|
||||||
if torrent_id == self.torrent_id:
|
if event.torrent_id == self.torrent_id:
|
||||||
old_name_len = len(old_name.split("/"))
|
old_name_len = len(old_name.split("/"))
|
||||||
name_len = len(name.split("/"))
|
name_len = len(event.filename.split("/"))
|
||||||
if old_name_len != name_len:
|
if old_name_len != name_len:
|
||||||
# The parent path list changes depending on which way the file
|
# The parent path list changes depending on which way the file
|
||||||
# is moving in the tree
|
# is moving in the tree
|
||||||
if old_name_len < name_len:
|
if old_name_len < name_len:
|
||||||
parent_path = [o for o in old_name.split("/")[:-1]]
|
parent_path = [o for o in old_name.split("/")[:-1]]
|
||||||
else:
|
else:
|
||||||
parent_path = [o for o in name.split("/")[:-1]]
|
parent_path = [o for o in event.filename.split("/")[:-1]]
|
||||||
# Find the iter to the parent folder we need to add a new folder
|
# Find the iter to the parent folder we need to add a new folder
|
||||||
# to.
|
# to.
|
||||||
def find_parent(model, path, itr, user_data):
|
def find_parent(model, path, itr, user_data):
|
||||||
if model[itr][0] == parent_path[0] + "/":
|
if model[itr][0] == parent_path[0] + "/":
|
||||||
if len(parent_path) == 1:
|
if len(parent_path) == 1:
|
||||||
# This is the parent iter
|
# This is the parent iter
|
||||||
to_create = name.split("/")[len(old_name.split("/")[:-1]):-1]
|
to_create = event.filename.split("/")[len(old_name.split("/")[:-1]):-1]
|
||||||
parent_iter = itr
|
parent_iter = itr
|
||||||
|
|
||||||
for tc in to_create:
|
for tc in to_create:
|
||||||
|
@ -648,8 +648,8 @@ class FilesTab(Tab):
|
||||||
|
|
||||||
# Find the iter for the file that needs to be moved
|
# Find the iter for the file that needs to be moved
|
||||||
def get_file_iter(model, path, itr, user_data):
|
def get_file_iter(model, path, itr, user_data):
|
||||||
if model[itr][5] == index:
|
if model[itr][5] == event.index:
|
||||||
model[itr][0] = name.split("/")[-1]
|
model[itr][0] = event.filename.split("/")[-1]
|
||||||
t = self.treestore.append(
|
t = self.treestore.append(
|
||||||
parent_iter,
|
parent_iter,
|
||||||
self.treestore.get(itr,
|
self.treestore.get(itr,
|
||||||
|
@ -668,7 +668,7 @@ class FilesTab(Tab):
|
||||||
if parent_path:
|
if parent_path:
|
||||||
self.treestore.foreach(find_parent, None)
|
self.treestore.foreach(find_parent, None)
|
||||||
else:
|
else:
|
||||||
new_folders = name.split("/")[:-1]
|
new_folders = event.filename.split("/")[:-1]
|
||||||
parent_iter = None
|
parent_iter = None
|
||||||
for f in new_folders:
|
for f in new_folders:
|
||||||
parent_iter = self.treestore.append(parent_iter,
|
parent_iter = self.treestore.append(parent_iter,
|
||||||
|
@ -682,8 +682,8 @@ class FilesTab(Tab):
|
||||||
else:
|
else:
|
||||||
# This is just changing a filename without any folder changes
|
# This is just changing a filename without any folder changes
|
||||||
def set_file_name(model, path, itr, user_data):
|
def set_file_name(model, path, itr, user_data):
|
||||||
if model[itr][5] == index:
|
if model[itr][5] == event.index:
|
||||||
model[itr][0] = os.path.split(name)[-1]
|
model[itr][0] = os.path.split(event.filename)[-1]
|
||||||
return True
|
return True
|
||||||
self.treestore.foreach(set_file_name, None)
|
self.treestore.foreach(set_file_name, None)
|
||||||
|
|
||||||
|
@ -729,40 +729,40 @@ class FilesTab(Tab):
|
||||||
self.treestore.remove(itr)
|
self.treestore.remove(itr)
|
||||||
itr = parent
|
itr = parent
|
||||||
|
|
||||||
def _on_torrentfolderrenamed_event(self, torrent_id, old_folder, new_folder):
|
def _on_torrentfolderrenamed_event(self, event):
|
||||||
log.debug("on_torrent_folder_renamed_signal")
|
log.debug("on_torrent_folder_renamed_signal")
|
||||||
log.debug("old_folder: %s new_folder: %s", old_folder, new_folder)
|
log.debug("old_folder: %s new_folder: %s", event.old, event.new)
|
||||||
|
|
||||||
if torrent_id not in self.files_list:
|
if event.torrent_id not in self.files_list:
|
||||||
return
|
return
|
||||||
|
|
||||||
if old_folder[-1] != "/":
|
if event.old[-1] != "/":
|
||||||
old_folder += "/"
|
event.old += "/"
|
||||||
if new_folder[-1] != "/":
|
if event.new[-1] != "/":
|
||||||
new_folder += "/"
|
event.new += "/"
|
||||||
|
|
||||||
for fd in self.files_list[torrent_id]:
|
for fd in self.files_list[event.torrent_id]:
|
||||||
if fd["path"].startswith(old_folder):
|
if fd["path"].startswith(event.old):
|
||||||
fd["path"] = fd["path"].replace(old_folder, new_folder, 1)
|
fd["path"] = fd["path"].replace(event.old, event.new, 1)
|
||||||
|
|
||||||
if torrent_id == self.torrent_id:
|
if event.torrent_id == self.torrent_id:
|
||||||
|
|
||||||
old_split = old_folder.split("/")
|
old_split = event.old.split("/")
|
||||||
try:
|
try:
|
||||||
old_split.remove("")
|
old_split.remove("")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
new_split = new_folder.split("/")
|
new_split = event.new.split("/")
|
||||||
try:
|
try:
|
||||||
new_split.remove("")
|
new_split.remove("")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
old_folder_iter = self.get_iter_at_path(old_folder)
|
old_folder_iter = self.get_iter_at_path(event.old)
|
||||||
old_folder_iter_parent = self.treestore.iter_parent(old_folder_iter)
|
old_folder_iter_parent = self.treestore.iter_parent(old_folder_iter)
|
||||||
|
|
||||||
new_folder_iter = self.get_iter_at_path(new_folder)
|
new_folder_iter = self.get_iter_at_path(event.new)
|
||||||
if len(new_split) == len(old_split):
|
if len(new_split) == len(old_split):
|
||||||
# These are at the same tree depth, so it's a simple rename
|
# These are at the same tree depth, so it's a simple rename
|
||||||
self.treestore[old_folder_iter][0] = new_split[-1] + "/"
|
self.treestore[old_folder_iter][0] = new_split[-1] + "/"
|
||||||
|
@ -782,9 +782,9 @@ class FilesTab(Tab):
|
||||||
# and if so, we delete it
|
# and if so, we delete it
|
||||||
self.remove_childless_folders(old_folder_iter_parent)
|
self.remove_childless_folders(old_folder_iter_parent)
|
||||||
|
|
||||||
def _on_torrentremoved_event(self, torrent_id):
|
def _on_torrentremoved_event(self, event):
|
||||||
if torrent_id in self.files_list:
|
if event.torrent_id in self.files_list:
|
||||||
del self.files_list[torrent_id]
|
del self.files_list[event.torrent_id]
|
||||||
|
|
||||||
def _on_drag_data_get_data(self, treeview, context, selection, target_id, etime):
|
def _on_drag_data_get_data(self, treeview, context, selection, target_id, etime):
|
||||||
paths = self.listview.get_selection().get_selected_rows()[1]
|
paths = self.listview.get_selection().get_selected_rows()[1]
|
||||||
|
|
|
@ -245,11 +245,11 @@ class MainWindow(component.Component):
|
||||||
else:
|
else:
|
||||||
self.window.set_title("Deluge")
|
self.window.set_title("Deluge")
|
||||||
|
|
||||||
def on_newversionavailable_event(self, new_version):
|
def on_newversionavailable_event(self, event):
|
||||||
if self.config["show_new_releases"]:
|
if self.config["show_new_releases"]:
|
||||||
from deluge.ui.gtkui.new_release_dialog import NewReleaseDialog
|
from deluge.ui.gtkui.new_release_dialog import NewReleaseDialog
|
||||||
reactor.callLater(5.0, NewReleaseDialog().show, new_version)
|
reactor.callLater(5.0, NewReleaseDialog().show, event.new_release)
|
||||||
|
|
||||||
def on_torrentfinished_event(self, torrent_id):
|
def on_torrentfinished_event(self, event):
|
||||||
from deluge.ui.gtkui.notification import Notification
|
from deluge.ui.gtkui.notification import Notification
|
||||||
Notification().notify(torrent_id)
|
Notification().notify(event.torrent_id)
|
||||||
|
|
|
@ -228,11 +228,11 @@ class MenuBar(component.Component):
|
||||||
return sep
|
return sep
|
||||||
|
|
||||||
### Callbacks ###
|
### Callbacks ###
|
||||||
def on_torrentstatechanged_event(self, torrent_id, state):
|
def on_torrentstatechanged_event(self, event):
|
||||||
if state == "Paused":
|
if event.state == "Paused":
|
||||||
self.update_menu()
|
self.update_menu()
|
||||||
|
|
||||||
def on_torrentresumed_event(self, torrent_id):
|
def on_torrentresumed_event(self, event):
|
||||||
self.update_menu()
|
self.update_menu()
|
||||||
|
|
||||||
def on_sessionpaused_event(self):
|
def on_sessionpaused_event(self):
|
||||||
|
|
|
@ -89,11 +89,11 @@ class PluginManager(deluge.pluginmanagerbase.PluginManagerBase,
|
||||||
for plugin in enabled_plugins:
|
for plugin in enabled_plugins:
|
||||||
self.enable_plugin(plugin)
|
self.enable_plugin(plugin)
|
||||||
|
|
||||||
def _on_plugin_enabled_event(self, name):
|
def _on_plugin_enabled_event(self, event):
|
||||||
self.enable_plugin(name)
|
self.enable_plugin(event.name)
|
||||||
|
|
||||||
def _on_plugin_disabled_event(self, name):
|
def _on_plugin_disabled_event(self, event):
|
||||||
self.disable_plugin(name)
|
self.disable_plugin(event.name)
|
||||||
|
|
||||||
## Hook functions
|
## Hook functions
|
||||||
def run_on_show_prefs(self):
|
def run_on_show_prefs(self):
|
||||||
|
|
|
@ -286,14 +286,14 @@ class StatusBar(component.Component):
|
||||||
client.core.get_session_status(keys).addCallback(self._on_get_session_status)
|
client.core.get_session_status(keys).addCallback(self._on_get_session_status)
|
||||||
client.core.get_free_space().addCallback(self._on_get_free_space)
|
client.core.get_free_space().addCallback(self._on_get_free_space)
|
||||||
|
|
||||||
def on_configvaluechanged_event(self, key, value):
|
def on_configvaluechanged_event(self, event):
|
||||||
"""
|
"""
|
||||||
This is called when we receive a ConfigValueChangedEvent from
|
This is called when we receive a ConfigValueChangedEvent from
|
||||||
the core.
|
the core.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if key in self.config_value_changed_dict.keys():
|
if event.key in self.config_value_changed_dict.keys():
|
||||||
self.config_value_changed_dict[key](value)
|
self.config_value_changed_dict[event.key](event.value)
|
||||||
|
|
||||||
def _on_max_connections_global(self, max_connections):
|
def _on_max_connections_global(self, max_connections):
|
||||||
self.max_connections = max_connections
|
self.max_connections = max_connections
|
||||||
|
|
|
@ -173,12 +173,12 @@ class SystemTray(component.Component):
|
||||||
"payload_upload_rate",
|
"payload_upload_rate",
|
||||||
"payload_download_rate"]).addCallback(self._on_get_session_status)
|
"payload_download_rate"]).addCallback(self._on_get_session_status)
|
||||||
|
|
||||||
def config_value_changed(self, key, value):
|
def config_value_changed(self, event):
|
||||||
"""This is called when we received a config_value_changed signal from
|
"""This is called when we received a config_value_changed signal from
|
||||||
the core."""
|
the core."""
|
||||||
|
|
||||||
if key in self.config_value_changed_dict.keys():
|
if event.key in self.config_value_changed_dict.keys():
|
||||||
self.config_value_changed_dict[key](value)
|
self.config_value_changed_dict[event.key](event.value)
|
||||||
|
|
||||||
def _on_max_download_speed(self, max_download_speed):
|
def _on_max_download_speed(self, max_download_speed):
|
||||||
if self.max_download_speed != max_download_speed:
|
if self.max_download_speed != max_download_speed:
|
||||||
|
|
|
@ -512,31 +512,31 @@ class TorrentView(listview.ListView, component.Component):
|
||||||
def on_drag_drop(self, widget, drag_context, x, y, timestamp):
|
def on_drag_drop(self, widget, drag_context, x, y, timestamp):
|
||||||
widget.stop_emission("drag-drop")
|
widget.stop_emission("drag-drop")
|
||||||
|
|
||||||
def on_torrentadded_event(self, torrent_id, from_state):
|
def on_torrentadded_event(self, event):
|
||||||
self.add_row(torrent_id)
|
self.add_row(event.torrent_id)
|
||||||
self.mark_dirty(torrent_id)
|
self.mark_dirty(event.torrent_id)
|
||||||
|
|
||||||
def on_torrentremoved_event(self, torrent_id):
|
def on_torrentremoved_event(self, event):
|
||||||
self.remove_row(torrent_id)
|
self.remove_row(event.torrent_id)
|
||||||
|
|
||||||
def on_torrentstatechanged_event(self, torrent_id, state):
|
def on_torrentstatechanged_event(self, event):
|
||||||
# Update the torrents state
|
# Update the torrents state
|
||||||
for row in self.liststore:
|
for row in self.liststore:
|
||||||
if not torrent_id == row[self.columns["torrent_id"].column_indices[0]]:
|
if not event.torrent_id == row[self.columns["torrent_id"].column_indices[0]]:
|
||||||
continue
|
continue
|
||||||
row[self.get_column_index(_("Progress"))[1]] = state
|
row[self.get_column_index(_("Progress"))[1]] = event.state
|
||||||
|
|
||||||
self.mark_dirty(torrent_id)
|
self.mark_dirty(event.torrent_id)
|
||||||
|
|
||||||
def on_sessionpaused_event(self):
|
def on_sessionpaused_event(self, event):
|
||||||
self.mark_dirty()
|
self.mark_dirty()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def on_sessionresumed_event(self):
|
def on_sessionresumed_event(self, event):
|
||||||
self.mark_dirty()
|
self.mark_dirty()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def on_torrentqueuechanged_event(self):
|
def on_torrentqueuechanged_event(self, event):
|
||||||
self.mark_dirty()
|
self.mark_dirty()
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
|
|
|
@ -234,21 +234,21 @@ class SessionProxy(component.Component):
|
||||||
d = client.core.get_torrents_status(filter_dict, keys, True)
|
d = client.core.get_torrents_status(filter_dict, keys, True)
|
||||||
return d.addCallback(on_status, None, keys)
|
return d.addCallback(on_status, None, keys)
|
||||||
|
|
||||||
def on_torrent_state_changed(self, torrent_id, state):
|
def on_torrent_state_changed(self, event):
|
||||||
if torrent_id in self.torrents:
|
if event.torrent_id in self.torrents:
|
||||||
self.torrents[torrent_id][1]["state"] = state
|
self.torrents[event.torrent_id][1]["state"] = event.state
|
||||||
self.cache_times[torrent_id]["state"] = time.time()
|
self.cache_times[event.torrent_id]["state"] = time.time()
|
||||||
|
|
||||||
def on_torrent_added(self, torrent_id, from_state):
|
def on_torrent_added(self, event):
|
||||||
self.torrents[torrent_id] = [time.time() - self.cache_time - 1, {}]
|
self.torrents[event.torrent_id] = [time.time() - self.cache_time - 1, {}]
|
||||||
self.cache_times[torrent_id] = {}
|
self.cache_times[event.torrent_id] = {}
|
||||||
def on_status(status):
|
def on_status(status):
|
||||||
self.torrents[torrent_id][1].update(status)
|
self.torrents[event.torrent_id][1].update(status)
|
||||||
t = time.time()
|
t = time.time()
|
||||||
for key in status:
|
for key in status:
|
||||||
self.cache_times[torrent_id][key] = t
|
self.cache_times[event.torrent_id][key] = t
|
||||||
client.core.get_torrent_status(torrent_id, []).addCallback(on_status)
|
client.core.get_torrent_status(event.torrent_id, []).addCallback(on_status)
|
||||||
|
|
||||||
def on_torrent_removed(self, torrent_id):
|
def on_torrent_removed(self, event):
|
||||||
del self.torrents[torrent_id]
|
del self.torrents[event.torrent_id]
|
||||||
del self.cache_times[torrent_id]
|
del self.cache_times[event.torrent_id]
|
||||||
|
|
|
@ -72,11 +72,11 @@ class PluginManager(PluginManagerBase, component.Component):
|
||||||
for plugin in plugins:
|
for plugin in plugins:
|
||||||
self.enable_plugin(plugin)
|
self.enable_plugin(plugin)
|
||||||
|
|
||||||
def _on_plugin_enabled_event(self, name):
|
def _on_plugin_enabled_event(self, event):
|
||||||
self.enable_plugin(name)
|
self.enable_plugin(event.name)
|
||||||
|
|
||||||
def _on_plugin_disabled_event(self, name):
|
def _on_plugin_disabled_event(self, event):
|
||||||
self.disable_plugin(name)
|
self.disable_plugin(event.name)
|
||||||
|
|
||||||
def disable_plugin(self, name):
|
def disable_plugin(self, name):
|
||||||
# Get the plugin instance
|
# Get the plugin instance
|
||||||
|
|
Loading…
Reference in New Issue