本文整理汇总了Python中safe.gui.tools.minimum_needs.needs_profile.NeedsProfile类的典型用法代码示例。如果您正苦于以下问题:Python NeedsProfile类的具体用法?Python NeedsProfile怎么用?Python NeedsProfile使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NeedsProfile类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_resource
def save_resource(self):
"""Accept the add/edit of the current resource.
"""
# --
# Hackorama to get this working outside the method that the
# parameters where defined in.
parameters_widget = [
self.parameters_scrollarea.layout().itemAt(i) for i in
range(self.parameters_scrollarea.layout().count())][0]
parameters = parameters_widget.widget().get_parameters()
# To store parameters, we need the english version.
translated_to_english = dict(
(y, x) for x, y in list(self.resource_parameters.items()))
resource = {}
for parameter in parameters:
resource[translated_to_english[parameter.name]] = parameter.value
# verify the parameters are ok - create a throw-away resource param
try:
parameter = ResourceParameter()
parameter.name = resource['Resource name']
parameter.help_text = resource['Resource description']
# Adding in the frequency property. This is not in the
# FloatParameter by default, so maybe we should subclass.
parameter.frequency = resource['Frequency']
parameter.description = NeedsProfile.format_sentence(
resource['Readable sentence'],
resource)
parameter.minimum_allowed_value = float(
resource['Minimum allowed'])
parameter.maximum_allowed_value = float(
resource['Maximum allowed'])
parameter.unit.name = resource['Unit']
parameter.unit.plural = resource['Units']
parameter.unit.abbreviation = resource['Unit abbreviation']
parameter.value = float(resource['Default'])
except ValueOutOfBounds as e:
warning = self.tr(
'Problem - default value is invalid') + '\n' + str(e)
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
except InvalidMaximumError as e:
warning = self.tr(
'Problem - maximum value is invalid') + '\n' + str(e)
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
except InvalidMinimumError as e:
warning = self.tr(
'Problem - minimum value is invalid') + '\n' + str(e)
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
# end of test for parameter validity
self.add_resource(resource)
self.switch_context(self.profile_edit_page)
示例2: _initializes_minimum_needs_fields
def _initializes_minimum_needs_fields():
"""Initialize minimum needs fields.
Minimum needs definitions are taken from currently used profile.
"""
needs_profile = NeedsProfile()
needs_profile.load()
fields = []
needs_parameters = needs_profile.get_needs_parameters()
for need_parameter in needs_parameters:
if isinstance(need_parameter, ResourceParameter):
format_args = {
'namespace': minimum_needs_namespace,
'key': _normalize_field_name(need_parameter.name),
'name': need_parameter.name,
'field_name': _normalize_field_name(need_parameter.name),
}
key = '{namespace}__{key}_count_field'.format(**format_args)
name = '{name}'.format(**format_args)
field_name = '{namespace}__{field_name}'.format(**format_args)
field_type = QVariant.LongLong # See issue #4039
length = 11 # See issue #4039
precision = 0
absolute = True
replace_null = False
description = need_parameter.description
field_definition = {
'key': key,
'name': name,
'field_name': field_name,
'type': field_type,
'length': length,
'precision': precision,
'absolute': absolute,
'description': description,
'replace_null': replace_null,
'unit_abbreviation': need_parameter.unit.abbreviation,
# Link to need_parameter
'need_parameter': need_parameter
}
fields.append(field_definition)
return fields
示例3: add_resource
def add_resource(self, resource):
"""Add a resource to the minimum needs table.
:param resource: The resource to be added
:type resource: dict
"""
updated_sentence = NeedsProfile.format_sentence(
resource['Readable sentence'], resource)
if self.edit_item:
item = self.edit_item
item.setText(updated_sentence)
self.edit_item = None
else:
item = QtGui.QListWidgetItem(updated_sentence)
item.resource_full = resource
self.resources_list.addItem(item)
示例4: save_resource
def save_resource(self):
"""Accept the add/edit of the current resource.
"""
# --
# Hackorama to get this working outside the method that the
# parameters where defined in.
parameters_widget = [
self.resource_widget.layout().itemAt(i) for i in
range(self.resource_widget.layout().count())][0]
parameters = parameters_widget.widget().get_parameters()
resource = {}
for parameter in parameters:
resource[parameter.name] = parameter.value
# verify the parameters are ok - create a throw-away resource param
try:
parameter = ResourceParameter()
parameter.name = resource['Resource name']
parameter.help_text = resource['Resource description']
# Adding in the frequency property. This is not in the
# FloatParameter by default, so maybe we should subclass.
parameter.frequency = resource['Frequency']
parameter.description = NeedsProfile.format_sentence(
resource['Readable sentence'],
resource)
parameter.minimum_allowed_value = float(
resource['Minimum allowed'])
parameter.maximum_allowed_value = float(
resource['Maximum allowed'])
parameter.unit.name = resource['Unit']
parameter.unit.plural = resource['Units']
parameter.unit.abbreviation = resource['Unit abbreviation']
parameter.value = float(resource['Default'])
except ValueOutOfBounds, e:
warning = self.tr(
'Problem - default value is invalid') + '\n' + e.message
# noinspection PyTypeChecker,PyArgumentList
QMessageBox.warning(None, 'InaSAFE', warning)
return
示例5: __init__
def __init__(self, parent=None, dock=None):
"""Constructor for the minimum needs dialog.
:param parent: Parent widget of this dialog.
:type parent: QWidget
:param dock: Dock widget instance that we can notify of changes.
:type dock: Dock
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.dock = dock
# These are in the little button bar at the top
# 'Remove resource' button
# noinspection PyUnresolvedReferences
self.remove_resource_button.clicked.connect(self.remove_resource)
self.remove_resource_button.setIcon(
QIcon(os.path.join(
resources_path(), 'img', 'icons', 'remove.svg')))
# Add resource
# noinspection PyUnresolvedReferences
self.add_resource_button.clicked.connect(self.add_new_resource)
self.add_resource_button.setIcon(
QIcon(os.path.join(
resources_path(), 'img', 'icons', 'add.svg')))
# Edit resource
# noinspection PyUnresolvedReferences
self.edit_resource_button.clicked.connect(self.edit_resource)
self.edit_resource_button.setIcon(
QIcon(os.path.join(
resources_path(), 'img', 'icons', 'edit.svg')))
# Discard changes to a resource
self.discard_changes_button = QPushButton(self.tr('Discard changes'))
self.button_box.addButton(
self.discard_changes_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.discard_changes_button.clicked.connect(self.discard_changes)
# Save changes to a resource
self.save_resource_button = QPushButton(self.tr('Save resource'))
self.button_box.addButton(
self.save_resource_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_resource_button.clicked.connect(self.save_resource)
# Export profile button
self.export_profile_button = QPushButton(self.tr('Export ...'))
self.button_box.addButton(
self.export_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.export_profile_button.clicked.connect(self.export_profile)
# Import profile button
self.import_profile_button = QPushButton(self.tr('Import ...'))
self.button_box.addButton(
self.import_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.import_profile_button.clicked.connect(self.import_profile)
# New profile button
self.new_profile_button = QPushButton(self.tr('New'))
self.button_box.addButton(
self.new_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.new_profile_button.clicked.connect(self.new_profile)
# Save profile button
self.save_profile_button = QPushButton(self.tr('Save'))
self.button_box.addButton(
self.save_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_profile_button.clicked.connect(self.save_profile)
# 'Save as' profile button
self.save_profile_as_button = QPushButton(self.tr('Save as'))
self.button_box.addButton(
self.save_profile_as_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_profile_as_button.clicked.connect(
self.save_profile_as)
# Set up things for context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
self.minimum_needs = NeedsProfile()
self.edit_item = None
# Remove profile button
# noinspection PyUnresolvedReferences
self.remove_profile_button.clicked.connect(self.remove_profile)
# These are all buttons that will get hidden on context change
# to the profile editing view
#.........这里部分代码省略.........
示例6: NeedsManagerDialog
class NeedsManagerDialog(QDialog, FORM_CLASS):
"""Dialog class for the InaSAFE global minimum needs configuration.
.. versionadded:: 2.2.
"""
def __init__(self, parent=None, dock=None):
"""Constructor for the minimum needs dialog.
:param parent: Parent widget of this dialog.
:type parent: QWidget
:param dock: Dock widget instance that we can notify of changes.
:type dock: Dock
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.dock = dock
# These are in the little button bar at the top
# 'Remove resource' button
# noinspection PyUnresolvedReferences
self.remove_resource_button.clicked.connect(self.remove_resource)
self.remove_resource_button.setIcon(
QIcon(os.path.join(
resources_path(), 'img', 'icons', 'remove.svg')))
# Add resource
# noinspection PyUnresolvedReferences
self.add_resource_button.clicked.connect(self.add_new_resource)
self.add_resource_button.setIcon(
QIcon(os.path.join(
resources_path(), 'img', 'icons', 'add.svg')))
# Edit resource
# noinspection PyUnresolvedReferences
self.edit_resource_button.clicked.connect(self.edit_resource)
self.edit_resource_button.setIcon(
QIcon(os.path.join(
resources_path(), 'img', 'icons', 'edit.svg')))
# Discard changes to a resource
self.discard_changes_button = QPushButton(self.tr('Discard changes'))
self.button_box.addButton(
self.discard_changes_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.discard_changes_button.clicked.connect(self.discard_changes)
# Save changes to a resource
self.save_resource_button = QPushButton(self.tr('Save resource'))
self.button_box.addButton(
self.save_resource_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_resource_button.clicked.connect(self.save_resource)
# Export profile button
self.export_profile_button = QPushButton(self.tr('Export ...'))
self.button_box.addButton(
self.export_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.export_profile_button.clicked.connect(self.export_profile)
# Import profile button
self.import_profile_button = QPushButton(self.tr('Import ...'))
self.button_box.addButton(
self.import_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.import_profile_button.clicked.connect(self.import_profile)
# New profile button
self.new_profile_button = QPushButton(self.tr('New'))
self.button_box.addButton(
self.new_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.new_profile_button.clicked.connect(self.new_profile)
# Save profile button
self.save_profile_button = QPushButton(self.tr('Save'))
self.button_box.addButton(
self.save_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_profile_button.clicked.connect(self.save_profile)
# 'Save as' profile button
self.save_profile_as_button = QPushButton(self.tr('Save as'))
self.button_box.addButton(
self.save_profile_as_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_profile_as_button.clicked.connect(
self.save_profile_as)
# Set up things for context help
self.help_button = self.button_box.button(QtGui.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
self.minimum_needs = NeedsProfile()
self.edit_item = None
#.........这里部分代码省略.........
示例7: NeedsManagerDialog
#.........这里部分代码省略.........
# noinspection PyUnresolvedReferences
self.import_profile_button.clicked.connect(self.import_profile)
# New profile button
self.new_profile_button = QPushButton(self.tr('New'))
self.button_box.addButton(
self.new_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.new_profile_button.clicked.connect(self.new_profile)
# Save profile button
self.save_profile_button = QPushButton(self.tr('Save'))
self.button_box.addButton(
self.save_profile_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_profile_button.clicked.connect(self.save_profile)
# 'Save as' profile button
self.save_profile_as_button = QPushButton(self.tr('Save as'))
self.button_box.addButton(
self.save_profile_as_button, QDialogButtonBox.ActionRole)
# noinspection PyUnresolvedReferences
self.save_profile_as_button.clicked.connect(
self.save_profile_as)
# Set up things for context help
self.help_button = self.button_box.button(
QtWidgets.QDialogButtonBox.Help)
# Allow toggling the help button
self.help_button.setCheckable(True)
self.help_button.toggled.connect(self.help_toggled)
self.main_stacked_widget.setCurrentIndex(1)
self.minimum_needs = NeedsProfile()
self.edit_item = None
# Remove profile button
# noinspection PyUnresolvedReferences
self.remove_profile_button.clicked.connect(self.remove_profile)
# These are all buttons that will get hidden on context change
# to the profile editing view
self.profile_editing_buttons = list()
self.profile_editing_buttons.append(self.remove_resource_button)
self.profile_editing_buttons.append(self.add_resource_button)
self.profile_editing_buttons.append(self.edit_resource_button)
self.profile_editing_buttons.append(self.export_profile_button)
self.profile_editing_buttons.append(self.import_profile_button)
self.profile_editing_buttons.append(self.new_profile_button)
self.profile_editing_buttons.append(self.save_profile_button)
self.profile_editing_buttons.append(self.save_profile_as_button)
# We also keep a list of all widgets to disable in context of resource
# editing (not hidden, just disabled)
self.profile_editing_widgets = self.profile_editing_buttons
self.profile_editing_widgets.append(self.remove_profile_button)
self.profile_editing_widgets.append(self.profile_combo)
# These are all buttons that will get hidden on context change
# to the resource editing view
self.resource_editing_buttons = list()
self.resource_editing_buttons.append(self.discard_changes_button)
self.resource_editing_buttons.append(self.save_resource_button)
for item in self.resource_editing_buttons:
item.hide()
self.load_profiles()
# Next 2 lines fixes issues #1388 #1389 #1390 #1391