本文整理汇总了Python中safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer类的典型用法代码示例。如果您正苦于以下问题:Python ParameterContainer类的具体用法?Python ParameterContainer怎么用?Python ParameterContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ParameterContainer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
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 use', '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_())
示例2: clear
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()
示例3: clear
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()
示例4: raster_changed
def raster_changed(self, index):
"""Executed when raster is changed
:param index: index of the selected raster
:return:
"""
registry = QgsMapLayerRegistry.instance()
layer_id = self.cbo_raster_input.itemData(
index, QtCore.Qt.UserRole)
layer = registry.mapLayer(layer_id)
layer_purpose = self.keyword_io.read_keywords(layer, 'layer_purpose')
if layer_purpose == 'hazard':
impact_function = self.if_registry.filter_by_hazard(
self.if_registry.impact_functions,
self.keyword_io.read_keywords(layer)
)
elif layer_purpose == 'exposure':
impact_function = self.if_registry.filter_by_exposure(
self.if_registry.impact_functions,
self.keyword_io.read_keywords(layer)
)
else:
impact_function = []
if impact_function:
parameters_dict = impact_function[0].parameters
threshold_list = []
for param_key, param_value in parameters_dict.iteritems():
if 'threshold' in param_key:
threshold_list.append(param_value)
if threshold_list:
param_container = ParameterContainer(threshold_list)
param_container.setup_ui(must_scroll=False)
self.threshold_editor.layout().addWidget(param_container)
else:
empty_threshold_label = QLabel(
self.tr('No threshold configuration available '
'for this layer'))
self.threshold_editor.layout().addWidget(
empty_threshold_label)
示例5: __init__
def __init__(self, parent=None):
"""Constructor for the tab.
:param parent: parent - widget to use as parent (Wizard Dialog).
:type parent: QWidget
"""
WizardStep.__init__(self, parent)
self.parameters = []
self.parameter_container = ParameterContainer()
self.kwExtraKeywordsGridLayout.addWidget(self.parameter_container)
示例6: set_widgets
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)
示例7: __init__
def __init__(self, parent=None):
"""Constructor for the tab.
:param parent: parent - widget to use as parent (Wizard Dialog).
:type parent: QWidget
"""
WizardStep.__init__(self, parent)
self.extra_parameters = [
(DefaultValueParameter, DefaultValueParameterWidget)
]
self.parameters = []
self.parameter_container = ParameterContainer(
extra_parameters=self.extra_parameters)
self.default_values_grid.addWidget(self.parameter_container)
示例8: __init__
def __init__(self, parent=None):
"""Constructor for the tab.
:param parent: parent - widget to use as parent (Wizard Dialog).
:type parent: QWidget
"""
WizardStep.__init__(self, parent)
self.extra_parameters = [
(DefaultSelectParameter, DefaultSelectParameterWidget)
]
self.parameters = []
self.parameter_container = ParameterContainer(
extra_parameters=self.extra_parameters)
self.kwExtraKeywordsGridLayout.addWidget(self.parameter_container)
self.message_label = QLabel()
示例9: StepKwInaSAFERasterDefaultValues
class StepKwInaSAFERasterDefaultValues(WizardStep, FORM_CLASS):
"""Keyword Wizard Step: InaSAFE Raster Default Values."""
def __init__(self, parent=None):
"""Constructor for the tab.
:param parent: parent - widget to use as parent (Wizard Dialog).
:type parent: QWidget
"""
WizardStep.__init__(self, parent)
self.extra_parameters = [
(DefaultValueParameter, DefaultValueParameterWidget)
]
self.parameters = []
self.parameter_container = ParameterContainer(
extra_parameters=self.extra_parameters)
self.default_values_grid.addWidget(self.parameter_container)
def is_ready_to_next_step(self):
"""Check if the step is complete.
If so, there is no reason to block the Next button.
:returns: True if new step may be enabled.
:rtype: bool
"""
return True
def get_next_step(self):
"""Find the proper step when user clicks the Next button.
:returns: The step to be switched to
:rtype: WizardStep instance or None
"""
new_step = self.parent.step_kw_source
return new_step
def inasafe_fields_for_the_layer(self):
"""Return a list of inasafe fields the current layer.
:returns: A list where each value represents inasafe field.
:rtype: list
"""
# Get hazard or exposure value
layer_purpose_key = self.parent.step_kw_purpose.selected_purpose()[
'key']
if layer_purpose_key != layer_purpose_aggregation['key']:
subcategory_key = self.parent.step_kw_subcategory.\
selected_subcategory()['key']
else:
subcategory_key = None
# Get all fields with replace_null = True
inasafe_fields = get_fields(
layer_purpose_key,
subcategory_key,
replace_null=True,
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:
#.........这里部分代码省略.........
示例10: set_up_resource_parameters
#.........这里部分代码省略.........
"shortened. For example when planning water rations "
"the units would be l.")
unit_abbreviation_parameter.is_required = True
unit_abbreviation_parameter.value = ''
minimum_parameter = FloatParameter('UUID-6')
minimum_parameter.name = tr('Minimum allowed')
minimum_parameter.is_required = True
minimum_parameter.precision = 2
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 = tr('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 50l. This is enforced when tweaking a minimum needs set '
'before an impact evaluation.')
maximum_parameter.value = 100.0
default_parameter = FloatParameter('UUID-8')
default_parameter.name = tr('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 = tr('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 = tr('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 }} {{ Unit }}/{{ Units }}/{{ Unit abbreviation }} of "
"{{ Resource name }}. Though no less than {{ Minimum allowed }} "
"and no more than {{ Maximum allowed }}. This should be provided "
"{{ 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)
示例11: restore_default_values_page
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 = []
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']
)
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)
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)
示例12: FieldMappingTab
#.........这里部分代码省略.........
'value': custom_value,
'type': SINGLE_DYNAMIC,
'constraint': {
'min': min_value,
'max': max_value,
'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, basestring):
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 constraints.items():
self.parameter_container.add_validator(
validators[key],
kwargs=value['kwargs'],
validation_message=value['message'])
self.parameter_layout.addWidget(self.parameter_container)
# 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' + tr(
'You can only map one field to one concept.')
示例13: populate_parameter
def populate_parameter(self):
"""Helper to setup the parameter widget."""
used_fields = []
self.parameters = []
for field in self.field_group.get('fields', []):
selected_option = DO_NOT_USE
options = OrderedDict([
(DO_NOT_USE,
{
'label': tr('Do not use'),
'value': None,
'type': STATIC,
'constraint': {}
}),
])
# Example: count
if field['absolute']:
# Used in field options
field_label = tr('Count fields')
else: # Example: ratio
# Used in field options
field_label = tr('Ratio fields')
global_default_value = get_inasafe_default_value_qsetting(
self.setting, GLOBAL, field['key'])
options[GLOBAL_DEFAULT] = {
'label': tr('Global default'),
'value': global_default_value,
'type': STATIC,
'constraint': {}
}
default_custom_value = get_inasafe_default_value_qsetting(
self.setting, RECENT, field['key'])
custom_value = self.metadata.get(
'inasafe_default_values', {}).get(
field['key'], default_custom_value)
if field['key'] in self.metadata.get(
'inasafe_default_values', {}):
if custom_value == global_default_value:
selected_option = GLOBAL_DEFAULT
else:
selected_option = CUSTOM_VALUE
min_value = field['default_value'].get('min_value', 0)
max_value = field['default_value'].get('max_value', 100)
default_step = (max_value - min_value) / 100.0
step = field['default_value'].get('increment', default_step)
options[CUSTOM_VALUE] = {
'label': tr('Custom'),
'value': custom_value,
'type': SINGLE_DYNAMIC,
'constraint': {
'min': min_value,
'max': max_value,
'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, basestring):
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 constraints.items():
self.parameter_container.add_validator(
validators[key],
kwargs=value['kwargs'],
validation_message=value['message'])
self.parameter_layout.addWidget(self.parameter_container)
# Set move or copy
if self.field_group.get('exclusive', False):
#.........这里部分代码省略.........
示例14: StepKwInaSAFEFields
class StepKwInaSAFEFields(WizardStep, FORM_CLASS):
"""Keyword Wizard Step: InaSAFE Fields"""
def __init__(self, parent=None):
"""Constructor for the tab.
:param parent: parent - widget to use as parent (Wizard Dialog).
:type parent: QWidget
"""
WizardStep.__init__(self, parent)
self.parameters = []
self.parameter_container = ParameterContainer()
self.kwExtraKeywordsGridLayout.addWidget(self.parameter_container)
def is_ready_to_next_step(self):
"""Check if the step is complete. If so, there is
no reason to block the Next button.
:returns: True if new step may be enabled.
:rtype: bool
"""
return True
def get_next_step(self):
"""Find the proper step when user clicks the Next button.
:returns: The step to be switched to
:rtype: WizardStep instance or None
"""
layer_purpose = self.parent.step_kw_purpose.selected_purpose()
if layer_purpose['key'] != layer_purpose_aggregation['key']:
subcategory = self.parent.step_kw_subcategory. \
selected_subcategory()
else:
subcategory = {'key': None}
# Check if it can go to inasafe default field step
default_inasafe_fields = get_fields(
layer_purpose['key'],
subcategory['key'],
replace_null=True,
in_group=False)
if default_inasafe_fields:
return self.parent.step_kw_default_inasafe_fields
# Any other case
return self.parent.step_kw_source
def inasafe_fields_for_the_layer(self):
"""Return a list of inasafe fields the current layer.
:returns: A list where each value represents inasafe field.
:rtype: list
"""
if (self.parent.get_layer_geometry_key() ==
layer_geometry_raster['key']):
return []
# Get hazard or exposure value
layer_purpose_key = self.parent.step_kw_purpose.selected_purpose()[
'key']
if layer_purpose_key != layer_purpose_aggregation['key']:
subcategory_key = self.parent.step_kw_subcategory.\
selected_subcategory()['key']
else:
subcategory_key = None
# Get all fields with replace_null = False
inasafe_fields = get_fields(
layer_purpose_key,
subcategory_key,
replace_null=False,
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_field = self.parent.get_existing_keyword(
'inasafe_fields')
# Remove old container and parameter
if self.parameter_container:
self.kwExtraKeywordsGridLayout.removeWidget(
self.parameter_container)
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():
#.........这里部分代码省略.........
示例15: set_widgets
def set_widgets(self):
"""Set widgets on the Extra Keywords tab."""
existing_inasafe_field = self.parent.get_existing_keyword(
'inasafe_fields')
# Remove old container and parameter
if self.parameter_container:
self.kwExtraKeywordsGridLayout.removeWidget(
self.parameter_container)
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)