backend rewrite cont, rebrand

This commit is contained in:
2025-12-06 00:41:38 +01:00
parent 8428efdbce
commit e651c8e18a
33 changed files with 498 additions and 428 deletions

View File

@@ -29,85 +29,32 @@ from gi.repository import Adw
from gi.repository import Gtk, Gio
from gi.repository import GLib
def get_config_dir(app_id: str) -> Path:
base = Path(GLib.get_user_config_dir())
cfg_dir = base / app_id
cfg_dir.mkdir(parents=True, exist_ok=True)
return cfg_dir
APP_ID = "gay.valhrafnaz.Gnomeframe"
CONFIG_DIR = get_config_dir(APP_ID)
CONFIG_FILE = CONFIG_DIR / "profile.json"
def load_profile() -> dict[str, bool]:
try:
with CONFIG_FILE.open("r", encoding="utf-8") as f:
data = json.load(f)
return {k: bool(v) for k, v in data.items()}
except FileNotFoundError:
return {}
except (json.JSONDecodeError, OSError) as exc:
print(f"Could not load profile: {exc}")
return {}
def save_profile(state: dict[str, bool]) -> None:
try:
CONFIG_DIR.mkdir(parents=True, exist_ok=True)
with CONFIG_FILE.open("w", encoding="utf-8") as f:
json.dump(state, f, indent=2, sort_keys=True)
except OSError as exc:
print(f"Failed to write profile: {exc}")
@Gtk.Template(resource_path='/gay/valhrafnaz/Gnomeframe/ui/window.ui')
class GnomeframeWindow(Adw.ApplicationWindow):
__gtype_name__ = 'GnomeframeWindow'
@Gtk.Template(resource_path='/gay/valhrafnaz/VoidManifest/ui/window.ui')
class VoidManifestWindow(Adw.ApplicationWindow):
__gtype_name__ = 'VoidManifestWindow'
viewstack = Gtk.Template.Child()
btn_reset_profile = Gtk.Template.Child()
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._profile: dict[str, bool] = load_profile()
self.app = self.get_application()
self._load_page_templates()
reset_action = Gio.SimpleAction.new("reset-selections", None)
reset_action.connect("activate", self._reset_all)
reset_action.connect("activate", self.app.reset_frames)
self.get_application().add_action(reset_action)
self.btn_reset_profile.connect("clicked", self._reset_all)
self.btn_reset_profile.connect("clicked", self.app.reset_frames)
self.connect("close-request", self._on_close_request)
# self.settings = Gio.Settings(schema_id="gay.valhrafnaz.Gnomeframe")
# self.settings.bind("window-width", self, "default-width", Gio.SettingsBindFlags.DEFAULT)
# self.settings.bind("window-height", self, "default-height", Gio.SettingsBindFlags.DEFAULT)
# self.settings.bind("window-maximized", self, "maximized", Gio.SettingsBindFlags.DEFAULT)
def _load_page_templates(self):
self.home_page = HomePage(parent=self.viewstack)
self.checklist_page = ChecklistPage(parent=self.viewstack, window=self)
self.settings_page = SettingsPage(parent=self.viewstack)
def _reset_all(self, param):
self._profile.clear()
button = self.checklist_page.btns_basic.get_first_child()
while button is not None:
if isinstance(button, Gtk.ToggleButton):
button.set_active(False)
button = button.get_next_sibling()
button = self.checklist_page.btns_prime.get_first_child()
while button is not None:
if isinstance(button, Gtk.ToggleButton):
button.set_active(False)
button = button.get_next_sibling()
save_profile(self._profile)
def _on_close_request(self, *args):
save_profile(self._profile)
self.app.save_profile(self.app.profile)
return False