本文整理汇总了Python中safe.gui.tools.minimum_needs.needs_profile.NeedsProfile.format_sentence方法的典型用法代码示例。如果您正苦于以下问题:Python NeedsProfile.format_sentence方法的具体用法?Python NeedsProfile.format_sentence怎么用?Python NeedsProfile.format_sentence使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.gui.tools.minimum_needs.needs_profile.NeedsProfile
的用法示例。
在下文中一共展示了NeedsProfile.format_sentence方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_resource
# 需要导入模块: from safe.gui.tools.minimum_needs.needs_profile import NeedsProfile [as 别名]
# 或者: from safe.gui.tools.minimum_needs.needs_profile.NeedsProfile import format_sentence [as 别名]
def save_resource(self):
"""Accept the add/edit of the current resource.
"""
# --
# Hackorama to get this working outside the method that the
# parameters where defined in.
parameters_widget = [
self.parameters_scrollarea.layout().itemAt(i) for i in
range(self.parameters_scrollarea.layout().count())][0]
parameters = parameters_widget.widget().get_parameters()
# To store parameters, we need the english version.
translated_to_english = dict(
(y, x) for x, y in list(self.resource_parameters.items()))
resource = {}
for parameter in parameters:
resource[translated_to_english[parameter.name]] = parameter.value
# verify the parameters are ok - create a throw-away resource param
try:
parameter = ResourceParameter()
parameter.name = resource['Resource name']
parameter.help_text = resource['Resource description']
# Adding in the frequency property. This is not in the
# FloatParameter by default, so maybe we should subclass.
parameter.frequency = resource['Frequency']
parameter.description = NeedsProfile.format_sentence(
resource['Readable sentence'],
resource)
parameter.minimum_allowed_value = float(
resource['Minimum allowed'])
parameter.maximum_allowed_value = float(
resource['Maximum allowed'])
parameter.unit.name = resource['Unit']
parameter.unit.plural = resource['Units']
parameter.unit.abbreviation = resource['Unit abbreviation']
parameter.value = float(resource['Default'])
except ValueOutOfBounds as e:
warning = self.tr(
'Problem - default value is invalid') + '\n' + str(e)
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
except InvalidMaximumError as e:
warning = self.tr(
'Problem - maximum value is invalid') + '\n' + str(e)
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
except InvalidMinimumError as e:
warning = self.tr(
'Problem - minimum value is invalid') + '\n' + str(e)
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
# end of test for parameter validity
self.add_resource(resource)
self.switch_context(self.profile_edit_page)
示例2: add_resource
# 需要导入模块: from safe.gui.tools.minimum_needs.needs_profile import NeedsProfile [as 别名]
# 或者: from safe.gui.tools.minimum_needs.needs_profile.NeedsProfile import format_sentence [as 别名]
def add_resource(self, resource):
"""Add a resource to the minimum needs table.
:param resource: The resource to be added
:type resource: dict
"""
updated_sentence = NeedsProfile.format_sentence(
resource['Readable sentence'], resource)
if self.edit_item:
item = self.edit_item
item.setText(updated_sentence)
self.edit_item = None
else:
item = QtGui.QListWidgetItem(updated_sentence)
item.resource_full = resource
self.resources_list.addItem(item)
示例3: save_resource
# 需要导入模块: from safe.gui.tools.minimum_needs.needs_profile import NeedsProfile [as 别名]
# 或者: from safe.gui.tools.minimum_needs.needs_profile.NeedsProfile import format_sentence [as 别名]
def save_resource(self):
"""Accept the add/edit of the current resource.
"""
# --
# Hackorama to get this working outside the method that the
# parameters where defined in.
parameters_widget = [
self.resource_widget.layout().itemAt(i) for i in
range(self.resource_widget.layout().count())][0]
parameters = parameters_widget.widget().get_parameters()
resource = {}
for parameter in parameters:
resource[parameter.name] = parameter.value
# verify the parameters are ok - create a throw-away resource param
try:
parameter = ResourceParameter()
parameter.name = resource['Resource name']
parameter.help_text = resource['Resource description']
# Adding in the frequency property. This is not in the
# FloatParameter by default, so maybe we should subclass.
parameter.frequency = resource['Frequency']
parameter.description = NeedsProfile.format_sentence(
resource['Readable sentence'],
resource)
parameter.minimum_allowed_value = float(
resource['Minimum allowed'])
parameter.maximum_allowed_value = float(
resource['Maximum allowed'])
parameter.unit.name = resource['Unit']
parameter.unit.plural = resource['Units']
parameter.unit.abbreviation = resource['Unit abbreviation']
parameter.value = float(resource['Default'])
except ValueOutOfBounds, e:
warning = self.tr(
'Problem - default value is invalid') + '\n' + e.message
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return