def save_file(self): """save file menu action""" if cfg.curr_file is None: return self.save_as() cfg.update_yaml_file(self.mainwindow.editor.text()) cfg.save_file() self.mainwindow.show_status_message("File is saved")
def transform(self, file): """Run transformation according rules in set file""" cfg.update_yaml_file(self.mainwindow.editor.text()) cfg.transform(file) # synchronize cfg document with editor text self.mainwindow.editor.setText(cfg.document, keep_history=True) self.mainwindow.reload()
def save_old_file(self): """ If file not saved, display confirmation dialeg and if is needed, do it return: False if action have to be aborted """ cfg.update_yaml_file(self.mainwindow.editor.text()) if cfg.changed: msg_box = QMessageBox() msg_box.setWindowTitle("Confirmation") msg_box.setIcon(QMessageBox.Question) msg_box.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Abort) msg_box.setDefaultButton(QMessageBox.Abort) msg_box.setText("The document has unsaved changes, do you want to save it?") reply = msg_box.exec_() if reply == QtWidgets.QMessageBox.Abort: return False if reply == QtWidgets.QMessageBox.Yes: if cfg.curr_file is None: return self.save_as() else: self.save_file() return True
def save_as(self): """save file menu action""" cfg.update_yaml_file(self.mainwindow.editor.text()) if cfg.curr_file is None: if cfg.imported_file_name is not None: new_file = cfg.imported_file_name else: new_file = cfg.config.last_data_dir + os.path.sep + "NewFile.yaml" else: new_file = cfg.curr_file dialog = QtWidgets.QFileDialog(self.mainwindow, 'Save as YAML File', new_file, "YAML Files (*.yaml)") dialog.setDefaultSuffix('.yaml') dialog.setFileMode(QtWidgets.QFileDialog.AnyFile) dialog.setAcceptMode(QtWidgets.QFileDialog.AcceptSave) dialog.setViewMode(QtWidgets.QFileDialog.Detail) if dialog.exec_(): file_name = dialog.selectedFiles()[0] cfg.save_as(file_name) self.mainwindow.update_recent_files() self._update_document_name() self.mainwindow.show_status_message("File is saved") return True return False