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


Python ParameterContainer.get_parameter_widgets方法代码示例

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


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

示例1: build_widget

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameter_widgets [as 别名]
    def build_widget(self, form_layout, name, parameter_value):
        """Create a new form element dynamically based from key_value type.

        The Parameter Container will be inserted to form_layout.

        :param form_layout: Mandatory a layout instance
        :type form_layout: QFormLayout

        :param name: Mandatory string referencing the key in the function
         configurable parameters dictionary.
        :type name: str

        :param parameter_value: Mandatory representing the value referenced
        by the key.
        :type parameter_value: object, list

        :returns: a function that return the value of widget

        :raises: None
        """
        input_values = None
        if parameter_value is not None:
            # create and add widget to the dialog box
            # default tab's layout
            parameter_container = ParameterContainer(parameter_value)
            parameter_container.setup_ui(must_scroll=False)
            for w in [w.widget() for w in
                      parameter_container.get_parameter_widgets()]:
                # Rizky : assign error handler for
                # InputListParameterWidget
                w.add_row_error_handler = self.explain_errors
            form_layout.addWidget(parameter_container)
            # bind parameter
            input_values = parameter_container.get_parameters
            self.values[name] = input_values
        else:
            LOGGER.debug('build_widget : parameter is None')
            LOGGER.debug(parameter_value)
        return input_values
开发者ID:akbargumbira,项目名称:inasafe,代码行数:41,代码来源:function_options_dialog.py

示例2: main

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

#.........这里部分代码省略.........
    group_parameter.custom_validator = _custom_validator

    parameters = [
        string_parameter,
        integer_parameter,
        boolean_parameter,
        float_parameter,
        float_parameter,
        boolean_parameter,
        integer_parameter,
        point_parameter,
        list_parameter,
        input_list_parameter,
        dict_parameter,
        group_parameter,
        select_parameter
    ]

    extra_parameters = [
        (PointParameter, PointParameterWidget)
    ]
    min_max_parameters = [min_integer_parameter, max_integer_parameter]

    description_text = (
        'These parameters are merely created for showing example only')
    # description_text = ''
    parameter_container = ParameterContainer(
        parameters,
        extra_parameters=extra_parameters,
        description_text=description_text)
    parameter_container.setup_ui()

    # create error handler
    parameter_widget = parameter_container.get_parameter_widgets()
    try:
        input_list_widget = [
            w.widget() for w in parameter_widget if
            isinstance(w.widget(), InputListParameterWidget)][0]

        def add_row_handler(exception):
            box = QMessageBox()
            box.critical(input_list_widget, 'Add Row Error', exception.message)

        input_list_widget.add_row_error_handler = add_row_handler
    except IndexError:
        pass

    parameter_container2 = ParameterContainer(
        extra_parameters=extra_parameters,
        description_text='Empty Parameter Container Description')
    parameter_container2.setup_ui()

    parameter_container3 = ParameterContainer(
        parameters=min_max_parameters,
        extra_parameters=extra_parameters,
        description_text='Minimum Maximum Parameter')
    parameter_container3.add_validator(validate_min_max)
    parameter_container3.setup_ui()

    def show_error_message(parent, exception):
        """Generate error message to handle parameter errors

        :param parent: The widget as a parent of message box
        :type parent: QWidget
        :param exception: python Exception or Error
        :type exception: Exception
开发者ID:inasafe,项目名称:parameters,代码行数:70,代码来源:main.py

示例3: FieldMappingTab

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import get_parameter_widgets [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


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