From 231c033b5ef7d2a14710b6b4ae53760eb21b16a6 Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Sat, 7 Nov 2020 15:55:06 +0200 Subject: [PATCH] - in GCode Editor added handlers for the Insert Code buttons --- CHANGELOG.md | 1 + appEditors/appGCodeEditor.py | 25 +++++++++++++++++-------- appObjects/FlatCAMCNCJob.py | 2 +- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 37a840a4..3693c8bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ CHANGELOG for FlatCAM beta - set the app to "Unstable" status - fixed an if/else selection in the AppObject.on_object_created() that made the plotting of CNCJob objects to be done twice and second time will disregard the Plot Kind Preference value - updated the GCode generation section. Now the GCode is generated only once, when a CNCJob object was created. If the user chose to use the GCode Editor the GCode is only updated. If the user chose to include or remove the CNC Code Snippets, only then the GCode is regenerated. This has a higher impact on CNCJobs with very complex and long GCode. +- in GCode Editor added handlers for the Insert Code buttons 7.11.2020 diff --git a/appEditors/appGCodeEditor.py b/appEditors/appGCodeEditor.py index 4cbae0bd..f0bf185c 100644 --- a/appEditors/appGCodeEditor.py +++ b/appEditors/appGCodeEditor.py @@ -47,7 +47,8 @@ class AppGCodeEditor(QtCore.QObject): # ################### SIGNALS ##################################################### # ################################################################################# self.ui.name_entry.returnPressed.connect(self.on_name_activate) - self.ui.update_gcode_button.clicked.connect(self.insert_gcode) + self.ui.update_gcode_button.clicked.connect(self.insert_code_snippet_1) + self.ui.update_gcode_sec_button.clicked.connect(self.insert_code_snippet_2) self.ui.exit_editor_button.clicked.connect(lambda: self.app.editor2object()) log.debug("Initialization of the GCode Editor is finished ...") @@ -138,19 +139,19 @@ class AppGCodeEditor(QtCore.QObject): self.ui.cnc_tools_table.setRowCount(n) # add the All Gcode selection - allgcode_item = QtWidgets.QTableWidgetItem('%s' % _("All GCode")) + allgcode_item = QtWidgets.QTableWidgetItem('%s' % _("All")) allgcode_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.cnc_tools_table.setItem(row_no, 1, allgcode_item) row_no += 1 # add the Header Gcode selection - header_item = QtWidgets.QTableWidgetItem('%s' % _("Header GCode")) + header_item = QtWidgets.QTableWidgetItem('%s' % _("Header")) header_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.cnc_tools_table.setItem(row_no, 1, header_item) row_no += 1 # add the Start Gcode selection - start_item = QtWidgets.QTableWidgetItem('%s' % _("Start GCode")) + start_item = QtWidgets.QTableWidgetItem('%s' % _("Start")) start_item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ui.cnc_tools_table.setItem(row_no, 1, start_item) @@ -545,13 +546,21 @@ class AppGCodeEditor(QtCore.QObject): self.buttonSave.setStyleSheet("QPushButton {color: red;}") self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as_red.png')) - def insert_gcode(self): + def insert_code_snippet_1(self): """ :return: :rtype: """ - pass + text = self.ui.prepend_text.toPlainText() + '\n' + my_text_cursor = self.edit_area.textCursor() + my_text_cursor.insertText(text) + + def insert_code_snippet_2(self): + + text = self.ui.append_text.toPlainText() + '\n' + my_text_cursor = self.edit_area.textCursor() + my_text_cursor.insertText(text) def edit_fcgcode(self, cnc_obj): """ @@ -684,7 +693,7 @@ class AppGCodeEditorUI: self.cnc_tools_table.setColumnCount(6) self.cnc_tools_table.setColumnWidth(0, 20) - self.cnc_tools_table.setHorizontalHeaderLabels(['#', _('Dia'), _('Offset'), _('Type'), _('TT'), '']) + self.cnc_tools_table.setHorizontalHeaderLabels(['#', _('GCode'), _('Offset'), _('Type'), _('TT'), '']) self.cnc_tools_table.setColumnHidden(5, True) # CNC Tools Table when made out of Excellon @@ -695,7 +704,7 @@ class AppGCodeEditorUI: self.exc_cnc_tools_table.setColumnCount(6) self.exc_cnc_tools_table.setColumnWidth(0, 20) - self.exc_cnc_tools_table.setHorizontalHeaderLabels(['#', _('Dia'), _('Drills'), _('Slots'), '', _("Cut Z")]) + self.exc_cnc_tools_table.setHorizontalHeaderLabels(['#', _('GCode'), _('Drills'), _('Slots'), '', _("Cut Z")]) self.exc_cnc_tools_table.setColumnHidden(4, True) separator_line = QtWidgets.QFrame() diff --git a/appObjects/FlatCAMCNCJob.py b/appObjects/FlatCAMCNCJob.py index 29f6d032..9477095b 100644 --- a/appObjects/FlatCAMCNCJob.py +++ b/appObjects/FlatCAMCNCJob.py @@ -2068,7 +2068,7 @@ class CNCJobObject(FlatCAMObj, CNCjob): self.app.inform.emit('[ERROR_NOTCL] %s %s...' % (_('Failed.'), _('CNC Machine Code could not be updated'))) return else: - self.source_file = gco + self.source_file = gco.getvalue() self.app.inform.emit('[success] %s...' % _('CNC Machine Code was updated')) def gcode_header(self, comment_start_symbol=None, comment_stop_symbol=None):