当前位置: 首页>>代码示例>>Python>>正文


Python ScenarioEventHandler.get_metadata_from_file方法代码示例

本文整理汇总了Python中horizons.scenario.ScenarioEventHandler.get_metadata_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python ScenarioEventHandler.get_metadata_from_file方法的具体用法?Python ScenarioEventHandler.get_metadata_from_file怎么用?Python ScenarioEventHandler.get_metadata_from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在horizons.scenario.ScenarioEventHandler的用法示例。


在下文中一共展示了ScenarioEventHandler.get_metadata_from_file方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _update_infos

# 需要导入模块: from horizons.scenario import ScenarioEventHandler [as 别名]
# 或者: from horizons.scenario.ScenarioEventHandler import get_metadata_from_file [as 别名]
	def _update_infos(self):
		"""Fill in infos of selected scenario to label"""
		lang_list = self._gui.findChild(name="uni_langlist")
		cur_selected_language = lang_list.selected_item
		lang_list.items = self._get_available_languages()
		if cur_selected_language in lang_list.items:
			lang_list.selected = lang_list.items.index(cur_selected_language)
		else:
			lang_list.selected = 0

		cur_locale = LANGUAGENAMES.get_by_value(lang_list.selected_item)
		translated_scenario = self._find_map_filename(cur_locale)
		if os.path.exists(translated_scenario):
			self._update_scenario_translation_infos(translated_scenario)
		else:
			try:
				default_locale, default_encoding = locale.getdefaultlocale()
			except ValueError: # OS X sometimes returns 'UTF-8' as locale, which is a ValueError
				default_locale = 'en'

			possibilities = [ # try to find a file for the system locale before falling back to en
				default_locale,
				default_locale.split('_')[0],
				'en',
			]

			lang_list.selected = 0
			for lang in possibilities:
				if LANGUAGENAMES[lang] in lang_list.items:
					lang_list.selected = lang_list.items.index(LANGUAGENAMES[lang])
					break

		try:
			difficulty, author, desc = ScenarioEventHandler.get_metadata_from_file(self._get_selected_map())
		except InvalidScenarioFileFormat as e:
			self._show_invalid_scenario_file_popup(e)
			return

		lbl = self._gui.findChild(name="uni_map_difficulty")
		#xgettext:python-format
		lbl.text = _("Difficulty: {difficulty}").format(difficulty=difficulty)

		lbl = self._gui.findChild(name="uni_map_author")
		#xgettext:python-format
		lbl.text = _("Author: {author}").format(author=author)

		lbl = self._gui.findChild(name="uni_map_desc")
		#xgettext:python-format
		lbl.text = _("Description: {desc}").format(desc=desc)
开发者ID:ThePawnBreak,项目名称:unknown-horizons,代码行数:51,代码来源:singleplayermenu.py

示例2: _update_scenario_translation_infos

# 需要导入模块: from horizons.scenario import ScenarioEventHandler [as 别名]
# 或者: from horizons.scenario.ScenarioEventHandler import get_metadata_from_file [as 别名]
	def _update_scenario_translation_infos(self, scenario):
		"""Fill in translation infos of selected scenario to translation label."""
		try:
			metadata = ScenarioEventHandler.get_metadata_from_file(scenario)
		except InvalidScenarioFileFormat as e:
			self._show_invalid_scenario_file_popup(e)
			return

		translation_status = metadata.get('translation_status', u'')
		lbl = self._gui.findChild(name="translation_status")
		lbl.text = translation_status

		lbl = self._gui.findChild(name="uni_map_difficulty")
		lbl.text = _("Difficulty: {difficulty}").format(difficulty=metadata['difficulty'])

		lbl = self._gui.findChild(name="uni_map_author")
		lbl.text = _("Author: {author}").format(author=metadata['author'])

		lbl = self._gui.findChild(name="uni_map_desc")
		lbl.text = _("Description: {desc}").format(desc=metadata['description'])
开发者ID:Rareson,项目名称:unknown-horizons,代码行数:22,代码来源:singleplayermenu.py


注:本文中的horizons.scenario.ScenarioEventHandler.get_metadata_from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。