本文整理汇总了Python中parameters.qt_widgets.parameter_container.ParameterContainer.add_validator方法的典型用法代码示例。如果您正苦于以下问题:Python ParameterContainer.add_validator方法的具体用法?Python ParameterContainer.add_validator怎么用?Python ParameterContainer.add_validator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类parameters.qt_widgets.parameter_container.ParameterContainer
的用法示例。
在下文中一共展示了ParameterContainer.add_validator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import add_validator [as 别名]
#.........这里部分代码省略.........
]
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
"""
box = QMessageBox()
box.critical(parent, 'Error occured', exception.message)
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)
button = QPushButton('Show parameters')
# noinspection PyUnresolvedReferences
button.clicked.connect(
partial(show_parameter, the_parameter_container=parameter_container))
validate_button = QPushButton('Validate parameters')
# noinspection PyUnresolvedReferences
validate_button.clicked.connect(
partial(show_parameter, the_parameter_container=parameter_container3))
widget = QWidget()
layout = QGridLayout()
layout.addWidget(parameter_container)
layout.addWidget(button)
layout.addWidget(parameter_container2)
layout.addWidget(parameter_container3)
layout.addWidget(validate_button)
widget.setLayout(layout)
widget.setGeometry(0, 0, 500, 500)
widget.show()
sys.exit(app.exec_())
示例2: FieldMappingTab
# 需要导入模块: from parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from parameters.qt_widgets.parameter_container.ParameterContainer import add_validator [as 别名]
#.........这里部分代码省略.........
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(
'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