further rewrites, interface fixes, added temporary icon
This commit is contained in:
2
src/gnomeframe/backend.py
Normal file
2
src/gnomeframe/backend.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This class manages the backend of the application, specifically profiles
|
||||
#
|
||||
@@ -19,11 +19,12 @@
|
||||
|
||||
import sys
|
||||
import gi
|
||||
import os
|
||||
|
||||
gi.require_version('Gtk', '4.0')
|
||||
gi.require_version('Adw', '1')
|
||||
|
||||
from gi.repository import Gtk, Gio, Adw
|
||||
from gi.repository import Gtk, Gio, Adw, GLib
|
||||
from .window import GnomeframeWindow
|
||||
|
||||
|
||||
@@ -33,6 +34,11 @@ class GnomeframeApplication(Adw.Application):
|
||||
super().__init__(application_id='gay.valhrafnaz.Gnomeframe',
|
||||
flags=Gio.ApplicationFlags.DEFAULT_FLAGS,
|
||||
resource_base_path='/gay/valhrafnaz/Gnomeframe')
|
||||
|
||||
data_dir = GLib.get_system_data_dirs()[0]
|
||||
resource = Gio.resource_load(os.path.join(data_dir, 'gnomeframe', 'gnomeframe.gresource'))
|
||||
Gio.Resource._register(resource)
|
||||
|
||||
self.create_action('quit', lambda *_: self.quit(), ['<control>q'])
|
||||
self.create_action('about', self.on_about_action)
|
||||
self.create_action('preferences', self.on_preferences_action)
|
||||
@@ -52,9 +58,9 @@ class GnomeframeApplication(Adw.Application):
|
||||
"""Callback for the app.about action."""
|
||||
about = Adw.AboutDialog(application_name='gnomeframe',
|
||||
application_icon='gay.valhrafnaz.Gnomeframe',
|
||||
developer_name='nihil',
|
||||
developer_name='valhrafnaz',
|
||||
version='0.1.0',
|
||||
developers=['nihil'],
|
||||
developers=['valhrafnaz'],
|
||||
copyright='© 2025 nihil')
|
||||
# Translators: Replace "translator-credits" with your name/username, and optionally an email or URL.
|
||||
about.set_translator_credits(_('translator-credits'))
|
||||
|
||||
@@ -4,11 +4,38 @@ import math
|
||||
from pathlib import Path
|
||||
from gi.repository import Gtk, Adw, GObject, 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
|
||||
|
||||
TOTAL_WARFRAMES=62 # pre uriel, valid until 10-12-2025
|
||||
APP_ID = "gay.valhrafnaz.Gnomeframe"
|
||||
CONFIG_DIR = get_config_dir(APP_ID)
|
||||
CONFIG_FILE = CONFIG_DIR / "profile.json"
|
||||
TOTAL_WARFRAMES=63 # post uriel, valid until whenever really
|
||||
TOTAL_PRIMES=49 # post gyre prime, valid until ca. may-2026
|
||||
|
||||
|
||||
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}")
|
||||
|
||||
frame_button_ids = [
|
||||
"ash",
|
||||
"atlas",
|
||||
@@ -138,7 +165,7 @@ frame_button_ids = [
|
||||
@Gtk.Template(resource_path="/gay/valhrafnaz/Gnomeframe/ui/checklist.ui")
|
||||
class ChecklistPage(Gtk.Box):
|
||||
__gtype_name__ = "ChecklistPage"
|
||||
|
||||
|
||||
# tooling for checklist
|
||||
frame_box = Gtk.Template.Child()
|
||||
btns_basic = Gtk.Template.Child()
|
||||
@@ -147,17 +174,17 @@ class ChecklistPage(Gtk.Box):
|
||||
basic_percent = Gtk.Template.Child()
|
||||
prime_counter = Gtk.Template.Child()
|
||||
prime_percent = Gtk.Template.Child()
|
||||
|
||||
|
||||
def __init__(self, *, parent: Adw.ViewStack, window):
|
||||
super().__init__()
|
||||
self._parent_window = window
|
||||
parent.add_titled(self, "checklist", "Checklist")
|
||||
wrapper = parent.get_page(self)
|
||||
wrapper.set_icon_name("check-round-outline2-symbolic")
|
||||
|
||||
|
||||
self._connect_frame_btns()
|
||||
self._calc_frames()
|
||||
|
||||
|
||||
def _connect_frame_btns(self):
|
||||
button = self.btns_basic.get_first_child()
|
||||
while button is not None:
|
||||
@@ -209,8 +236,8 @@ class ChecklistPage(Gtk.Box):
|
||||
if btn_id == "GtkToggleButton":
|
||||
print("what")
|
||||
return
|
||||
self._profile[btn_id] = btn.get_active()
|
||||
super.save_profile(self._profile)
|
||||
self._parent_window._profile[btn_id] = btn.get_active()
|
||||
save_profile(self._parent_window._profile)
|
||||
self._calc_frames()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ 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)
|
||||
print(f"Found config dir at: {cfg_dir}")
|
||||
return cfg_dir
|
||||
|
||||
APP_ID = "gay.valhrafnaz.Gnomeframe"
|
||||
@@ -66,9 +65,10 @@ def save_profile(state: dict[str, bool]) -> None:
|
||||
@Gtk.Template(resource_path='/gay/valhrafnaz/Gnomeframe/ui/window.ui')
|
||||
class GnomeframeWindow(Adw.ApplicationWindow):
|
||||
__gtype_name__ = 'GnomeframeWindow'
|
||||
|
||||
|
||||
viewstack = Gtk.Template.Child()
|
||||
|
||||
btn_reset_profile = Gtk.Template.Child()
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@@ -79,19 +79,20 @@ class GnomeframeWindow(Adw.ApplicationWindow):
|
||||
reset_action.connect("activate", self._reset_all)
|
||||
self.get_application().add_action(reset_action)
|
||||
|
||||
self.btn_reset_profile.connect("clicked", self._reset_all)
|
||||
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.settings_page = SettingsPage(parent=self.viewstack)
|
||||
self.checklist_page = ChecklistPage(parent=self.viewstack, window=self)
|
||||
self.settings_page = SettingsPage(parent=self.viewstack)
|
||||
|
||||
def _reset_all(self, action, param):
|
||||
def _reset_all(self, param):
|
||||
self._profile.clear()
|
||||
button = self.checklist_page.btns_basic.get_first_child()
|
||||
while button is not None:
|
||||
|
||||
Reference in New Issue
Block a user