本文整理汇总了Python中lutris.game.Game.save方法的典型用法代码示例。如果您正苦于以下问题:Python Game.save方法的具体用法?Python Game.save怎么用?Python Game.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lutris.game.Game
的用法示例。
在下文中一共展示了Game.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_platforms
# 需要导入模块: from lutris.game import Game [as 别名]
# 或者: from lutris.game.Game import save [as 别名]
def update_platforms():
pga_games = pga.get_games(filter_installed=True)
for pga_game in pga_games:
if pga_game.get('platform') or not pga_game['runner']:
continue
game = Game(id=pga_game['id'])
game.set_platform_from_runner()
game.save()
示例2: fill_missing_platforms
# 需要导入模块: from lutris.game import Game [as 别名]
# 或者: from lutris.game.Game import save [as 别名]
def fill_missing_platforms():
"""Sets the platform on games where it's missing.
This should never happen.
"""
pga_games = pga.get_games(filter_installed=True)
for pga_game in pga_games:
if pga_game.get("platform") or not pga_game["runner"]:
continue
game = Game(game_id=pga_game["id"])
logger.error("Providing missing platorm for game %s", game.slug)
game.set_platform_from_runner()
if game.platform:
game.save(metadata_only=True)
示例3: GameDialogCommon
# 需要导入模块: from lutris.game import Game [as 别名]
# 或者: from lutris.game.Game import save [as 别名]
#.........这里部分代码省略.........
# Advanced settings checkbox
checkbox = Gtk.CheckButton(label="Show advanced options")
value = settings.read_setting('show_advanced_options')
if value == 'True':
checkbox.set_active(value)
checkbox.connect("toggled", self.on_show_advanced_options_toggled)
self.action_area.pack_start(checkbox, False, False, 5)
# Buttons
hbox = Gtk.HBox()
cancel_button = Gtk.Button(label="Cancel")
cancel_button.connect("clicked", self.on_cancel_clicked)
hbox.pack_start(cancel_button, True, True, 10)
button = Gtk.Button(label=label)
button.connect("clicked", button_callback)
hbox.pack_start(button, True, True, 0)
self.action_area.pack_start(hbox, True, True, 0)
def set_advanced_options_visible(self, value):
"""Change visibility of advanced options across all config tabs."""
widgets = self.system_box.get_children()
if self.runner_name:
widgets += self.runner_box.get_children()
if self.game:
widgets += self.game_box.get_children()
for widget in widgets:
if widget.get_style_context().has_class('advanced'):
widget.set_visible(value)
if value:
widget.set_no_show_all(not value)
widget.show_all()
def on_show_advanced_options_toggled(self, checkbox):
value = True if checkbox.get_active() else False
settings.write_setting('show_advanced_options', value)
self.set_advanced_options_visible(value)
def on_runner_changed(self, widget):
"""Action called when runner drop down is changed."""
runner_index = widget.get_active()
current_page = self.notebook.get_current_page()
if runner_index == 0:
self.runner_name = None
self.lutris_config = LutrisConfig()
else:
self.runner_name = widget.get_model()[runner_index][1]
# XXX DANGER ZONE
self.lutris_config = LutrisConfig(runner_slug=self.runner_name,
level='game')
self.rebuild_tabs()
self.notebook.set_current_page(current_page)
def on_cancel_clicked(self, widget=None):
"""Dialog destroy callback."""
self.destroy()
def is_valid(self):
name = self.name_entry.get_text()
if not self.runner_name:
ErrorDialog("Runner not provided")
return False
if not name:
ErrorDialog("Please fill in the name")
return False
return True
def on_save(self, _button):
"""Save game info and destroy widget. Return True if success."""
if not self.is_valid():
return False
name = self.name_entry.get_text()
# Do not modify slug
if not self.slug:
self.slug = slugify(name)
if not self.game:
self.game = Game(self.slug)
self.game.config = self.lutris_config
if not self.lutris_config.game_slug:
self.lutris_config.game_slug = self.slug
self.lutris_config.save()
runner_class = runners.import_runner(self.runner_name)
runner = runner_class(self.lutris_config)
self.game.name = name
self.game.slug = self.slug
self.game.runner_name = self.runner_name
self.game.directory = runner.game_path
self.game.is_installed = True
self.game.save()
self.destroy()
logger.debug("Saved %s", name)
self.saved = True
示例4: _write_config
# 需要导入模块: from lutris.game import Game [as 别名]
# 或者: from lutris.game.Game import save [as 别名]
def _write_config(self):
"""Write the game configuration in the DB and config file.
This needs to be unfucked
"""
if self.extends:
logger.info(
"This is an extension to %s, not creating a new game entry",
self.extends,
)
return
configpath = make_game_config_id(self.slug)
config_filename = os.path.join(settings.CONFIG_DIR, "games/%s.yml" % configpath)
if self.requires:
# Load the base game config
required_game = pga.get_game_by_field(self.requires, field="installer_slug")
base_config = LutrisConfig(
runner_slug=self.runner, game_config_id=required_game["configpath"]
)
config = base_config.game_level
else:
config = {"game": {}}
self.game_id = pga.add_or_update(
name=self.game_name,
runner=self.runner,
slug=self.game_slug,
directory=self.target_path,
installed=1,
installer_slug=self.slug,
parent_slug=self.requires,
year=self.year,
steamid=self.steamid,
configpath=configpath,
id=self.game_id,
)
game = Game(self.game_id)
game.save()
logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)
# Config update
if "system" in self.script:
config["system"] = self._substitute_config(self.script["system"])
if self.runner in self.script and self.script[self.runner]:
config[self.runner] = self._substitute_config(self.script[self.runner])
# Game options such as exe or main_file can be added at the root of the
# script as a shortcut, this integrates them into the game config
# properly
launcher, launcher_value = _get_game_launcher(self.script)
if isinstance(launcher_value, list):
game_files = []
for game_file in launcher_value:
if game_file in self.game_files:
game_files.append(self.game_files[game_file])
else:
game_files.append(game_file)
config["game"][launcher] = game_files
elif launcher_value:
if launcher_value in self.game_files:
launcher_value = self.game_files[launcher_value]
elif self.target_path and os.path.exists(
os.path.join(self.target_path, launcher_value)
):
launcher_value = os.path.join(self.target_path, launcher_value)
config["game"][launcher] = launcher_value
if "game" in self.script:
try:
config["game"].update(self.script["game"])
except ValueError:
raise ScriptingError("Invalid 'game' section", self.script["game"])
config["game"] = self._substitute_config(config["game"])
yaml_config = yaml.safe_dump(config, default_flow_style=False)
with open(config_filename, "w") as config_file:
config_file.write(yaml_config)
示例5: GameDialogCommon
# 需要导入模块: from lutris.game import Game [as 别名]
# 或者: from lutris.game.Game import save [as 别名]
#.........这里部分代码省略.........
def _build_runner_tab(self, config_level):
if self.runner_name:
self.runner_box = RunnerBox(self.lutris_config)
runner_sw = self.build_scrolled_window(self.runner_box)
else:
runner_sw = Gtk.Label(label=self.no_runner_label)
self._add_notebook_tab(runner_sw, "Runner options")
def _build_system_tab(self, config_level):
self.system_box = SystemBox(self.lutris_config)
self.system_sw = self.build_scrolled_window(self.system_box)
self._add_notebook_tab(self.system_sw, "System options")
def _add_notebook_tab(self, widget, label):
self.notebook.append_page(widget, Gtk.Label(label=label))
def build_action_area(self, button_callback, callback2=None):
self.action_area.set_layout(Gtk.ButtonBoxStyle.EDGE)
# Advanced settings checkbox
checkbox = Gtk.CheckButton(label="Show advanced options")
value = settings.read_setting('show_advanced_options')
if value == 'True':
checkbox.set_active(value)
checkbox.connect("toggled", self.on_show_advanced_options_toggled)
self.action_area.pack_start(checkbox, False, False, 5)
# Buttons
hbox = Gtk.HBox()
cancel_button = Gtk.Button(label="Cancel")
cancel_button.connect("clicked", self.on_cancel_clicked)
hbox.pack_start(cancel_button, True, True, 10)
save_button = Gtk.Button(label="Save")
if callback2:
save_button.connect("clicked", button_callback, callback2)
else:
save_button.connect("clicked", button_callback)
hbox.pack_start(save_button, True, True, 0)
self.action_area.pack_start(hbox, True, True, 0)
def on_show_advanced_options_toggled(self, checkbox):
value = True if checkbox.get_active() else False
settings.write_setting('show_advanced_options', value)
self._set_advanced_options_visible(value)
def _set_advanced_options_visible(self, value):
"""Change visibility of advanced options across all config tabs."""
widgets = self.system_box.get_children()
if self.runner_name:
widgets += self.runner_box.get_children()
if self.game:
widgets += self.game_box.get_children()
for widget in widgets:
if widget.get_style_context().has_class('advanced'):
widget.set_visible(value)
if value:
widget.set_no_show_all(not value)
widget.show_all()
def on_runner_changed(self, widget):
"""Action called when runner drop down is changed."""
runner_index = widget.get_active()
current_page = self.notebook.get_current_page()
示例6: _write_config
# 需要导入模块: from lutris.game import Game [as 别名]
# 或者: from lutris.game.Game import save [as 别名]
def _write_config(self):
"""Write the game configuration in the DB and config file."""
if self.extends:
logger.info('This is an extension to %s, not creating a new game entry',
self.extends)
return
configpath = make_game_config_id(self.slug)
config_filename = os.path.join(settings.CONFIG_DIR, "games/%s.yml" % configpath)
if self.requires:
# Load the base game config
required_game = pga.get_game_by_field(self.requires, field='installer_slug')
base_config = LutrisConfig(
runner_slug=self.runner,
game_config_id=required_game['configpath']
)
config = base_config.game_level
else:
config = {
'game': {},
}
self.game_id = pga.add_or_update(
name=self.name,
runner=self.runner,
slug=self.game_slug,
directory=self.target_path,
installed=1,
installer_slug=self.slug,
parent_slug=self.requires,
year=self.year,
steamid=self.steamid,
configpath=configpath,
id=self.game_id
)
game = Game(self.game_id)
game.set_platform_from_runner()
game.save()
logger.debug("Saved game entry %s (%d)", self.game_slug, self.game_id)
# Config update
if 'system' in self.script:
config['system'] = self._substitute_config(self.script['system'])
if self.runner in self.script and self.script[self.runner]:
config[self.runner] = self._substitute_config(
self.script[self.runner]
)
# Game options such as exe or main_file can be added at the root of the
# script as a shortcut, this integrates them into the game config
# properly
launcher, launcher_value = self._get_game_launcher()
if type(launcher_value) == list:
game_files = []
for game_file in launcher_value:
if game_file in self.game_files:
game_files.append(self.game_files[game_file])
else:
game_files.append(game_file)
config['game'][launcher] = game_files
elif launcher_value:
if launcher_value in self.game_files:
launcher_value = (
self.game_files[launcher_value]
)
elif self.target_path and os.path.exists(
os.path.join(self.target_path, launcher_value)
):
launcher_value = os.path.join(self.target_path, launcher_value)
config['game'][launcher] = launcher_value
if 'game' in self.script:
config['game'].update(self.script['game'])
config['game'] = self._substitute_config(config['game'])
yaml_config = yaml.safe_dump(config, default_flow_style=False)
with open(config_filename, "w") as config_file:
config_file.write(yaml_config)