mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-11 04:02:40 -03:00
Rip out all of the adjust size logic and let Qt just handle it
This commit is contained in:
parent
50c0d91c57
commit
5a2ca669a1
4 changed files with 2 additions and 84 deletions
|
@ -36,7 +36,6 @@ class Mode(QtWidgets.QWidget):
|
||||||
starting_server_step3 = QtCore.pyqtSignal()
|
starting_server_step3 = QtCore.pyqtSignal()
|
||||||
starting_server_error = QtCore.pyqtSignal(str)
|
starting_server_error = QtCore.pyqtSignal(str)
|
||||||
set_server_active = QtCore.pyqtSignal(bool)
|
set_server_active = QtCore.pyqtSignal(bool)
|
||||||
adjust_size = QtCore.pyqtSignal(int)
|
|
||||||
|
|
||||||
def __init__(self, common, qtapp, app, status_bar, server_status_label, system_tray, filenames=None, local_only=False):
|
def __init__(self, common, qtapp, app, status_bar, server_status_label, system_tray, filenames=None, local_only=False):
|
||||||
super(Mode, self).__init__()
|
super(Mode, self).__init__()
|
||||||
|
@ -50,8 +49,6 @@ class Mode(QtWidgets.QWidget):
|
||||||
|
|
||||||
self.filenames = filenames
|
self.filenames = filenames
|
||||||
|
|
||||||
self.setMinimumWidth(self.common.min_window_width)
|
|
||||||
|
|
||||||
# The web object gets created in init()
|
# The web object gets created in init()
|
||||||
self.web = None
|
self.web = None
|
||||||
|
|
||||||
|
@ -83,7 +80,7 @@ class Mode(QtWidgets.QWidget):
|
||||||
# Hack to allow a minimum width on the main 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
|
# Note: It's up to the downstream Mode to add this to its layout
|
||||||
self.min_width_widget = QtWidgets.QWidget()
|
self.min_width_widget = QtWidgets.QWidget()
|
||||||
self.min_width_widget.setMinimumWidth(self.common.min_window_width)
|
self.min_width_widget.setMinimumWidth(600)
|
||||||
|
|
||||||
def init(self):
|
def init(self):
|
||||||
"""
|
"""
|
||||||
|
@ -332,23 +329,3 @@ class Mode(QtWidgets.QWidget):
|
||||||
Handle REQUEST_UPLOAD_FINISHED event.
|
Handle REQUEST_UPLOAD_FINISHED event.
|
||||||
"""
|
"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def resize_window(self):
|
|
||||||
"""
|
|
||||||
We call this to force the OnionShare window to resize itself to be smaller.
|
|
||||||
For this to do anything, the Mode needs to override it and call:
|
|
||||||
|
|
||||||
self.adjust_size.emit(min_width)
|
|
||||||
|
|
||||||
It can calculate min_width (the new minimum window width) based on what
|
|
||||||
widgets are visible.
|
|
||||||
"""
|
|
||||||
pass
|
|
||||||
|
|
||||||
def show(self):
|
|
||||||
"""
|
|
||||||
Always resize the window after showing this Mode widget.
|
|
||||||
"""
|
|
||||||
super(Mode, self).show()
|
|
||||||
self.qtapp.processEvents()
|
|
||||||
self.resize_window()
|
|
||||||
|
|
|
@ -196,12 +196,3 @@ class ReceiveMode(Mode):
|
||||||
|
|
||||||
def update_primary_action(self):
|
def update_primary_action(self):
|
||||||
self.common.log('ReceiveMode', 'update_primary_action')
|
self.common.log('ReceiveMode', 'update_primary_action')
|
||||||
|
|
||||||
# Resize window
|
|
||||||
self.resize_window()
|
|
||||||
|
|
||||||
def resize_window(self):
|
|
||||||
min_width = self.common.min_window_width
|
|
||||||
if self.history.isVisible():
|
|
||||||
min_width += 300
|
|
||||||
self.adjust_size.emit(min_width)
|
|
||||||
|
|
|
@ -321,21 +321,12 @@ class ShareMode(Mode):
|
||||||
self.primary_action.hide()
|
self.primary_action.hide()
|
||||||
self.info_label.hide()
|
self.info_label.hide()
|
||||||
|
|
||||||
# Resize window
|
|
||||||
self.resize_window()
|
|
||||||
|
|
||||||
def reset_info_counters(self):
|
def reset_info_counters(self):
|
||||||
"""
|
"""
|
||||||
Set the info counters back to zero.
|
Set the info counters back to zero.
|
||||||
"""
|
"""
|
||||||
self.history.reset()
|
self.history.reset()
|
||||||
|
|
||||||
def resize_window(self):
|
|
||||||
min_width = self.common.min_window_width
|
|
||||||
if self.history.isVisible():
|
|
||||||
min_width += 300
|
|
||||||
self.adjust_size.emit(min_width)
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _compute_total_size(filenames):
|
def _compute_total_size(filenames):
|
||||||
total_size = 0
|
total_size = 0
|
||||||
|
|
|
@ -45,7 +45,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
|
|
||||||
self.common = common
|
self.common = common
|
||||||
self.common.log('OnionShareGui', '__init__')
|
self.common.log('OnionShareGui', '__init__')
|
||||||
self.common.min_window_width = 460
|
self.setMinimumWidth(700)
|
||||||
|
|
||||||
self.onion = onion
|
self.onion = onion
|
||||||
self.qtapp = qtapp
|
self.qtapp = qtapp
|
||||||
|
@ -133,7 +133,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.share_mode.server_status.url_copied.connect(self.copy_url)
|
self.share_mode.server_status.url_copied.connect(self.copy_url)
|
||||||
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
||||||
self.share_mode.set_server_active.connect(self.set_server_active)
|
self.share_mode.set_server_active.connect(self.set_server_active)
|
||||||
self.share_mode.adjust_size.connect(self.adjust_size)
|
|
||||||
|
|
||||||
# Receive mode
|
# Receive mode
|
||||||
self.receive_mode = ReceiveMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray, None, self.local_only)
|
self.receive_mode = ReceiveMode(self.common, qtapp, app, self.status_bar, self.server_status_label, self.system_tray, None, self.local_only)
|
||||||
|
@ -148,7 +147,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.receive_mode.server_status.url_copied.connect(self.copy_url)
|
self.receive_mode.server_status.url_copied.connect(self.copy_url)
|
||||||
self.receive_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
self.receive_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
|
||||||
self.receive_mode.set_server_active.connect(self.set_server_active)
|
self.receive_mode.set_server_active.connect(self.set_server_active)
|
||||||
self.receive_mode.adjust_size.connect(self.adjust_size)
|
|
||||||
|
|
||||||
self.update_mode_switcher()
|
self.update_mode_switcher()
|
||||||
self.update_server_status_indicator()
|
self.update_server_status_indicator()
|
||||||
|
@ -169,9 +167,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.setCentralWidget(central_widget)
|
self.setCentralWidget(central_widget)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
# Adjust window size, to start with a minimum window width
|
|
||||||
self.adjust_size(self.common.min_window_width)
|
|
||||||
|
|
||||||
# The server isn't active yet
|
# The server isn't active yet
|
||||||
self.set_server_active(False)
|
self.set_server_active(False)
|
||||||
|
|
||||||
|
@ -200,14 +195,12 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
self.receive_mode_button.setStyleSheet(self.common.css['mode_switcher_unselected_style'])
|
self.receive_mode_button.setStyleSheet(self.common.css['mode_switcher_unselected_style'])
|
||||||
|
|
||||||
self.receive_mode.hide()
|
self.receive_mode.hide()
|
||||||
self.adjust_size(self.common.min_window_width)
|
|
||||||
self.share_mode.show()
|
self.share_mode.show()
|
||||||
else:
|
else:
|
||||||
self.share_mode_button.setStyleSheet(self.common.css['mode_switcher_unselected_style'])
|
self.share_mode_button.setStyleSheet(self.common.css['mode_switcher_unselected_style'])
|
||||||
self.receive_mode_button.setStyleSheet(self.common.css['mode_switcher_selected_style'])
|
self.receive_mode_button.setStyleSheet(self.common.css['mode_switcher_selected_style'])
|
||||||
|
|
||||||
self.share_mode.hide()
|
self.share_mode.hide()
|
||||||
self.adjust_size(self.common.min_window_width)
|
|
||||||
self.receive_mode.show()
|
self.receive_mode.show()
|
||||||
|
|
||||||
self.update_server_status_indicator()
|
self.update_server_status_indicator()
|
||||||
|
@ -450,40 +443,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
||||||
# Disable settings menu action when server is active
|
# Disable settings menu action when server is active
|
||||||
self.settings_action.setEnabled(not active)
|
self.settings_action.setEnabled(not active)
|
||||||
|
|
||||||
def adjust_size(self, min_width):
|
|
||||||
"""
|
|
||||||
Recursively adjust size on all widgets. min_width is the new minimum width
|
|
||||||
of the window.
|
|
||||||
"""
|
|
||||||
self.setMinimumWidth(min_width)
|
|
||||||
|
|
||||||
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)
|
|
||||||
widget.adjustSize()
|
|
||||||
|
|
||||||
# Adjust sizes of each mode
|
|
||||||
for mode in [self.share_mode, self.receive_mode]:
|
|
||||||
self.qtapp.processEvents()
|
|
||||||
adjust_size_widget(mode)
|
|
||||||
|
|
||||||
# Adjust window size
|
|
||||||
self.qtapp.processEvents()
|
|
||||||
self.adjustSize()
|
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
self.common.log('OnionShareGui', 'closeEvent')
|
self.common.log('OnionShareGui', 'closeEvent')
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue