OnionShareGui.adjust_size now recursively runs adjustSize() on all widgets

This commit is contained in:
Micah Lee 2018-09-28 15:05:43 -07:00
parent 4bec79f494
commit e29bb99f16
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 39 additions and 12 deletions

View File

@ -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):

View File

@ -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):
"""

View File

@ -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()