Merge branch 'main' into libadwaita-1.4
This commit is contained in:
33
src/game.py
33
src/game.py
@@ -23,7 +23,7 @@ import shlex
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from time import time
|
||||
from typing import Any
|
||||
from typing import Any, Optional
|
||||
|
||||
from gi.repository import Adw, GObject, Gtk
|
||||
|
||||
@@ -57,7 +57,7 @@ class Game(Gtk.Box):
|
||||
hidden: bool = False
|
||||
last_played: int = 0
|
||||
name: str
|
||||
developer: str | None = None
|
||||
developer: Optional[str] = None
|
||||
removed: bool = False
|
||||
blacklisted: bool = False
|
||||
game_cover: GameCover = None
|
||||
@@ -66,8 +66,7 @@ class Game(Gtk.Box):
|
||||
def __init__(self, data: dict[str, Any], **kwargs: Any) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.win = shared.win
|
||||
self.app = self.win.get_application()
|
||||
self.app = shared.win.get_application()
|
||||
self.version = shared.SPEC_VERSION
|
||||
|
||||
self.update_values(data)
|
||||
@@ -97,22 +96,22 @@ class Game(Gtk.Box):
|
||||
def save(self) -> None:
|
||||
self.emit("save-ready", {})
|
||||
|
||||
def create_toast(self, title: str, action: str | None = None) -> None:
|
||||
def create_toast(self, title: str, action: Optional[str] = None) -> None:
|
||||
toast = Adw.Toast.new(title.format(self.name))
|
||||
toast.set_priority(Adw.ToastPriority.HIGH)
|
||||
toast.set_use_markup(False)
|
||||
|
||||
if action:
|
||||
toast.set_button_label(_("Undo"))
|
||||
toast.connect("button-clicked", self.win.on_undo_action, self, action)
|
||||
toast.connect("button-clicked", shared.win.on_undo_action, self, action)
|
||||
|
||||
if (self, action) in self.win.toasts.keys():
|
||||
if (self, action) in shared.win.toasts.keys():
|
||||
# Dismiss the toast if there already is one
|
||||
self.win.toasts[(self, action)].dismiss()
|
||||
shared.win.toasts[(self, action)].dismiss()
|
||||
|
||||
self.win.toasts[(self, action)] = toast
|
||||
shared.win.toasts[(self, action)] = toast
|
||||
|
||||
self.win.toast_overlay.add_toast(toast)
|
||||
shared.win.toast_overlay.add_toast(toast)
|
||||
|
||||
def launch(self) -> None:
|
||||
self.last_played = int(time())
|
||||
@@ -129,7 +128,7 @@ class Game(Gtk.Box):
|
||||
# pylint: disable=consider-using-with
|
||||
subprocess.Popen(
|
||||
args,
|
||||
cwd=Path.home(),
|
||||
cwd=shared.home,
|
||||
shell=True,
|
||||
start_new_session=True,
|
||||
creationflags=subprocess.CREATE_NEW_PROCESS_GROUP if os.name == "nt" else 0, # type: ignore
|
||||
@@ -145,8 +144,8 @@ class Game(Gtk.Box):
|
||||
self.hidden = not self.hidden
|
||||
self.save()
|
||||
|
||||
if self.win.navigation_view.get_visible_page() == self.win.details_page:
|
||||
self.win.navigation_view.pop()
|
||||
if shared.win.navigation_view.get_visible_page() == shared.win.details_page:
|
||||
shared.win.navigation_view.pop()
|
||||
|
||||
self.update()
|
||||
|
||||
@@ -163,8 +162,8 @@ class Game(Gtk.Box):
|
||||
self.save()
|
||||
self.update()
|
||||
|
||||
if self.win.navigation_view.get_visible_page() == self.win.details_page:
|
||||
self.win.navigation_view.pop()
|
||||
if shared.win.navigation_view.get_visible_page() == shared.win.details_page:
|
||||
shared.win.navigation_view.pop()
|
||||
|
||||
# The variable is the title of the game
|
||||
self.create_toast(_("{} removed").format(self.name), "remove")
|
||||
@@ -176,7 +175,7 @@ class Game(Gtk.Box):
|
||||
self.cover.set_opacity(int(not loading))
|
||||
self.spinner.set_spinning(loading)
|
||||
|
||||
def get_cover_path(self) -> Path | None:
|
||||
def get_cover_path(self) -> Optional[Path]:
|
||||
cover_path = shared.covers_dir / f"{self.game_id}.gif"
|
||||
if cover_path.is_file():
|
||||
return cover_path # type: ignore
|
||||
@@ -198,7 +197,7 @@ class Game(Gtk.Box):
|
||||
if shared.schema.get_boolean("cover-launches-game") ^ button:
|
||||
self.launch()
|
||||
else:
|
||||
self.win.show_details_page(self)
|
||||
shared.win.show_details_page(self)
|
||||
|
||||
def set_play_icon(self) -> None:
|
||||
self.play_button.set_icon_name(
|
||||
|
||||
Reference in New Issue
Block a user