Move settings into the main window
Replace the modal settings dialog with a shared Settings tab accessible from the main window and tray menu, with explicit Save and Cancel behavior. Improve changelog navigation from update notices and update usage, licensing, and implementation documentation.
This commit is contained in:
15
arm/about.py
15
arm/about.py
@@ -203,17 +203,22 @@ class AboutPage(QWidget):
|
||||
|
||||
def show_document(self, name):
|
||||
if name not in self.documents:
|
||||
return
|
||||
return False
|
||||
path = document(name)
|
||||
self.document_group.setTitle(self.documents[name])
|
||||
try:
|
||||
self.browser.setMarkdown(path.read_text(encoding="utf-8"))
|
||||
if name == "CHANGELOG.md" and self.isVisible():
|
||||
self.updates.dismiss_success_notice()
|
||||
except (OSError, UnicodeError) as exc:
|
||||
LOG.warning("Unable to read About document %s: %s", name, exc)
|
||||
self.browser.setPlainText(f"Unable to open {name}.")
|
||||
return False
|
||||
self.browser.verticalScrollBar().setValue(0)
|
||||
return True
|
||||
|
||||
def open_changelog(self):
|
||||
if self.show_document("CHANGELOG.md"):
|
||||
self.updates.dismiss_success_notice()
|
||||
self.browser.setFocus()
|
||||
|
||||
def show_license(self):
|
||||
try:
|
||||
@@ -226,7 +231,9 @@ class AboutPage(QWidget):
|
||||
dialog.deleteLater()
|
||||
|
||||
def open_link(self, target):
|
||||
if target in self.documents:
|
||||
if target == "CHANGELOG.md":
|
||||
self.open_changelog()
|
||||
elif target in self.documents:
|
||||
self.show_document(target)
|
||||
elif QUrl(target).scheme() == "https":
|
||||
QDesktopServices.openUrl(QUrl(target))
|
||||
|
||||
@@ -27,7 +27,7 @@ from .branding import DARK, LIGHT, PUBLISHER, WEBSITE, application_icon, set_win
|
||||
from .collect import Collectors
|
||||
from .config import STATIC_TRAY_MODE, ConfigStore, Target, data_path, machine_ids, monitor_choices
|
||||
from .credentials import CredentialStore
|
||||
from .dialogs import ConnectionsDialog, SettingsDialog, TargetDialog
|
||||
from .dialogs import ConnectionsDialog, SettingsPage, TargetDialog
|
||||
from .graphs import Dashboard, tray_icon
|
||||
from .history_db import HistoryDb
|
||||
from .model import ALL, LOCAL, TOTAL, Connection
|
||||
@@ -99,6 +99,8 @@ class Application(QObject):
|
||||
self.about_page.updates.quit_requested.connect(self.close_for_update)
|
||||
self.expanded = Monitor(self.dashboard, True, self.request_archive, self.open_expanded,
|
||||
self.set_pin, self.toggle_machine, self.reorder_machines, self.about_page)
|
||||
self.settings_page = SettingsPage(self)
|
||||
self.expanded.tabs.insertTab(1, self.settings_page, "Settings")
|
||||
self.expanded.setWindowIcon(self.brand_icon)
|
||||
self.window_geometry = WindowGeometry(self.expanded, self.root / "monitor-window.bin")
|
||||
self.popup = Monitor(self.dashboard, False, self.request_archive, self.open_expanded, self.set_pin,
|
||||
@@ -120,7 +122,6 @@ class Application(QObject):
|
||||
self.view_timer.timeout.connect(self.refresh_views)
|
||||
self.view_timer.start()
|
||||
self.manager = None
|
||||
self.settings_dialog = None
|
||||
self._closed = False
|
||||
self.qt.styleHints().colorSchemeChanged.connect(self.change_brand_theme)
|
||||
self.change_brand_theme()
|
||||
@@ -395,16 +396,7 @@ class Application(QObject):
|
||||
self.process_message = message
|
||||
|
||||
def open_settings(self):
|
||||
if self.settings_dialog:
|
||||
self.settings_dialog.raise_()
|
||||
return
|
||||
dialog = SettingsDialog(self)
|
||||
self.settings_dialog = dialog
|
||||
try:
|
||||
dialog.exec()
|
||||
finally:
|
||||
self.settings_dialog = None
|
||||
dialog.deleteLater()
|
||||
self.expanded.show_page(self.settings_page)
|
||||
|
||||
def manage(self):
|
||||
if self.manager:
|
||||
@@ -519,7 +511,7 @@ class Application(QObject):
|
||||
QMessageBox.warning(self.expanded, "Start with Windows", str(exc))
|
||||
|
||||
def about(self):
|
||||
self.expanded.show_page(about=True)
|
||||
self.expanded.show_page(self.about_page)
|
||||
|
||||
def check_for_updates(self):
|
||||
self.about()
|
||||
@@ -530,8 +522,7 @@ class Application(QObject):
|
||||
self.popup.hide()
|
||||
self.about()
|
||||
if changelog:
|
||||
self.about_page.show_document("CHANGELOG.md")
|
||||
self.about_page.browser.setFocus()
|
||||
self.about_page.open_changelog()
|
||||
else:
|
||||
self.about_page.updates.buttons["Check for Updates"].setFocus()
|
||||
|
||||
|
||||
@@ -101,24 +101,31 @@ class DeviceChoices(Choices):
|
||||
self.setVisible(False)
|
||||
|
||||
|
||||
class SettingsDialog(QDialog):
|
||||
class SettingsPage(QWidget):
|
||||
def __init__(self, app):
|
||||
super().__init__()
|
||||
self.app = app
|
||||
self.cfg = app.settings
|
||||
self.setWindowTitle("ARM Settings")
|
||||
self.resize(610, 610)
|
||||
self.tabs = None
|
||||
layout = QVBoxLayout(self)
|
||||
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
||||
buttons.accepted.connect(self.save)
|
||||
buttons.rejected.connect(self.reload)
|
||||
layout.addWidget(buttons)
|
||||
self.timer = QTimer(self, interval=1500)
|
||||
self.timer.timeout.connect(self.update_diagnostics)
|
||||
|
||||
def reload(self):
|
||||
index = self.tabs.currentIndex() if self.tabs is not None else 0
|
||||
if self.tabs is not None:
|
||||
self.tabs.hide()
|
||||
self.layout().removeWidget(self.tabs)
|
||||
self.tabs.deleteLater()
|
||||
self.cfg = self.app.settings
|
||||
self.controls = {}
|
||||
self.tabs = QTabWidget()
|
||||
self.colors = dict(self.cfg.colors)
|
||||
self.network_colors = dict(self.cfg.network_colors)
|
||||
self.background = self.cfg.background
|
||||
layout = QVBoxLayout(self)
|
||||
layout.addWidget(self.tabs)
|
||||
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Save | QDialogButtonBox.StandardButton.Cancel)
|
||||
buttons.accepted.connect(self.save)
|
||||
buttons.rejected.connect(self.reject)
|
||||
layout.addWidget(buttons)
|
||||
self.general()
|
||||
self.tray()
|
||||
self.hover()
|
||||
@@ -126,12 +133,23 @@ class SettingsDialog(QDialog):
|
||||
self.remote()
|
||||
self.history()
|
||||
self.diagnostics()
|
||||
self.timer = QTimer(self)
|
||||
self.timer.setInterval(1500)
|
||||
self.timer.timeout.connect(self.update_diagnostics)
|
||||
self.tabs.setCurrentIndex(index)
|
||||
self.layout().insertWidget(0, self.tabs, 1)
|
||||
self.tabs.currentChanged.connect(self.update_diagnostics)
|
||||
self.initial = self.values()
|
||||
self.initial_startup = self.startup.isChecked()
|
||||
self.update_diagnostics()
|
||||
|
||||
def showEvent(self, event):
|
||||
if self.tabs is None or (self.values() == self.initial and self.startup.isChecked() == self.initial_startup):
|
||||
self.reload()
|
||||
super().showEvent(event)
|
||||
self.timer.start()
|
||||
self.update_diagnostics()
|
||||
self.window_geometry = WindowGeometry(self, app.root / "settings-window.bin")
|
||||
|
||||
def hideEvent(self, event):
|
||||
self.timer.stop()
|
||||
super().hideEvent(event)
|
||||
|
||||
def section(self, title):
|
||||
page = QWidget()
|
||||
@@ -261,20 +279,26 @@ class SettingsDialog(QDialog):
|
||||
form.addRow(self.diagnostic)
|
||||
|
||||
def update_diagnostics(self):
|
||||
self.diagnostic.setText(self.app.diagnostics())
|
||||
if self.diagnostic.isVisible():
|
||||
self.diagnostic.setText(self.app.diagnostics())
|
||||
|
||||
def values(self):
|
||||
return {**{key: getter() for key, getter in self.controls.items()},
|
||||
"background": self.background, "colors": dict(self.colors),
|
||||
"network_colors": dict(self.network_colors)}
|
||||
|
||||
def save(self):
|
||||
updates = {key: getter() for key, getter in self.controls.items()}
|
||||
cfg = replace(self.app.settings, **updates, background=self.background, colors=self.colors,
|
||||
network_colors=self.network_colors)
|
||||
updates = {key: value for key, value in self.values().items() if value != self.initial[key]}
|
||||
startup = self.startup.isChecked()
|
||||
try:
|
||||
self.app.apply(cfg)
|
||||
if self.startup.isChecked() != self.app.startup_enabled():
|
||||
self.app.set_startup(self.startup.isChecked())
|
||||
if updates:
|
||||
self.app.apply(replace(self.app.settings, **updates))
|
||||
if startup != self.initial_startup and startup != self.app.startup_enabled():
|
||||
self.app.set_startup(startup)
|
||||
except (OSError, ValueError) as exc:
|
||||
QMessageBox.warning(self, "Settings", str(exc))
|
||||
return
|
||||
self.accept()
|
||||
self.reload()
|
||||
|
||||
|
||||
class TargetDialog(QDialog):
|
||||
|
||||
@@ -304,10 +304,12 @@ class Monitor(QWidget):
|
||||
def monitor_visible(self):
|
||||
return self.isVisible() and (not self.expanded or self.tabs.currentWidget() is self.resource_page)
|
||||
|
||||
def show_page(self, about=False):
|
||||
self.tabs.setCurrentWidget(self.about_page if about else self.resource_page)
|
||||
def show_page(self, page=None):
|
||||
self.tabs.setCurrentWidget(self.resource_page if page is None else page)
|
||||
self.ensurePolished()
|
||||
self.layout().activate()
|
||||
if self.isMinimized():
|
||||
self.setWindowState(self.windowState() & ~Qt.WindowState.WindowMinimized)
|
||||
self.show()
|
||||
fit_work_area(self)
|
||||
self.raise_()
|
||||
|
||||
Reference in New Issue
Block a user