本文整理汇总了Python中safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer.get_parameters方法的典型用法代码示例。如果您正苦于以下问题:Python ParameterContainer.get_parameters方法的具体用法?Python ParameterContainer.get_parameters怎么用?Python ParameterContainer.get_parameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer
的用法示例。
在下文中一共展示了ParameterContainer.get_parameters方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FieldMappingTab
# 需要导入模块: from safe_extras.parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]
#.........这里部分代码省略.........
# 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.')
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' + 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
"""
try:
parameters = self.parameter_container.get_parameters(True)
except InvalidValidationException as e:
raise OriginalValidationException(e)
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.fieldNameIndex(field_name)
unique_values = 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))
示例2: StepKwDefaultInaSAFEFields
# 需要导入模块: from safe_extras.parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]
#.........这里部分代码省略.........
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 use'
parameter_widget.widget().set_selected_radio_button()
# 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, DefaultSelectParameterWidget):
parameter_widget.set_default(default)
# Set selected radio button to 'Do not use'
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(range(self.kwExtraKeywordsGridLayout.count())):
self.kwExtraKeywordsGridLayout.itemAt(i).widget().setParent(None)
self.parameters = []
self.parameter_container = ParameterContainer()
def is_good_age_ratios(self):
"""Method to check the sum of age ratio is 1.
:returns: True if the sum is 1 or the sum less than 1 but there is
示例3: StepKwInaSAFEFields
# 需要导入模块: from safe_extras.parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]
#.........这里部分代码省略.........
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():
# 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()
示例4: StepKwInaSAFERasterDefaultValues
# 需要导入模块: from safe_extras.parameters.qt_widgets.parameter_container import ParameterContainer [as 别名]
# 或者: from safe_extras.parameters.qt_widgets.parameter_container.ParameterContainer import get_parameters [as 别名]
#.........这里部分代码省略.........
: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:
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()