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


Python ParameterContainer.setup_ui方法代码示例

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


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

示例1: build_minimum_needs_form

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [as 别名]
    def build_minimum_needs_form(self, parameters):
        """Build minimum needs tab.

        :param parameters: A list containing element of form
        :type parameters: list
        """
        # create minimum needs tab
        scroll_layout = QVBoxLayout()
        scroll_widget = QWidget()
        scroll_widget.setLayout(scroll_layout)
        scroll = QScrollArea()
        scroll.setWidgetResizable(True)
        scroll.setWidget(scroll_widget)
        main_layout = QVBoxLayout()
        main_layout.addWidget(scroll)
        main_widget = QWidget()
        main_widget.setLayout(main_layout)

        extra_parameters = [(ResourceParameter, ResourceParameterWidget)]
        parameter_container = ParameterContainer(
            parameters=parameters, extra_parameters=extra_parameters)
        parameter_container.setup_ui()
        scroll_layout.addWidget(parameter_container)
        self.tabWidget.addTab(main_widget, self.tr('Minimum Needs'))
        self.tabWidget.tabBar().setVisible(True)
        self.values['minimum needs'] = parameter_container.get_parameters
开发者ID:akbargumbira,项目名称:inasafe,代码行数:28,代码来源:function_options_dialog.py

示例2: build_post_processor_form

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [as 别名]
    def build_post_processor_form(self, form_elements):
        """Build Post Processor Tab.

        :param form_elements: A Dictionary containing element of form.
        :type form_elements: dict
        """
        scroll_layout = QVBoxLayout()
        scroll_widget = QWidget()
        scroll_widget.setLayout(scroll_layout)
        scroll = QScrollArea()
        scroll.setWidgetResizable(True)
        scroll.setWidget(scroll_widget)
        main_layout = QVBoxLayout()
        main_layout.addWidget(scroll)
        main_widget = QWidget()
        main_widget.setLayout(main_layout)

        self.tabWidget.addTab(main_widget, self.tr('Postprocessors'))
        self.tabWidget.tabBar().setVisible(True)

        # create elements for the tab
        values = OrderedDict()
        for label, parameters in form_elements.items():
            parameter_container = ParameterContainer(parameters)
            parameter_container.setup_ui(must_scroll=False)
            scroll_layout.addWidget(parameter_container)
            input_values = parameter_container.get_parameters
            values[label] = input_values

        self.values['postprocessors'] = values
        scroll_layout.addStretch()
开发者ID:akbargumbira,项目名称:inasafe,代码行数:33,代码来源:function_options_dialog.py

示例3: main

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [as 别名]
def main():
    """Main function to run the example."""
    app = QApplication([])

    default_value_parameter = DefaultValueParameter()
    default_value_parameter.name = 'Value parameter'
    default_value_parameter.help_text = 'Help text'
    default_value_parameter.description = 'Description'
    default_value_parameter.labels = [
        'Setting', 'Do not report', 'Custom']
    default_value_parameter.options = [0, 1, None]

    parameters = [
        default_value_parameter
    ]

    extra_parameters = [
        (DefaultValueParameter, DefaultValueParameterWidget)
    ]

    parameter_container = ParameterContainer(
        parameters, extra_parameters=extra_parameters)
    parameter_container.setup_ui()

    widget = QWidget()
    layout = QGridLayout()
    layout.addWidget(parameter_container)

    widget.setLayout(layout)
    widget.setGeometry(0, 0, 500, 500)

    widget.show()

    sys.exit(app.exec_())
开发者ID:akbargumbira,项目名称:inasafe,代码行数:36,代码来源:example.py

示例4: build_widget

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

示例5: main

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

#.........这里部分代码省略.........
        if not valid:
            raise Exception('Parameter not valid')

    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
开发者ID:inasafe,项目名称:parameters,代码行数:70,代码来源:main.py

示例6: main

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [as 别名]
def main():
    """Main function to run the example."""
    from safe.test.utilities import get_qgis_app
    QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app(qsetting=INASAFE_TEST)

    options = OrderedDict([
        (DO_NOT_REPORT,
         {
             'label': 'Do not report',
             'value': None,
             'type': STATIC,
             'constraint': {}
         }),
        (GLOBAL_DEFAULT,
         {
             'label': 'Global default',
             'value': 0.5,
             'type': STATIC,
             'constraint': {}
         }),
        (CUSTOM_VALUE,
         {
             'label': 'Custom',
             'value': 0.7,  # Taken from keywords / recent value
             'type': SINGLE_DYNAMIC,
             'constraint':
                 {
                     'min': 0,
                     'max': 1
                 }
         }),
        (FIELDS,
         {
             'label': 'Ratio fields',
             'value': ['field A', 'field B', 'field C'],  # Taken from keywords
             'type': MULTIPLE_DYNAMIC,
             'constraint': {}
         })
    ])

    default_value_parameter = GroupSelectParameter()
    default_value_parameter.name = 'Group Select parameter'
    default_value_parameter.help_text = 'Help text'
    default_value_parameter.description = 'Description'
    default_value_parameter.options = options
    default_value_parameter.selected = 'ratio fields'

    parameters = [
        default_value_parameter
    ]

    extra_parameters = [
        (GroupSelectParameter, GroupSelectParameterWidget)
    ]

    parameter_container = ParameterContainer(
        parameters, extra_parameters=extra_parameters)
    parameter_container.setup_ui()

    widget = QWidget()
    layout = QGridLayout()
    layout.addWidget(parameter_container)

    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
        """
        box = QMessageBox()
        box.critical(parent, 'Error occured', str(exception))

    def show_parameter(the_parameter_container):
        """Print the value of parameter.

        :param the_parameter_container: A parameter container
        :type the_parameter_container: ParameterContainer
        """
        def show_parameter_value(a_parameter):
            if isinstance(a_parameter, GroupParameter):
                for param in a_parameter.value:
                    show_parameter_value(param)
            else:
                print((a_parameter.guid, a_parameter.name, a_parameter.value))

        try:
            the_parameters = the_parameter_container.get_parameters()
            if the_parameters:
                for parameter in the_parameters:
                    show_parameter_value(parameter)
        except Exception as inst:
            show_error_message(parameter_container, inst)

    print_button = QPushButton('Print Result')
    # noinspection PyUnresolvedReferences
    print_button.clicked.connect(
        partial(show_parameter, the_parameter_container=parameter_container))

#.........这里部分代码省略.........
开发者ID:inasafe,项目名称:inasafe,代码行数:103,代码来源:example_group_select.py

示例7: restore_default_values_page

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [as 别名]
    def restore_default_values_page(self):
        """Setup UI for default values setting."""
        # Clear parameters so it doesn't add parameters when
        # restore from changes.
        if self.default_value_parameters:
            self.default_value_parameters = []
        if self.default_value_parameter_containers:
            self.default_value_parameter_containers = []

        for i in reversed(list(range(self.container_layout.count()))):
            widget = self.container_layout.itemAt(i).widget()
            if widget is not None:
                widget.setParent(None)

        default_fields = all_default_fields()

        for field_group in all_field_groups:
            settable_fields = []
            for field in field_group['fields']:
                if field not in default_fields:
                    continue
                else:
                    settable_fields.append(field)
                    default_fields.remove(field)

            if not settable_fields:
                continue
            # Create group box for each field group
            group_box = QGroupBox(self)
            group_box.setTitle(field_group['name'])
            self.container_layout.addWidget(group_box)
            parameters = []
            for settable_field in settable_fields:
                parameter = self.default_field_to_parameter(settable_field)
                if parameter:
                    parameters.append(parameter)
            parameter_container = ParameterContainer(
                parameters,
                description_text=field_group['description'],
                extra_parameters=extra_parameter
            )
            parameter_container.setup_ui(must_scroll=False)
            group_box_inner_layout = QVBoxLayout()
            group_box_inner_layout.addWidget(parameter_container)
            group_box.setLayout(group_box_inner_layout)

            # Add to attribute
            self.default_value_parameter_containers.append(parameter_container)

        # Only show non-groups default fields if there is one
        if len(default_fields) > 0:
            for default_field in default_fields:
                parameter = self.default_field_to_parameter(default_field)
                if parameter:
                    self.default_value_parameters.append(parameter)

            description_text = tr(
                'In this options you can change the global default values for '
                'these variables.')
            parameter_container = ParameterContainer(
                self.default_value_parameters,
                description_text=description_text,
                extra_parameters=extra_parameter
            )
            parameter_container.setup_ui(must_scroll=False)
            self.other_group_box = QGroupBox(tr('Non-group fields'))
            other_group_inner_layout = QVBoxLayout()
            other_group_inner_layout.addWidget(parameter_container)
            self.other_group_box.setLayout(other_group_inner_layout)
            self.container_layout.addWidget(self.other_group_box)

            # Add to attribute
            self.default_value_parameter_containers.append(parameter_container)
开发者ID:inasafe,项目名称:inasafe,代码行数:75,代码来源:options_dialog.py

示例8: StepKwInaSAFERasterDefaultValues

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

示例9: GroupParameterWidget

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

示例10: StepKwDefaultInaSAFEFields

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

#.........这里部分代码省略.........
            parameter.is_required = False
            parameter.description = inasafe_field['description']
            parameter.help_text = inasafe_field['help_text']
            parameter.element_type = str
            parameter.options_list = option_list
            parameter.value = no_field
            parameter.default_labels = get_inasafe_default_value_fields(
                self.parent.setting, inasafe_field['key'])[0]
            parameter.default_values = get_inasafe_default_value_fields(
                self.parent.setting, inasafe_field['key'])[1]
            parameter.minimum = inasafe_field['default_value'].get(
                'min_value')
            parameter.maximum = inasafe_field['default_value'].get(
                'max_value')
            # 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 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
开发者ID:inasafe,项目名称:inasafe,代码行数:69,代码来源:step_kw47_default_inasafe_fields.py

示例11: main

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [as 别名]
def main():
    """Main function to run the example."""
    app = QApplication([])

    options = OrderedDict([
        (DO_NOT_REPORT,
         {
             'label': 'Do not report',
             'value': None,
             'type': STATIC,
             'constraint': {}
         }),
        (GLOBAL_DEFAULT,
         {
             'label': 'Global default',
             'value': 0.5,
             'type': STATIC,
             'constraint': {}
         }),
        (CUSTOM_VALUE,
         {
             'label': 'Custom',
             'value': 0.7,  # Taken from keywords / recent value
             'type': SINGLE_DYNAMIC,
             'constraint':
                 {
                     'min': 0,
                     'max': 1
                 }
         }),
        (FIELDS,
         {
             'label': 'Ratio fields',
             'value': ['field A', 'field B', 'field C'],  # Taken from keywords
             'type': MULTIPLE_DYNAMIC,
             'constraint': {}
         })
    ])

    default_value_parameter = GroupSelectParameter()
    default_value_parameter.name = 'Group Select parameter'
    default_value_parameter.help_text = 'Help text'
    default_value_parameter.description = 'Description'
    default_value_parameter.options = options
    default_value_parameter.selected = 'ratio fields'

    parameters = [
        default_value_parameter
    ]

    extra_parameters = [
        (GroupSelectParameter, GroupSelectParameterWidget)
    ]

    parameter_container = ParameterContainer(
        parameters, extra_parameters=extra_parameters)
    parameter_container.setup_ui()

    widget = QWidget()
    layout = QGridLayout()
    layout.addWidget(parameter_container)

    widget.setLayout(layout)
    widget.setGeometry(0, 0, 500, 500)

    widget.show()

    sys.exit(app.exec_())
开发者ID:akbargumbira,项目名称:inasafe,代码行数:70,代码来源:example_group_select.py

示例12: set_up_resource_parameters

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

#.........这里部分代码省略.........
        minimum_parameter.minimum_allowed_value = -99999.0
        minimum_parameter.maximum_allowed_value = 99999.0
        minimum_parameter.help_text = tr(
            'The minimum allowable quantity per person. ')
        minimum_parameter.description = tr(
            '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. This is enforced when tweaking a minimum needs set '
            'before an impact evaluation')
        minimum_parameter.value = 0.00

        maximum_parameter = FloatParameter('UUID-7')
        maximum_parameter.name = self.resource_parameters['Maximum allowed']
        maximum_parameter.is_required = True
        maximum_parameter.precision = 2
        maximum_parameter.minimum_allowed_value = -99999.0
        maximum_parameter.maximum_allowed_value = 99999.0
        maximum_parameter.help_text = tr(
            'The maximum allowable quantity per person. ')
        maximum_parameter.description = tr(
            '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 67l. This is enforced when tweaking a maximum needs set '
            'before an impact evaluation.')
        maximum_parameter.value = 100.0

        default_parameter = FloatParameter('UUID-8')
        default_parameter.name = self.resource_parameters['Default']
        default_parameter.is_required = True
        default_parameter.precision = 2
        default_parameter.minimum_allowed_value = -99999.0
        default_parameter.maximum_allowed_value = 99999.0
        default_parameter.help_text = tr(
            'The default allowable quantity per person. ')
        default_parameter.description = tr(
            "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 weekly should be 67l.")
        default_parameter.value = 10.0

        frequency_parameter = StringParameter('UUID-9')
        frequency_parameter.name = self.resource_parameters['Frequency']
        frequency_parameter.help_text = tr(
            "The frequency that this resource needs to be provided to a "
            "displaced person. e.g. weekly, daily, once etc.")
        frequency_parameter.description = tr(
            "The <b>frequency</b> informs the aid worker how regularly this "
            "resource needs to be provided to the displaced person.")
        frequency_parameter.is_required = True
        frequency_parameter.value = tr('weekly')

        sentence_parameter = TextParameter('UUID-10')
        sentence_parameter.name = self.resource_parameters['Readable sentence']
        sentence_parameter.help_text = tr(
            'A readable presentation of the resource.')
        sentence_parameter.description = tr(
            "A <b>readable sentence</b> is a presentation of the resource "
            "that displays all pertinent information. If you are unsure then "
            "use the default. Properties should be included using double "
            "curly brackets '{{' '}}'. Including the resource name would be "
            "achieved by including e.g. {{ Resource name }}")
        sentence_parameter.is_required = True
        sentence_parameter.value = tr(
            'A displaced person should be provided with '
            '%(default value)s %(unit)s/%(units)s/%(unit abbreviation)s of '
            '%(resource name)s. Though no less than %(minimum allowed)s '
            'and no more than %(maximum allowed)s. This should be provided '
            '%(frequency)s.' % {
                'default value': '{{ Default }}',
                'unit': '{{ Unit }}',
                'units': '{{ Units }}',
                'unit abbreviation': '{{ Unit abbreviation }}',
                'resource name': '{{ Resource name }}',
                'minimum allowed': '{{ Minimum allowed }}',
                'maximum allowed': '{{ Maximum allowed }}',
                'frequency': '{{ Frequency }}'
            })

        parameters = [
            name_parameter,
            description_parameter,
            unit_parameter,
            units_parameter,
            unit_abbreviation_parameter,
            default_parameter,
            minimum_parameter,
            maximum_parameter,
            frequency_parameter,
            sentence_parameter
        ]
        parameter_container = ParameterContainer(parameters)
        parameter_container.setup_ui()

        layout = QGridLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.addWidget(parameter_container)
        self.parameters_scrollarea.setLayout(layout)
开发者ID:timlinux,项目名称:inasafe,代码行数:104,代码来源:needs_manager_dialog.py

示例13: FieldMappingTab

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

#.........这里部分代码省略.........
                        'step': step
                    }
                }

            custom_fields = self.metadata.get('inasafe_fields', {}).get(
                field['key'], [])
            if field['key'] in self.metadata.get('inasafe_fields', {}):
                selected_option = FIELDS
            if isinstance(custom_fields, str):
                custom_fields = [custom_fields]
            options[FIELDS] = {
                'label': field_label,
                'value': custom_fields,
                'type': MULTIPLE_DYNAMIC,
                'constraint': {}
            }
            used_fields.extend(custom_fields)

            parameter = GroupSelectParameter()
            parameter.guid = field['key']
            parameter.name = field['name']
            parameter.options = options
            parameter.selected = selected_option
            parameter.help_text = field['help_text']
            parameter.description = field['description']

            self.parameters.append(parameter)

        self.parameter_container = ParameterContainer(
            parameters=self.parameters,
            extra_parameters=self.extra_parameters,
            vertical=False
        )
        self.parameter_container.setup_ui()

        constraints = self.field_group.get('constraints', {})

        for key, value in list(constraints.items()):
            self.parameter_container.add_validator(
                validators[key],
                kwargs=value['kwargs'],
                validation_message=value['message'])

        self.parameter_layout.addWidget(self.parameter_container)

        default_ratio_help_text = tr(
            'By default, InaSAFE will calculate the default ratio '
            'however users have the option to include this in the '
            'analysis report. If you do not want to see the default '
            '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(
开发者ID:inasafe,项目名称:inasafe,代码行数:70,代码来源:field_mapping_tab.py

示例14: StepKwInaSAFEFields

# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import setup_ui [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.setup_ui方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。