Show and hide autostart/autostop timer widgets when the mode settings are toggled

This commit is contained in:
Micah Lee 2019-11-02 18:08:14 -07:00
parent ed1c3e1bc8
commit f04452777d
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
3 changed files with 64 additions and 51 deletions

View File

@ -67,25 +67,6 @@ class Mode(QtWidgets.QWidget):
self.web_thread = None
self.startup_thread = None
# Header
# Note: It's up to the downstream Mode to add this to its layout
self.header_label = QtWidgets.QLabel()
self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"])
self.header_label.setAlignment(QtCore.Qt.AlignHCenter)
self.mode_settings_widget = ModeSettingsWidget(
self.common, self.tab.tab_id, self.tab.mode_settings
)
self.mode_settings_widget.change_persistent.connect(self.change_persistent)
header_layout = QtWidgets.QVBoxLayout()
header_layout.setContentsMargins(0, 0, 0, 0)
header_layout.addWidget(self.header_label)
header_layout.addWidget(self.mode_settings_widget)
self.header = QtWidgets.QWidget()
self.header.setLayout(header_layout)
# Server status
self.server_status = ServerStatus(
self.common,
@ -105,6 +86,28 @@ class Mode(QtWidgets.QWidget):
self.starting_server_early.connect(self.start_server_early)
self.starting_server_error.connect(self.start_server_error)
# Header
# Note: It's up to the downstream Mode to add this to its layout
self.header_label = QtWidgets.QLabel()
self.header_label.setStyleSheet(self.common.gui.css["mode_header_label"])
self.header_label.setAlignment(QtCore.Qt.AlignHCenter)
self.mode_settings_widget = ModeSettingsWidget(
self.common, self.tab.tab_id, self.tab.mode_settings
)
self.mode_settings_widget.change_persistent.connect(self.change_persistent)
self.mode_settings_widget.update_server_status.connect(
self.server_status.update
)
header_layout = QtWidgets.QVBoxLayout()
header_layout.setContentsMargins(0, 0, 0, 0)
header_layout.addWidget(self.header_label)
header_layout.addWidget(self.mode_settings_widget)
self.header = QtWidgets.QWidget()
self.header.setLayout(header_layout)
# Primary action
# Note: It's up to the downstream Mode to add this to its layout
self.primary_action_layout = QtWidgets.QVBoxLayout()

View File

@ -28,6 +28,7 @@ class ModeSettingsWidget(QtWidgets.QWidget):
"""
change_persistent = QtCore.pyqtSignal(int, bool)
update_server_status = QtCore.pyqtSignal()
def __init__(self, common, tab_id, mode_settings):
super(ModeSettingsWidget, self).__init__()
@ -149,11 +150,13 @@ class ModeSettingsWidget(QtWidgets.QWidget):
self.settings.set(
"general", "autostart_timer", self.autostart_timer_checkbox.isChecked()
)
self.update_server_status.emit()
def autostop_timer_checkbox_clicked(self):
self.settings.set(
"general", "autostop_timer", self.autostop_timer_checkbox.isChecked()
)
self.update_server_status.emit()
def legacy_checkbox_clicked(self):
self.settings.set("general", "legacy", self.legacy_checkbox.isChecked())

View File

@ -291,6 +291,10 @@ class ServerStatus(QtWidgets.QWidget):
"""
Update the GUI elements based on the current state.
"""
self.common.log("ServerStatus", "update")
autostart_timer = self.settings.get("general", "autostart_timer")
autostop_timer = self.settings.get("general", "autostop_timer")
# Set the URL fields
if self.status == self.STATUS_STARTED:
# The backend Onion may have saved new settings, such as the private key.
@ -302,18 +306,47 @@ class ServerStatus(QtWidgets.QWidget):
if not self.settings.get("persistent", "password"):
self.settings.set("persistent", "password", self.web.password)
self.settings.save()
if self.settings.get("general", "autostart_timer"):
self.autostart_timer_container.hide()
if self.settings.get("general", "autostop_timer"):
self.autostop_timer_container.hide()
else:
self.url_description.hide()
self.url.hide()
self.copy_url_button.hide()
self.copy_hidservauth_button.hide()
# Autostart and autostop timers
if self.status == self.STATUS_STOPPED:
if autostart_timer:
self.autostart_timer_container.show()
else:
self.autostart_timer_container.hide()
if autostop_timer:
self.autostop_timer_container.show()
else:
self.autostop_timer_container.hide()
elif self.status == self.STATUS_STARTED:
self.autostart_timer_container.hide()
self.autostop_timer_container.hide()
if autostop_timer:
self.server_button.setToolTip(
strings._("gui_stop_server_autostop_timer_tooltip").format(
self.autostop_timer_widget.dateTime().toString(
"h:mm AP, MMMM dd, yyyy"
)
)
)
elif self.status == self.STATUS_WORKING:
self.autostart_timer_container.hide()
self.autostop_timer_container.hide()
if autostart_timer:
self.server_button.setToolTip(
strings._("gui_start_server_autostart_timer_tooltip").format(
self.autostart_timer_widget.dateTime().toString(
"h:mm AP, MMMM dd, yyyy"
)
)
)
# Button
if (
self.mode == self.common.gui.MODE_SHARE
@ -340,10 +373,6 @@ class ServerStatus(QtWidgets.QWidget):
else:
self.server_button.setText(strings._("gui_receive_start_server"))
self.server_button.setToolTip("")
if self.settings.get("general", "autostart_timer"):
self.autostart_timer_container.show()
if self.settings.get("general", "autostop_timer"):
self.autostop_timer_container.show()
elif self.status == self.STATUS_STARTED:
self.server_button.setStyleSheet(
self.common.gui.css["server_status_button_started"]
@ -355,17 +384,6 @@ class ServerStatus(QtWidgets.QWidget):
self.server_button.setText(strings._("gui_share_stop_server"))
else:
self.server_button.setText(strings._("gui_receive_stop_server"))
if self.settings.get("general", "autostart_timer"):
self.autostart_timer_container.hide()
if self.settings.get("general", "autostop_timer"):
self.autostop_timer_container.hide()
self.server_button.setToolTip(
strings._("gui_stop_server_autostop_timer_tooltip").format(
self.autostop_timer_widget.dateTime().toString(
"h:mm AP, MMMM dd, yyyy"
)
)
)
elif self.status == self.STATUS_WORKING:
self.server_button.setStyleSheet(
self.common.gui.css["server_status_button_working"]
@ -390,17 +408,6 @@ class ServerStatus(QtWidgets.QWidget):
)
self.server_button.setEnabled(False)
self.server_button.setText(strings._("gui_please_wait"))
if self.settings.get("general", "autostart_timer"):
self.autostart_timer_container.hide()
self.server_button.setToolTip(
strings._("gui_start_server_autostart_timer_tooltip").format(
self.autostart_timer_widget.dateTime().toString(
"h:mm AP, MMMM dd, yyyy"
)
)
)
if self.settings.get("general", "autostop_timer"):
self.autostop_timer_container.hide()
def server_button_clicked(self):
"""