Merge branch 'main' into libadwaita-1.4
This commit is contained in:
@@ -17,9 +17,13 @@
|
||||
#
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from gi.repository import Adw, Gtk
|
||||
from typing import Any
|
||||
|
||||
from gi.repository import Adw, Gio, GLib, Gtk
|
||||
|
||||
from src import shared
|
||||
from src.game import Game
|
||||
from src.game_cover import GameCover
|
||||
from src.utils.relative_date import relative_date
|
||||
|
||||
|
||||
@@ -73,13 +77,13 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
hidden_search_entry = Gtk.Template.Child()
|
||||
hidden_search_button = Gtk.Template.Child()
|
||||
|
||||
game_covers = {}
|
||||
toasts = {}
|
||||
active_game = None
|
||||
details_view_game_cover = None
|
||||
sort_state = "a-z"
|
||||
filter_state = "all"
|
||||
source_rows = {}
|
||||
game_covers: dict = {}
|
||||
toasts: dict = {}
|
||||
active_game: Game
|
||||
details_view_game_cover: GameCover | None = None
|
||||
sort_state: str = "a-z"
|
||||
filter_state: str = "all"
|
||||
source_rows: dict = {}
|
||||
|
||||
def create_source_rows(self):
|
||||
def get_removed(source_id):
|
||||
@@ -204,7 +208,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
if self.overlay_split_view.get_collapsed():
|
||||
self.overlay_split_view.set_show_sidebar(False)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
def __init__(self, **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.details_view.set_measure_overlay(self.details_view_toolbar_view, True)
|
||||
@@ -249,11 +253,11 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
style_manager.connect("notify::dark", self.set_details_view_opacity)
|
||||
style_manager.connect("notify::high-contrast", self.set_details_view_opacity)
|
||||
|
||||
def search_changed(self, _widget, hidden):
|
||||
def search_changed(self, _widget: Any, hidden: bool) -> None:
|
||||
# Refresh search filter on keystroke in search box
|
||||
(self.hidden_library if hidden else self.library).invalidate_filter()
|
||||
|
||||
def set_library_child(self):
|
||||
def set_library_child(self) -> None:
|
||||
child, hidden_child = self.notice_empty, self.hidden_notice_empty
|
||||
|
||||
for game in shared.store:
|
||||
@@ -286,7 +290,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
remove_from_overlay(self.hidden_notice_empty)
|
||||
remove_from_overlay(self.hidden_notice_no_results)
|
||||
|
||||
def filter_func(self, child):
|
||||
def filter_func(self, child: Gtk.Widget) -> bool:
|
||||
game = child.get_child()
|
||||
text = (
|
||||
(
|
||||
@@ -314,10 +318,10 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
return not filtered
|
||||
|
||||
def set_active_game(self, _widget, _pspec, game):
|
||||
def set_active_game(self, _widget: Any, _pspec: Any, game: Game) -> None:
|
||||
self.active_game = game
|
||||
|
||||
def show_details_page(self, game):
|
||||
def show_details_page(self, game: Game) -> None:
|
||||
self.active_game = game
|
||||
|
||||
self.details_view_cover.set_opacity(int(not game.loading))
|
||||
@@ -365,7 +369,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
self.set_details_view_opacity()
|
||||
|
||||
def set_details_view_opacity(self, *_args):
|
||||
def set_details_view_opacity(self, *_args: Any) -> None:
|
||||
if self.navigation_view.get_visible_page() != self.details_page:
|
||||
return
|
||||
|
||||
@@ -376,12 +380,12 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
return
|
||||
|
||||
self.details_view_blurred_cover.set_opacity(
|
||||
1 - self.details_view_game_cover.luminance[0]
|
||||
1 - self.details_view_game_cover.luminance[0] # type: ignore
|
||||
if style_manager.get_dark()
|
||||
else self.details_view_game_cover.luminance[1]
|
||||
else self.details_view_game_cover.luminance[1] # type: ignore
|
||||
)
|
||||
|
||||
def sort_func(self, child1, child2):
|
||||
def sort_func(self, child1: Gtk.Widget, child2: Gtk.Widget) -> int:
|
||||
var, order = "name", True
|
||||
|
||||
if self.sort_state in ("newest", "oldest"):
|
||||
@@ -391,7 +395,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
elif self.sort_state == "a-z":
|
||||
order = False
|
||||
|
||||
def get_value(index):
|
||||
def get_value(index: int) -> str:
|
||||
return str(
|
||||
getattr((child1.get_child(), child2.get_child())[index], var)
|
||||
).lower()
|
||||
@@ -412,24 +416,24 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
)
|
||||
self.overlay_split_view.set_show_sidebar(value)
|
||||
|
||||
def on_go_to_parent_action(self, *_args):
|
||||
def on_go_to_parent_action(self, *_args: Any) -> None:
|
||||
if self.navigation_view.get_visible_page() == self.details_page:
|
||||
self.navigation_view.pop()
|
||||
|
||||
def on_go_home_action(self, *_args):
|
||||
def on_go_home_action(self, *_args: Any) -> None:
|
||||
self.navigation_view.pop_to_page(self.library_page)
|
||||
|
||||
def on_show_hidden_action(self, *_args):
|
||||
def on_show_hidden_action(self, *_args: Any) -> None:
|
||||
self.navigation_view.push(self.hidden_library_page)
|
||||
|
||||
def on_sort_action(self, action, state):
|
||||
def on_sort_action(self, action: Gio.SimpleAction, state: GLib.Variant) -> None:
|
||||
action.set_state(state)
|
||||
self.sort_state = str(state).strip("'")
|
||||
self.library.invalidate_sort()
|
||||
|
||||
shared.state_schema.set_string("sort-mode", self.sort_state)
|
||||
|
||||
def on_toggle_search_action(self, *_args):
|
||||
def on_toggle_search_action(self, *_args: Any) -> None:
|
||||
if self.navigation_view.get_visible_page() == self.library_page:
|
||||
search_bar = self.search_bar
|
||||
search_entry = self.search_entry
|
||||
@@ -446,7 +450,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
search_entry.set_text("")
|
||||
|
||||
def on_escape_action(self, *_args):
|
||||
def on_escape_action(self, *_args: Any) -> None:
|
||||
if (
|
||||
self.get_focus() == self.search_entry.get_focus_child()
|
||||
or self.hidden_search_entry.get_focus_child()
|
||||
@@ -455,7 +459,7 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
else:
|
||||
self.navigation_view.pop()
|
||||
|
||||
def show_details_page_search(self, widget):
|
||||
def show_details_page_search(self, widget: Gtk.Widget) -> None:
|
||||
library = (
|
||||
self.hidden_library if widget == self.hidden_search_entry else self.library
|
||||
)
|
||||
@@ -471,30 +475,39 @@ class CartridgesWindow(Adw.ApplicationWindow):
|
||||
|
||||
index += 1
|
||||
|
||||
def on_undo_action(self, _widget, game=None, undo=None):
|
||||
def on_undo_action(
|
||||
self, _widget: Any, game: Game | None = None, undo: str | None = None
|
||||
) -> None:
|
||||
if not game: # If the action was activated via Ctrl + Z
|
||||
if shared.importer and (
|
||||
shared.importer.imported_game_ids or shared.importer.removed_game_ids
|
||||
):
|
||||
shared.importer.undo_import()
|
||||
return
|
||||
|
||||
try:
|
||||
game = tuple(self.toasts.keys())[-1][0]
|
||||
undo = tuple(self.toasts.keys())[-1][1]
|
||||
except IndexError:
|
||||
return
|
||||
|
||||
if undo == "hide":
|
||||
game.toggle_hidden(False)
|
||||
if game:
|
||||
if undo == "hide":
|
||||
game.toggle_hidden(False)
|
||||
|
||||
elif undo == "remove":
|
||||
game.removed = False
|
||||
game.save()
|
||||
game.update()
|
||||
elif undo == "remove":
|
||||
game.removed = False
|
||||
game.save()
|
||||
game.update()
|
||||
|
||||
self.toasts[(game, undo)].dismiss()
|
||||
self.toasts.pop((game, undo))
|
||||
self.toasts[(game, undo)].dismiss()
|
||||
self.toasts.pop((game, undo))
|
||||
|
||||
def on_open_menu_action(self, *_args):
|
||||
def on_open_menu_action(self, *_args: Any) -> None:
|
||||
if self.navigation_view.get_visible_page() == self.library_page:
|
||||
self.primary_menu_button.popup()
|
||||
elif self.navigation_view.get_visible_page() == self.hidden_library_page:
|
||||
self.hidden_primary_menu_button.popup()
|
||||
|
||||
def on_close_action(self, *_args):
|
||||
def on_close_action(self, *_args: Any) -> None:
|
||||
self.close()
|
||||
|
||||
Reference in New Issue
Block a user