mirror of
https://github.com/onionshare/onionshare.git
synced 2024-10-01 01:35:40 -04:00
Modes now get to choose a new minimum window width when resizing
This commit is contained in:
parent
e29bb99f16
commit
cddc8c06d4
@ -36,7 +36,7 @@ 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()
|
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__()
|
||||||
@ -332,3 +332,22 @@ 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.resize_window()
|
||||||
|
@ -168,6 +168,9 @@ 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(450)
|
||||||
|
|
||||||
# The server isn't active yet
|
# The server isn't active yet
|
||||||
self.set_server_active(False)
|
self.set_server_active(False)
|
||||||
|
|
||||||
@ -444,10 +447,14 @@ 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):
|
def adjust_size(self, min_width):
|
||||||
"""
|
"""
|
||||||
Recursively adjust size on all widgets
|
Recursively adjust size on all widgets. min_width is the new minimum width
|
||||||
|
of the window.
|
||||||
"""
|
"""
|
||||||
|
self.common.log("OnionShareGui", "adjust_size", "min_width={}".format(min_width))
|
||||||
|
self.setMinimumWidth(min_width)
|
||||||
|
|
||||||
# Recursively adjust sizes for the modes
|
# Recursively adjust sizes for the modes
|
||||||
def adjust_size_layout(layout):
|
def adjust_size_layout(layout):
|
||||||
count = layout.count()
|
count = layout.count()
|
||||||
@ -465,8 +472,6 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
layout = widget.layout()
|
layout = widget.layout()
|
||||||
if layout:
|
if layout:
|
||||||
adjust_size_layout(layout)
|
adjust_size_layout(layout)
|
||||||
# Processing Qt events before adjusting size makes each .adjustSize() actually count
|
|
||||||
self.qtapp.processEvents()
|
|
||||||
widget.adjustSize()
|
widget.adjustSize()
|
||||||
|
|
||||||
# Adjust sizes of each mode
|
# Adjust sizes of each mode
|
||||||
@ -474,6 +479,7 @@ class OnionShareGui(QtWidgets.QMainWindow):
|
|||||||
adjust_size_widget(mode)
|
adjust_size_widget(mode)
|
||||||
|
|
||||||
# Adjust window size
|
# Adjust window size
|
||||||
|
self.qtapp.processEvents()
|
||||||
self.adjustSize()
|
self.adjustSize()
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def closeEvent(self, e):
|
||||||
|
@ -235,7 +235,7 @@ class ReceiveMode(Mode):
|
|||||||
self.info_widget.hide()
|
self.info_widget.hide()
|
||||||
|
|
||||||
# Resize window
|
# Resize window
|
||||||
self.adjust_size.emit()
|
self.resize_window()
|
||||||
|
|
||||||
def toggle_uploads(self):
|
def toggle_uploads(self):
|
||||||
"""
|
"""
|
||||||
@ -252,4 +252,10 @@ class ReceiveMode(Mode):
|
|||||||
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle_selected.png')) )
|
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/uploads_toggle_selected.png')) )
|
||||||
self.info_toggle_button.setFlat(False)
|
self.info_toggle_button.setFlat(False)
|
||||||
|
|
||||||
self.adjust_size.emit()
|
self.resize_window()
|
||||||
|
|
||||||
|
def resize_window(self):
|
||||||
|
min_width = 450
|
||||||
|
if self.uploads.isVisible():
|
||||||
|
min_width += 300
|
||||||
|
self.adjust_size.emit(min_width)
|
||||||
|
@ -330,7 +330,7 @@ class ShareMode(Mode):
|
|||||||
self.info_widget.hide()
|
self.info_widget.hide()
|
||||||
|
|
||||||
# Resize window
|
# Resize window
|
||||||
self.adjust_size.emit()
|
self.resize_window()
|
||||||
|
|
||||||
def reset_info_counters(self):
|
def reset_info_counters(self):
|
||||||
"""
|
"""
|
||||||
@ -379,7 +379,13 @@ class ShareMode(Mode):
|
|||||||
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png')) )
|
self.info_toggle_button.setIcon( QtGui.QIcon(self.common.get_resource_path('images/downloads_toggle_selected.png')) )
|
||||||
self.info_toggle_button.setFlat(False)
|
self.info_toggle_button.setFlat(False)
|
||||||
|
|
||||||
self.adjust_size.emit()
|
self.resize_window()
|
||||||
|
|
||||||
|
def resize_window(self):
|
||||||
|
min_width = 450
|
||||||
|
if self.downloads.isVisible():
|
||||||
|
min_width += 300
|
||||||
|
self.adjust_size.emit(min_width)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _compute_total_size(filenames):
|
def _compute_total_size(filenames):
|
||||||
|
Loading…
Reference in New Issue
Block a user