Compare commits
5 Commits
rewrite-cl
...
rewrite-si
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
faaef4bd5e | ||
|
|
3c18ae0964 | ||
|
|
46a30614c3 | ||
|
|
afa9b4ca84 | ||
|
|
b6d73e0efe |
@@ -19,11 +19,6 @@ class Application(Adw.Application):
|
||||
def __init__(self):
|
||||
super().__init__(application_id=APP_ID)
|
||||
|
||||
@override
|
||||
def do_startup(self):
|
||||
Adw.Application.do_startup(self)
|
||||
self.props.style_manager.props.color_scheme = Adw.ColorScheme.PREFER_DARK
|
||||
|
||||
self.add_action_entries((
|
||||
("quit", lambda *_: self.quit()),
|
||||
("about", lambda *_: self._present_about_dialog()),
|
||||
@@ -33,6 +28,11 @@ class Application(Adw.Application):
|
||||
sources.load()
|
||||
collections.load()
|
||||
|
||||
@override
|
||||
def do_startup(self):
|
||||
Adw.Application.do_startup(self)
|
||||
Adw.StyleManager.get_default().props.color_scheme = Adw.ColorScheme.PREFER_DARK
|
||||
|
||||
@override
|
||||
def do_activate(self):
|
||||
window = self.props.active_window or Window(application=self)
|
||||
|
||||
@@ -112,6 +112,11 @@ class Gamepad(GObject.Object):
|
||||
focus_widget.activate()
|
||||
return
|
||||
|
||||
if self.window.sidebar.get_focus_child():
|
||||
selected_item = self.window.sidebar.get_selected_item()
|
||||
self.window.navigate_sidebar(self.window.sidebar, item=selected_item)
|
||||
return
|
||||
|
||||
self.window.grid.activate_action(
|
||||
"list.activate-item",
|
||||
GLib.Variant.new_uint32(self._get_current_position()),
|
||||
@@ -136,7 +141,20 @@ class Gamepad(GObject.Object):
|
||||
open_menu.grab_focus()
|
||||
return
|
||||
|
||||
self.window.grid.grab_focus()
|
||||
grid_visible = self.window.view_stack.props.visible_child_name == "grid"
|
||||
if self._is_focused_on_top_bar():
|
||||
focus_widget = self.window.grid if grid_visible else self.window.sidebar
|
||||
|
||||
# If the grid is not visible (i.e no search results or imports)
|
||||
# the searchbar is focused as a fallback.
|
||||
fallback_child = (
|
||||
self.window.grid
|
||||
if self.window.sidebar.get_focus_child()
|
||||
else self.window.sidebar
|
||||
)
|
||||
focus_widget = fallback_child if grid_visible else self.window.search_entry
|
||||
|
||||
focus_widget.grab_focus()
|
||||
self.window.props.focus_visible = True
|
||||
|
||||
def _navigate_to_game_position(self, new_pos: int):
|
||||
@@ -147,24 +165,67 @@ class Gamepad(GObject.Object):
|
||||
|
||||
def _move_horizontally(self, direction: Gtk.DirectionType):
|
||||
if self._is_focused_on_top_bar():
|
||||
if not self.window.header_bar.child_focus(direction):
|
||||
self.window.header_bar.keynav_failed(direction)
|
||||
if self.window.header_bar.child_focus(direction):
|
||||
self.window.props.focus_visible = True
|
||||
return
|
||||
|
||||
# The usual behaviour of child_focus() on the header bar on the
|
||||
# left will result in the above child focus to fail, so
|
||||
# we need to manually check the user is going left to then focus the
|
||||
# sidebar.
|
||||
|
||||
if direction is not self._get_rtl_direction(
|
||||
Gtk.DirectionType.RIGHT, Gtk.DirectionType.LEFT
|
||||
):
|
||||
self.window.header_bar.keynav_failed(direction)
|
||||
return
|
||||
|
||||
self.window.sidebar.grab_focus()
|
||||
self.window.props.focus_visible = True
|
||||
return
|
||||
|
||||
if self._can_navigate_games_page():
|
||||
self._navigate_to_game_position(
|
||||
self._get_current_position()
|
||||
+ (
|
||||
-1
|
||||
if direction
|
||||
== self._get_rtl_direction(
|
||||
Gtk.DirectionType.RIGHT, Gtk.DirectionType.LEFT
|
||||
)
|
||||
else 1
|
||||
)
|
||||
if self.window.sidebar.get_focus_child():
|
||||
# The usual behaviour of child_focus() on the sidebar
|
||||
# would result in the + button being focused, instead of the grid
|
||||
# so we need to grab the focus of the grid if the user inputs the
|
||||
# corresponding direction to the grid.
|
||||
|
||||
grid_direction = self._get_rtl_direction(
|
||||
Gtk.DirectionType.LEFT, Gtk.DirectionType.RIGHT
|
||||
)
|
||||
|
||||
# Focus the first game when re-entering from sidebar
|
||||
if direction is grid_direction:
|
||||
self.window.grid.scroll_to(0, Gtk.ListScrollFlags.FOCUS, None)
|
||||
self.window.grid.grab_focus()
|
||||
return
|
||||
|
||||
self.window.sidebar.keynav_failed(direction)
|
||||
return
|
||||
|
||||
if self._can_navigate_games_page():
|
||||
if not self._get_focused_game():
|
||||
return
|
||||
|
||||
new_pos = self._get_current_position() + (
|
||||
-1
|
||||
if direction
|
||||
== self._get_rtl_direction(
|
||||
Gtk.DirectionType.RIGHT, Gtk.DirectionType.LEFT
|
||||
)
|
||||
else 1
|
||||
)
|
||||
|
||||
# If the user is focused on the first game and tries to go
|
||||
# back another game, instead of failing, the focus should
|
||||
# change to the sidebar.
|
||||
|
||||
if new_pos < 0:
|
||||
self.window.sidebar.grab_focus()
|
||||
self.window.props.focus_visible = True
|
||||
return
|
||||
|
||||
self._navigate_to_game_position(new_pos)
|
||||
return
|
||||
|
||||
if self.window.navigation_view.props.visible_page_tag == "details":
|
||||
@@ -184,6 +245,14 @@ class Gamepad(GObject.Object):
|
||||
self.window.grid.grab_focus()
|
||||
return
|
||||
|
||||
if self.window.sidebar.get_focus_child():
|
||||
if self.window.sidebar.child_focus(direction):
|
||||
self.window.props.focus_visible = True
|
||||
return
|
||||
|
||||
self.window.sidebar.keynav_failed(direction)
|
||||
return
|
||||
|
||||
if self._can_navigate_games_page():
|
||||
if not (game := self._get_focused_game()):
|
||||
return
|
||||
|
||||
@@ -54,8 +54,6 @@ class _SourceModule(Protocol):
|
||||
class Source(GObject.Object, Gio.ListModel): # pyright: ignore[reportIncompatibleMethodOverride]
|
||||
"""A source of games to import."""
|
||||
|
||||
__gtype_name__ = __qualname__
|
||||
|
||||
id = GObject.Property(type=str)
|
||||
name = GObject.Property(type=str)
|
||||
icon_name = GObject.Property(type=str)
|
||||
@@ -67,11 +65,11 @@ class Source(GObject.Object, Gio.ListModel): # pyright: ignore[reportIncompatib
|
||||
|
||||
self.id, self.name, self._module = module.ID, module.NAME, module
|
||||
self.bind_property(
|
||||
"id",
|
||||
"name",
|
||||
self,
|
||||
"icon-name",
|
||||
GObject.BindingFlags.SYNC_CREATE,
|
||||
lambda _, ident: f"{ident}-symbolic",
|
||||
lambda _, name: f"{name}-symbolic",
|
||||
)
|
||||
|
||||
try:
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel
|
||||
|
||||
from collections.abc import Callable
|
||||
from typing import Any
|
||||
|
||||
from gi.repository import Gtk
|
||||
|
||||
|
||||
def _closure[**P, R](func: Callable[P, R]) -> object: # gi._gtktemplate.CallThing
|
||||
@Gtk.Template.Callback()
|
||||
@staticmethod
|
||||
def wrapper(_obj, *args: P.args, **kwargs: P.kwargs) -> R:
|
||||
return func(*args, **kwargs)
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
@_closure
|
||||
def boolean(value: object) -> bool:
|
||||
"""Get a boolean for `value`."""
|
||||
return bool(value)
|
||||
|
||||
|
||||
@_closure
|
||||
def concat(*strings: str) -> str:
|
||||
"""Join `strings`."""
|
||||
return "".join(strings)
|
||||
|
||||
|
||||
@_closure
|
||||
def either[T](first: T, second: T) -> T:
|
||||
"""Return `first` or `second`."""
|
||||
return first or second
|
||||
|
||||
|
||||
@_closure
|
||||
def format_string(string: str, *args: Any) -> str:
|
||||
"""Format `string` with `args`."""
|
||||
return string.format(*args)
|
||||
|
||||
|
||||
@_closure
|
||||
def if_else[T](condition: object, first: T, second: T) -> T:
|
||||
"""Return `first` or `second` depending on `condition`."""
|
||||
return first if condition else second
|
||||
@@ -2,7 +2,7 @@ using Gtk 4.0;
|
||||
using Adw 1;
|
||||
|
||||
template $CollectionDetails: Adw.Dialog {
|
||||
title: bind $either(template.collection as <$Collection>.name, _("New Collection")) as <string>;
|
||||
title: bind $_or(template.collection as <$Collection>.name, _("New Collection")) as <string>;
|
||||
content-width: 360;
|
||||
default-widget: apply_button;
|
||||
focus-widget: name_entry;
|
||||
@@ -31,7 +31,7 @@ template $CollectionDetails: Adw.Dialog {
|
||||
Button apply_button {
|
||||
action-name: "details.apply";
|
||||
icon-name: "apply-symbolic";
|
||||
tooltip-text: bind $if_else(template.collection as <$Collection>.in-model, _("Apply"), _("Add")) as <string>;
|
||||
tooltip-text: bind $_if_else(template.collection as <$Collection>.in-model, _("Apply"), _("Add")) as <string>;
|
||||
|
||||
styles [
|
||||
"suggested-action",
|
||||
|
||||
@@ -2,14 +2,13 @@
|
||||
# SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel
|
||||
|
||||
from itertools import product
|
||||
from typing import Any, NamedTuple, cast
|
||||
from typing import Any, NamedTuple, TypeVar, cast
|
||||
|
||||
from gi.repository import Adw, Gio, GObject, Gtk
|
||||
|
||||
from cartridges import collections
|
||||
from cartridges.collections import Collection
|
||||
from cartridges.config import PREFIX
|
||||
from cartridges.ui import closures
|
||||
|
||||
|
||||
class _Icon(NamedTuple):
|
||||
@@ -41,6 +40,8 @@ _ICONS = (
|
||||
_Icon("fist", "✊"),
|
||||
)
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
|
||||
@Gtk.Template.from_resource(f"{PREFIX}/collection-details.ui")
|
||||
class CollectionDetails(Adw.Dialog):
|
||||
@@ -55,9 +56,6 @@ class CollectionDetails(Adw.Dialog):
|
||||
|
||||
_selected_icon: str
|
||||
|
||||
either = closures.either
|
||||
if_else = closures.if_else
|
||||
|
||||
@GObject.Property(type=Collection)
|
||||
def collection(self) -> Collection:
|
||||
"""The collection that `self` represents."""
|
||||
@@ -132,3 +130,11 @@ class CollectionDetails(Adw.Dialog):
|
||||
|
||||
collections.save()
|
||||
self.close()
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _or(self, _obj, first: _T, second: _T) -> _T:
|
||||
return first or second
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _if_else(self, _obj, condition: object, first: _T, second: _T) -> _T:
|
||||
return first if condition else second
|
||||
|
||||
@@ -5,27 +5,27 @@ template $Cover: Adw.Bin {
|
||||
child: Adw.Clamp {
|
||||
orientation: vertical;
|
||||
unit: px;
|
||||
maximum-size: bind template.height;
|
||||
tightening-threshold: bind template.height;
|
||||
maximum-size: bind _picture.height-request;
|
||||
tightening-threshold: bind _picture.height-request;
|
||||
|
||||
child: Adw.Clamp {
|
||||
unit: px;
|
||||
maximum-size: bind template.width;
|
||||
tightening-threshold: bind template.width;
|
||||
maximum-size: bind _picture.width-request;
|
||||
tightening-threshold: bind _picture.width-request;
|
||||
|
||||
child: Adw.ViewStack {
|
||||
name: "cover";
|
||||
visible-child-name: bind $if_else(template.paintable, "cover", "icon") as <string>;
|
||||
visible-child-name: bind $_get_stack_child(template.paintable) as <string>;
|
||||
overflow: hidden;
|
||||
enable-transitions: true;
|
||||
|
||||
Adw.ViewStackPage {
|
||||
name: "cover";
|
||||
|
||||
child: Picture {
|
||||
child: Picture _picture {
|
||||
paintable: bind template.paintable;
|
||||
width-request: bind template.width;
|
||||
height-request: bind template.height;
|
||||
width-request: 200;
|
||||
height-request: 300;
|
||||
content-fit: cover;
|
||||
};
|
||||
}
|
||||
@@ -34,10 +34,7 @@ template $Cover: Adw.Bin {
|
||||
name: "icon";
|
||||
|
||||
child: Image {
|
||||
icon-name: bind $concat(
|
||||
template.root as <Window>.application as <Application>.application-id,
|
||||
"-symbolic"
|
||||
) as <string>;
|
||||
icon-name: bind template.app-icon-name;
|
||||
pixel-size: 80;
|
||||
|
||||
styles [
|
||||
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
from gi.repository import Adw, Gdk, GObject, Gtk
|
||||
|
||||
from cartridges.config import PREFIX
|
||||
from cartridges.ui import closures
|
||||
from cartridges.config import APP_ID, PREFIX
|
||||
|
||||
|
||||
@Gtk.Template.from_resource(f"{PREFIX}/cover.ui")
|
||||
@@ -13,9 +12,12 @@ class Cover(Adw.Bin):
|
||||
|
||||
__gtype_name__ = __qualname__
|
||||
|
||||
picture = GObject.Property(lambda self: self._picture, type=Gtk.Picture)
|
||||
paintable = GObject.Property(type=Gdk.Paintable)
|
||||
width = GObject.Property(type=int, default=200)
|
||||
height = GObject.Property(type=int, default=300)
|
||||
app_icon_name = GObject.Property(type=str, default=f"{APP_ID}-symbolic")
|
||||
|
||||
concat = closures.concat
|
||||
if_else = closures.if_else
|
||||
_picture = Gtk.Template.Child()
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _get_stack_child(self, _obj, paintable: Gdk.Paintable | None) -> str:
|
||||
return "cover" if paintable else "icon"
|
||||
|
||||
@@ -5,7 +5,7 @@ using Adw 1;
|
||||
template $GameDetails: Adw.NavigationPage {
|
||||
name: "details";
|
||||
tag: "details";
|
||||
title: bind $either(template.game as <$Game>.name, _("Add Game")) as <string>;
|
||||
title: bind $_or(template.game as <$Game>.name, _("Add Game")) as <string>;
|
||||
hidden => $_cancel();
|
||||
|
||||
ShortcutController {
|
||||
@@ -101,7 +101,7 @@ template $GameDetails: Adw.NavigationPage {
|
||||
|
||||
Label developer_label {
|
||||
label: bind template.game as <$Game>.developer;
|
||||
visible: bind $boolean(template.game as <$Game>.developer) as <bool>;
|
||||
visible: bind $_bool(template.game as <$Game>.developer) as <bool>;
|
||||
halign: start;
|
||||
max-width-chars: 36;
|
||||
wrap: true;
|
||||
@@ -119,20 +119,14 @@ template $GameDetails: Adw.NavigationPage {
|
||||
spacing: 9;
|
||||
|
||||
Label last_played_label {
|
||||
label: bind $format_string(
|
||||
_("Last played: {}"),
|
||||
$_pretty_date(template.game as <$Game>.last_played) as <string>
|
||||
) as <string>;
|
||||
label: bind $_date_label(_("Last played: {}"), template.game as <$Game>.last_played) as <string>;
|
||||
halign: start;
|
||||
wrap: true;
|
||||
wrap-mode: word_char;
|
||||
}
|
||||
|
||||
Label added_label {
|
||||
label: bind $format_string(
|
||||
_("Added: {}"),
|
||||
$_pretty_date(template.game as <$Game>.added) as <string>
|
||||
) as <string>;
|
||||
label: bind $_date_label(_("Added: {}"), template.game as <$Game>.added) as <string>;
|
||||
halign: start;
|
||||
wrap: true;
|
||||
wrap-mode: word_char;
|
||||
@@ -382,7 +376,7 @@ template $GameDetails: Adw.NavigationPage {
|
||||
|
||||
Button apply_button {
|
||||
action-name: "details.apply";
|
||||
label: bind $if_else(template.game as <$Game>.added, _("Apply"), _("Add")) as <string>;
|
||||
label: bind $_if_else(template.game as <$Game>.added, _("Apply"), _("Add")) as <string>;
|
||||
|
||||
styles [
|
||||
"pill",
|
||||
|
||||
@@ -12,8 +12,8 @@ template $GameItem: Box {
|
||||
|
||||
Adw.Clamp {
|
||||
unit: px;
|
||||
maximum-size: bind cover.width;
|
||||
tightening-threshold: bind cover.width;
|
||||
maximum-size: bind cover.picture as <Picture>.width-request;
|
||||
tightening-threshold: bind cover.picture as <Picture>.width-request;
|
||||
|
||||
child: Overlay {
|
||||
child: $Cover cover {
|
||||
|
||||
@@ -7,7 +7,7 @@ import sys
|
||||
import time
|
||||
from datetime import UTC, datetime
|
||||
from gettext import gettext as _
|
||||
from typing import Any, cast
|
||||
from typing import Any, TypeVar, cast
|
||||
from urllib.parse import quote
|
||||
|
||||
from gi.repository import Adw, Gdk, Gio, GLib, GObject, Gtk
|
||||
@@ -16,7 +16,6 @@ from cartridges import games, sources
|
||||
from cartridges.config import PREFIX
|
||||
from cartridges.games import Game
|
||||
from cartridges.sources import imported
|
||||
from cartridges.ui import closures
|
||||
|
||||
from .collections import CollectionsBox
|
||||
from .cover import Cover # noqa: F401
|
||||
@@ -27,6 +26,8 @@ _REQUIRED_PROPERTIES = {
|
||||
prop.name for prop in games.PROPERTIES if prop.editable and prop.required
|
||||
}
|
||||
|
||||
_T = TypeVar("_T")
|
||||
|
||||
|
||||
@Gtk.Template.from_resource(f"{PREFIX}/game-details.ui")
|
||||
class GameDetails(Adw.NavigationPage):
|
||||
@@ -43,11 +44,6 @@ class GameDetails(Adw.NavigationPage):
|
||||
|
||||
sort_changed = GObject.Signal()
|
||||
|
||||
boolean = closures.boolean
|
||||
either = closures.either
|
||||
format_string = closures.format_string
|
||||
if_else = closures.if_else
|
||||
|
||||
@GObject.Property(type=Game)
|
||||
def game(self) -> Game:
|
||||
"""The game whose details to show."""
|
||||
@@ -151,6 +147,14 @@ class GameDetails(Adw.NavigationPage):
|
||||
else:
|
||||
self.collections_box.finish()
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _or(self, _obj, first: _T, second: _T) -> _T:
|
||||
return first or second
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _if_else(self, _obj, condition: object, first: _T, second: _T) -> _T:
|
||||
return first if condition else second
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _downscale_image(self, _obj, cover: Gdk.Texture | None) -> Gdk.Texture | None:
|
||||
if cover and (renderer := cast(Gtk.Native, self.props.root).get_renderer()):
|
||||
@@ -161,10 +165,10 @@ class GameDetails(Adw.NavigationPage):
|
||||
return None
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _pretty_date(self, _obj, timestamp: int) -> str:
|
||||
def _date_label(self, _obj, label: str, timestamp: int) -> str:
|
||||
date = datetime.fromtimestamp(timestamp, UTC)
|
||||
now = datetime.now(UTC)
|
||||
return (
|
||||
return label.format(
|
||||
_("Never")
|
||||
if not timestamp
|
||||
else _("Today")
|
||||
@@ -186,6 +190,10 @@ class GameDetails(Adw.NavigationPage):
|
||||
else date.strftime("%Y")
|
||||
)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _bool(self, _obj, o: object) -> bool:
|
||||
return bool(o)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _format_more_info(self, _obj, label: str) -> str:
|
||||
executable = _("program")
|
||||
|
||||
@@ -19,24 +19,7 @@ _SORT_MODES = {
|
||||
"oldest": ("added", False),
|
||||
}
|
||||
|
||||
filter_ = Gtk.EveryFilter()
|
||||
filter_.append(
|
||||
Gtk.BoolFilter(
|
||||
expression=Gtk.PropertyExpression.new(Game, None, "removed"),
|
||||
invert=True,
|
||||
)
|
||||
)
|
||||
filter_.append(
|
||||
Gtk.BoolFilter(
|
||||
expression=Gtk.PropertyExpression.new(Game, None, "blacklisted"),
|
||||
invert=True,
|
||||
)
|
||||
)
|
||||
model = Gtk.FilterListModel(
|
||||
model=Gtk.FlattenListModel.new(sources.model),
|
||||
filter=filter_,
|
||||
watch_items=True, # pyright: ignore[reportCallIssue]
|
||||
)
|
||||
model = Gtk.FlattenListModel.new(sources.model)
|
||||
|
||||
|
||||
class GameSorter(Gtk.Sorter):
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
python.install_sources(
|
||||
files(
|
||||
'__init__.py',
|
||||
'closures.py',
|
||||
'collection_details.py',
|
||||
'collections.py',
|
||||
'cover.py',
|
||||
'game_details.py',
|
||||
'game_item.py',
|
||||
'games.py',
|
||||
'sources.py',
|
||||
'window.py',
|
||||
),
|
||||
subdir: 'cartridges' / 'ui',
|
||||
|
||||
@@ -1,44 +0,0 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
# SPDX-FileCopyrightText: Copyright 2025 Jamie Gravendeel
|
||||
|
||||
from gi.repository import Adw, Gio, GObject, Gtk
|
||||
|
||||
from cartridges import sources
|
||||
from cartridges.sources import Source
|
||||
from cartridges.ui import games
|
||||
|
||||
|
||||
class SourceSidebarItem(Adw.SidebarItem): # pyright: ignore[reportAttributeAccessIssue]
|
||||
"""A sidebar item representing a source."""
|
||||
|
||||
model = GObject.Property(type=Gio.ListModel)
|
||||
|
||||
@GObject.Property(type=Source)
|
||||
def source(self) -> Source:
|
||||
"""The source that `self` represents."""
|
||||
return self._source
|
||||
|
||||
@source.setter
|
||||
def source(self, source: Source):
|
||||
self._source = source
|
||||
flags = GObject.BindingFlags.SYNC_CREATE
|
||||
source.bind_property("name", self, "title", flags)
|
||||
source.bind_property("icon-name", self, "icon-name", flags)
|
||||
|
||||
self.model = Gtk.FilterListModel(
|
||||
model=source,
|
||||
filter=games.filter_,
|
||||
watch_items=True, # pyright: ignore[reportCallIssue]
|
||||
)
|
||||
# https://gitlab.gnome.org/GNOME/gtk/-/issues/7959
|
||||
self.model.connect(
|
||||
"items-changed",
|
||||
lambda *_: self.set_property("visible", self.model.props.n_items),
|
||||
)
|
||||
self.props.visible = self.model.props.n_items
|
||||
|
||||
|
||||
model = Gtk.SortListModel.new(
|
||||
sources.model,
|
||||
Gtk.StringSorter.new(Gtk.PropertyExpression.new(Source, None, "name")),
|
||||
)
|
||||
@@ -94,10 +94,6 @@ template $Window: Adw.ApplicationWindow {
|
||||
}
|
||||
}
|
||||
|
||||
Adw.SidebarSection sources {
|
||||
title: _("Sources");
|
||||
}
|
||||
|
||||
Adw.SidebarSection collections {
|
||||
title: _("Collections");
|
||||
|
||||
@@ -212,17 +208,17 @@ template $Window: Adw.ApplicationWindow {
|
||||
}
|
||||
|
||||
content: Adw.ToastOverlay toast_overlay {
|
||||
child: Adw.ViewStack {
|
||||
visible-child-name: bind $if_else(
|
||||
child: Adw.ViewStack view_stack {
|
||||
visible-child-name: bind $_if_else(
|
||||
grid.model as <NoSelection>.n-items,
|
||||
"grid",
|
||||
$if_else(
|
||||
$_if_else(
|
||||
template.search-text,
|
||||
"empty-search",
|
||||
$if_else(
|
||||
$_if_else(
|
||||
template.collection,
|
||||
"empty-collection",
|
||||
$if_else(template.show-hidden, "empty-hidden", "empty") as <string>
|
||||
$_if_else(template.show-hidden, "empty-hidden", "empty") as <string>
|
||||
) as <string>
|
||||
) as <string>
|
||||
) as <string>;
|
||||
@@ -266,6 +262,16 @@ template $Window: Adw.ApplicationWindow {
|
||||
expression: expr item as <$Game>.hidden;
|
||||
invert: bind template.show-hidden inverted;
|
||||
}
|
||||
|
||||
BoolFilter {
|
||||
expression: expr item as <$Game>.removed;
|
||||
invert: true;
|
||||
}
|
||||
|
||||
BoolFilter {
|
||||
expression: expr item as <$Game>.blacklisted;
|
||||
invert: true;
|
||||
}
|
||||
};
|
||||
|
||||
model: bind template.model;
|
||||
@@ -310,10 +316,7 @@ template $Window: Adw.ApplicationWindow {
|
||||
|
||||
child: Adw.StatusPage {
|
||||
icon-name: bind template.collection as <$Collection>.icon-name;
|
||||
title: bind $format_string(
|
||||
_("No Games in {}"),
|
||||
template.collection as <$Collection>.name,
|
||||
) as <string>;
|
||||
title: bind $_format(_("No Games in {}"), template.collection as <$Collection>.name) as <string>;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,22 +6,21 @@
|
||||
import sys
|
||||
from collections.abc import Callable
|
||||
from gettext import gettext as _
|
||||
from typing import Any, cast
|
||||
from typing import Any, TypeVar, cast
|
||||
|
||||
from gi.repository import Adw, Gio, GLib, GObject, Gtk
|
||||
|
||||
from cartridges import STATE_SETTINGS
|
||||
from cartridges.collections import Collection
|
||||
from cartridges.config import PREFIX, PROFILE
|
||||
from cartridges.sources import Source, imported
|
||||
from cartridges.ui import closures, collections, games, sources
|
||||
from cartridges.sources import imported
|
||||
from cartridges.ui import collections, games
|
||||
|
||||
from .collection_details import CollectionDetails
|
||||
from .collections import CollectionFilter, CollectionSidebarItem
|
||||
from .game_details import GameDetails
|
||||
from .game_item import GameItem # noqa: F401
|
||||
from .games import GameSorter
|
||||
from .sources import SourceSidebarItem
|
||||
|
||||
if sys.platform.startswith("linux"):
|
||||
from cartridges import gamepads
|
||||
@@ -35,6 +34,7 @@ SORT_MODES = {
|
||||
"oldest": ("added", True),
|
||||
}
|
||||
|
||||
_T = TypeVar("_T")
|
||||
type _UndoFunc = Callable[[], Any]
|
||||
|
||||
|
||||
@@ -46,7 +46,6 @@ class Window(Adw.ApplicationWindow):
|
||||
|
||||
split_view: Adw.OverlaySplitView = Gtk.Template.Child()
|
||||
sidebar: Adw.Sidebar = Gtk.Template.Child() # pyright: ignore[reportAttributeAccessIssue]
|
||||
sources: Adw.SidebarSection = Gtk.Template.Child() # pyright: ignore[reportAttributeAccessIssue]
|
||||
collections: Adw.SidebarSection = Gtk.Template.Child() # pyright: ignore[reportAttributeAccessIssue]
|
||||
new_collection_item: Adw.SidebarItem = Gtk.Template.Child() # pyright: ignore[reportAttributeAccessIssue]
|
||||
collection_menu: Gio.Menu = Gtk.Template.Child()
|
||||
@@ -57,6 +56,7 @@ class Window(Adw.ApplicationWindow):
|
||||
sort_button: Gtk.MenuButton = Gtk.Template.Child()
|
||||
main_menu_button: Gtk.MenuButton = Gtk.Template.Child()
|
||||
toast_overlay: Adw.ToastOverlay = Gtk.Template.Child()
|
||||
view_stack: Adw.ViewStack = Gtk.Template.Child()
|
||||
grid: Gtk.GridView = Gtk.Template.Child()
|
||||
sorter: GameSorter = Gtk.Template.Child()
|
||||
collection_filter: CollectionFilter = Gtk.Template.Child()
|
||||
@@ -73,9 +73,6 @@ class Window(Adw.ApplicationWindow):
|
||||
_collection_removed_signal: int | None = None
|
||||
_selected_sidebar_item = 0
|
||||
|
||||
format_string = closures.format_string
|
||||
if_else = closures.if_else
|
||||
|
||||
@GObject.Property(type=Collection)
|
||||
def collection(self) -> Collection | None:
|
||||
"""The currently selected collection."""
|
||||
@@ -113,7 +110,6 @@ class Window(Adw.ApplicationWindow):
|
||||
|
||||
# https://gitlab.gnome.org/GNOME/gtk/-/issues/7901
|
||||
self.search_entry.set_key_capture_widget(self)
|
||||
self.sources.bind_model(sources.model, self._create_source_item)
|
||||
self.collections.bind_model(
|
||||
collections.model,
|
||||
lambda collection: CollectionSidebarItem(collection=collection),
|
||||
@@ -168,17 +164,26 @@ class Window(Adw.ApplicationWindow):
|
||||
|
||||
self.toast_overlay.add_toast(toast)
|
||||
|
||||
def _create_source_item(self, source: Source) -> SourceSidebarItem:
|
||||
item = SourceSidebarItem(source=source)
|
||||
item.connect(
|
||||
"notify::visible",
|
||||
lambda item, _: self._source_empty() if not item.props.visible else None,
|
||||
)
|
||||
return item
|
||||
def navigate_sidebar(self, sidebar: Adw.Sidebar, item: Adw.SidebarItem): # pyright: ignore[reportAttributeAccessIssue]
|
||||
"""Select given item in the sidebar.
|
||||
|
||||
def _source_empty(self):
|
||||
self.model = games.model
|
||||
self.sidebar.props.selected = 0
|
||||
Item should correspond to a collection, or the all game category/
|
||||
new collection buttons.
|
||||
"""
|
||||
match item:
|
||||
case self.new_collection_item:
|
||||
self._add_collection()
|
||||
sidebar.props.selected = self._selected_sidebar_item
|
||||
case CollectionSidebarItem():
|
||||
self.collection = item.collection
|
||||
case _:
|
||||
self.collection = None
|
||||
|
||||
if item is not self.new_collection_item:
|
||||
self._selected_sidebar_item = sidebar.props.selected
|
||||
|
||||
if self.split_view.props.collapsed:
|
||||
self.split_view.props.show_sidebar = False
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _show_sidebar_title(self, _obj, layout: str) -> bool:
|
||||
@@ -187,27 +192,7 @@ class Window(Adw.ApplicationWindow):
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _navigate(self, sidebar: Adw.Sidebar, index: int): # pyright: ignore[reportAttributeAccessIssue]
|
||||
item = sidebar.get_item(index)
|
||||
|
||||
match item:
|
||||
case self.new_collection_item:
|
||||
self._add_collection()
|
||||
sidebar.props.selected = self._selected_sidebar_item
|
||||
case SourceSidebarItem():
|
||||
self.collection = None
|
||||
self.model = item.model
|
||||
case CollectionSidebarItem():
|
||||
self.collection = item.collection
|
||||
self.model = games.model
|
||||
case _:
|
||||
self.collection = None
|
||||
self.model = games.model
|
||||
|
||||
if item is not self.new_collection_item:
|
||||
self._selected_sidebar_item = index
|
||||
|
||||
if self.split_view.props.collapsed:
|
||||
self.split_view.props.show_sidebar = False
|
||||
self.navigate_sidebar(sidebar, sidebar.get_item(index))
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _update_selection(self, sidebar: Adw.Sidebar, *_args): # pyright: ignore[reportAttributeAccessIssue]
|
||||
@@ -235,6 +220,14 @@ class Window(Adw.ApplicationWindow):
|
||||
Gamepad.window = self # pyright: ignore[reportPossiblyUnboundVariable]
|
||||
gamepads.setup_monitor() # pyright: ignore[reportPossiblyUnboundVariable]
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _if_else(self, _obj, condition: object, first: _T, second: _T) -> _T:
|
||||
return first if condition else second
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _format(self, _obj, string: str, *args: Any) -> str:
|
||||
return string.format(*args)
|
||||
|
||||
@Gtk.Template.Callback()
|
||||
def _show_details(self, grid: Gtk.GridView, position: int):
|
||||
self.details.game = cast(Gio.ListModel, grid.props.model).get_item(position)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none"><path fill="#000" fill-rule="evenodd" d="m7.872 16-3.817-3.083L2 2.79 7.872 0l5.871 2.789-2.055 10.128zm0-4.257-.294-.293-.88-7.927 1.1-1.908 1.174 1.908-.807 7.927zm-.294.367-.147.367-1.761.294-.294-.66.294-.662 1.761.294zm-.073.734-.22 1.541.587.294.587-.294-.22-1.541-.367-.22zm.807-.367-.147-.367.147-.367 1.761-.293.294.66-.294.66z" clip-rule="evenodd"/></svg>
|
||||
|
Before Width: | Height: | Size: 440 B |
@@ -4,10 +4,6 @@
|
||||
<file>apply-symbolic.svg</file>
|
||||
<file>cancel-symbolic.svg</file>
|
||||
<file>filter-symbolic.svg</file>
|
||||
<!-- Sources -->
|
||||
<file>heroic-symbolic.svg</file>
|
||||
<file>imported-symbolic.svg</file>
|
||||
<file>steam-symbolic.svg</file>
|
||||
<!-- Categories -->
|
||||
<file>collection-symbolic.svg</file>
|
||||
<file>ball-symbolic.svg</file>
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="#222" d="M7 1v6H1v2h6v6h2V9h6V7H9V1zm0 0"/></svg>
|
||||
|
Before Width: | Height: | Size: 144 B |
@@ -1 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none"><g clip-path="url(#a)"><path fill="#000" fill-rule="evenodd" d="M9.352 5.1a1.509 1.509 0 1 0 2.51 1.675A1.509 1.509 0 0 0 9.352 5.1m2.923-.277a2.009 2.009 0 1 1-3.34 2.231 2.009 2.009 0 0 1 3.34-2.23ZM5.01 12.131l-.983-.407a1.7 1.7 0 0 0 3.108-.103 1.696 1.696 0 0 0-1.213-2.29 1.7 1.7 0 0 0-.966.07l1.015.421a1.249 1.249 0 0 1-.96 2.307zM2.546 2.121A8 8 0 0 1 7.966 0l.003.013a7.99 7.99 0 0 1 7.159 4.432 7.996 7.996 0 0 1-4.277 11.018 7.99 7.99 0 0 1-8.274-1.558A8 8 0 0 1 .279 10.18l3.064 1.267A2.264 2.264 0 0 0 7.823 11v-.107l2.718-1.938h.063A3.016 3.016 0 1 0 7.589 5.94v.031l-1.906 2.76h-.126c-.454 0-.898.138-1.273.395L0 7.354A8 8 0 0 1 2.546 2.12Z" clip-rule="evenodd"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
||||
|
Before Width: | Height: | Size: 842 B |
@@ -6,7 +6,6 @@ cartridges/sources/__init__.py
|
||||
cartridges/sources/heroic.py
|
||||
cartridges/sources/imported.py
|
||||
cartridges/sources/steam.py
|
||||
cartridges/ui/closures.py
|
||||
cartridges/ui/collection-details.blp
|
||||
cartridges/ui/collection_details.py
|
||||
cartridges/ui/collections.py
|
||||
@@ -18,7 +17,6 @@ cartridges/ui/game_details.py
|
||||
cartridges/ui/game_item.py
|
||||
cartridges/ui/games.py
|
||||
cartridges/ui/shortcuts-dialog.blp
|
||||
cartridges/ui/sources.py
|
||||
cartridges/ui/window.blp
|
||||
cartridges/ui/window.py
|
||||
data/page.kramo.Cartridges.desktop.in
|
||||
|
||||
Reference in New Issue
Block a user