From e29bb99f16f69be68dbee1667400a3a99451bd56 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Fri, 28 Sep 2018 15:05:43 -0700 Subject: [PATCH] OnionShareGui.adjust_size now recursively runs adjustSize() on all widgets --- onionshare_gui/onionshare_gui.py | 31 +++++++++++++++++++++++-- onionshare_gui/receive_mode/__init__.py | 10 ++++---- onionshare_gui/share_mode/__init__.py | 10 ++++---- 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/onionshare_gui/onionshare_gui.py b/onionshare_gui/onionshare_gui.py index a95b75c9..5469c57c 100644 --- a/onionshare_gui/onionshare_gui.py +++ b/onionshare_gui/onionshare_gui.py @@ -445,8 +445,35 @@ class OnionShareGui(QtWidgets.QMainWindow): self.settings_action.setEnabled(not active) def adjust_size(self): - self.share_mode.adjustSize() - self.receive_mode.adjustSize() + """ + Recursively adjust size on all widgets + """ + # Recursively adjust sizes for the modes + def adjust_size_layout(layout): + count = layout.count() + for i in range(count): + item = layout.itemAt(i) + if item: + child_widget = item.widget() + if child_widget: + adjust_size_widget(child_widget) + child_layout = item.layout() + if child_layout: + adjust_size_layout(child_layout) + + def adjust_size_widget(widget): + layout = widget.layout() + if layout: + adjust_size_layout(layout) + # Processing Qt events before adjusting size makes each .adjustSize() actually count + self.qtapp.processEvents() + widget.adjustSize() + + # Adjust sizes of each mode + for mode in [self.share_mode, self.receive_mode]: + adjust_size_widget(mode) + + # Adjust window size self.adjustSize() def closeEvent(self, e): diff --git a/onionshare_gui/receive_mode/__init__.py b/onionshare_gui/receive_mode/__init__.py index efad618a..dab37ef2 100644 --- a/onionshare_gui/receive_mode/__init__.py +++ b/onionshare_gui/receive_mode/__init__.py @@ -94,11 +94,11 @@ class ReceiveMode(Mode): self.main_layout.addStretch() self.main_layout.addWidget(self.min_width_widget) - # Layout - self.layout = QtWidgets.QHBoxLayout() - self.layout.addLayout(self.main_layout) - self.layout.addWidget(self.uploads) - self.setLayout(self.layout) + # Wrapper layout + self.wrapper_layout = QtWidgets.QHBoxLayout() + self.wrapper_layout.addLayout(self.main_layout) + self.wrapper_layout.addWidget(self.uploads) + self.setLayout(self.wrapper_layout) def get_stop_server_shutdown_timeout_text(self): """ diff --git a/onionshare_gui/share_mode/__init__.py b/onionshare_gui/share_mode/__init__.py index cf33e8b1..c0cb6d39 100644 --- a/onionshare_gui/share_mode/__init__.py +++ b/onionshare_gui/share_mode/__init__.py @@ -122,11 +122,11 @@ class ShareMode(Mode): self.main_layout.addWidget(self.primary_action) self.main_layout.addWidget(self.min_width_widget) - # Layout - self.layout = QtWidgets.QHBoxLayout() - self.layout.addLayout(self.main_layout) - self.layout.addWidget(self.downloads) - self.setLayout(self.layout) + # Wrapper layout + self.wrapper_layout = QtWidgets.QHBoxLayout() + self.wrapper_layout.addLayout(self.main_layout) + self.wrapper_layout.addWidget(self.downloads) + self.setLayout(self.wrapper_layout) # Always start with focus on file selection self.file_selection.setFocus()