Allow installing from within the main window

This commit is contained in:
Mathieu Comandon 2013-07-10 02:02:08 +02:00
parent fe0251e256
commit 8a5f82fb28
4 changed files with 43 additions and 24 deletions

View file

@ -188,7 +188,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_stock">False</property>
<signal name="activate" handler="game_launch" swapped="no"/>
<signal name="activate" handler="on_game_clicked" swapped="no"/>
</object>
</child>
<child>
@ -278,7 +278,7 @@
<property name="label" translatable="yes">Play</property>
<property name="use_underline">True</property>
<property name="stock_id">gtk-media-play</property>
<signal name="clicked" handler="game_launch" swapped="no"/>
<signal name="clicked" handler="on_game_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>

View file

@ -32,18 +32,27 @@ class Game(object):
"""" This class takes cares about loading the configuration for a game
and running it.
"""
def __init__(self, name):
self.name = name
self.runner = None
def __init__(self, slug):
self.slug = slug
self.game_thread = None
self.heartbeat = None
self.game_config = None
self.load_config()
game_data = pga.get_game_by_slug(slug)
self.runner = game_data['runner']
self.directory = game_data['directory']
if self.is_installed:
self.load_config()
@property
def is_installed(self):
return bool(self.runner) and os.path.exists(self.directory)
def get_real_name(self):
""" Return the real game's name if available. """
return self.game_config['realname'] \
if "realname" in self.game_config.config else self.name
if "realname" in self.game_config.config else self.slug
def get_runner(self):
""" Return the runner's name """
@ -51,20 +60,18 @@ class Game(object):
def load_config(self):
""" Load the game's configuration. """
self.game_config = LutrisConfig(game=self.name)
self.game_config = LutrisConfig(game=self.slug)
if not self.game_config.is_valid():
logger.error("Invalid game config for %s" % self.name)
logger.error("Invalid game config for %s" % self.slug)
else:
runner_class = import_runner(self.get_runner())
runner_class = import_runner(self.runner)
self.runner = runner_class(self.game_config)
def remove(self, from_library=False, from_disk=False):
logger.debug("Uninstalling %s" % self.name)
if from_disk:
game_info = pga.get_game_by_slug(self.name)
shutil.rmtree(game_info['directory'])
shutil.rmtree(self.directory)
if from_library:
pga.delete_game(self.name)
pga.delete_game(self.slug)
self.game_config.remove()
def prelaunch(self):

View file

@ -10,6 +10,7 @@ from lutris import pga
from lutris import settings
from lutris.game import Game
from lutris.shortcuts import create_launcher
from lutris.installer import InstallerDialog
from lutris.util import resources
from lutris.util.log import logger
@ -84,7 +85,7 @@ class LutrisWindow(object):
#Contextual menu
menu_actions = [
('Play', self.game_launch),
('Play', self.on_game_clicked),
('Configure', self.edit_game_configuration),
('Create desktop shortcut', self.create_desktop_shortcut),
('Create global menu shortcut', self.create_menu_shortcut)
@ -117,7 +118,7 @@ class LutrisWindow(object):
"""Connects signals from the view with the main window.
This must be called each time the view is rebuilt.
"""
self.view.connect("game-activated", self.game_launch)
self.view.connect("game-activated", self.on_game_clicked)
self.view.connect("game-selected", self.game_selection_changed)
self.window.connect("configure-event", self.get_size)
@ -200,11 +201,15 @@ class LutrisWindow(object):
def on_search_entry_changed(self, widget):
self.view.emit('filter-updated', widget.get_text())
def game_launch(self, *args):
def on_game_clicked(self, *args):
"""Launch a game"""
if self.view.selected_game:
self.running_game = Game(self.view.selected_game)
self.running_game.play()
game_slug = self.view.selected_game[0]
if game_slug:
self.running_game = Game(game_slug)
if self.running_game.is_installed:
self.running_game.play()
else:
InstallerDialog(game_slug, self)
def reset(self, *args):
"""Reset the desktop to it's initial state"""

View file

@ -527,16 +527,16 @@ class InstallerDialog(Gtk.Dialog):
# icon_dest = join(settings.DATA_DIR, "icons/%s.png" % self.game_slug)
# http.download_asset(icon_url, icon_dest, True)
def __init__(self, game_ref):
def __init__(self, game_ref, parent=None):
Gtk.Dialog.__init__(self)
self.parent = parent
# Dialog properties
self.set_size_request(600, 480)
self.set_default_size(600, 480)
self.set_resizable(False)
# Default signals
self.connect('destroy', lambda q: Gtk.main_quit())
self.connect('destroy', self.on_destroy)
# Interpreter
self.interpreter = ScriptInterpreter(game_ref, self)
@ -587,6 +587,12 @@ class InstallerDialog(Gtk.Dialog):
label = Gtk.Label("Click install to continue")
self.show_all()
def on_destroy(self, widget):
if self.parent:
self.destroy()
else:
Gtk.main_quit()
def on_target_changed(self, text_entry):
""" Sets the installation target for the game """
self.interpreter.target_path = text_entry.get_text()
@ -597,7 +603,8 @@ class InstallerDialog(Gtk.Dialog):
def ask_user_for_file(self):
dlg = FileDialog()
return dlg.filename
filename = getattr(dlg, 'filename', '')
return filename
def clean_widgets(self):
for child_widget in self.widget_box.get_children():