diff --git a/src/Mod/CAM/Path/Post/Utils.py b/src/Mod/CAM/Path/Post/Utils.py index 9c01bf2030..7a694e1990 100644 --- a/src/Mod/CAM/Path/Post/Utils.py +++ b/src/Mod/CAM/Path/Post/Utils.py @@ -208,7 +208,7 @@ class GCodeHighlighter(QtGui.QSyntaxHighlighter): class GCodeEditorDialog(QtGui.QDialog): - def __init__(self, parent=None, refactored=False): + def __init__(self, text="", parent=None, refactored=False): if parent is None: parent = FreeCADGui.getMainWindow() QtGui.QDialog.__init__(self, parent) @@ -222,24 +222,35 @@ class GCodeEditorDialog(QtGui.QDialog): font.setFixedPitch(True) font.setPointSize(10) self.editor.setFont(font) - self.editor.setText("G01 X55 Y4.5 F300.0") + self.editor.setText(text) layout.addWidget(self.editor) # buttons depending on the post processor used if refactored: self.buttons = QtGui.QDialogButtonBox( - QtGui.QDialogButtonBox.Apply + QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Discard | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self, ) + # Swap the button text as to not change the old cancel behaviour for the user + self.buttons.button(QtGui.QDialogButtonBox.Discard).setIcon( + self.buttons.button(QtGui.QDialogButtonBox.Cancel).icon() + ) + self.buttons.button(QtGui.QDialogButtonBox.Discard).setText( + self.buttons.button(QtGui.QDialogButtonBox.Cancel).text() + ) + self.buttons.button(QtGui.QDialogButtonBox.Cancel).setIcon(QtGui.QIcon()) + self.buttons.button(QtGui.QDialogButtonBox.Cancel).setText("Abort") else: self.buttons = QtGui.QDialogButtonBox( QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self, ) + + self.buttons.button(QtGui.QDialogButtonBox.Ok).setDisabled(True) layout.addWidget(self.buttons) # restore placement and size @@ -254,8 +265,13 @@ class GCodeEditorDialog(QtGui.QDialog): if width > 0 and height > 0: self.resize(width, height) + # connect signals + self.editor.textChanged.connect(self.text_changed) self.buttons.clicked.connect(self.clicked) + def text_changed(self): + self.buttons.button(QtGui.QDialogButtonBox.Ok).setDisabled(False) + def clicked(self, button): match self.buttons.buttonRole(button): case QtGui.QDialogButtonBox.RejectRole: @@ -320,6 +336,7 @@ def editor(gcode): dia = GCodeEditorDialog() dia.editor.setText(gcode) + dia.buttons.button(QtGui.QDialogButtonBox.Ok).setDisabled(True) gcodeSize = len(dia.editor.toPlainText()) if gcodeSize <= mhs: # because of poor performance, syntax highlighting is diff --git a/src/Mod/CAM/Path/Post/UtilsExport.py b/src/Mod/CAM/Path/Post/UtilsExport.py index da5023548f..3e77638e3a 100644 --- a/src/Mod/CAM/Path/Post/UtilsExport.py +++ b/src/Mod/CAM/Path/Post/UtilsExport.py @@ -336,16 +336,15 @@ def export_common(values: Values, objectslist, filename: str) -> str: if len(final) > 100000: print("Skipping editor since output is greater than 100kb") else: - dia = PostUtils.GCodeEditorDialog(refactored=True) # the editor expects lines to end in "\n", and returns lines ending in "\n" if values["END_OF_LINE_CHARACTERS"] == "\n": - dia.editor.setText(final) + dia = PostUtils.GCodeEditorDialog(final, refactored=True) editor_result = dia.exec_() if editor_result == 1: final = dia.editor.toPlainText() else: final_for_editor = "\n".join(gcode) - dia.editor.setText(final_for_editor) + dia = PostUtils.GCodeEditorDialog(final_for_editor, refactored=True) editor_result = dia.exec_() if editor_result == 1: final_for_editor = dia.editor.toPlainText() @@ -362,7 +361,7 @@ def export_common(values: Values, objectslist, filename: str) -> str: final = final_for_editor.replace("\n", values["END_OF_LINE_CHARACTERS"]) if editor_result == 0: - print("canceled postprocessing.") + print("aborted postprocessing.") return None if not filename == "-":