Update to the current non-blocking stuff. Also, allow selecting files from a torrent...
[python-gnt.git] / example / delugent / signals.py
bloba41487d8204c24d632a93528e8ab5533b796df79
2 # signals.py
4 # Copyright (C) 2007 Andrew Resch ('andar') <andrewresch@gmail.com>
5 # 2007 Sadrul Habib Chowdhury <imadil@gmail.com>
6 #
7 # Deluge and Delugent are free software.
8 #
9 # You may redistribute it and/or modify it under the terms of the
10 # GNU General Public License, as published by the Free Software
11 # Foundation; either version 2 of the License, or (at your option)
12 # any later version.
14 # deluge and delugent is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 # See the GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with deluge. If not, write to:
21 # The Free Software Foundation, Inc.,
22 # 51 Franklin Street, Fifth Floor
23 # Boston, MA 02110-1301, USA.
25 # In addition, as a special exception, the copyright holders give
26 # permission to link the code of portions of this program with the OpenSSL
27 # library.
28 # You must obey the GNU General Public License in all respects for all of
29 # the code used other than OpenSSL. If you modify file(s) with this
30 # exception, you may extend this exception to your version of the file(s),
31 # but you are not obligated to do so. If you do not wish to do so, delete
32 # this exception statement from your version. If you delete this exception
33 # statement from all source files in the program, then also delete it here.
35 from deluge.ui.signalreceiver import SignalReceiver
36 from deluge.log import LOG as log
37 import local
39 class Signals:
40 def __init__(self, list):
41 self.torrentlist = list
42 self.receiver = SignalReceiver(6200)
43 self.receiver.start()
45 for name, callback in (
46 ("torrent_added", self.torrent_added_signal),
47 ("torrent_removed", self.torrent_removed_signal),
48 ("torrent_paused", self.torrent_paused),
49 ("torrent_resumed", self.torrent_resumed),
50 ("torrent_all_paused", self.torrent_all_paused),
51 ("torrent_all_resumed", self.torrent_all_resumed),
52 ("config_value_changed", self.config_value_changed),
54 self.receiver.connect_to_signal(name, callback)
56 def __del__(self):
57 #if self.receiver:
58 # self.receiver.shutdown()
59 pass
61 def torrent_added_signal(self, torrent_id):
62 log.debug("torrent_added signal received..")
63 log.debug("torrent id: %s", torrent_id)
64 # Add the torrent to the treeview
65 self.torrentlist.add_torrent(torrent_id)
67 def torrent_removed_signal(self, torrent_id):
68 log.debug("torrent_remove signal received..")
69 log.debug("torrent id: %s", torrent_id)
70 # Remove the torrent from the treeview
71 self.torrentlist.remove_torrent(torrent_id)
73 def torrent_paused(self, torrent_id):
74 log.debug("torrent_paused signal received..")
75 self.torrentlist.update_torrent(torrent_id)
77 def torrent_resumed(self, torrent_id):
78 log.debug("torrent_resumed signal received..")
79 self.torrentlist.update_torrent(torrent_id)
81 def torrent_all_paused(self):
82 log.debug("torrent_all_paused signal received..")
83 self.torrentlist.update_all()
85 def torrent_all_resumed(self):
86 log.debug("torrent_all_resumed signal received..")
87 self.torrentlist.update_all()
89 def config_value_changed(self, key, value):
90 log.debug("config value changed: (%s, %s)\n" % (key, value))
91 local.configs[key] = value