From 3b7655824d07ab9bad0f2f9b5764d418071fdc59 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 24 Feb 2022 20:13:34 +0530 Subject: Chose the active tab in settings based on what is clicked --- desktop/onionshare/connection_tab.py | 2 +- desktop/onionshare/main_window.py | 35 ++++++----------------------- desktop/onionshare/resources/locale/en.json | 1 + desktop/onionshare/settings_parent_tab.py | 23 +++++++++---------- desktop/onionshare/tab_widget.py | 12 ++++++---- 5 files changed, 27 insertions(+), 46 deletions(-) diff --git a/desktop/onionshare/connection_tab.py b/desktop/onionshare/connection_tab.py index a3355db4..0b60a8b4 100644 --- a/desktop/onionshare/connection_tab.py +++ b/desktop/onionshare/connection_tab.py @@ -149,7 +149,7 @@ class AutoConnectTab(QtWidgets.QWidget): self.curr_settings.save() def open_tor_settings(self): - self.parent.open_settings_tab(from_autoconnect=True) + self.parent.open_settings_tab(from_autoconnect=True, active_tab='tor') def first_launch_widget_connect_clicked(self): """ diff --git a/desktop/onionshare/main_window.py b/desktop/onionshare/main_window.py index 0de47fe4..eef12028 100644 --- a/desktop/onionshare/main_window.py +++ b/desktop/onionshare/main_window.py @@ -106,24 +106,6 @@ class MainWindow(QtWidgets.QMainWindow): ) self.status_bar.addPermanentWidget(self.status_bar.server_status_indicator) - # Tor settings button - self.tor_settings_button = QtWidgets.QPushButton() - self.tor_settings_button.setDefault(False) - self.tor_settings_button.setFixedSize(40, 50) - self.tor_settings_button.setIcon( - QtGui.QIcon( - GuiCommon.get_resource_path( - "images/{}_tor_settings.png".format(self.common.gui.color_mode) - ) - ) - ) - self.tor_settings_button.clicked.connect(self.open_tor_settings) - self.tor_settings_button.setStyleSheet(self.common.gui.css["settings_button"]) - self.status_bar.addPermanentWidget(self.tor_settings_button) - - if os.environ.get("ONIONSHARE_HIDE_TOR_SETTINGS") == "1": - self.tor_settings_button.hide() - # Settings button self.settings_button = QtWidgets.QPushButton() self.settings_button.setDefault(False) @@ -240,25 +222,22 @@ class MainWindow(QtWidgets.QMainWindow): """ Open the TorSettingsTab """ - self.common.log("MainWindow", "open_tor_settings") - from_autoconnect = False - for tab_id in self.tabs.tabs: - if type(self.tabs.tabs[tab_id]) is AutoConnectTab: - from_autoconnect = True - break - self.tabs.open_settings_tab(from_autoconnect) + self._open_settings(active_tab='tor') def open_settings(self): """ - Open the SettingsTab + Open the general SettingsTab """ - self.common.log("MainWindow", "open_settings") + self._open_settings(active_tab='general') + + def _open_settings(self, active_tab): + self.common.log("MainWindow", f"open settings with active tab: {active_tab}") from_autoconnect = False for tab_id in self.tabs.tabs: if type(self.tabs.tabs[tab_id]) is AutoConnectTab: from_autoconnect = True break - self.tabs.open_settings_tab(from_autoconnect) + self.tabs.open_settings_tab(from_autoconnect, active_tab=active_tab) def settings_have_changed(self): self.common.log("OnionShareGui", "settings_have_changed") diff --git a/desktop/onionshare/resources/locale/en.json b/desktop/onionshare/resources/locale/en.json index 8b4a6301..bce88b2b 100644 --- a/desktop/onionshare/resources/locale/en.json +++ b/desktop/onionshare/resources/locale/en.json @@ -60,6 +60,7 @@ "gui_autoconnect_circumventing_censorship_got_bridges": "Got bridges! Trying to reconnect to Tor", "gui_autoconnect_could_not_connect_to_tor_api": "Could not connect to the Tor API. Make sure you are connected to the internet before trying again.", "gui_settings_window_title": "Settings", + "gui_general_settings_window_title": "Settings", "gui_settings_autoupdate_label": "Check for new version", "gui_settings_autoupdate_option": "Notify me when a new version is available", "gui_settings_autoupdate_timestamp": "Last checked: {}", diff --git a/desktop/onionshare/settings_parent_tab.py b/desktop/onionshare/settings_parent_tab.py index 722c518f..883ba922 100644 --- a/desktop/onionshare/settings_parent_tab.py +++ b/desktop/onionshare/settings_parent_tab.py @@ -20,7 +20,7 @@ class SettingsParentTab(QtWidgets.QTabWidget): bring_to_front = QtCore.Signal() close_this_tab = QtCore.Signal() - def __init__(self, common, tab_id, parent=None, active_tab='tor', from_autoconnect=False): + def __init__(self, common, tab_id, parent=None, active_tab='general', from_autoconnect=False): super(SettingsParentTab, self).__init__() self.parent = parent self.common = common @@ -29,38 +29,35 @@ class SettingsParentTab(QtWidgets.QTabWidget): # Keep track of tabs in a dictionary that maps tab_id to tab. # Each tab has a unique, auto-incremented id (tab_id). This is different than the # tab's index, which changes as tabs are re-arranged. - # self.tabs = {} + self.tabs = { + 'general': 0, + 'tor': 1, + } self.tab_id = tab_id - # self.current_tab_id = 0 # Each tab has a unique id - # self.tor_settings_tab = None + self.current_tab_id = self.tabs[active_tab] # Use a custom tab bar tab_bar = TabBar() self.setTabBar(tab_bar) - settings_tab = SettingsTab(self.common, 0, parent=self) + settings_tab = SettingsTab(self.common, self.tabs['general'], parent=self) self.tor_settings_tab = TorSettingsTab( self.common, - 1, + self.tabs['tor'], self.parent.are_tabs_active(), self.parent.status_bar, parent=self, from_autoconnect=from_autoconnect, ) + self.addTab(settings_tab, strings._("gui_general_settings_window_title")) self.addTab( self.tor_settings_tab, strings._("gui_tor_settings_window_title") ) - self.addTab(settings_tab, strings._("gui_settings_window_title")) # Set up the tab widget self.setMovable(False) self.setTabsClosable(False) self.setUsesScrollButtons(False) - # self.setDocumentMode(True) - # self.setStyleSheet(self.common.gui.css["tab_widget"]) - - # self.tabCloseRequested.connect(self.close_tab) - - # self.move_new_tab_button() + self.setCurrentIndex(self.current_tab_id) class TabBar(QtWidgets.QTabBar): """ diff --git a/desktop/onionshare/tab_widget.py b/desktop/onionshare/tab_widget.py index c1f63c3a..a9b34030 100644 --- a/desktop/onionshare/tab_widget.py +++ b/desktop/onionshare/tab_widget.py @@ -26,8 +26,6 @@ from . import strings from .tab import Tab from .threads import EventHandlerThread from .gui_common import GuiCommon -from .tor_settings_tab import TorSettingsTab -from .settings_tab import SettingsTab from .settings_parent_tab import SettingsParentTab from .connection_tab import AutoConnectTab @@ -228,7 +226,7 @@ class TabWidget(QtWidgets.QTabWidget): index = self.addTab(connection_tab, strings._("gui_autoconnect_start")) self.setCurrentIndex(index) - def open_settings_tab(self, from_autoconnect=False, active_tab='tor'): + def open_settings_tab(self, from_autoconnect=False, active_tab='general'): self.common.log("TabWidget", "open_settings_tab") # See if a settings tab is already open, and if so switch to it @@ -237,7 +235,13 @@ class TabWidget(QtWidgets.QTabWidget): self.setCurrentIndex(self.indexOf(self.tabs[tab_id])) return - settings_tab = SettingsParentTab(self.common, self.current_tab_id,active_tab=active_tab, parent=self, from_autoconnect=from_autoconnect) + settings_tab = SettingsParentTab( + self.common, + self.current_tab_id, + active_tab=active_tab, + parent=self, + from_autoconnect=from_autoconnect + ) settings_tab.close_this_tab.connect(self.close_settings_tab) self.tor_settings_tab = settings_tab.tor_settings_tab self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) -- cgit v1.2.3-54-g00ecf