Rework the signalreceiver a bit to help address errors on exit.
A few UI tweaks.
This commit is contained in:
parent
efd1f18082
commit
89cad666d5
|
@ -430,6 +430,8 @@ class ConnectionManager(component.Component):
|
|||
|
||||
uri = "http://" + uri
|
||||
if status == HOSTLIST_STATUS.index("Connected"):
|
||||
# Stop all the components first.
|
||||
component.stop()
|
||||
# If we are connected to this host, then we will disconnect.
|
||||
client.set_core_uri(None)
|
||||
self._update()
|
||||
|
|
|
@ -79,10 +79,10 @@ class RemoveTorrentDialog:
|
|||
self.dialog.show()
|
||||
|
||||
def on_button_ok_clicked(self, widget):
|
||||
#data = self.glade.get_widget("chk_data").get_active()
|
||||
#torrent = self.glade.get_widget("chk_torrents").get_active()
|
||||
client.remove_torrent(
|
||||
self.torrent_ids, self.remove_torrentfile, self.remove_data)
|
||||
# Unselect all to avoid issues with the selection changed event
|
||||
component.get("TorrentView").treeview.get_selection().unselect_all()
|
||||
self.dialog.destroy()
|
||||
|
||||
def on_button_cancel_clicked(self, widget):
|
||||
|
|
|
@ -87,23 +87,26 @@ class Signals(component.Component):
|
|||
log.debug("torrent id: %s", torrent_id)
|
||||
# Remove the torrent from the treeview
|
||||
component.get("TorrentView").remove_row(torrent_id)
|
||||
component.get("TorrentDetails").clear()
|
||||
|
||||
def torrent_paused(self, torrent_id):
|
||||
log.debug("torrent_paused signal received..")
|
||||
component.get("TorrentView").update()
|
||||
component.get("ToolBar").update_buttons()
|
||||
|
||||
def torrent_resumed(self, torrent_id):
|
||||
log.debug("torrent_resumed signal received..")
|
||||
component.get("TorrentView").update()
|
||||
component.get("ToolBar").update_buttons()
|
||||
|
||||
def torrent_all_paused(self):
|
||||
log.debug("torrent_all_paused signal received..")
|
||||
component.get("TorrentView").update()
|
||||
component.get("ToolBar").update_buttons()
|
||||
|
||||
def torrent_all_resumed(self):
|
||||
log.debug("torrent_all_resumed signal received..")
|
||||
component.get("TorrentView").update()
|
||||
component.get("ToolBar").update_buttons()
|
||||
|
||||
def config_value_changed(self, key, value):
|
||||
log.debug("config_value_changed signal received..")
|
||||
|
|
|
@ -38,9 +38,6 @@ pygtk.require('2.0')
|
|||
import gtk, gtk.glade
|
||||
import gettext
|
||||
import gobject
|
||||
import cPickle as pickle
|
||||
import time
|
||||
import traceback
|
||||
|
||||
import deluge.common
|
||||
import deluge.component as component
|
||||
|
@ -357,7 +354,6 @@ class TorrentView(listview.ListView, component.Component):
|
|||
def remove_row(self, torrent_id):
|
||||
"""Removes a row with torrent_id"""
|
||||
for row in self.liststore:
|
||||
# Check if this row is the row we want to remove
|
||||
if row[0] == torrent_id:
|
||||
self.liststore.remove(row.iter)
|
||||
# Force an update of the torrentview
|
||||
|
@ -433,4 +429,3 @@ class TorrentView(listview.ListView, component.Component):
|
|||
component.get("TorrentDetails").update()
|
||||
component.get("ToolBar").update_buttons()
|
||||
|
||||
|
||||
|
|
|
@ -42,21 +42,21 @@ import deluge.SimpleXMLRPCServer as SimpleXMLRPCServer
|
|||
from SocketServer import ThreadingMixIn
|
||||
import deluge.xmlrpclib as xmlrpclib
|
||||
import threading
|
||||
import socket
|
||||
|
||||
from deluge.log import LOG as log
|
||||
|
||||
class SignalReceiver(
|
||||
ThreadingMixIn,
|
||||
SimpleXMLRPCServer.SimpleXMLRPCServer):
|
||||
class SignalReceiver(ThreadingMixIn, SimpleXMLRPCServer.SimpleXMLRPCServer):
|
||||
|
||||
def __init__(self):
|
||||
log.debug("SignalReceiver init..")
|
||||
gobject.threads_init()
|
||||
# gobject.threads_init()
|
||||
|
||||
# Set to true so that the receiver thread will exit
|
||||
self._shutdown = False
|
||||
|
||||
self.signals = {}
|
||||
self.emitted_signals = []
|
||||
|
||||
self.remote = False
|
||||
|
||||
|
@ -68,19 +68,13 @@ class SignalReceiver(
|
|||
try:
|
||||
client.deregister_client()
|
||||
client.force_call()
|
||||
except:
|
||||
pass
|
||||
except Exception, e:
|
||||
log.debug("Unable to deregister client from server: %s", e)
|
||||
|
||||
log.debug("Shutting down signalreceiver")
|
||||
|
||||
# Hacky.. sends a request to our local receiver to ensure that it
|
||||
# shutdowns.. This is because handle_request() is a blocking call.
|
||||
receiver = xmlrpclib.ServerProxy("http://localhost:" + str(self.port),
|
||||
allow_none=True)
|
||||
try:
|
||||
receiver.emit_signal("shutdown", None)
|
||||
except:
|
||||
# We don't care about errors at this point
|
||||
pass
|
||||
self.socket.shutdown(socket.SHUT_RDWR)
|
||||
return
|
||||
|
||||
def set_remote(self, remote):
|
||||
self.remote = remote
|
||||
|
@ -114,6 +108,9 @@ class SignalReceiver(
|
|||
client.register_client(str(self.port))
|
||||
|
||||
t = threading.Thread(target=self.handle_thread)
|
||||
|
||||
gobject.timeout_add(50, self.handle_signals)
|
||||
|
||||
try:
|
||||
t.start()
|
||||
except Exception, e:
|
||||
|
@ -129,23 +126,20 @@ class SignalReceiver(
|
|||
|
||||
def emit_signal(self, signal, *data):
|
||||
"""Exported method used by the core to emit a signal to the client"""
|
||||
try:
|
||||
if data != None:
|
||||
self.emitted_signals.append((signal, data))
|
||||
return
|
||||
|
||||
def handle_signals(self):
|
||||
for signal, data in self.emitted_signals:
|
||||
try:
|
||||
for callback in self.signals[signal]:
|
||||
try:
|
||||
gobject.idle_add(callback, *data)
|
||||
except:
|
||||
log.warning("Unable to call callback for signal %s",
|
||||
signal)
|
||||
else:
|
||||
for callback in self.signals[signal]:
|
||||
try:
|
||||
gobject.idle_add(callback)
|
||||
except:
|
||||
log.warning("Unable to call callback for signal %s",
|
||||
signal)
|
||||
except KeyError:
|
||||
log.debug("There are no callbacks registered for signal '%s'", signal)
|
||||
gobject.idle_add(callback, *data)
|
||||
|
||||
except Exception, e:
|
||||
log.warning("Unable to call callback for signal %s: %s", signal, e)
|
||||
|
||||
self.emitted_signals = []
|
||||
return True
|
||||
|
||||
def connect_to_signal(self, signal, callback):
|
||||
"""Connect to a signal"""
|
||||
|
@ -155,4 +149,3 @@ class SignalReceiver(
|
|||
except KeyError:
|
||||
self.signals[signal] = [callback]
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue