mirror of
https://github.com/lutris/lutris
synced 2024-09-04 15:03:35 +00:00
Display slug in game info
This commit is contained in:
parent
ade05ff056
commit
ad1868d5ea
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -11,5 +11,5 @@ tags
|
|||
PYSMELLTAGS
|
||||
lutris.e4p
|
||||
.coverage
|
||||
tests/fixtures/pga.db
|
||||
pga.db
|
||||
tests/coverage/*
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
"""Configuration dialogs"""
|
||||
from gi.repository import Gtk, Pango
|
||||
|
||||
from lutris.util.log import logger
|
||||
from lutris.config import LutrisConfig
|
||||
from lutris.game import Game
|
||||
from lutris import pga
|
||||
|
@ -28,16 +29,13 @@ class GameDialogCommon(object):
|
|||
)
|
||||
return runner_liststore
|
||||
|
||||
def get_name_entry(self, name=None):
|
||||
"""Build a text field containing the given name."""
|
||||
name_box = Gtk.HBox()
|
||||
name_label = Gtk.Label(label="Name")
|
||||
name_box.pack_start(name_label, False, False, 20)
|
||||
self.name_entry = Gtk.Entry()
|
||||
if name:
|
||||
self.name_entry.set_text(name)
|
||||
name_box.pack_start(self.name_entry, True, True, 20)
|
||||
return name_box
|
||||
def build_entry_box(self, entry, label_text=None):
|
||||
box = Gtk.HBox()
|
||||
if label_text:
|
||||
label = Gtk.Label(label=label_text)
|
||||
box.pack_start(label, False, False, 20)
|
||||
box.pack_start(entry, True, True, 20)
|
||||
return box
|
||||
|
||||
def get_runner_dropdown(self):
|
||||
runner_liststore = self.get_runner_liststore()
|
||||
|
@ -74,10 +72,18 @@ class GameDialogCommon(object):
|
|||
|
||||
def build_info_tab(self):
|
||||
info_box = VBox()
|
||||
game_name = self.game.name if self.game else None
|
||||
name_box = self.get_name_entry(game_name)
|
||||
self.name_entry = Gtk.Entry()
|
||||
if self.game:
|
||||
self.name_entry.set_text(self.game.name)
|
||||
name_box = self.build_entry_box(self.name_entry, "Name")
|
||||
info_box.pack_start(name_box, False, False, 5)
|
||||
|
||||
self.slug_entry = Gtk.Entry()
|
||||
if self.game:
|
||||
self.slug_entry.set_text(self.game.slug)
|
||||
slug_box = self.build_entry_box(self.slug_entry, "Identifier")
|
||||
info_box.pack_start(slug_box, False, False, 5)
|
||||
|
||||
runner_dropdown = self.get_runner_dropdown()
|
||||
runner_box = Gtk.HBox()
|
||||
runner_box.pack_start(runner_dropdown, False, False, 20)
|
||||
|
@ -161,19 +167,25 @@ class GameDialogCommon(object):
|
|||
def on_save(self, _button):
|
||||
"""Save game info and destroy widget. Return True if success."""
|
||||
name = self.name_entry.get_text()
|
||||
if self.runner_name and name:
|
||||
self.lutris_config.config_type = 'game'
|
||||
if not self.lutris_config.game:
|
||||
self.lutris_config.game = slugify(name)
|
||||
self.lutris_config.save()
|
||||
self.slug = self.lutris_config.game
|
||||
runner_class = lutris.runners.import_runner(self.runner_name)
|
||||
runner = runner_class(self.lutris_config)
|
||||
pga.add_or_update(name, self.runner_name, slug=self.slug,
|
||||
directory=runner.game_path,
|
||||
installed=1)
|
||||
self.destroy()
|
||||
return True
|
||||
if not self.runner_name:
|
||||
logger.error("Missing runner")
|
||||
return False
|
||||
if not name:
|
||||
logger.error("Missing game name")
|
||||
return False
|
||||
self.lutris_config.config_type = 'game'
|
||||
if not self.lutris_config.game:
|
||||
self.lutris_config.game = slugify(name)
|
||||
self.lutris_config.save()
|
||||
self.slug = self.lutris_config.game
|
||||
runner_class = lutris.runners.import_runner(self.runner_name)
|
||||
runner = runner_class(self.lutris_config)
|
||||
pga.add_or_update(name, self.runner_name, slug=self.slug,
|
||||
directory=runner.game_path,
|
||||
installed=1)
|
||||
self.destroy()
|
||||
logger.debug("Saved %s", name)
|
||||
return True
|
||||
|
||||
|
||||
class AddGameDialog(Dialog, GameDialogCommon):
|
||||
|
|
|
@ -532,7 +532,7 @@ class Label(Gtk.Label):
|
|||
class VBox(Gtk.VBox):
|
||||
def __init__(self):
|
||||
GObject.GObject.__init__(self)
|
||||
self.set_margin_top(30)
|
||||
self.set_margin_top(20)
|
||||
|
||||
|
||||
class Dialog(Gtk.Dialog):
|
||||
|
@ -543,3 +543,4 @@ class Dialog(Gtk.Dialog):
|
|||
self.set_title(title)
|
||||
if parent:
|
||||
self.set_transient_for(parent)
|
||||
self.set_destroy_with_parent(True)
|
||||
|
|
|
@ -13,8 +13,10 @@ def get():
|
|||
data_path = os.path.normpath(os.path.join(sys.path[0], 'data'))
|
||||
else:
|
||||
import lutris
|
||||
data_path = os.path.dirname(lutris.__file__)
|
||||
lutris_module = lutris.__file__
|
||||
data_path = os.path.join(
|
||||
os.path.dirname(os.path.dirname(lutris_module)), 'data'
|
||||
)
|
||||
if not os.path.exists(data_path):
|
||||
print("data_path can't be found at : %s" % data_path)
|
||||
exit()
|
||||
raise IOError("data_path can't be found at : %s" % data_path)
|
||||
return data_path
|
||||
|
|
|
@ -5,6 +5,7 @@ from lutris.config import check_config
|
|||
# from lutris import settings
|
||||
# from lutris import pga
|
||||
from lutris.gui import config_dialogs
|
||||
from lutris.gui.lutriswindow import LutrisWindow
|
||||
from unittest import TestCase
|
||||
from lutris import runners
|
||||
|
||||
|
@ -23,7 +24,8 @@ class TestGameDialogCommon(TestCase):
|
|||
class TestGameDialog(TestCase):
|
||||
def setUp(self):
|
||||
check_config()
|
||||
self.dlg = config_dialogs.AddGameDialog(None)
|
||||
lutris_window = LutrisWindow()
|
||||
self.dlg = config_dialogs.AddGameDialog(lutris_window)
|
||||
|
||||
def get_notebook(self):
|
||||
return self.dlg.vbox.get_children()[0]
|
||||
|
@ -36,9 +38,6 @@ class TestGameDialog(TestCase):
|
|||
def get_game_box(self):
|
||||
return self.get_viewport(1)
|
||||
|
||||
def get_runner_dropdown(self):
|
||||
return self.get_viewport(0).get_children()[1].get_children()[0]
|
||||
|
||||
def get_buttons(self):
|
||||
return self.dlg.vbox.get_children()[1]
|
||||
|
||||
|
@ -53,7 +52,7 @@ class TestGameDialog(TestCase):
|
|||
self.assertEqual(buttons[0].get_label(), 'Cancel')
|
||||
self.assertEqual(buttons[1].get_label(), 'Add')
|
||||
|
||||
self.get_runner_dropdown().set_active(1)
|
||||
self.dlg.runner_dropdown.set_active(1)
|
||||
self.assertEqual(self.dlg.lutris_config.runner, runners.__all__[0])
|
||||
game_box = self.get_game_box()
|
||||
self.assertEqual(game_box.runner_name, runners.__all__[0])
|
||||
|
@ -64,7 +63,7 @@ class TestGameDialog(TestCase):
|
|||
def test_can_add_game(self):
|
||||
name_entry = self.dlg.name_entry
|
||||
name_entry.set_text("Test game")
|
||||
self.get_runner_dropdown().set_active(1)
|
||||
self.dlg.runner_dropdown.set_active(1)
|
||||
|
||||
game_box = self.get_game_box()
|
||||
exe_box = game_box.get_children()[0].get_children()[0]
|
||||
|
|
Loading…
Reference in a new issue