From e215493ee849cf2f0a77e390b49a786d198a439a Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Fri, 27 Jun 2008 23:05:49 +0000 Subject: [PATCH] Fix #307 gui updates from Sadrul. --- deluge/ui/gtkui/menubar.py | 11 ++++++ deluge/ui/gtkui/options_tab.py | 2 ++ deluge/ui/gtkui/preferences.py | 65 +++++++++++++++++----------------- deluge/ui/gtkui/signals.py | 4 +++ deluge/ui/gtkui/torrentview.py | 4 ++- 5 files changed, 52 insertions(+), 34 deletions(-) diff --git a/deluge/ui/gtkui/menubar.py b/deluge/ui/gtkui/menubar.py index 8b8a49bb6..cdbce2573 100644 --- a/deluge/ui/gtkui/menubar.py +++ b/deluge/ui/gtkui/menubar.py @@ -201,6 +201,17 @@ class MenuBar(component.Component): self.window.main_glade.get_widget("separatormenuitem").hide() self.window.main_glade.get_widget("menuitem_quitdaemon").hide() + def update_menu(self): + selected = component.get('TorrentView').get_selected_torrents() + if not selected or len(selected) == 0: + # No torrent is selected. Disable the 'Torrents' menu + self.menu_torrent.set_sensitive(False) + return + + self.menu_torrent.set_sensitive(True) + # XXX: Should also update Pause/Resume/Remove menuitems. + # Any better way than duplicating toolbar.py:update_buttons in here? + def add_torrentmenu_separator(self): sep = gtk.SeparatorMenuItem() self.torrentmenu.append(sep) diff --git a/deluge/ui/gtkui/options_tab.py b/deluge/ui/gtkui/options_tab.py index d88ec240e..596a01a04 100644 --- a/deluge/ui/gtkui/options_tab.py +++ b/deluge/ui/gtkui/options_tab.py @@ -69,8 +69,10 @@ class OptionsTab(Tab): # Only use the first torrent in the list or return if None selected if len(torrent_id) != 0: torrent_id = torrent_id[0] + self._child_widget.set_sensitive(True) else: # No torrent is selected in the torrentview + self._child_widget.set_sensitive(False) return if torrent_id != self.prev_torrent_id: diff --git a/deluge/ui/gtkui/preferences.py b/deluge/ui/gtkui/preferences.py index b47f9067b..4715dc77e 100644 --- a/deluge/ui/gtkui/preferences.py +++ b/deluge/ui/gtkui/preferences.py @@ -599,39 +599,38 @@ class Preferences(component.Component): except: return - # Disable the focus dialog checkbox if the show dialog isn't active. - if widget == self.glade.get_widget("chk_show_dialog"): - self.glade.get_widget("chk_focus_dialog").set_sensitive(value) - - # Disable the port spinners if random ports is selected. - if widget == self.glade.get_widget("chk_random_port"): - log.debug("chk_random_port set to: %s", value) - self.glade.get_widget("spin_port_min").set_sensitive(not value) - self.glade.get_widget("spin_port_max").set_sensitive(not value) - - # Disable all the tray options if tray is not used. - if widget == self.glade.get_widget("chk_use_tray"): - self.glade.get_widget("chk_min_on_close").set_sensitive(value) - self.glade.get_widget("chk_start_in_tray").set_sensitive(value) - self.glade.get_widget("chk_lock_tray").set_sensitive(value) - if value == True: - lock = self.glade.get_widget("chk_lock_tray").get_active() - self.glade.get_widget("txt_tray_password").set_sensitive(lock) - self.glade.get_widget("password_label").set_sensitive(lock) - else: - self.glade.get_widget("txt_tray_password").set_sensitive(value) - self.glade.get_widget("password_label").set_sensitive(value) - - if widget == self.glade.get_widget("chk_lock_tray"): - self.glade.get_widget("txt_tray_password").set_sensitive(value) - self.glade.get_widget("password_label").set_sensitive(value) - - # Disable the file manager combo box if custom is selected. - if widget == self.glade.get_widget("radio_open_folder_custom"): - self.glade.get_widget("combo_file_manager").set_sensitive(not value) - self.glade.get_widget("txt_open_folder_location").set_sensitive( - value) - + dependents = { + "chk_show_dialog": {"chk_focus_dialog": True}, + "chk_random_port": {"spin_port_min": False, + "spin_port_max": False}, + "chk_use_tray": {"chk_min_on_close": True, + "chk_start_in_tray": True, + "chk_lock_tray": True}, + "chk_lock_tray": {"txt_tray_password": True, + "password_label": True}, + "radio_open_folder_custom": {"combo_file_manager": False, + "txt_open_folder_location": True}, + "chk_move_completed" : {"move_completed_path_button" : True}, + "chk_copy_torrent_file" : {"torrent_files_button" : True}, + "chk_autoadd" : {"folder_autoadd" : True}, + "chk_seed_ratio" : {"spin_share_ratio": True, + "chk_remove_ratio" : True} + } + + def update_dependent_widgets(name, value): + dependency = dependents[name] + for dep in dependency.keys(): + depwidget = self.glade.get_widget(dep) + sensitive = [not value, value][dependency[dep]] + depwidget.set_sensitive(sensitive) + if dep in dependents: + update_dependent_widgets(dep, depwidget.get_active() and sensitive) + + for key in dependents.keys(): + if widget != self.glade.get_widget(key): + continue + update_dependent_widgets(key, value) + def on_button_ok_clicked(self, data): log.debug("on_button_ok_clicked") self.set_config() diff --git a/deluge/ui/gtkui/signals.py b/deluge/ui/gtkui/signals.py index 0c06d14c9..517ea08a8 100644 --- a/deluge/ui/gtkui/signals.py +++ b/deluge/ui/gtkui/signals.py @@ -92,21 +92,25 @@ class Signals(component.Component): log.debug("torrent_paused signal received..") component.get("TorrentView").update() component.get("ToolBar").update_buttons() + component.get("MenuBar").update_menu() def torrent_resumed(self, torrent_id): log.debug("torrent_resumed signal received..") component.get("TorrentView").update() component.get("ToolBar").update_buttons() + component.get("MenuBar").update_menu() def torrent_all_paused(self): log.debug("torrent_all_paused signal received..") component.get("TorrentView").update() component.get("ToolBar").update_buttons() + component.get("MenuBar").update_menu() def torrent_all_resumed(self): log.debug("torrent_all_resumed signal received..") component.get("TorrentView").update() component.get("ToolBar").update_buttons() + component.get("MenuBar").update_menu() def config_value_changed(self, key, value): log.debug("config_value_changed signal received..") diff --git a/deluge/ui/gtkui/torrentview.py b/deluge/ui/gtkui/torrentview.py index 460b47c14..741fe25ea 100644 --- a/deluge/ui/gtkui/torrentview.py +++ b/deluge/ui/gtkui/torrentview.py @@ -330,6 +330,7 @@ class TorrentView(listview.ListView, component.Component): # Update the toolbar buttons just in case some state has changed component.get("ToolBar").update_buttons() + component.get("MenuBar").update_menu() def _on_get_torrents_status(self, status): """Callback function for get_torrents_status(). 'status' should be a @@ -431,4 +432,5 @@ class TorrentView(listview.ListView, component.Component): log.debug("on_selection_changed") component.get("TorrentDetails").update() component.get("ToolBar").update_buttons() - + component.get("MenuBar").update_menu() +