source: deluge/ui/console/eventlog.py@ a10382

2.0.x develop extjs4-port
Last change on this file since a10382 was a10382, checked in by Andrew Resch <andrewresch@gmail.com>, 16 years ago

Add support for setting config values

  • Property mode set to 100644
File size: 3.8 KB
Line 
1#
2# eventlog.py
3#
4# Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com>
5#
6# Deluge is free software.
7#
8# You may redistribute it and/or modify it under the terms of the
9# GNU General Public License, as published by the Free Software
10# Foundation; either version 3 of the License, or (at your option)
11# any later version.
12#
13# deluge is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16# See the GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with deluge. If not, write to:
20# The Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor
22# Boston, MA 02110-1301, USA.
23#
24
25
26import deluge.component as component
27import deluge.common
28import colors
29from deluge.ui.client import client
30
31from deluge.log import LOG as log
32
33class EventLog(component.Component):
34 """
35 Prints out certain events as they are received from the core.
36 """
37 def __init__(self):
38 component.Component.__init__(self, "EventLog")
39 self.console = component.get("ConsoleUI")
40
41 client.register_event_handler("TorrentAddedEvent", self.on_torrent_added_event)
42 client.register_event_handler("PreTorrentRemovedEvent", self.on_torrent_removed_event)
43 client.register_event_handler("TorrentStateChangedEvent", self.on_torrent_state_changed_event)
44 client.register_event_handler("TorrentFinishedEvent", self.on_torrent_finished_event)
45 client.register_event_handler("NewVersionAvailableEvent", self.on_new_version_available_event)
46 client.register_event_handler("SessionPausedEvent", self.on_session_paused_event)
47 client.register_event_handler("SessionResumedEvent", self.on_session_resumed_event)
48 client.register_event_handler("ConfigValueChangedEvent", self.on_config_value_changed_event)
49
50 def on_torrent_added_event(self, torrent_id):
51 def on_torrent_status(status):
52 self.console.write("{!event!}* TorrentAdded: {!info!}%s (%s)" % (status["name"], torrent_id))
53 client.core.get_torrent_status(torrent_id, ["name"]).addCallback(on_torrent_status)
54
55 def on_torrent_removed_event(self, torrent_id):
56 self.console.write("{!event!}* TorrentRemovedEvent: {!info!}%s (%s)" %
57 (self.console.get_torrent_name(torrent_id), torrent_id))
58
59 def on_torrent_state_changed_event(self, torrent_id, state):
60 log.debug("on_torrent_state_changed_event!")
61 # Modify the state string color
62 if state in colors.state_color:
63 state = colors.state_color[state] + state
64
65 self.console.write("{!event!}* TorrentStateChanged: %s {!info!}%s (%s)" %
66 (state, self.console.get_torrent_name(torrent_id), torrent_id))
67
68 def on_torrent_paused_event(self, torrent_id):
69 self.console.write("{!event!}* TorrentPaused: {!info!}%s (%s)" %
70 (self.console.get_torrent_name(torrent_id), torrent_id))
71
72 def on_torrent_finished_event(self, torrent_id):
73 self.console.write("{!event!}* TorrentFinished: {!info!}%s (%s)" %
74 (self.console.get_torrent_name(torrent_id), torrent_id))
75
76 def on_new_version_available_event(self, version):
77 self.console.write("{!event!}* NewVersionAvailable: {!info!}%s" %
78 (version))
79
80 def on_session_paused_event(self):
81 self.console.write("{!event!}* SessionPaused")
82
83 def on_session_resumed_event(self):
84 self.console.write("{!event!}* SessionResumed")
85
86 def on_config_value_changed_event(self, key, value):
87 color = "{!white,black,bold!}"
88 if type(value) in colors.type_color:
89 color = colors.type_color[type(value)]
90
91 self.console.write("{!event!}* ConfigValueChanged: {!input!}%s: %s%s" %
92 (key, color, value))
Note: See TracBrowser for help on using the repository browser.