From 525526316ce7b5f465a96b908ee1470bec4fb381 Mon Sep 17 00:00:00 2001 From: Marcos Pinto Date: Sat, 16 Jun 2007 05:45:22 +0000 Subject: [PATCH] connect queue to top --- glade/torrent_menu.glade | 1 + plugins/BlocklistImport/__init__.py | 15 ++++++------- plugins/BlocklistImport/ui.py | 27 +++++++++++++++++++++-- src/core.py | 3 +++ src/interface.py | 34 ++++++++++++++++++++++------- 5 files changed, 62 insertions(+), 18 deletions(-) diff --git a/glade/torrent_menu.glade b/glade/torrent_menu.glade index 6eeea398c..68584024d 100644 --- a/glade/torrent_menu.glade +++ b/glade/torrent_menu.glade @@ -46,6 +46,7 @@ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK Top True + True diff --git a/plugins/BlocklistImport/__init__.py b/plugins/BlocklistImport/__init__.py index d754fbaf6..8a04268f8 100644 --- a/plugins/BlocklistImport/__init__.py +++ b/plugins/BlocklistImport/__init__.py @@ -49,30 +49,30 @@ class BlocklistImport: def loadlist(self, fetch=False): # FIXME - #self.gtkprog.start() + self.gtkprog.start() # Attempt initial import - # FIXME: Make async if fetch: - print "Downloading blocklist..." + self.gtkprog.start_download() filename, headers = urllib.urlretrieve(self.config.get('url'), filename=self.blockfile, reporthook=self._download_update) - print "Done" + + self.gtkprog.start_import() self.core.reset_ip_filter() reader = PGReader(self.blockfile) ips = reader.next() while ips: - print "Blocking",ips self.core.add_range_to_ip_filter(*ips) + self.gtkprog.import_prog() ips = reader.next() reader.close() + self.gtkprog.end_import() - # FIXME - #self.gtkprog.stop() + self.gtkprog.stop() def configure(self): self.gtkconf.start() @@ -88,7 +88,6 @@ class BlocklistImport: self.core.reset_ip_filter() def unload(self): - #self.config.save_to_file(self.config_file) self.core.reset_ip_filter() def update(self): diff --git a/plugins/BlocklistImport/ui.py b/plugins/BlocklistImport/ui.py index e9aecab49..ae2358525 100644 --- a/plugins/BlocklistImport/ui.py +++ b/plugins/BlocklistImport/ui.py @@ -58,7 +58,7 @@ class GTKConfig(gtk.Dialog): class GTKProgress(gtk.Dialog): def __init__(self, plugin): - gtk.Dialog.__init__(self, title="Setting-Up Blocklist", + gtk.Dialog.__init__(self, title="Loading Blocklist", flags=gtk.DIALOG_MODAL, buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)) # Setup @@ -76,17 +76,40 @@ class GTKProgress(gtk.Dialog): self.hide_all() + def start_download(self): + self.progress.set_text("Downloading") + self.update() + def download_prog(self, fract): if fract > 1.0: fract = 1.0 self.progress.set_fraction(fract) + self.update() + + def start_import(self): + self.progress.set_text("Importing") + self.progress.set_pulse_step(0.0075) + self.update() + + def import_prog(self): + self.progress.pulse() + self.update() + + def end_import(self): + self.progress.set_text("Complete") + self.progress.set_fraction(1.0) + self.update() def cancel(self, dialog, response): self.hide_all() def start(self): - print "showing all" self.show_all() + self.update() def stop(self): self.hide_all() + + def update(self): + while gtk.events_pending(): + not gtk.main_iteration(block=True) diff --git a/src/core.py b/src/core.py index 3b38d3a1a..f5d1deb5e 100644 --- a/src/core.py +++ b/src/core.py @@ -406,6 +406,9 @@ class Manager: # Queueing functions + def queue_top(self, unique_ID, enforce_queue=True): + self.state.queue.insert(0,self.state.queue.pop(self.get_queue_index(unique_ID))) + def queue_up(self, unique_ID, enforce_queue=True): curr_index = self.get_queue_index(unique_ID) if curr_index > 0: diff --git a/src/interface.py b/src/interface.py index 85020b0fa..a1aac6483 100644 --- a/src/interface.py +++ b/src/interface.py @@ -51,6 +51,7 @@ class DelugeGTK: gettext.install(APP, DIR) self.is_running = False + self.update_queue = [] self.ipc_manager = ipc_manager.Manager(self) self.torrent_file_queue = [] #Start the Deluge Manager: @@ -105,17 +106,13 @@ class DelugeGTK: except KeyError: pass - enable_plugins = self.config.get('enabled_plugins', str, default="").split(':') - - for plugin in enable_plugins: - try: - self.plugins.enable_plugin(plugin) - except KeyError: - pass self.apply_prefs() self.load_window_geometry() self.manager.pe_settings(self.config.get("encout_state", int, default=common.EncState.enabled), self.config.get("encin_state", int, default=common.EncState.enabled), self.config.get("enclevel_type", int, default=common.EncLevel.both), self.config.get("pref_rc4", bool, default=True)) + # Load plugins after GTK is initialised + self.update_queue.append(self.load_plugins) + def external_add_torrent(self, torrent_file): print "Ding!" print "Got torrent externally:", os.path.basename(torrent_file) @@ -158,6 +155,7 @@ class DelugeGTK: "queue_up": self.q_torrent_up, "queue_down": self.q_torrent_down, "queue_bottom": self.q_to_bottom, + "queue_top": self.q_to_top, }) def build_tray_icon(self): @@ -264,6 +262,7 @@ class DelugeGTK: "queue_up": self.q_torrent_up, "queue_down": self.q_torrent_down, "queue_bottom": self.q_to_bottom, + "queue_top": self.q_to_top, }) self.torrent_menu.connect("focus", self.torrent_menu_focus) # UID, Q#, Name, Size, Progress, Message, Seeders, Peers, DL, UL, ETA, Share @@ -656,9 +655,22 @@ class DelugeGTK: gtk.main() except KeyboardInterrupt: self.manager.quit() - + + def load_plugins(self): + enable_plugins = self.config.get('enabled_plugins', str, default="").split(':') + for plugin in enable_plugins: + try: + self.plugins.enable_plugin(plugin) + except KeyError: + pass + ## Call via a timer to update the interface def update(self): + self.update_queue.reverse() + while len(self.update_queue) > 0: + f = self.update_queue.pop() + f() + # We need to apply the queue changes self.manager.apply_queue() # Make sure that the interface still exists @@ -1045,6 +1057,12 @@ class DelugeGTK: if torrent is not None: self.manager.queue_bottom(torrent) self.update() + + def q_to_top(self, widget): + torrent = self.get_selected_torrent() + if torrent is not None: + self.manager.queue_top(torrent) + self.update() def toolbar_toggle(self, widget): if widget.get_active():