From 6d42f2234eeee8f2622c8244775c7dbf02e5503a Mon Sep 17 00:00:00 2001 From: Alex Dedul Date: Mon, 16 Jul 2007 13:59:22 +0000 Subject: [PATCH] Plugins and preferences dialogs code clean up. --- src/dialogs.py | 15 ++++++------- src/interface.py | 57 ++++++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/src/dialogs.py b/src/dialogs.py index aefd0571a..18d3535ad 100644 --- a/src/dialogs.py +++ b/src/dialogs.py @@ -38,7 +38,7 @@ import pref PREFS_FILENAME = "prefs.state" class PreferencesDlg: - def __init__(self, parent, preferences): + def __init__(self, preferences, active_port): self.glade = gtk.glade.XML(common.get_glade_file("preferences_dialog.glade"), domain='deluge') self.dialog = self.glade.get_widget("pref_dialog") self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png")) @@ -48,8 +48,9 @@ class PreferencesDlg: 'on_ask_save' : self.toggle_move_chk, 'on_btn_testport_clicked': self.TestPort, }) - self.parent = parent + self.preferences = preferences + self.active_port = str(active_port) def show(self): # Load settings into dialog @@ -86,7 +87,7 @@ class PreferencesDlg: self.glade.get_widget("download_path_button").set_filename(self.preferences.get("default_download_path")) self.glade.get_widget("chk_enable_files_dialog").set_active(self.preferences.get("enable_files_dialog")) self.glade.get_widget("chk_compact").set_active(self.preferences.get("use_compact_storage")) - self.glade.get_widget("active_port_label").set_text(str(self.parent.manager.get_state()['port'])) + self.glade.get_widget("active_port_label").set_text(str(self.active_port)) self.glade.get_widget("spin_port_min").set_value(self.preferences.get("listen_on")[0]) self.glade.get_widget("spin_port_max").set_value(self.preferences.get("listen_on")[1]) self.glade.get_widget("spin_max_upload").set_value(self.preferences.get("max_upload_speed")) @@ -149,8 +150,8 @@ class PreferencesDlg: return r def TestPort(self, widget): - activep = str(self.parent.manager.get_state()['port']) - common.open_url_in_browser(self.dialog,'http://www.deluge-torrent.org/test-port.php?port=%s' %activep) + common.open_url_in_browser(self.dialog, + 'http://www.deluge-torrent.org/test-port.php?port=%s' % self.active_port) def tray_toggle(self, widget): @@ -199,7 +200,7 @@ class FilesDlg: return r class PluginDlg: - def __init__(self, parent, plugins): + def __init__(self, plugins): self.glade = gtk.glade.XML(common.get_glade_file("plugin_dialog.glade"), domain='deluge') self.dialog = self.glade.get_widget("plugin_dialog") self.dialog.set_icon_from_file(common.get_pixmap("deluge32.png")) @@ -215,9 +216,7 @@ class PluginDlg: name_col.set_expand(True) dgtk.add_toggle_column(self.view, _("Enabled"), 1, toggled_signal=self.plugin_toggled) self.glade.signal_autoconnect({'plugin_pref': self.plugin_pref}) - self.parent = parent self.plugins = plugins - def show(self): self.store.clear() diff --git a/src/interface.py b/src/interface.py index c7f5b1d96..36d3de457 100644 --- a/src/interface.py +++ b/src/interface.py @@ -99,8 +99,6 @@ class DelugeGTK: else: self.has_tray = True - self.preferences_dialog = dialogs.PreferencesDlg(self, self.config) - self.plugin_dialog = dialogs.PluginDlg(self, self.plugins) self.build_torrent_table() self.build_summary_tab() self.build_file_tab() @@ -128,8 +126,8 @@ class DelugeGTK: "remove_torrent": self.remove_torrent_clicked, "menu_quit": self.quit, ## Edit Menu - "pref_clicked": self.show_pref_dialog, - "plugins_clicked": self.show_plugin_dialog, + "pref_clicked": self.show_preferences_dialog_clicked, + "plugins_clicked": self.show_plugin_dialog_clicked, ## View Menu "toolbar_toggle": self.toolbar_toggle, "infopane_toggle": self.infopane_toggle, @@ -162,13 +160,13 @@ class DelugeGTK: self.tray_glade = gtk.glade.XML(common.get_glade_file("tray_menu.glade"), domain='deluge') self.tray_menu = self.tray_glade.get_widget("tray_menu") self.tray_glade.signal_autoconnect({ - "quit": self.quit, - "plugins": self.show_plugin_dialog, - "preferences": self.show_pref_dialog, - "add_torrent": self.add_torrent_clicked, - "clear_finished": self.clear_finished, - "show_hide_window_toggled": self.show_hide_window_toggled - }) + "quit": self.quit, + "plugins": self.show_plugin_dialog_clicked, + "preferences": self.show_preferences_dialog_clicked, + "add_torrent": self.add_torrent_clicked, + "clear_finished": self.clear_finished, + "show_hide_window_toggled": self.show_hide_window_toggled + }) self.tray_glade.get_widget("download-limit-image").set_from_file(common.get_pixmap('downloading16.png')) self.tray_glade.get_widget("upload-limit-image").set_from_file(common.get_pixmap('seeding16.png')) @@ -351,12 +349,10 @@ class DelugeGTK: if comingnext == "mainwinshow": self.window.show() elif comingnext == "prefwinshow": - self.preferences_dialog.show() - self.apply_prefs() - self.config.save_to_file() + self.show_preferences_dialog() elif comingnext == "quitus": - self.window.hide() - self.shutdown() + self.window.hide() + self.shutdown() tray_lock.destroy() return True @@ -655,24 +651,23 @@ class DelugeGTK: def show_about_dialog(self, arg=None): dialogs.show_about_dialog() - def show_pref_dialog(self, arg=None): - if self.window.get_property("visible"): - # Only apply the prefs if the user pressed OK in the prefs dialog - if self.preferences_dialog.show() == 1: - self.apply_prefs() - self.config.save() + def show_preferences_dialog(self): + active_port = self.manager.get_state()['port'] + preferences_dialog = dialogs.PreferencesDlg(self.config, active_port) + # Only apply the prefs if the user pressed OK in the prefs dialog + if preferences_dialog.show() == 1: + self.apply_prefs() + self.config.save() + def show_preferences_dialog_clicked(self, arg=None): + if self.config.get("lock_tray") == True: + self.unlock_tray("prefwinshow") else: - if self.config.get("lock_tray") == True: - self.unlock_tray("prefwinshow") - else: - # Only apply the prefs if the user pressed OK in the prefs dialog - if self.preferences_dialog.show() == 1: - self.apply_prefs() - self.config.save() + self.show_preferences_dialog() - def show_plugin_dialog(self, arg=None): - self.plugin_dialog.show() + def show_plugin_dialog_clicked(self, arg=None): + plugin_dialog = dialogs.PluginDlg(self.plugins) + plugin_dialog.show() def apply_prefs(self): # Show tray icon if necessary