mirror of
https://github.com/lutris/lutris
synced 2024-09-05 23:46:21 +00:00
Update sidebar when a game is installed
This commit is contained in:
parent
4d6be01287
commit
ddae43b99d
|
@ -44,6 +44,7 @@ class Game(GObject.Object):
|
|||
"game-stopped": (GObject.SIGNAL_RUN_FIRST, None, (int,)),
|
||||
"game-removed": (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
"game-updated": (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
"game-installed": (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
}
|
||||
|
||||
def __init__(self, game_id=None):
|
||||
|
|
|
@ -178,7 +178,15 @@ class Application(Gtk.Application):
|
|||
self.run_in_background = False
|
||||
|
||||
def show_window(self, window_class, **kwargs):
|
||||
"""Instanciate a window keeping 1 instance max"""
|
||||
"""Instanciate a window keeping 1 instance max
|
||||
|
||||
Params:
|
||||
window_class (Gtk.Window): class to create the instance from
|
||||
kwargs (dict): Additional arguments to pass to the instanciated window
|
||||
|
||||
Returns:
|
||||
Gtk.Window: the existing window instance or a newly created one
|
||||
"""
|
||||
window_key = str(window_class) + str(kwargs)
|
||||
if self.app_windows.get(window_key):
|
||||
self.app_windows[window_key].present()
|
||||
|
@ -186,6 +194,7 @@ class Application(Gtk.Application):
|
|||
window_inst = window_class(application=self, **kwargs)
|
||||
window_inst.connect("destroy", self.on_app_window_destroyed, str(kwargs))
|
||||
self.app_windows[window_key] = window_inst
|
||||
return window_inst
|
||||
|
||||
def on_app_window_destroyed(self, app_window, kwargs_str):
|
||||
"""Remove the reference to the window when it has been destroyed"""
|
||||
|
|
|
@ -3,7 +3,7 @@ import os
|
|||
import time
|
||||
import webbrowser
|
||||
|
||||
from gi.repository import Gtk
|
||||
from gi.repository import Gtk, GObject
|
||||
|
||||
from lutris import api, pga, settings
|
||||
from lutris.installer import interpreter
|
||||
|
@ -28,6 +28,7 @@ from lutris.util.strings import add_url_tags, escape_gtk_label
|
|||
|
||||
class InstallerWindow(BaseApplicationWindow):
|
||||
"""GUI for the install process."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
game_slug=None,
|
||||
|
|
|
@ -105,6 +105,7 @@ class LutrisWindow(Gtk.ApplicationWindow):
|
|||
GObject.add_emission_hook(Game, "game-updated", self.on_game_updated)
|
||||
GObject.add_emission_hook(Game, "game-removed", self.on_game_updated)
|
||||
GObject.add_emission_hook(Game, "game-started", self.on_game_started)
|
||||
GObject.add_emission_hook(Game, "game-installed", self.on_game_installed)
|
||||
GObject.add_emission_hook(
|
||||
GenericPanel, "running-game-selected", self.game_selection_changed
|
||||
)
|
||||
|
@ -612,7 +613,11 @@ class LutrisWindow(Gtk.ApplicationWindow):
|
|||
if game.is_installed:
|
||||
self.application.launch(game)
|
||||
else:
|
||||
self.application.show_window(InstallerWindow, parent=self, game_slug=game.slug)
|
||||
self.application.show_window(
|
||||
InstallerWindow,
|
||||
parent=self,
|
||||
game_slug=game.slug
|
||||
)
|
||||
|
||||
@GtkTemplate.Callback
|
||||
def on_disconnect(self, *_args):
|
||||
|
@ -761,6 +766,9 @@ class LutrisWindow(Gtk.ApplicationWindow):
|
|||
logger.error("%s crashed", game)
|
||||
dialogs.ErrorDialog(error, parent=self)
|
||||
|
||||
def on_game_installed(self, game):
|
||||
self.game_selection_changed(None, game)
|
||||
|
||||
def on_game_started(self, game):
|
||||
self.game_panel.refresh()
|
||||
return True
|
||||
|
|
|
@ -20,7 +20,7 @@ class GamePanel(GenericPanel):
|
|||
super().__init__()
|
||||
self.game.connect("game-start", self.on_game_start)
|
||||
self.game.connect("game-started", self.on_game_started)
|
||||
self.game.connect("game-stopped", self.on_game_stop)
|
||||
self.game.connect("game-stopped", self.on_game_state_changed)
|
||||
|
||||
def place_content(self):
|
||||
self.put(self.get_close_button(), 276, 16)
|
||||
|
@ -245,8 +245,8 @@ class GamePanel(GenericPanel):
|
|||
self.buttons["play"].set_label("Play")
|
||||
self.buttons["play"].set_sensitive(True)
|
||||
|
||||
def on_game_stop(self, _widget, _game_id=None):
|
||||
"""Called when a game is stopped (`game-stopped` signal)"""
|
||||
def on_game_state_changed(self, _widget, _game_id=None):
|
||||
"""Generic callback to trigger a refresh"""
|
||||
self.refresh()
|
||||
|
||||
def on_close(self, _widget):
|
||||
|
|
|
@ -638,7 +638,7 @@ class ScriptInterpreter(CommandsMixin):
|
|||
path = self._substitute(launcher_value)
|
||||
if not os.path.isabs(path) and self.target_path:
|
||||
path = os.path.join(self.target_path, path)
|
||||
self._write_config()
|
||||
self._save_game()
|
||||
if path and not os.path.isfile(path) and self.runner not in ("web", "browser"):
|
||||
self.parent.set_status(
|
||||
"The executable at path %s can't be found, please check the destination folder.\n"
|
||||
|
@ -650,7 +650,7 @@ class ScriptInterpreter(CommandsMixin):
|
|||
|
||||
self.parent.on_install_finished()
|
||||
|
||||
def _write_config(self):
|
||||
def _save_game(self):
|
||||
"""Write the game configuration in the DB and config file.
|
||||
|
||||
This needs to be unfucked
|
||||
|
@ -730,6 +730,7 @@ class ScriptInterpreter(CommandsMixin):
|
|||
yaml_config = yaml.safe_dump(config, default_flow_style=False)
|
||||
with open(config_filename, "w") as config_file:
|
||||
config_file.write(yaml_config)
|
||||
game.emit("game-installed")
|
||||
|
||||
def _substitute_config(self, script_config):
|
||||
"""Substitute values such as $GAMEDIR in a config dict."""
|
||||
|
|
Loading…
Reference in a new issue