feat: make checkboxes in lock-step

This commit is contained in:
aclist committed 2026-07-11 16:33:40 +09:00
1 parent 8733094267
commit 2f61cc7ff7
1 file changed
+32 -45
+32 -45
View File
@@ -18,6 +18,7 @@ from dzgui.const.constants import (
from dzgui.const.boilerplate import config_boilerplate from dzgui.const.boilerplate import config_boilerplate
from dzgui.const.endpoints import BM_API_SETUP, STEAM_API_SETUP from dzgui.const.endpoints import BM_API_SETUP, STEAM_API_SETUP
from dzgui.const.enum import Preferences from dzgui.const.enum import Preferences
from dzgui.config import freedesktop
from dzgui.config.query import lookup from dzgui.config.query import lookup
from dzgui.init.migrate import migrate_legacy_conf from dzgui.init.migrate import migrate_legacy_conf
from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager from dzgui.managers.threading import call_on_thread, StoredFunc, ThreadingManager
@@ -49,12 +50,6 @@ class PageNum(Enum):
FINAL = 8 FINAL = 8
class Shortcut(Enum):
STEAM = 1
DESKTOP = 2
START = 3
class DescriptionArea(Gtk.Box): class DescriptionArea(Gtk.Box):
def __init__(self, text: str): def __init__(self, text: str):
super().__init__(orientation=Gtk.Orientation.VERTICAL) super().__init__(orientation=Gtk.Orientation.VERTICAL)
@@ -584,10 +579,9 @@ class Assistant(Gtk.Assistant):
class CheckboxWithLabel(Gtk.Box): class CheckboxWithLabel(Gtk.Box):
def __init__(self, text: str, blurb_text: str, enum: Shortcut) -> None: def __init__(self, text: str, blurb_text: str) -> None:
super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=5) super().__init__(orientation=Gtk.Orientation.VERTICAL, spacing=5)
self.enum = enum
self.button = Gtk.CheckButton(label=text) self.button = Gtk.CheckButton(label=text)
self.button.set_active(True) self.button.set_active(True)
blurb = Gtk.Label(label=f"- {blurb_text}", halign=Gtk.Align.START, margin_start=20) blurb = Gtk.Label(label=f"- {blurb_text}", halign=Gtk.Align.START, margin_start=20)
@@ -595,12 +589,14 @@ class CheckboxWithLabel(Gtk.Box):
for el in self.button, blurb: for el in self.button, blurb:
self.add(el) self.add(el)
def get_enum(self) -> Shortcut: def get_checkbox(self) -> Gtk.CheckButton:
return self.enum return self.button
def get_active(self) -> bool: def get_active(self) -> bool:
return self.button.get_active() return self.button.get_active()
def set_active(self, state: bool) -> None:
self.button.set_active(state)
class ShortcutCreationPage(ScrolledWizardPage): class ShortcutCreationPage(ScrolledWizardPage):
def __init__(self, shortcut: Path) -> None: def __init__(self, shortcut: Path) -> None:
@@ -617,29 +613,29 @@ class ShortcutCreationPage(ScrolledWizardPage):
) )
self.page_type = Gtk.AssistantPageType.INTRO self.page_type = Gtk.AssistantPageType.INTRO
# TODO: pass enums label, blurb = wizard.checkbox_steam_shortcut
for checkbox in ( self.steam_checkbox = CheckboxWithLabel(label, blurb)
(wizard.checkbox_steam_shortcut, Shortcut.STEAM),
(wizard.checkbox_desktop_shortcut, Shortcut.DESKTOP), label, blurb = wizard.checkbox_start_menu
(wizard.checkbox_start_menu, Shortcut.START), self.start_menu_checkbox = CheckboxWithLabel(label, blurb)
): cb = self.start_menu_checkbox.get_checkbox()
box, enum = checkbox cb.connect("toggled", self._on_start_menu_toggled)
label, blurb = box
checkbox = CheckboxWithLabel(label, blurb, enum) label, blurb = wizard.checkbox_desktop_shortcut
self.checks_area.add(checkbox) self.desktop_checkbox = CheckboxWithLabel(label, blurb)
for el in (self.steam_checkbox, self.start_menu_checkbox, self.desktop_checkbox):
self.checks_area.add(el)
self.add_start(self.checks_area) self.add_start(self.checks_area)
self.show_all() self.show_all()
self.connect("map", self._on_map) self.connect("map", self._on_map)
""" def _on_start_menu_toggled(self, button: Gtk.CheckButton) -> None:
TODO: checkboxes for: state = button.get_active()
[] steam shortcut (adds a new shortcut. it will not replace or update existing DZGUI shortcuts) if not state:
[] add to desktop (PATH) self.desktop_checkbox.set_active(state)
[] add to start menu (free desktop) self.desktop_checkbox.set_sensitive(state)
checkbox with blurb below
# TODO: warn about how to back up
"""
def _on_map(self, page: "ScrolledWizardPage") -> None: def _on_map(self, page: "ScrolledWizardPage") -> None:
EMITTER.emit("step_complete") EMITTER.emit("step_complete")
@@ -647,25 +643,16 @@ class ShortcutCreationPage(ScrolledWizardPage):
def set_steam_path(self, path: Path) -> None: def set_steam_path(self, path: Path) -> None:
self.steam_path = path self.steam_path = path
# TODO: move elsewhere
def write_desktop_file(self) -> None:
# .local/share/applications/dzgui/dzgui.desktop
pass
def create_shortcuts(self) -> None: def create_shortcuts(self) -> None:
# NOTE: best-effort, permissive even on failure (page is already marked as complete) # NOTE: best-effort, permissive even on failure (page is already marked as complete)
for box in self.checks_area.get_children(): if self.steam_checkbox.get_active():
if not box.get_active(): add_steam_shortcut(self.steam_path, self.shortcut_path)
continue
match box.get_enum(): if self.start_menu_checkbox.get_active():
case Shortcut.STEAM: desktop_file = freedesktop.write_desktop_file(self.shortcut_path)
add_steam_shortcut(self.steam_path, self.shortcut_path)
case Shortcut.DESKTOP: if self.desktop_checkbox.get_active():
pass freedesktop.write_desktop_shortcut(desktop_file)
case Shortcut.START:
pass
case _:
pass
class SteamPathPage(ScrolledWizardPage): class SteamPathPage(ScrolledWizardPage):