cartridges: Make GSettings constant
This commit is contained in:
@@ -24,8 +24,8 @@ from gi.repository import Gio, GLib
|
|||||||
from .config import APP_ID, LOCALEDIR, PKGDATADIR
|
from .config import APP_ID, LOCALEDIR, PKGDATADIR
|
||||||
|
|
||||||
DATA_DIR = Path(GLib.get_user_data_dir(), "cartridges")
|
DATA_DIR = Path(GLib.get_user_data_dir(), "cartridges")
|
||||||
settings = Gio.Settings.new(APP_ID)
|
SETTINGS = Gio.Settings.new(APP_ID)
|
||||||
state_settings = Gio.Settings.new(f"{APP_ID}.State")
|
STATE_SETTINGS = Gio.Settings.new(f"{APP_ID}.State")
|
||||||
|
|
||||||
_RESOURCES = ("data", "icons", "ui")
|
_RESOURCES = ("data", "icons", "ui")
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from typing import Any
|
|||||||
|
|
||||||
from gi.repository import Gio, GObject
|
from gi.repository import Gio, GObject
|
||||||
|
|
||||||
from cartridges import settings
|
from cartridges import SETTINGS
|
||||||
|
|
||||||
|
|
||||||
class Collection(GObject.Object):
|
class Collection(GObject.Object):
|
||||||
@@ -35,7 +35,7 @@ class Collection(GObject.Object):
|
|||||||
|
|
||||||
|
|
||||||
def _get_collections() -> Generator[Collection]:
|
def _get_collections() -> Generator[Collection]:
|
||||||
for data in settings.get_value("collections").unpack():
|
for data in SETTINGS.get_value("collections").unpack():
|
||||||
if data.get("removed"):
|
if data.get("removed"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from typing import Any, override
|
|||||||
|
|
||||||
from gi.repository import Gtk
|
from gi.repository import Gtk
|
||||||
|
|
||||||
from cartridges import state_settings
|
from cartridges import STATE_SETTINGS
|
||||||
from cartridges.games import Game
|
from cartridges.games import Game
|
||||||
|
|
||||||
_SORT_MODES = {
|
_SORT_MODES = {
|
||||||
@@ -31,13 +31,13 @@ class GameSorter(Gtk.Sorter):
|
|||||||
def __init__(self, **kwargs: Any):
|
def __init__(self, **kwargs: Any):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
|
|
||||||
state_settings.connect(
|
STATE_SETTINGS.connect(
|
||||||
"changed::sort-mode", lambda *_: self.changed(Gtk.SorterChange.DIFFERENT)
|
"changed::sort-mode", lambda *_: self.changed(Gtk.SorterChange.DIFFERENT)
|
||||||
)
|
)
|
||||||
|
|
||||||
@override
|
@override
|
||||||
def do_compare(self, game1: Game, game2: Game) -> Gtk.Ordering: # pyright: ignore[reportIncompatibleMethodOverride]
|
def do_compare(self, game1: Game, game2: Game) -> Gtk.Ordering: # pyright: ignore[reportIncompatibleMethodOverride]
|
||||||
prop, invert = _SORT_MODES[state_settings.get_string("sort-mode")]
|
prop, invert = _SORT_MODES[STATE_SETTINGS.get_string("sort-mode")]
|
||||||
a = (game2 if invert else game1).get_property(prop)
|
a = (game2 if invert else game1).get_property(prop)
|
||||||
b = (game1 if invert else game2).get_property(prop)
|
b = (game1 if invert else game2).get_property(prop)
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from typing import Any, TypeVar, cast
|
|||||||
|
|
||||||
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
||||||
|
|
||||||
from cartridges import collections, games, state_settings
|
from cartridges import STATE_SETTINGS, collections, games
|
||||||
from cartridges.collections import Collection
|
from cartridges.collections import Collection
|
||||||
from cartridges.config import PREFIX, PROFILE
|
from cartridges.config import PREFIX, PROFILE
|
||||||
from cartridges.games import Game
|
from cartridges.games import Game
|
||||||
@@ -78,10 +78,10 @@ class Window(Adw.ApplicationWindow):
|
|||||||
self.settings = self.get_settings()
|
self.settings = self.get_settings()
|
||||||
|
|
||||||
flags = Gio.SettingsBindFlags.DEFAULT
|
flags = Gio.SettingsBindFlags.DEFAULT
|
||||||
state_settings.bind("width", self, "default-width", flags)
|
STATE_SETTINGS.bind("width", self, "default-width", flags)
|
||||||
state_settings.bind("height", self, "default-height", flags)
|
STATE_SETTINGS.bind("height", self, "default-height", flags)
|
||||||
state_settings.bind("is-maximized", self, "maximized", flags)
|
STATE_SETTINGS.bind("is-maximized", self, "maximized", flags)
|
||||||
state_settings.bind("show-sidebar", self.split_view, "show-sidebar", flags)
|
STATE_SETTINGS.bind("show-sidebar", self.split_view, "show-sidebar", flags)
|
||||||
|
|
||||||
# https://gitlab.gnome.org/GNOME/gtk/-/issues/7901
|
# https://gitlab.gnome.org/GNOME/gtk/-/issues/7901
|
||||||
self.search_entry.set_key_capture_widget(self)
|
self.search_entry.set_key_capture_widget(self)
|
||||||
@@ -90,8 +90,8 @@ class Window(Adw.ApplicationWindow):
|
|||||||
lambda collection: CollectionSidebarItem(collection=collection),
|
lambda collection: CollectionSidebarItem(collection=collection),
|
||||||
)
|
)
|
||||||
|
|
||||||
self.add_action(state_settings.create_action("show-sidebar"))
|
self.add_action(STATE_SETTINGS.create_action("show-sidebar"))
|
||||||
self.add_action(state_settings.create_action("sort-mode"))
|
self.add_action(STATE_SETTINGS.create_action("sort-mode"))
|
||||||
self.add_action(Gio.PropertyAction.new("show-hidden", self, "show-hidden"))
|
self.add_action(Gio.PropertyAction.new("show-hidden", self, "show-hidden"))
|
||||||
self.add_action_entries((
|
self.add_action_entries((
|
||||||
("search", lambda *_: self.search_entry.grab_focus()),
|
("search", lambda *_: self.search_entry.grab_focus()),
|
||||||
|
|||||||
Reference in New Issue
Block a user