From 9f920f43532b009f8683cf7a929dd8be7269d983 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 2 Nov 2019 18:29:24 -0700 Subject: [PATCH] Move mode settings widget into the primary action layout, and tweak window size --- onionshare_gui/main_window.py | 2 +- onionshare_gui/tab/mode/__init__.py | 25 ++++++------------- .../tab/mode/receive_mode/__init__.py | 5 ++-- .../tab/mode/share_mode/__init__.py | 6 ++--- .../tab/mode/website_mode/__init__.py | 6 ++--- onionshare_gui/widgets.py | 11 ++++++++ 6 files changed, 28 insertions(+), 27 deletions(-) diff --git a/onionshare_gui/main_window.py b/onionshare_gui/main_window.py index c1bb57bf..e6f5606e 100644 --- a/onionshare_gui/main_window.py +++ b/onionshare_gui/main_window.py @@ -41,7 +41,7 @@ class MainWindow(QtWidgets.QMainWindow): self.common.log("MainWindow", "__init__") # Initialize the window - self.setMinimumWidth(820) + self.setMinimumWidth(1040) self.setMinimumHeight(700) self.setWindowTitle("OnionShare") self.setWindowIcon( diff --git a/onionshare_gui/tab/mode/__init__.py b/onionshare_gui/tab/mode/__init__.py index 3ed1172a..2c95d445 100644 --- a/onionshare_gui/tab/mode/__init__.py +++ b/onionshare_gui/tab/mode/__init__.py @@ -86,12 +86,7 @@ class Mode(QtWidgets.QWidget): self.starting_server_early.connect(self.start_server_early) self.starting_server_error.connect(self.start_server_error) - # Header - # Note: It's up to the downstream Mode to add this to its layout - self.header_label = QtWidgets.QLabel() - self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"]) - self.header_label.setAlignment(QtCore.Qt.AlignHCenter) - + # Mode settings widget self.mode_settings_widget = ModeSettingsWidget( self.common, self.tab.tab_id, self.tab.mode_settings ) @@ -100,26 +95,20 @@ class Mode(QtWidgets.QWidget): self.server_status.update ) - header_layout = QtWidgets.QVBoxLayout() - header_layout.setContentsMargins(0, 0, 0, 0) - header_layout.addWidget(self.header_label) - header_layout.addWidget(self.mode_settings_widget) - - self.header = QtWidgets.QWidget() - self.header.setLayout(header_layout) + # Header + # Note: It's up to the downstream Mode to add this to its layout + self.header_label = QtWidgets.QLabel() + self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"]) + self.header_label.setAlignment(QtCore.Qt.AlignHCenter) # Primary action # Note: It's up to the downstream Mode to add this to its layout self.primary_action_layout = QtWidgets.QVBoxLayout() + self.primary_action_layout.addWidget(self.mode_settings_widget) self.primary_action_layout.addWidget(self.server_status) self.primary_action = QtWidgets.QWidget() self.primary_action.setLayout(self.primary_action_layout) - # Hack to allow a minimum width on the main layout - # Note: It's up to the downstream Mode to add this to its layout - self.min_width_widget = QtWidgets.QWidget() - self.min_width_widget.setMinimumWidth(600) - def init(self): """ Add custom initialization here. diff --git a/onionshare_gui/tab/mode/receive_mode/__init__.py b/onionshare_gui/tab/mode/receive_mode/__init__.py index 0c6ff031..f7bcbd1c 100644 --- a/onionshare_gui/tab/mode/receive_mode/__init__.py +++ b/onionshare_gui/tab/mode/receive_mode/__init__.py @@ -24,6 +24,7 @@ from onionshare.web import Web from ..history import History, ToggleHistory, ReceiveHistoryItem from .. import Mode +from ....widgets import MinimumWidthWidget class ReceiveMode(Mode): @@ -111,7 +112,7 @@ class ReceiveMode(Mode): self.main_layout.addWidget(receive_warning) self.main_layout.addWidget(self.primary_action) self.main_layout.addStretch() - self.main_layout.addWidget(self.min_width_widget) + self.main_layout.addWidget(MinimumWidthWidget(700)) # Column layout self.column_layout = QtWidgets.QHBoxLayout() @@ -120,7 +121,7 @@ class ReceiveMode(Mode): # Wrapper layout self.wrapper_layout = QtWidgets.QVBoxLayout() - self.wrapper_layout.addWidget(self.header) + self.wrapper_layout.addWidget(self.header_label) self.wrapper_layout.addLayout(self.column_layout) self.setLayout(self.wrapper_layout) diff --git a/onionshare_gui/tab/mode/share_mode/__init__.py b/onionshare_gui/tab/mode/share_mode/__init__.py index 42478be4..7d195e42 100644 --- a/onionshare_gui/tab/mode/share_mode/__init__.py +++ b/onionshare_gui/tab/mode/share_mode/__init__.py @@ -29,7 +29,7 @@ from ..file_selection import FileSelection from .threads import CompressThread from .. import Mode from ..history import History, ToggleHistory, ShareHistoryItem -from ....widgets import Alert +from ....widgets import Alert, MinimumWidthWidget class ShareMode(Mode): @@ -137,7 +137,7 @@ class ShareMode(Mode): self.main_layout.addLayout(top_bar_layout) self.main_layout.addLayout(self.file_selection) self.main_layout.addWidget(self.primary_action) - self.main_layout.addWidget(self.min_width_widget) + self.main_layout.addWidget(MinimumWidthWidget(700)) # Column layout self.column_layout = QtWidgets.QHBoxLayout() @@ -146,7 +146,7 @@ class ShareMode(Mode): # Wrapper layout self.wrapper_layout = QtWidgets.QVBoxLayout() - self.wrapper_layout.addWidget(self.header) + self.wrapper_layout.addWidget(self.header_label) self.wrapper_layout.addLayout(self.column_layout) self.setLayout(self.wrapper_layout) diff --git a/onionshare_gui/tab/mode/website_mode/__init__.py b/onionshare_gui/tab/mode/website_mode/__init__.py index 51ee17ef..4a099488 100644 --- a/onionshare_gui/tab/mode/website_mode/__init__.py +++ b/onionshare_gui/tab/mode/website_mode/__init__.py @@ -31,7 +31,7 @@ from onionshare.web import Web from ..file_selection import FileSelection from .. import Mode from ..history import History, ToggleHistory -from ....widgets import Alert +from ....widgets import Alert, MinimumWidthWidget class WebsiteMode(Mode): @@ -137,7 +137,7 @@ class WebsiteMode(Mode): self.main_layout.addLayout(top_bar_layout) self.main_layout.addLayout(self.file_selection) self.main_layout.addWidget(self.primary_action) - self.main_layout.addWidget(self.min_width_widget) + self.main_layout.addWidget(MinimumWidthWidget(700)) # Column layout self.column_layout = QtWidgets.QHBoxLayout() @@ -146,7 +146,7 @@ class WebsiteMode(Mode): # Wrapper layout self.wrapper_layout = QtWidgets.QVBoxLayout() - self.wrapper_layout.addWidget(self.header) + self.wrapper_layout.addWidget(self.header_label) self.wrapper_layout.addLayout(self.column_layout) self.setLayout(self.wrapper_layout) diff --git a/onionshare_gui/widgets.py b/onionshare_gui/widgets.py index d16485fe..74ef2c88 100644 --- a/onionshare_gui/widgets.py +++ b/onionshare_gui/widgets.py @@ -79,3 +79,14 @@ class AddFileDialog(QtWidgets.QFileDialog): def accept(self): self.common.log("AddFileDialog", "accept") QtWidgets.QDialog.accept(self) + + +class MinimumWidthWidget(QtWidgets.QWidget): + """ + An empty widget with a minimum width, just to force layouts to behave + """ + + def __init__(self, width): + super(MinimumWidthWidget, self).__init__() + self.setMinimumWidth(width) +