Plugins and preferences dialogs code clean up.

This commit is contained in:
Alex Dedul 2007-07-16 13:59:22 +00:00
parent 468667d068
commit 6d42f2234e
2 changed files with 33 additions and 39 deletions

View File

@ -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,10 +216,8 @@ 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()
for plugin in self.plugins.get_available_plugins():

View File

@ -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,
@ -163,8 +161,8 @@ class DelugeGTK:
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,
"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
@ -351,9 +349,7 @@ 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()
@ -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"):
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 self.preferences_dialog.show() == 1:
if preferences_dialog.show() == 1:
self.apply_prefs()
self.config.save()
else:
def show_preferences_dialog_clicked(self, arg=None):
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