本文整理汇总了Python中safe.gui.tools.minimum_needs.needs_profile.NeedsProfile.read_from_file方法的典型用法代码示例。如果您正苦于以下问题:Python NeedsProfile.read_from_file方法的具体用法?Python NeedsProfile.read_from_file怎么用?Python NeedsProfile.read_from_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.gui.tools.minimum_needs.needs_profile.NeedsProfile
的用法示例。
在下文中一共展示了NeedsProfile.read_from_file方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NeedsManagerDialog
# 需要导入模块: from safe.gui.tools.minimum_needs.needs_profile import NeedsProfile [as 别名]
# 或者: from safe.gui.tools.minimum_needs.needs_profile.NeedsProfile import read_from_file [as 别名]
#.........这里部分代码省略.........
'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)
def import_profile(self):
""" Import minimum needs from an existing json file.
The minimum needs are loaded from a file into the table. This state
is only saved if the form is accepted.
"""
# noinspection PyCallByClass,PyTypeChecker
file_name_dialog = QFileDialog(self)
file_name_dialog.setAcceptMode(QFileDialog.AcceptOpen)
file_name_dialog.setNameFilter(self.tr('JSON files (*.json *.JSON)'))
file_name_dialog.setDefaultSuffix('json')
path_name = resources_path('minimum_needs')
file_name_dialog.setDirectory(path_name)
if file_name_dialog.exec_():
file_name = file_name_dialog.selectedFiles()[0]
else:
return -1
if self.minimum_needs.read_from_file(file_name) == -1:
return -1
self.clear_resource_list()
self.populate_resource_list()
self.switch_context(self.profile_edit_page)
def export_profile(self):
""" Export minimum needs to a json file.
This method will save the current state of the minimum needs setup.
Then open a dialog allowing the user to browse to the desired
destination location and allow the user to save the needs as a json
file.
"""
file_name_dialog = QFileDialog(self)
file_name_dialog.setAcceptMode(QFileDialog.AcceptSave)
file_name_dialog.setNameFilter(self.tr('JSON files (*.json *.JSON)'))
file_name_dialog.setDefaultSuffix('json')
file_name = None
if file_name_dialog.exec_():
file_name = file_name_dialog.selectedFiles()[0]
if file_name != '' and file_name is not None:
self.minimum_needs.write_to_file(file_name)
def save_profile(self):
""" Save the current state of the minimum needs widget.
The minimum needs widget current state is saved to the QSettings via
the appropriate QMinimumNeeds class' method.
"""
minimum_needs = {'resources': []}
for index in range(self.resources_list.count()):