From 681402dfa9f88bfce12004db3f8a0b7b7a7baa4d Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 24 Feb 2022 18:04:26 +0530 Subject: [PATCH 1/6] Moving tor settings and app settings as subtabs under a parent settings tab --- desktop/onionshare/main_window.py | 7 ++- desktop/onionshare/settings_parent_tab.py | 72 +++++++++++++++++++++++ desktop/onionshare/tab_widget.py | 8 ++- 3 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 desktop/onionshare/settings_parent_tab.py diff --git a/desktop/onionshare/main_window.py b/desktop/onionshare/main_window.py index 9c6f455f..61119683 100644 --- a/desktop/onionshare/main_window.py +++ b/desktop/onionshare/main_window.py @@ -253,7 +253,12 @@ class MainWindow(QtWidgets.QMainWindow): Open the SettingsTab """ self.common.log("MainWindow", "open_settings") - self.tabs.open_settings_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) def settings_have_changed(self): self.common.log("OnionShareGui", "settings_have_changed") diff --git a/desktop/onionshare/settings_parent_tab.py b/desktop/onionshare/settings_parent_tab.py new file mode 100644 index 00000000..2e372983 --- /dev/null +++ b/desktop/onionshare/settings_parent_tab.py @@ -0,0 +1,72 @@ +from PySide2 import QtCore, QtWidgets, QtGui + +from onionshare_cli.mode_settings import ModeSettings + +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 .connection_tab import AutoConnectTab + + +class SettingsParentTab(QtWidgets.QTabWidget): + """ + The settings tab widget containing the tor settings + and app settings subtabs + """ + + bring_to_front = QtCore.Signal() + close_this_tab = QtCore.Signal() + + def __init__(self, common, tab_id, parent=None, active_tab='tor', from_autoconnect=False): + super(SettingsParentTab, self).__init__() + self.parent = parent + self.common = common + self.common.log("SettingsParentTab", "__init__") + + # 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.tab_id = tab_id + # self.current_tab_id = 0 # Each tab has a unique id + # self.tor_settings_tab = None + + # Use a custom tab bar + tab_bar = TabBar() + self.setTabBar(tab_bar) + settings_tab = SettingsTab(self.common, 0) + tor_settings_tab = TorSettingsTab( + self.common, + 1, + self.parent.are_tabs_active(), + self.parent.status_bar, + from_autoconnect, + ) + self.addTab( + 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() + +class TabBar(QtWidgets.QTabBar): + """ + A custom tab bar + """ + + move_new_tab_button = QtCore.Signal() + + def __init__(self): + super(TabBar, self).__init__() diff --git a/desktop/onionshare/tab_widget.py b/desktop/onionshare/tab_widget.py index 29f443ac..05285a61 100644 --- a/desktop/onionshare/tab_widget.py +++ b/desktop/onionshare/tab_widget.py @@ -28,6 +28,7 @@ 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 @@ -98,6 +99,7 @@ class TabWidget(QtWidgets.QTabWidget): for tab_id in self.tabs: if not ( type(self.tabs[tab_id]) is SettingsTab + or type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is TorSettingsTab or type(self.tabs[tab_id]) is AutoConnectTab ): @@ -139,6 +141,7 @@ class TabWidget(QtWidgets.QTabWidget): # If it's Settings or Tor Settings, ignore if ( type(self.tabs[tab_id]) is SettingsTab + or type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is TorSettingsTab or type(self.tabs[tab_id]) is AutoConnectTab ): @@ -238,7 +241,7 @@ class TabWidget(QtWidgets.QTabWidget): self.setCurrentIndex(self.indexOf(self.tabs[tab_id])) return - settings_tab = SettingsTab(self.common, self.current_tab_id) + settings_tab = SettingsParentTab(self.common, self.current_tab_id, parent=self) settings_tab.close_this_tab.connect(self.close_settings_tab) self.tabs[self.current_tab_id] = settings_tab self.current_tab_id += 1 @@ -315,6 +318,7 @@ class TabWidget(QtWidgets.QTabWidget): for tab_id in self.tabs: if not ( type(self.tabs[tab_id]) is SettingsTab + or type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is TorSettingsTab or type(self.tabs[tab_id]) is AutoConnectTab ): @@ -333,6 +337,7 @@ class TabWidget(QtWidgets.QTabWidget): if ( type(self.tabs[tab_id]) is SettingsTab + or type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is TorSettingsTab or type(self.tabs[tab_id]) is AutoConnectTab ): @@ -425,6 +430,7 @@ class TabWidget(QtWidgets.QTabWidget): for tab_id in self.tabs: if not ( type(self.tabs[tab_id]) is SettingsTab + or type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is TorSettingsTab or type(self.tabs[tab_id]) is AutoConnectTab ): From 631478fc3ecbcb2dde135e2c36bdc9df77e682b9 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 24 Feb 2022 18:14:06 +0530 Subject: [PATCH 2/6] Fix the settings tab calls --- desktop/onionshare/connection_tab.py | 2 +- desktop/onionshare/main_window.py | 2 +- desktop/onionshare/settings_parent_tab.py | 4 +- desktop/onionshare/tab_widget.py | 70 ++++++++++++----------- 4 files changed, 40 insertions(+), 38 deletions(-) diff --git a/desktop/onionshare/connection_tab.py b/desktop/onionshare/connection_tab.py index e67ca483..a3355db4 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_tor_settings_tab(from_autoconnect=True) + self.parent.open_settings_tab(from_autoconnect=True) def first_launch_widget_connect_clicked(self): """ diff --git a/desktop/onionshare/main_window.py b/desktop/onionshare/main_window.py index 61119683..0de47fe4 100644 --- a/desktop/onionshare/main_window.py +++ b/desktop/onionshare/main_window.py @@ -246,7 +246,7 @@ class MainWindow(QtWidgets.QMainWindow): if type(self.tabs.tabs[tab_id]) is AutoConnectTab: from_autoconnect = True break - self.tabs.open_tor_settings_tab(from_autoconnect) + self.tabs.open_settings_tab(from_autoconnect) def open_settings(self): """ diff --git a/desktop/onionshare/settings_parent_tab.py b/desktop/onionshare/settings_parent_tab.py index 2e372983..0c2f548f 100644 --- a/desktop/onionshare/settings_parent_tab.py +++ b/desktop/onionshare/settings_parent_tab.py @@ -38,7 +38,7 @@ class SettingsParentTab(QtWidgets.QTabWidget): tab_bar = TabBar() self.setTabBar(tab_bar) settings_tab = SettingsTab(self.common, 0) - tor_settings_tab = TorSettingsTab( + self.tor_settings_tab = TorSettingsTab( self.common, 1, self.parent.are_tabs_active(), @@ -46,7 +46,7 @@ class SettingsParentTab(QtWidgets.QTabWidget): from_autoconnect, ) self.addTab( - tor_settings_tab, strings._("gui_tor_settings_window_title") + self.tor_settings_tab, strings._("gui_tor_settings_window_title") ) self.addTab(settings_tab, strings._("gui_settings_window_title")) diff --git a/desktop/onionshare/tab_widget.py b/desktop/onionshare/tab_widget.py index 05285a61..27bbfdb2 100644 --- a/desktop/onionshare/tab_widget.py +++ b/desktop/onionshare/tab_widget.py @@ -232,47 +232,49 @@ class TabWidget(QtWidgets.QTabWidget): index = self.addTab(connection_tab, strings._("gui_autoconnect_start")) self.setCurrentIndex(index) - def open_settings_tab(self): + def open_settings_tab(self, from_autoconnect=False, active_tab='tor'): self.common.log("TabWidget", "open_settings_tab") # See if a settings tab is already open, and if so switch to it for tab_id in self.tabs: - if type(self.tabs[tab_id]) is SettingsTab: + if type(self.tabs[tab_id]) is SettingsParentTab: self.setCurrentIndex(self.indexOf(self.tabs[tab_id])) return - settings_tab = SettingsParentTab(self.common, self.current_tab_id, parent=self) + 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) + settings_tab.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) + settings_tab.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected) self.tabs[self.current_tab_id] = settings_tab self.current_tab_id += 1 index = self.addTab(settings_tab, strings._("gui_settings_window_title")) self.setCurrentIndex(index) - def open_tor_settings_tab(self, from_autoconnect=False): - self.common.log("TabWidget", "open_tor_settings_tab") + # def open_tor_settings_tab(self, from_autoconnect=False): + # self.common.log("TabWidget", "open_tor_settings_tab") - # See if a settings tab is already open, and if so switch to it - for tab_id in self.tabs: - if type(self.tabs[tab_id]) is TorSettingsTab: - self.setCurrentIndex(self.indexOf(self.tabs[tab_id])) - return + # # See if a settings tab is already open, and if so switch to it + # for tab_id in self.tabs: + # if type(self.tabs[tab_id]) is TorSettingsTab: + # self.setCurrentIndex(self.indexOf(self.tabs[tab_id])) + # return - self.tor_settings_tab = TorSettingsTab( - self.common, - self.current_tab_id, - self.are_tabs_active(), - self.status_bar, - from_autoconnect, - ) - self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab) - self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) - self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected) - self.tabs[self.current_tab_id] = self.tor_settings_tab - self.current_tab_id += 1 - index = self.addTab( - self.tor_settings_tab, strings._("gui_tor_settings_window_title") - ) - self.setCurrentIndex(index) + # self.tor_settings_tab = TorSettingsTab( + # self.common, + # self.current_tab_id, + # self.are_tabs_active(), + # self.status_bar, + # from_autoconnect, + # ) + # self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab) + # self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) + # self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected) + # self.tabs[self.current_tab_id] = self.tor_settings_tab + # self.current_tab_id += 1 + # index = self.addTab( + # self.tor_settings_tab, strings._("gui_tor_settings_window_title") + # ) + # self.setCurrentIndex(index) def change_title(self, tab_id, title): shortened_title = title @@ -384,15 +386,15 @@ class TabWidget(QtWidgets.QTabWidget): self.close_tab(index) return - def close_settings_tab(self): - self.common.log("TabWidget", "close_settings_tab") - for tab_id in self.tabs: - if type(self.tabs[tab_id]) is SettingsTab: - index = self.indexOf(self.tabs[tab_id]) - self.close_tab(index) - return + # def close_settings_tab(self): + # self.common.log("TabWidget", "close_settings_tab") + # for tab_id in self.tabs: + # if type(self.tabs[tab_id]) is SettingsTab: + # index = self.indexOf(self.tabs[tab_id]) + # self.close_tab(index) + # return - def close_tor_settings_tab(self): + def close_settings_tab(self): self.common.log("TabWidget", "close_tor_settings_tab") for tab_id in list(self.tabs): if type(self.tabs[tab_id]) is AutoConnectTab: From 42aa4e99521aee70ec3c5ce60aa842496f4d5276 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 24 Feb 2022 18:37:59 +0530 Subject: [PATCH 3/6] Cleanup code --- desktop/onionshare/settings_parent_tab.py | 5 +- desktop/onionshare/settings_tab.py | 7 +- desktop/onionshare/tab_widget.py | 103 ++++++---------------- desktop/onionshare/tor_settings_tab.py | 9 +- 4 files changed, 38 insertions(+), 86 deletions(-) diff --git a/desktop/onionshare/settings_parent_tab.py b/desktop/onionshare/settings_parent_tab.py index 0c2f548f..722c518f 100644 --- a/desktop/onionshare/settings_parent_tab.py +++ b/desktop/onionshare/settings_parent_tab.py @@ -37,13 +37,14 @@ class SettingsParentTab(QtWidgets.QTabWidget): # Use a custom tab bar tab_bar = TabBar() self.setTabBar(tab_bar) - settings_tab = SettingsTab(self.common, 0) + settings_tab = SettingsTab(self.common, 0, parent=self) self.tor_settings_tab = TorSettingsTab( self.common, 1, self.parent.are_tabs_active(), self.parent.status_bar, - from_autoconnect, + parent=self, + from_autoconnect=from_autoconnect, ) self.addTab( self.tor_settings_tab, strings._("gui_tor_settings_window_title") diff --git a/desktop/onionshare/settings_tab.py b/desktop/onionshare/settings_tab.py index 58843a0d..cf2261b6 100644 --- a/desktop/onionshare/settings_tab.py +++ b/desktop/onionshare/settings_tab.py @@ -33,9 +33,7 @@ class SettingsTab(QtWidgets.QWidget): Settings dialog. """ - close_this_tab = QtCore.Signal() - - def __init__(self, common, tab_id): + def __init__(self, common, tab_id, parent=None): super(SettingsTab, self).__init__() self.common = common @@ -43,6 +41,7 @@ class SettingsTab(QtWidgets.QWidget): self.system = platform.system() self.tab_id = tab_id + self.parent = parent # Automatic updates options @@ -283,7 +282,7 @@ class SettingsTab(QtWidgets.QWidget): # Save the new settings settings.save() - self.close_this_tab.emit() + self.parent.close_this_tab.emit() def help_clicked(self): """ diff --git a/desktop/onionshare/tab_widget.py b/desktop/onionshare/tab_widget.py index 27bbfdb2..c1f63c3a 100644 --- a/desktop/onionshare/tab_widget.py +++ b/desktop/onionshare/tab_widget.py @@ -98,9 +98,7 @@ class TabWidget(QtWidgets.QTabWidget): # Clean up each tab for tab_id in self.tabs: if not ( - type(self.tabs[tab_id]) is SettingsTab - or type(self.tabs[tab_id]) is SettingsParentTab - or type(self.tabs[tab_id]) is TorSettingsTab + type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is AutoConnectTab ): self.tabs[tab_id].cleanup() @@ -140,9 +138,7 @@ class TabWidget(QtWidgets.QTabWidget): # If it's Settings or Tor Settings, ignore if ( - type(self.tabs[tab_id]) is SettingsTab - or type(self.tabs[tab_id]) is SettingsParentTab - or type(self.tabs[tab_id]) is TorSettingsTab + type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is AutoConnectTab ): # Blank the server status indicator @@ -243,39 +239,14 @@ class TabWidget(QtWidgets.QTabWidget): 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) - settings_tab.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) - settings_tab.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected) + self.tor_settings_tab = settings_tab.tor_settings_tab + self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) + self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected) self.tabs[self.current_tab_id] = settings_tab self.current_tab_id += 1 index = self.addTab(settings_tab, strings._("gui_settings_window_title")) self.setCurrentIndex(index) - # def open_tor_settings_tab(self, from_autoconnect=False): - # self.common.log("TabWidget", "open_tor_settings_tab") - - # # See if a settings tab is already open, and if so switch to it - # for tab_id in self.tabs: - # if type(self.tabs[tab_id]) is TorSettingsTab: - # self.setCurrentIndex(self.indexOf(self.tabs[tab_id])) - # return - - # self.tor_settings_tab = TorSettingsTab( - # self.common, - # self.current_tab_id, - # self.are_tabs_active(), - # self.status_bar, - # from_autoconnect, - # ) - # self.tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab) - # self.tor_settings_tab.tor_is_connected.connect(self.tor_is_connected) - # self.tor_settings_tab.tor_is_disconnected.connect(self.tor_is_disconnected) - # self.tabs[self.current_tab_id] = self.tor_settings_tab - # self.current_tab_id += 1 - # index = self.addTab( - # self.tor_settings_tab, strings._("gui_tor_settings_window_title") - # ) - # self.setCurrentIndex(index) - def change_title(self, tab_id, title): shortened_title = title if len(shortened_title) > 11: @@ -319,9 +290,7 @@ class TabWidget(QtWidgets.QTabWidget): persistent_tabs = [] for tab_id in self.tabs: if not ( - type(self.tabs[tab_id]) is SettingsTab - or type(self.tabs[tab_id]) is SettingsParentTab - or type(self.tabs[tab_id]) is TorSettingsTab + type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is AutoConnectTab ): tab = self.widget(self.indexOf(self.tabs[tab_id])) @@ -338,14 +307,12 @@ class TabWidget(QtWidgets.QTabWidget): tab_id = tab.tab_id if ( - type(self.tabs[tab_id]) is SettingsTab - or type(self.tabs[tab_id]) is SettingsParentTab - or type(self.tabs[tab_id]) is TorSettingsTab + type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is AutoConnectTab ): self.common.log("TabWidget", "closing a settings tab") - if type(self.tabs[tab_id]) is TorSettingsTab: + if type(self.tabs[tab_id]) is SettingsParentTab: self.tor_settings_tab = None # Remove the tab @@ -386,16 +353,8 @@ class TabWidget(QtWidgets.QTabWidget): self.close_tab(index) return - # def close_settings_tab(self): - # self.common.log("TabWidget", "close_settings_tab") - # for tab_id in self.tabs: - # if type(self.tabs[tab_id]) is SettingsTab: - # index = self.indexOf(self.tabs[tab_id]) - # self.close_tab(index) - # return - def close_settings_tab(self): - self.common.log("TabWidget", "close_tor_settings_tab") + self.common.log("TabWidget", "close_settings_tab") for tab_id in list(self.tabs): if type(self.tabs[tab_id]) is AutoConnectTab: # If we are being returned to the AutoConnectTab, but @@ -405,7 +364,7 @@ class TabWidget(QtWidgets.QTabWidget): if self.common.gui.onion.is_authenticated(): self.common.log( "TabWidget", - "close_tor_settings_tab", + "close_settings_tab", "Tor is connected and we can auto-connect, so closing the tab", ) index = self.indexOf(self.tabs[tab_id]) @@ -414,13 +373,13 @@ class TabWidget(QtWidgets.QTabWidget): self.tabs[tab_id].reload_settings() self.common.log( "TabWidget", - "close_tor_settings_tab", + "close_settings_tab", "Reloading settings in case they changed in the TorSettingsTab. Not auto-connecting", ) break # List of indices may have changed due to the above, so we loop over it again as another copy for tab_id in list(self.tabs): - if type(self.tabs[tab_id]) is TorSettingsTab: + if type(self.tabs[tab_id]) is SettingsParentTab: index = self.indexOf(self.tabs[tab_id]) self.close_tab(index) return @@ -431,9 +390,7 @@ class TabWidget(QtWidgets.QTabWidget): """ for tab_id in self.tabs: if not ( - type(self.tabs[tab_id]) is SettingsTab - or type(self.tabs[tab_id]) is SettingsParentTab - or type(self.tabs[tab_id]) is TorSettingsTab + type(self.tabs[tab_id]) is SettingsParentTab or type(self.tabs[tab_id]) is AutoConnectTab ): mode = self.tabs[tab_id].get_mode() @@ -456,29 +413,23 @@ class TabWidget(QtWidgets.QTabWidget): def tor_is_connected(self): for tab_id in self.tabs: - if type(self.tabs[tab_id]) is SettingsTab: - self.tabs[tab_id].tor_is_connected() - else: - if not ( - type(self.tabs[tab_id]) is TorSettingsTab - or type(self.tabs[tab_id]) is AutoConnectTab - ): - mode = self.tabs[tab_id].get_mode() - if mode: - mode.tor_connection_started() + if not ( + type(self.tabs[tab_id]) is SettingsParentTab + or type(self.tabs[tab_id]) is AutoConnectTab + ): + mode = self.tabs[tab_id].get_mode() + if mode: + mode.tor_connection_started() def tor_is_disconnected(self): for tab_id in self.tabs: - if type(self.tabs[tab_id]) is SettingsTab: - self.tabs[tab_id].tor_is_disconnected() - else: - if not ( - type(self.tabs[tab_id]) is TorSettingsTab - or type(self.tabs[tab_id]) is AutoConnectTab - ): - mode = self.tabs[tab_id].get_mode() - if mode: - mode.tor_connection_stopped() + if not ( + type(self.tabs[tab_id]) is SettingsParentTab + or type(self.tabs[tab_id]) is AutoConnectTab + ): + mode = self.tabs[tab_id].get_mode() + if mode: + mode.tor_connection_stopped() class TabBar(QtWidgets.QTabBar): diff --git a/desktop/onionshare/tor_settings_tab.py b/desktop/onionshare/tor_settings_tab.py index 9c9ea593..347dbcbf 100644 --- a/desktop/onionshare/tor_settings_tab.py +++ b/desktop/onionshare/tor_settings_tab.py @@ -43,7 +43,7 @@ class TorSettingsTab(QtWidgets.QWidget): tor_is_disconnected = QtCore.Signal() def __init__( - self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False + self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False, parent=None ): super(TorSettingsTab, self).__init__() @@ -55,6 +55,7 @@ class TorSettingsTab(QtWidgets.QWidget): self.system = platform.system() self.tab_id = tab_id + self.parent = parent self.from_autoconnect = from_autoconnect # Connection type: either automatic, control port, or socket file @@ -746,9 +747,9 @@ class TorSettingsTab(QtWidgets.QWidget): self.tor_con.show() self.tor_con.start(settings) else: - self.close_this_tab.emit() + self.parent.close_this_tab.emit() else: - self.close_this_tab.emit() + self.parent.close_this_tab.emit() def tor_con_success(self): """ @@ -779,7 +780,7 @@ class TorSettingsTab(QtWidgets.QWidget): # Tell the tabs that Tor is connected self.tor_is_connected.emit() # Close the tab - self.close_this_tab.emit() + self.parent.close_this_tab.emit() self.tor_con_type = None From f4f7cf993c683612b3c6f834cf7bee11ec51a1af Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 24 Feb 2022 20:13:34 +0530 Subject: [PATCH 4/6] 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) From 23cec0cdd11e584492aeb9a1052e8dfc6e96a7bd Mon Sep 17 00:00:00 2001 From: Saptak S Date: Thu, 24 Feb 2022 21:02:08 +0530 Subject: [PATCH 5/6] Adds styles for the tab bar --- desktop/onionshare/gui_common.py | 9 +++++++++ desktop/onionshare/resources/locale/en.json | 2 +- desktop/onionshare/settings_parent_tab.py | 6 ++++-- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/desktop/onionshare/gui_common.py b/desktop/onionshare/gui_common.py index 4cf0f010..c717fd22 100644 --- a/desktop/onionshare/gui_common.py +++ b/desktop/onionshare/gui_common.py @@ -121,6 +121,15 @@ class GuiCommon: font-weight: bold; font-size: 20px; }""", + "settings_subtab_bar": """ + QTabBar::tab { + background: transparent; + } + QTabBar::tab:selected { + border-bottom: 3px solid; + border-color: #4E064F; + padding: 3px + }""", "mode_new_tab_button": """ QPushButton { font-weight: bold; diff --git a/desktop/onionshare/resources/locale/en.json b/desktop/onionshare/resources/locale/en.json index bce88b2b..9627b4d9 100644 --- a/desktop/onionshare/resources/locale/en.json +++ b/desktop/onionshare/resources/locale/en.json @@ -60,7 +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_general_settings_window_title": "General", "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 883ba922..030cacc0 100644 --- a/desktop/onionshare/settings_parent_tab.py +++ b/desktop/onionshare/settings_parent_tab.py @@ -37,7 +37,7 @@ class SettingsParentTab(QtWidgets.QTabWidget): self.current_tab_id = self.tabs[active_tab] # Use a custom tab bar - tab_bar = TabBar() + tab_bar = TabBar(self.common) self.setTabBar(tab_bar) settings_tab = SettingsTab(self.common, self.tabs['general'], parent=self) self.tor_settings_tab = TorSettingsTab( @@ -66,5 +66,7 @@ class TabBar(QtWidgets.QTabBar): move_new_tab_button = QtCore.Signal() - def __init__(self): + def __init__(self, common): super(TabBar, self).__init__() + self.setStyleSheet(common.gui.css['settings_subtab_bar']) + From a6550d2196ac471e641f863b817115f8cff44253 Mon Sep 17 00:00:00 2001 From: Saptak S Date: Mon, 28 Feb 2022 12:34:01 +0530 Subject: [PATCH 6/6] Replace double quotes with single quotes --- desktop/onionshare/connection_tab.py | 2 +- desktop/onionshare/main_window.py | 4 ++-- desktop/onionshare/settings_parent_tab.py | 20 ++++++++++---------- desktop/onionshare/tab_widget.py | 4 ++-- desktop/onionshare/tor_settings_tab.py | 8 +++++++- 5 files changed, 22 insertions(+), 16 deletions(-) diff --git a/desktop/onionshare/connection_tab.py b/desktop/onionshare/connection_tab.py index 0b60a8b4..2bb2a79c 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, active_tab='tor') + 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 eef12028..b2bd01e9 100644 --- a/desktop/onionshare/main_window.py +++ b/desktop/onionshare/main_window.py @@ -222,13 +222,13 @@ class MainWindow(QtWidgets.QMainWindow): """ Open the TorSettingsTab """ - self._open_settings(active_tab='tor') + self._open_settings(active_tab="tor") def open_settings(self): """ Open the general SettingsTab """ - self._open_settings(active_tab='general') + self._open_settings(active_tab="general") def _open_settings(self, active_tab): self.common.log("MainWindow", f"open settings with active tab: {active_tab}") diff --git a/desktop/onionshare/settings_parent_tab.py b/desktop/onionshare/settings_parent_tab.py index 030cacc0..2ade0e05 100644 --- a/desktop/onionshare/settings_parent_tab.py +++ b/desktop/onionshare/settings_parent_tab.py @@ -20,7 +20,9 @@ class SettingsParentTab(QtWidgets.QTabWidget): bring_to_front = QtCore.Signal() close_this_tab = QtCore.Signal() - def __init__(self, common, tab_id, parent=None, active_tab='general', 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 @@ -30,8 +32,8 @@ class SettingsParentTab(QtWidgets.QTabWidget): # 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 = { - 'general': 0, - 'tor': 1, + "general": 0, + "tor": 1, } self.tab_id = tab_id self.current_tab_id = self.tabs[active_tab] @@ -39,19 +41,17 @@ class SettingsParentTab(QtWidgets.QTabWidget): # Use a custom tab bar tab_bar = TabBar(self.common) self.setTabBar(tab_bar) - settings_tab = SettingsTab(self.common, self.tabs['general'], parent=self) + settings_tab = SettingsTab(self.common, self.tabs["general"], parent=self) self.tor_settings_tab = TorSettingsTab( self.common, - self.tabs['tor'], + 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(self.tor_settings_tab, strings._("gui_tor_settings_window_title")) # Set up the tab widget self.setMovable(False) @@ -59,6 +59,7 @@ class SettingsParentTab(QtWidgets.QTabWidget): self.setUsesScrollButtons(False) self.setCurrentIndex(self.current_tab_id) + class TabBar(QtWidgets.QTabBar): """ A custom tab bar @@ -68,5 +69,4 @@ class TabBar(QtWidgets.QTabBar): def __init__(self, common): super(TabBar, self).__init__() - self.setStyleSheet(common.gui.css['settings_subtab_bar']) - + self.setStyleSheet(common.gui.css["settings_subtab_bar"]) diff --git a/desktop/onionshare/tab_widget.py b/desktop/onionshare/tab_widget.py index a9b34030..0a59c20d 100644 --- a/desktop/onionshare/tab_widget.py +++ b/desktop/onionshare/tab_widget.py @@ -226,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='general'): + 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 @@ -240,7 +240,7 @@ class TabWidget(QtWidgets.QTabWidget): self.current_tab_id, active_tab=active_tab, parent=self, - from_autoconnect=from_autoconnect + from_autoconnect=from_autoconnect, ) settings_tab.close_this_tab.connect(self.close_settings_tab) self.tor_settings_tab = settings_tab.tor_settings_tab diff --git a/desktop/onionshare/tor_settings_tab.py b/desktop/onionshare/tor_settings_tab.py index 347dbcbf..0e72c3b8 100644 --- a/desktop/onionshare/tor_settings_tab.py +++ b/desktop/onionshare/tor_settings_tab.py @@ -43,7 +43,13 @@ class TorSettingsTab(QtWidgets.QWidget): tor_is_disconnected = QtCore.Signal() def __init__( - self, common, tab_id, are_tabs_active, status_bar, from_autoconnect=False, parent=None + self, + common, + tab_id, + are_tabs_active, + status_bar, + from_autoconnect=False, + parent=None, ): super(TorSettingsTab, self).__init__()