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


Python NeedsProfile.format_sentence方法代码示例

本文整理汇总了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)
开发者ID:inasafe,项目名称:inasafe,代码行数:61,代码来源:needs_manager_dialog.py

示例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)
开发者ID:lucernae,项目名称:inasafe,代码行数:18,代码来源:needs_manager_dialog.py

示例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
开发者ID:severinmenard,项目名称:inasafe,代码行数:42,代码来源:needs_manager_dialog.py


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