本文整理汇总了Python中safe.gui.tools.minimum_needs.needs_profile.NeedsProfile.write_to_file方法的典型用法代码示例。如果您正苦于以下问题:Python NeedsProfile.write_to_file方法的具体用法?Python NeedsProfile.write_to_file怎么用?Python NeedsProfile.write_to_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类safe.gui.tools.minimum_needs.needs_profile.NeedsProfile
的用法示例。
在下文中一共展示了NeedsProfile.write_to_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 write_to_file [as 别名]
#.........这里部分代码省略.........
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()):
item = self.resources_list.item(index)
minimum_needs['resources'].append(item.resource_full)
minimum_needs['provenance'] = self.provenance.text()
minimum_needs['profile'] = self.profile_combo.itemText(
self.profile_combo.currentIndex()
)
self.minimum_needs.update_minimum_needs(minimum_needs)
self.minimum_needs.save()
self.minimum_needs.save_profile(minimum_needs['profile'])
self.mark_current_profile_as_saved()
def save_profile_as(self):
"""Save the minimum needs under a new profile name.
"""
# noinspection PyCallByClass,PyTypeChecker
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')
dir = os.path.join(QgsApplication.qgisSettingsDirPath(),
'inasafe', 'minimum_needs')
file_name_dialog.setDirectory(expanduser(dir))
if file_name_dialog.exec_():