mirror of
https://github.com/onionshare/onionshare.git
synced 2024-12-26 07:49:48 -05:00
Make the persistent button an image label instead, and only show it whne the persistent checkbox is checked
This commit is contained in:
parent
5e93b50f9c
commit
b017b3268c
@ -42,6 +42,7 @@ class Mode(QtWidgets.QWidget):
|
||||
starting_server_error = QtCore.pyqtSignal(str)
|
||||
starting_server_early = QtCore.pyqtSignal()
|
||||
set_server_active = QtCore.pyqtSignal(bool)
|
||||
change_persistent = QtCore.pyqtSignal(int, bool)
|
||||
|
||||
def __init__(self, tab):
|
||||
super(Mode, self).__init__()
|
||||
@ -71,7 +72,8 @@ class Mode(QtWidgets.QWidget):
|
||||
self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"])
|
||||
self.header_label.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
|
||||
self.mode_settings = ModeSettings(self.common)
|
||||
self.mode_settings = ModeSettings(self.common, self.tab.tab_id)
|
||||
self.mode_settings.change_persistent.connect(self.change_persistent)
|
||||
|
||||
header_layout = QtWidgets.QVBoxLayout()
|
||||
header_layout.setContentsMargins(0, 0, 0, 0)
|
||||
|
@ -27,15 +27,19 @@ class ModeSettings(QtWidgets.QWidget):
|
||||
A settings widget
|
||||
"""
|
||||
|
||||
def __init__(self, common):
|
||||
change_persistent = QtCore.pyqtSignal(int, bool)
|
||||
|
||||
def __init__(self, common, tab_id):
|
||||
super(ModeSettings, self).__init__()
|
||||
self.common = common
|
||||
self.tab_id = tab_id
|
||||
|
||||
# Downstream Mode need to fill in this layout with its settings
|
||||
self.mode_specific_layout = QtWidgets.QVBoxLayout()
|
||||
|
||||
# Persistent
|
||||
self.persistent_checkbox = QtWidgets.QCheckBox()
|
||||
self.persistent_checkbox.clicked.connect(self.persistent_checkbox_clicked)
|
||||
self.persistent_checkbox.setCheckState(QtCore.Qt.Unchecked)
|
||||
self.persistent_checkbox.setText(strings._("mode_settings_persistent_checkbox"))
|
||||
|
||||
@ -123,6 +127,9 @@ class ModeSettings(QtWidgets.QWidget):
|
||||
else:
|
||||
self.client_auth_checkbox.hide()
|
||||
|
||||
def persistent_checkbox_clicked(self):
|
||||
self.change_persistent.emit(self.tab_id, self.persistent_checkbox.isChecked())
|
||||
|
||||
def toggle_advanced_clicked(self):
|
||||
if self.advanced_widget.isVisible():
|
||||
self.advanced_widget.hide()
|
||||
|
@ -40,6 +40,7 @@ class Tab(QtWidgets.QWidget):
|
||||
|
||||
change_title = QtCore.pyqtSignal(int, str)
|
||||
change_icon = QtCore.pyqtSignal(int, str)
|
||||
change_persistent = QtCore.pyqtSignal(int, bool)
|
||||
|
||||
def __init__(self, common, tab_id, system_tray, status_bar, filenames=None):
|
||||
super(Tab, self).__init__()
|
||||
@ -56,7 +57,7 @@ class Tab(QtWidgets.QWidget):
|
||||
# Start the OnionShare app
|
||||
self.app = OnionShare(common, self.common.gui.onion, self.common.gui.local_only)
|
||||
|
||||
# New tab widget
|
||||
# Widgets to display on a new tab
|
||||
share_button = QtWidgets.QPushButton(strings._("gui_new_tab_share_button"))
|
||||
share_button.setStyleSheet(self.common.gui.css["mode_new_tab_button"])
|
||||
share_description = QtWidgets.QLabel(strings._("gui_new_tab_share_description"))
|
||||
@ -137,13 +138,16 @@ class Tab(QtWidgets.QWidget):
|
||||
"website": {"disable_csp": False},
|
||||
}
|
||||
|
||||
# Persistence button
|
||||
self.persistence_button = QtWidgets.QPushButton()
|
||||
self.persistence_button.setDefault(False)
|
||||
self.persistence_button.setFlat(True)
|
||||
self.persistence_button.setFixedSize(30, 30)
|
||||
self.persistence_button.clicked.connect(self.persistence_button_clicked)
|
||||
self.update_persistence_button()
|
||||
# Persistent image
|
||||
self.persistent_image_label = QtWidgets.QLabel()
|
||||
self.persistent_image_label.setPixmap(
|
||||
QtGui.QPixmap.fromImage(
|
||||
QtGui.QImage(
|
||||
self.common.get_resource_path("images/persistent_enabled.png")
|
||||
)
|
||||
)
|
||||
)
|
||||
self.persistent_image_label.setFixedSize(30, 30)
|
||||
|
||||
def share_mode_clicked(self):
|
||||
self.common.log("Tab", "share_mode_clicked")
|
||||
@ -151,6 +155,8 @@ class Tab(QtWidgets.QWidget):
|
||||
self.new_tab.hide()
|
||||
|
||||
self.share_mode = ShareMode(self)
|
||||
self.share_mode.change_persistent.connect(self.change_persistent)
|
||||
|
||||
self.layout.addWidget(self.share_mode)
|
||||
self.share_mode.show()
|
||||
|
||||
@ -185,6 +191,8 @@ class Tab(QtWidgets.QWidget):
|
||||
self.new_tab.hide()
|
||||
|
||||
self.receive_mode = ReceiveMode(self)
|
||||
self.receive_mode.change_persistent.connect(self.change_persistent)
|
||||
|
||||
self.layout.addWidget(self.receive_mode)
|
||||
self.receive_mode.show()
|
||||
|
||||
@ -221,6 +229,8 @@ class Tab(QtWidgets.QWidget):
|
||||
self.new_tab.hide()
|
||||
|
||||
self.website_mode = WebsiteMode(self)
|
||||
self.website_mode.change_persistent.connect(self.change_persistent)
|
||||
|
||||
self.layout.addWidget(self.website_mode)
|
||||
self.website_mode.show()
|
||||
|
||||
@ -497,29 +507,6 @@ class Tab(QtWidgets.QWidget):
|
||||
else:
|
||||
return None
|
||||
|
||||
def persistence_button_clicked(self):
|
||||
self.common.log("Tab", "persistence_button_clicked")
|
||||
if self.tab_settings["persistent"]["enabled"]:
|
||||
self.tab_settings["persistent"]["enabled"] = False
|
||||
else:
|
||||
self.tab_settings["persistent"]["enabled"] = True
|
||||
self.update_persistence_button()
|
||||
|
||||
def update_persistence_button(self):
|
||||
self.common.log("Tab", "update_persistence_button")
|
||||
if self.tab_settings["persistent"]["enabled"]:
|
||||
self.persistence_button.setIcon(
|
||||
QtGui.QIcon(
|
||||
self.common.get_resource_path("images/persistent_enabled.png")
|
||||
)
|
||||
)
|
||||
else:
|
||||
self.persistence_button.setIcon(
|
||||
QtGui.QIcon(
|
||||
self.common.get_resource_path("images/persistent_disabled.png")
|
||||
)
|
||||
)
|
||||
|
||||
def close_tab(self):
|
||||
self.common.log("Tab", "close_tab")
|
||||
if self.mode is None:
|
||||
|
@ -90,6 +90,7 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
tab = Tab(self.common, self.tab_id, self.system_tray, self.status_bar)
|
||||
tab.change_title.connect(self.change_title)
|
||||
tab.change_icon.connect(self.change_icon)
|
||||
tab.change_persistent.connect(self.change_persistent)
|
||||
self.tabs[self.tab_id] = tab
|
||||
self.tab_id += 1
|
||||
|
||||
@ -101,15 +102,25 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
index = self.indexOf(self.tabs[tab_id])
|
||||
self.setTabText(index, title)
|
||||
|
||||
# Now that a mode has been selected, add persistence button
|
||||
self.tabBar().setTabButton(
|
||||
index, QtWidgets.QTabBar.LeftSide, self.tabs[tab_id].persistence_button
|
||||
)
|
||||
|
||||
def change_icon(self, tab_id, icon_path):
|
||||
index = self.indexOf(self.tabs[tab_id])
|
||||
self.setTabIcon(index, QtGui.QIcon(self.common.get_resource_path(icon_path)))
|
||||
|
||||
def change_persistent(self, tab_id, is_persistent):
|
||||
index = self.indexOf(self.tabs[tab_id])
|
||||
if is_persistent:
|
||||
self.tabBar().setTabButton(
|
||||
index,
|
||||
QtWidgets.QTabBar.LeftSide,
|
||||
self.tabs[tab_id].persistent_image_label,
|
||||
)
|
||||
else:
|
||||
invisible_widget = QtWidgets.QWidget()
|
||||
invisible_widget.setFixedSize(0, 0)
|
||||
self.tabBar().setTabButton(
|
||||
index, QtWidgets.QTabBar.LeftSide, invisible_widget
|
||||
)
|
||||
|
||||
def close_tab(self, index):
|
||||
self.common.log("TabWidget", "close_tab", f"{index}")
|
||||
tab = self.widget(index)
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.3 KiB |
Binary file not shown.
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 3.3 KiB |
Loading…
Reference in New Issue
Block a user