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


Python ParameterContainer.get_parameters方法代码示例

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


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

示例1: main

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]

#.........这里部分代码省略.........
        'in their preparations for a disaster.')
    name_parameter.is_required = True
    name_parameter.value = ''

    description_parameter = StringParameter('UUID-1')
    description_parameter.name = 'Resource description'
    description_parameter.help_text = (
        'Description of the resource that will be provided as part of minimum '
        'needs. e.g. Tea, Water etc.')
    description_parameter.description = (
        'Description of the resource that will be provided as part of minimum '
        'needs. e.g. Tea, Water etc.')
    description_parameter.is_required = True
    description_parameter.value = ''

    unit_parameter = StringParameter('UUID-2')
    unit_parameter.name = 'Units'
    unit_parameter.help_text = (
        'Unit for the resources. e.g. litres, kg etc.')
    unit_parameter.description = (
        'A <b>unit</b> the basic measurement unit used for computing the '
        'allowance per individual. For example when planning water rations '
        'the units would be litres.')
    unit_parameter.is_required = True
    unit_parameter.value = ''

    minimum_parameter = FloatParameter('UUID-3')
    minimum_parameter.name = 'Minimum allowed'
    minimum_parameter.is_required = True
    minimum_parameter.precision = 3
    minimum_parameter.minimum_allowed_value = -99999.0
    minimum_parameter.maximum_allowed_value = 99999.0
    minimum_parameter.help_text = 'The minimum allowable quantity per person. '
    minimum_parameter.description = (
        'The <b>minimum</b> is the minimum allowed quantity of the resource '
        'per person. For example you may dictate that the water ration per '
        'person per day should never be allowed to be less than 0.5l.')
    minimum_parameter.value = 1.0

    maximum_parameter = FloatParameter('UUID-3')
    maximum_parameter.name = 'Minimum allowed'
    maximum_parameter.is_required = True
    maximum_parameter.precision = 3
    maximum_parameter.minimum_allowed_value = -99999.0
    maximum_parameter.maximum_allowed_value = 99999.0
    maximum_parameter.help_text = 'The maximum allowable quantity per person. '
    maximum_parameter.description = (
        'The <b>maximum</b> is the maximum allowed quantity of the resource '
        'per person. For example you may dictate that the water ration per '
        'person per day should never be allowed to be more than 50l.')
    maximum_parameter.value = 1.0

    maximum_parameter = FloatParameter('UUID-4')
    maximum_parameter.name = 'Minimum allowed'
    maximum_parameter.is_required = True
    maximum_parameter.precision = 3
    maximum_parameter.minimum_allowed_value = -99999.0
    maximum_parameter.maximum_allowed_value = 99999.0
    maximum_parameter.help_text = 'The maximum allowable quantity per person. '
    maximum_parameter.description = (
        'The <b>maximum</b> is the maximum allowed quantity of the resource '
        'per person. For example you may dictate that the water ration per '
        'person per day should never be allowed to be more than 50l.')
    maximum_parameter.value = 1.0

    default_parameter = FloatParameter('UUID-5')
    default_parameter.name = 'Default'
    default_parameter.is_required = True
    default_parameter.precision = 3
    default_parameter.minimum_allowed_value = -99999.0
    default_parameter.default_allowed_value = 99999.0
    default_parameter.help_text = 'The default allowable quantity per person. '
    default_parameter.description = (
        'The <b>default</b> is the default allowed quantity of the resource '
        'per person. For example you may indicate that the water ration per '
        'person per day should be 25l.')
    default_parameter.value = 1.0

    parameters = [
        name_parameter,
        description_parameter,
        unit_parameter,
        minimum_parameter,
        maximum_parameter,
        default_parameter]
    parameter_container = ParameterContainer(parameters)

    widget = QWidget()
    layout = QGridLayout()
    layout.addWidget(parameter_container)
    widget.setLayout(layout)
    widget.setGeometry(0, 0, 500, 500)

    widget.show()

    new_parameters = parameter_container.get_parameters()
    for new_parameter in new_parameters:
        print(new_parameter.name, new_parameter.value)

    sys.exit(application.exec_())
开发者ID:inasafe,项目名称:parameters,代码行数:104,代码来源:resource_example.py

示例2: GroupParameterWidget

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]
class GroupParameterWidget(GenericParameterWidget):
    """Widget class for List parameter."""
    def __init__(self, parameter, parent=None):
        """Constructor

        .. versionadded:: 2.2

        :param parameter: A GroupParameter object.
        :type parameter: GroupParameter

        """
        super(GroupParameterWidget, self).__init__(parameter, parent)

        # Get the parameter label and use its value as the checkbox text
        label_item = self.input_layout.itemAt(0)
        label_widget = label_item.widget()
        text = label_widget.text()
        self._enable_check_box = QCheckBox(text)
        # Tooltips
        self.setToolTip('Tick here to enable ' + self._parameter.name)

        # add all widget in the group
        self._group_layout = QVBoxLayout()
        self._group_layout.setSpacing(0)

        if not self._parameter.is_required:
            self.input_layout.insertWidget(0, self._enable_check_box)
            # now we don't need the parameter label anymore so chuck it
            self.input_layout.removeItem(label_item)
            # Make the sub group appear indented
            self._group_layout.setContentsMargins(20, 0, 0, 0)
        else:
            self._parameter.enable_parameter = True

        self.main_layout.addLayout(self._group_layout)

        # Why are we doing imports here? TS
        from parameters.qt_widgets.parameter_container import ParameterContainer

        self.param_container = ParameterContainer(
            parameters=self._parameter.value)
        self.param_container.setup_ui(must_scroll=parameter.must_scroll)

        # add handlers
        # noinspection PyUnresolvedReferences
        self._enable_check_box.stateChanged.connect(
            self.on_enable_checkbox_changed)
        self._enable_check_box.setChecked(self._parameter.enable_parameter)
        self.on_enable_checkbox_changed(self._parameter.enable_parameter)

        self._group_layout.addWidget(self.param_container)

    def on_enable_checkbox_changed(self, state):
        if state:
            self.param_container.show()
        else:
            self.param_container.hide()
        self._parameter.enable_parameter = state

    def get_parameter(self):
        """Obtain list parameter object from the current widget state.

        :returns: A ListParameter from the current state of widget

        """
        if self._parameter.enable_parameter:
            parameters = self.param_container.get_parameters()
            self._parameter.value = parameters
            self._parameter.validate()

        return self._parameter
开发者ID:ismailsunni,项目名称:parameters,代码行数:73,代码来源:group_parameter_widget.py

示例3: StepKwInaSAFERasterDefaultValues

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]

#.........这里部分代码省略.........
            in_group=False)
        # remove compulsory field since it has been set in previous step
        try:
            inasafe_fields.remove(get_compulsory_fields(
                layer_purpose_key, subcategory_key))
        except ValueError:
            pass
        return inasafe_fields

    # noinspection PyTypeChecker
    def set_widgets(self):
        """Set widgets on the Extra Keywords tab."""
        existing_inasafe_default_values = self.parent.get_existing_keyword(
            'inasafe_default_values')
        # Remove old container and parameter
        if self.parameter_container:
            self.default_values_grid.removeWidget(
                self.parameter_container)
        if self.parameters:
            self.parameters = []

        # Iterate through all inasafe fields
        # existing_inasafe_default_values

        for inasafe_field in self.inasafe_fields_for_the_layer():
            # Create DefaultSelectParameter
            parameter = DefaultValueParameter()
            parameter.guid = inasafe_field['key']
            parameter.name = inasafe_field['name']
            parameter.is_required = False
            parameter.help_text = inasafe_field['default_value']['description']
            # parameter.description = inasafe_field['default_value']
            parameter.element_type = unicode
            parameter.labels = get_inasafe_default_value_fields(
                self.parent.setting, inasafe_field['key'])[0]
            parameter.options = get_inasafe_default_value_fields(
                self.parent.setting, inasafe_field['key'])[1]

            if existing_inasafe_default_values:
                existing_default_value = existing_inasafe_default_values.get(
                    inasafe_field['key'])
                if existing_default_value:
                    parameter.default = existing_default_value

            self.parameters.append(parameter)

        # Create the parameter container and add to the wizard.
        self.parameter_container = ParameterContainer(
            self.parameters, extra_parameters=self.extra_parameters)
        self.parameter_container.setup_ui()
        self.default_values_grid.addWidget(self.parameter_container)

        # Set default value to None
        for parameter_widget in self.parameter_container.\
                get_parameter_widgets():
            parameter_widget.widget().set_value(None)
        # Set default value from existing keywords
        if existing_inasafe_default_values:
            for guid, default in existing_inasafe_default_values.items():
                parameter_widget = self.parameter_container.\
                    get_parameter_widget_by_guid(guid)
                if isinstance(parameter_widget, DefaultValueParameterWidget):
                    parameter_widget.set_value(default)

    def get_inasafe_default_values(self):
        """Return inasafe default from the current wizard state.

        :returns: Dictionary of key and value from InaSAFE Default Values.
        :rtype: dict
        """
        inasafe_default_values = {}
        parameters = self.parameter_container.get_parameters(True)
        for parameter in parameters:
            if parameter.value is not None:
                inasafe_default_values[parameter.guid] = parameter.value

        return inasafe_default_values

    def clear(self):
        """Clear current state."""
        # Adapted from http://stackoverflow.com/a/13103617/1198772
        for i in reversed(range(self.default_values_grid.count())):
            self.default_values_grid.itemAt(i).widget().setParent(None)
        self.parameters = []
        self.parameter_container = ParameterContainer()

    def help_content(self):
        """Return the content of help for this step wizard.

            We only needs to re-implement this method in each wizard step.

        :returns: A message object contains help.
        :rtype: m.Message
        """
        message = m.Message()
        message.add(m.Paragraph(tr(
            'In this wizard step: {step_name}, you will be able to '
            'set a value that corresponded with a InaSAFE field '
            'concept as default value.').format(step_name=self.step_name)))
        return message
开发者ID:timlinux,项目名称:inasafe,代码行数:104,代码来源:step_kw49_inasafe_raster_default_values.py

示例4: StepKwDefaultInaSAFEFields

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]

#.........这里部分代码省略.........
            if existing_inasafe_field:
                existing_value = existing_inasafe_field.get(
                    inasafe_field['key'])
                if existing_value:
                    if existing_value in parameter.options_list:
                        parameter.value = existing_value

            if existing_inasafe_default_values:
                existing_default_value = existing_inasafe_default_values.get(
                    inasafe_field['key'])
                if existing_default_value:
                    parameter.default = existing_default_value

            self.parameters.append(parameter)

        # Create the parameter container and add to the wizard.
        self.parameter_container = ParameterContainer(
            self.parameters, extra_parameters=self.extra_parameters)
        self.parameter_container.setup_ui()
        self.kwExtraKeywordsGridLayout.addWidget(self.parameter_container)
        # Add Message label
        self.kwExtraKeywordsGridLayout.addWidget(self.message_label)

        # Set default value to None
        for parameter_widget in self.parameter_container.\
                get_parameter_widgets():
            parameter_widget.widget().set_default(None)
            # Set selected radio button to 'Do not report'
            parameter_widget.widget().set_selected_radio_button()
        # Set default value from existing keywords
        if existing_inasafe_default_values:
            for guid, default in list(existing_inasafe_default_values.items()):
                parameter_widget = self.parameter_container.\
                    get_parameter_widget_by_guid(guid)
                if isinstance(parameter_widget, DefaultSelectParameterWidget):
                    parameter_widget.set_default(default)
                    # Set selected radio button to 'Do not report'
                    parameter_widget.set_selected_radio_button()

    def get_inasafe_fields(self):
        """Return inasafe fields from the current wizard state.

        :returns: Dictionary of key and value from InaSAFE Fields.
        :rtype: dict
        """
        inasafe_fields = {}
        parameters = self.parameter_container.get_parameters(True)
        for parameter in parameters:
            if not parameter.value == no_field:
                inasafe_fields[parameter.guid] = parameter.value

        return inasafe_fields

    def get_inasafe_default_values(self):
        """Return inasafe default from the current wizard state.

        :returns: Dictionary of key and value from InaSAFE Default Values.
        :rtype: dict
        """
        inasafe_default_values = {}
        parameters = self.parameter_container.get_parameters(True)
        for parameter in parameters:
            if parameter.default is not None:
                inasafe_default_values[parameter.guid] = parameter.default

        return inasafe_default_values

    def clear(self):
        """Clear current state."""
        # Adapted from http://stackoverflow.com/a/13103617/1198772
        for i in reversed(list(range(self.kwExtraKeywordsGridLayout.count()))):
            self.kwExtraKeywordsGridLayout.itemAt(i).widget().setParent(None)
        self.parameters = []
        self.parameter_container = ParameterContainer()

    @property
    def step_name(self):
        """Get the human friendly name for the wizard step.

        :returns: The name of the wizard step.
        :rtype: str
        """
        return tr('InaSAFE Default Field Step')

    def help_content(self):
        """Return the content of help for this step wizard.

            We only needs to re-implement this method in each wizard step.

        :returns: A message object contains help.
        :rtype: m.Message
        """
        message = m.Message()
        message.add(m.Paragraph(tr(
            'In this wizard step: {step_name}, you will be able to '
            'set a field that corresponded with a InaSAFE field '
            'concept. It also allows you to set a default value for all '
            'feature if you do not want to use any field').format(
            step_name=self.step_name)))
        return message
开发者ID:inasafe,项目名称:inasafe,代码行数:104,代码来源:step_kw47_default_inasafe_fields.py

示例5: FieldMappingTab

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]

#.........这里部分代码省略.........
            'results in the report choose "do not report".')
        # Set move or copy
        if self.field_group.get('exclusive', False):
            # If exclusive, do not add used field.
            self.populate_field_list(excluded_fields=used_fields)
            # Use move action since it's exclusive
            self.field_list.setDefaultDropAction(Qt.MoveAction)
            # Just make sure that the signal is disconnected
            try:
                # noinspection PyUnresolvedReferences
                self.field_list.itemChanged.disconnect(self.drop_remove)
            except TypeError:
                pass
            # Set header
            header_text = self.field_group['description']
            header_text += '\n\n' + default_ratio_help_text
            header_text += '\n\n' + tr(
                'You can only map one field to one concept.')
        else:
            # If not exclusive, add all field.
            self.populate_field_list()
            # Use copy action since it's not exclusive
            self.field_list.setDefaultDropAction(Qt.CopyAction)
            # noinspection PyUnresolvedReferences
            self.field_list.itemChanged.connect(
                partial(self.drop_remove, field_list=self.field_list))
            self.connect_drop_remove_parameter()
            # Set header
            header_text = self.field_group['description']
            header_text += '\n\n' + default_ratio_help_text
            header_text += '\n\n' + tr(
                'You can map one field to more than one concepts.')

        self.header_label.setText(header_text)

    def get_parameter_value(self):
        """Get parameter of the tab.

        :returns: Dictionary of parameters by type in this format:
            {'fields': {}, 'values': {}}.
        :rtype: dict
        """
        parameters = self.parameter_container.get_parameters(True)
        field_parameters = {}
        value_parameters = {}
        for parameter in parameters:
            if parameter.selected_option_type() in [SINGLE_DYNAMIC, STATIC]:
                value_parameters[parameter.guid] = parameter.value
            elif parameter.selected_option_type() == MULTIPLE_DYNAMIC:
                field_parameters[parameter.guid] = parameter.value
        return {
            'fields': field_parameters,
            'values': value_parameters
        }

    def update_footer(self):
        """Update footer when the field list change."""
        field_item = self.field_list.currentItem()

        if not field_item:
            self.footer_label.setText('')
            return

        field_name = field_item.data(Qt.UserRole)
        field = self.layer.fields().field(field_name)

        index = self.layer.fields().lookupField(field_name)
        unique_values = list(self.layer.uniqueValues(index))
        pretty_unique_values = ', '.join([str(v) for v in unique_values[:10]])

        footer_text = tr('Field type: {0}\n').format(field.typeName())
        footer_text += tr('Unique values: {0}').format(pretty_unique_values)
        self.footer_label.setText(footer_text)

    def connect_drop_remove_parameter(self):
        parameter_widgets = self.parameter_container.get_parameter_widgets()
        for parameter_widget in parameter_widgets:
            field_list = parameter_widget.widget().list_widget
            field_list.itemChanged.connect(
                partial(self.drop_remove, field_list=field_list))

    @staticmethod
    def drop_remove(*args, **kwargs):
        """Action when we need to remove dropped item.

        :param *args: Position arguments.
        :type *args: list

        :param kwargs: Keywords arguments.
        :type kwargs: dict
        """
        dropped_item = args[0]
        field_list = kwargs['field_list']
        num_duplicate = 0
        for i in range(field_list.count()):
            if dropped_item.text() == field_list.item(i).text():
                num_duplicate += 1
        if num_duplicate > 1:
            # Notes(IS): For some reason, removeItemWidget is not working.
            field_list.takeItem(field_list.row(dropped_item))
开发者ID:inasafe,项目名称:inasafe,代码行数:104,代码来源:field_mapping_tab.py

示例6: StepKwInaSAFEFields

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]

#.........这里部分代码省略.........
        if self.parameters:
            self.parameters = []

        layer_data_provider = self.parent.layer.dataProvider()

        # Iterate through all inasafe fields
        for inasafe_field in self.inasafe_fields_for_the_layer():
            # Option for Not Available
            option_list = [no_field]
            for field in layer_data_provider.fields():
                # Check the field type
                if isinstance(inasafe_field['type'], list):
                    if field.type() in inasafe_field['type']:
                        field_name = field.name()
                        option_list.append('%s' % field_name)
                else:
                    if field.type() == inasafe_field['type']:
                        field_name = field.name()
                        option_list.append('%s' % field_name)

            # If there is no option, pass
            if option_list == [no_field]:
                continue

            # Create SelectParameter
            select_parameter = SelectParameter()
            select_parameter.guid = inasafe_field['key']
            select_parameter.name = inasafe_field['name']
            select_parameter.is_required = False
            select_parameter.description = inasafe_field['description']
            select_parameter.help_text = inasafe_field['help_text']
            select_parameter.element_type = unicode
            select_parameter.options_list = option_list
            select_parameter.value = no_field
            # Check if there is already value in the metadata.
            if existing_inasafe_field:
                existing_value = existing_inasafe_field.get(
                    inasafe_field['key'])
                if existing_value:
                    if existing_value in select_parameter.options_list:
                        select_parameter.value = existing_value

            self.parameters.append(select_parameter)

        # Create the parameter container and add to the wizard.
        self.parameter_container = ParameterContainer(self.parameters)
        self.parameter_container.setup_ui()
        self.kwExtraKeywordsGridLayout.addWidget(self.parameter_container)

        if not self.parameters:
            no_field_message = tr(
                'There is no available field that has match type for the '
                'InaSAFE fields. You can click next.')
            self.lblInaSAFEFields.setText(no_field_message)

    def get_inasafe_fields(self):
        """Return inasafe fields from the current wizard state.

        :returns: Dictionary of key and value from InaSAFE Fields.
        :rtype: dict
        """
        inasafe_fields = {}
        parameters = self.parameter_container.get_parameters(True)
        for parameter in parameters:
            if not parameter.value == no_field:
                inasafe_fields[parameter.guid] = parameter.value

        return inasafe_fields

    def clear(self):
        """Clear current state."""
        # Adapted from http://stackoverflow.com/a/13103617/1198772
        for i in reversed(range(self.kwExtraKeywordsGridLayout.count())):
            self.kwExtraKeywordsGridLayout.itemAt(i).widget().setParent(None)
        self.parameters = []
        self.parameter_container = ParameterContainer()

    @property
    def step_name(self):
        """Get the human friendly name for the wizard step.

        :returns: The name of the wizard step.
        :rtype: str
        """
        return tr('InaSAFE Field Step')

    def help_content(self):
        """Return the content of help for this step wizard.

            We only needs to re-implement this method in each wizard step.

        :returns: A message object contains help.
        :rtype: m.Message
        """
        message = m.Message()
        message.add(m.Paragraph(tr(
            'In this wizard step: {step_name}, you will be able to '
            'set a field that corresponded with a InaSAFE field '
            'concept.').format(step_name=self.step_name)))
        return message
开发者ID:akbargumbira,项目名称:inasafe,代码行数:104,代码来源:step_kw45_inasafe_fields.py


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