本文整理汇总了Python中horizons.util.savegameupgrader.SavegameUpgrader.can_upgrade方法的典型用法代码示例。如果您正苦于以下问题:Python SavegameUpgrader.can_upgrade方法的具体用法?Python SavegameUpgrader.can_upgrade怎么用?Python SavegameUpgrader.can_upgrade使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类horizons.util.savegameupgrader.SavegameUpgrader
的用法示例。
在下文中一共展示了SavegameUpgrader.can_upgrade方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tmp_show_details
# 需要导入模块: from horizons.util.savegameupgrader import SavegameUpgrader [as 别名]
# 或者: from horizons.util.savegameupgrader.SavegameUpgrader import can_upgrade [as 别名]
def tmp_show_details():
"""Fetches details of selected savegame and displays it"""
gui.findChild(name="screenshot").image = None
map_file = None
map_file_index = gui.collectData(savegamelist)
savegame_details_box = gui.findChild(name="savegame_details")
savegame_details_parent = savegame_details_box.parent
if map_file_index == -1:
if savegame_details_box not in savegame_details_parent.hidden_children:
savegame_details_parent.hideChild(savegame_details_box)
return
else:
savegame_details_parent.showChild(savegame_details_box)
try:
map_file = map_files[map_file_index]
except IndexError:
# this was a click in the savegame list, but not on an element
# it happens when the savegame list is empty
return
savegame_info = SavegameManager.get_metadata(map_file)
if savegame_info.get('screenshot'):
# try to find a writable location, that is accessible via relative paths
# (required by fife)
fd, filename = tempfile.mkstemp()
try:
path_rel = os.path.relpath(filename)
except ValueError: # the relative path sometimes doesn't exist on win
os.close(fd)
os.unlink(filename)
# try again in the current dir, it's often writable
fd, filename = tempfile.mkstemp(dir=os.curdir)
try:
path_rel = os.path.relpath(filename)
except ValueError:
fd, filename = None, None
if fd:
with os.fdopen(fd, "w") as f:
f.write(savegame_info['screenshot'])
# fife only supports relative paths
gui.findChild(name="screenshot").image = path_rel
os.unlink(filename)
# savegamedetails
details_label = gui.findChild(name="savegamedetails_lbl")
details_label.text = u""
if savegame_info['timestamp'] == -1:
details_label.text += _("Unknown savedate")
else:
savetime = time.strftime("%c", time.localtime(savegame_info['timestamp']))
#xgettext:python-format
details_label.text += _("Saved at {time}").format(time=savetime.decode('utf-8'))
details_label.text += u'\n'
counter = savegame_info['savecounter']
# N_ takes care of plural forms for different languages
#xgettext:python-format
details_label.text += N_("Saved {amount} time",
"Saved {amount} times",
counter).format(amount=counter)
details_label.text += u'\n'
from horizons.constants import VERSION
try:
#xgettext:python-format
details_label.text += _("Savegame version {version}").format(
version=savegame_info['savegamerev'])
if savegame_info['savegamerev'] != VERSION.SAVEGAMEREVISION:
if not SavegameUpgrader.can_upgrade(savegame_info['savegamerev']):
details_label.text += u" " + _("(probably incompatible)")
except KeyError:
# this should only happen for very old savegames, so having this unfriendly
# error is ok (savegame is quite certainly fully unusable).
details_label.text += u" " + _("Incompatible version")
gui.adaptLayout()