From e3732a3bfaa109fb3d0c21fe3cd44ac26efca5ec Mon Sep 17 00:00:00 2001 From: Aaron <57018940+0dm@users.noreply.github.com> Date: Fri, 2 Jun 2023 11:37:36 -0400 Subject: [PATCH] save & sync switch states --- openadapt/app/cards.py | 5 +++-- openadapt/app/util.py | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/openadapt/app/cards.py b/openadapt/app/cards.py index 06d629f27..b21e22b4b 100644 --- a/openadapt/app/cards.py +++ b/openadapt/app/cards.py @@ -1,12 +1,13 @@ from nicegui import ui from subprocess import Popen from openadapt.app.objects.local_file_picker import local_file_picker +from openadapt.app.util import set_dark, sync_switch def settings(dark_mode): with ui.dialog() as settings, ui.card(): - ui.switch("Dark mode", on_change=lambda: dark_mode.toggle()) - + s = ui.switch("Dark mode", on_change=lambda: set_dark(dark_mode, s.value)) + sync_switch(s, dark_mode) ui.button("Close", on_click=lambda: settings.close()) settings.open() diff --git a/openadapt/app/util.py b/openadapt/app/util.py index 3a4a35488..3a80edf8e 100644 --- a/openadapt/app/util.py +++ b/openadapt/app/util.py @@ -41,3 +41,11 @@ def on_export(dest): os.remove("openadapt.db.bz2") ui.notify("Exported data.") + + +def sync_switch(switch, prop): + switch.value = prop.value + + +def set_dark(dark_mode, value): + dark_mode.value = value