def on_save_json(self, *args):
"""Triggered when save-button is clicked.
Displays a save dialog, fetches GUI data into merge, and saves as JSON into the selected file."""
self.notify_task('Saving..', 0)
_filename = filedialog.asksaveasfilename(initialfile= self.filename, defaultextension=".json",
filetypes=[('JSON files', '.json'), ('all files', '.*')],
title="Choose location")
if _filename:
self._gui_to_merge()
self.notify_task('Saving(Generating JS)..', 0)
_json = self.merge.as_json()
self.notify_task('Saving(Writing file)..', 50)
with open (_filename, "w") as _f:
json.dump(_json, fp=_f, sort_keys=True, indent=4)
self.notify_task('Saving..done.', 100)
else:
self.notify_task('Saving cancelled.', 0)
评论列表
文章目录