- added some icons in the Code Editor

- replaced some icons in the app
- in Code Editor, when changing text, the Save Code button will change color (text and icon) to red and after save it will revert the color to the default one
- in Code Editor some methods rework
This commit is contained in:
Marius Stanciu 2020-07-18 00:26:03 +03:00 committed by Marius
parent 1b15d2a2c1
commit 8409c74e23
29 changed files with 61 additions and 61 deletions

View File

@ -7,6 +7,13 @@ CHANGELOG for FlatCAM beta
=================================================
18.07.2020
- added some icons in the Code Editor
- replaced some icons in the app
- in Code Editor, when changing text, the Save Code button will change color (text and icon) to red and after save it will revert the color to the default one
- in Code Editor some methods rework
16.07.2020
- added a new method for GCode generation for Geometry objects

View File

@ -72,13 +72,17 @@ class AppTextEditor(QtWidgets.QWidget):
self.code_editor.setPlainText(text)
self.buttonPreview = QtWidgets.QPushButton(_('Print Preview'))
self.buttonPreview.setIcon(QtGui.QIcon(self.app.resource_location + '/preview32.png'))
self.buttonPreview.setToolTip(_("Open a OS standard Preview Print window."))
self.buttonPreview.setMinimumWidth(100)
self.buttonPrint = QtWidgets.QPushButton(_('Print Code'))
self.buttonPrint.setIcon(QtGui.QIcon(self.app.resource_location + '/printer32.png'))
self.buttonPrint.setToolTip(_("Open a OS standard Print window."))
self.buttonPrint.setMinimumWidth(100)
self.buttonFind = QtWidgets.QPushButton(_('Find in Code'))
self.buttonFind.setIcon(QtGui.QIcon(self.app.resource_location + '/find32.png'))
self.buttonFind.setToolTip(_("Will search and highlight in yellow the string in the Find box."))
self.buttonFind.setMinimumWidth(100)
@ -86,6 +90,7 @@ class AppTextEditor(QtWidgets.QWidget):
self.entryFind.setToolTip(_("Find box. Enter here the strings to be searched in the text."))
self.buttonReplace = QtWidgets.QPushButton(_('Replace With'))
self.buttonReplace.setIcon(QtGui.QIcon(self.app.resource_location + '/replace32.png'))
self.buttonReplace.setToolTip(_("Will replace the string from the Find box with the one in the Replace box."))
self.buttonReplace.setMinimumWidth(100)
@ -97,17 +102,23 @@ class AppTextEditor(QtWidgets.QWidget):
"with the text in the 'Replace' box.."))
self.button_copy_all = QtWidgets.QPushButton(_('Copy All'))
self.button_copy_all.setIcon(QtGui.QIcon(self.app.resource_location + '/copy_file32.png'))
self.button_copy_all.setToolTip(_("Will copy all the text in the Code Editor to the clipboard."))
self.button_copy_all.setMinimumWidth(100)
self.buttonOpen = QtWidgets.QPushButton(_('Open Code'))
self.buttonOpen.setIcon(QtGui.QIcon(self.app.resource_location + '/folder32_bis.png'))
self.buttonOpen.setToolTip(_("Will open a text file in the editor."))
self.buttonOpen.setMinimumWidth(100)
self.buttonSave = QtWidgets.QPushButton(_('Save Code'))
self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
self.buttonSave.setToolTip(_("Will save the text in the editor into a file."))
self.buttonSave.setMinimumWidth(100)
self.buttonRun = QtWidgets.QPushButton(_('Run Code'))
self.buttonRun.setToolTip(_("Will run the TCL commands found in the text file, one by one."))
self.buttonRun.setMinimumWidth(100)
self.buttonRun.hide()
@ -169,7 +180,26 @@ class AppTextEditor(QtWidgets.QWidget):
# enable = not self.ui.code_editor.document().isEmpty()
# self.ui.buttonPrint.setEnabled(enable)
# self.ui.buttonPreview.setEnabled(enable)
pass
self.buttonSave.setStyleSheet("QPushButton {color: red;}")
self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as_red.png'))
def load_text(self, text, move_to_start=False, move_to_end=False, clear_text=True, as_html=False):
self.code_editor.textChanged.disconnect()
if clear_text:
# first clear previous text in text editor (if any)
self.code_editor.clear()
self.code_editor.setReadOnly(False)
if as_html is False:
self.code_editor.setPlainText(text)
else:
self.code_editor.setHtml(text)
if move_to_start:
self.code_editor.moveCursor(QtGui.QTextCursor.Start)
elif move_to_end:
self.code_editor.moveCursor(QtGui.QTextCursor.End)
self.code_editor.textChanged.connect(self.handleTextChanged)
def handleOpen(self, filt=None):
self.app.defaults.report_usage("handleOpen()")
@ -268,6 +298,8 @@ class AppTextEditor(QtWidgets.QWidget):
with open(filename, 'w') as f:
for line in my_gcode:
f.write(line)
self.buttonSave.setStyleSheet("")
self.buttonSave.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
except FileNotFoundError:
self.app.inform.emit('[WARNING] %s' % _("No such file or directory"))
return

View File

@ -2028,14 +2028,13 @@ class CNCObjectUI(ObjectUI):
# GO Button
self.export_gcode_button = QtWidgets.QPushButton(_('Save CNC Code'))
self.export_gcode_button.setIcon(QtGui.QIcon(self.app.resource_location + '/save_as.png'))
self.export_gcode_button.setToolTip(
_("Opens dialog to save G-Code\n"
"file.")
)
# h_lay.addWidget(self.modify_gcode_button)
h_lay.addWidget(self.export_gcode_button)
# self.custom_box.addWidget(self.export_gcode_button)
class ScriptObjectUI(ObjectUI):

View File

@ -579,10 +579,6 @@ class CNCJobObject(FlatCAMObj, CNCjob):
self.app.ui.position_label.setText("")
self.app.ui.rel_position_label.setText("")
# first clear previous text in text editor (if any)
self.gcode_editor_tab.code_editor.clear()
self.gcode_editor_tab.code_editor.setReadOnly(False)
self.gcode_editor_tab.code_editor.completer_enable = False
self.gcode_editor_tab.buttonRun.hide()
@ -592,20 +588,12 @@ class CNCJobObject(FlatCAMObj, CNCjob):
self.gcode_editor_tab.t_frame.hide()
# then append the text from GCode to the text editor
try:
self.gcode_editor_tab.code_editor.setPlainText(self.app.gcode_edited.getvalue())
# for line in self.app.gcode_edited:
# QtWidgets.QApplication.processEvents()
#
# proc_line = str(line).strip('\n')
# self.gcode_editor_tab.code_editor.append(proc_line)
self.gcode_editor_tab.load_text(self.app.gcode_edited.getvalue(), move_to_start=True, clear_text=True)
except Exception as e:
log.debug('FlatCAMCNNJob.on_edit_code_click() -->%s' % str(e))
self.app.inform.emit('[ERROR] %s %s' % ('FlatCAMCNNJob.on_edit_code_click() -->', str(e)))
return
self.gcode_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
self.gcode_editor_tab.handleTextChanged()
self.gcode_editor_tab.t_frame.show()
self.app.proc_container.view.set_idle()

View File

@ -84,10 +84,6 @@ class DocumentObject(FlatCAMObj):
self.document_editor_tab.code_editor.setStyleSheet(stylesheet)
# first clear previous text in text editor (if any)
self.document_editor_tab.code_editor.clear()
self.document_editor_tab.code_editor.setReadOnly(self._read_only)
self.document_editor_tab.buttonRun.hide()
self.ui.autocomplete_cb.set_value(self.app.defaults['document_autocompleter'])
@ -138,14 +134,16 @@ class DocumentObject(FlatCAMObj):
self.ui.font_size_cb.setCurrentIndex(int(self.app.defaults['document_font_size']))
self.document_editor_tab.handleTextChanged()
# self.document_editor_tab.handleTextChanged()
self.ser_attrs = ['options', 'kind', 'source_file']
if Qt.mightBeRichText(self.source_file):
self.document_editor_tab.code_editor.setHtml(self.source_file)
# self.document_editor_tab.code_editor.setHtml(self.source_file)
self.document_editor_tab.load_text(self.source_file, move_to_start=True, clear_text=True, as_html=True)
else:
for line in self.source_file.splitlines():
self.document_editor_tab.code_editor.append(line)
# for line in self.source_file.splitlines():
# self.document_editor_tab.code_editor.append(line)
self.document_editor_tab.load_text(self.source_file, move_to_start=True, clear_text=True, as_html=False)
self.build_ui()

View File

@ -135,14 +135,11 @@ class ScriptObject(FlatCAMObj):
self.script_editor_tab.t_frame.hide()
try:
self.script_editor_tab.code_editor.setPlainText(self.source_file)
# for line in self.source_file.splitlines():
# QtWidgets.QApplication.processEvents()
# self.script_editor_tab.code_editor.append(line)
# self.script_editor_tab.code_editor.setPlainText(self.source_file)
self.script_editor_tab.load_text(self.source_file, move_to_end=True)
except Exception as e:
log.debug("ScriptObject.set_ui() --> %s" % str(e))
self.script_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.End)
self.script_editor_tab.t_frame.show()
self.app.proc_container.view.set_idle()

View File

@ -1072,10 +1072,6 @@ class ToolCalibration(AppTool):
self.app.ui.position_label.setText("")
self.app.ui.rel_position_label.setText("")
# first clear previous text in text editor (if any)
self.gcode_editor_tab.code_editor.clear()
self.gcode_editor_tab.code_editor.setReadOnly(False)
self.gcode_editor_tab.code_editor.completer_enable = False
self.gcode_editor_tab.buttonRun.hide()
@ -1085,13 +1081,11 @@ class ToolCalibration(AppTool):
self.gcode_editor_tab.t_frame.hide()
# then append the text from GCode to the text editor
try:
self.gcode_editor_tab.code_editor.setPlainText(gcode)
self.gcode_editor_tab.load_text(gcode, move_to_start=True, clear_text=True)
except Exception as e:
self.app.inform.emit('[ERROR] %s %s' % ('ERROR -->', str(e)))
return
self.gcode_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
self.gcode_editor_tab.t_frame.show()
self.app.proc_container.view.set_idle()

View File

@ -3269,7 +3269,8 @@ class IsoUI:
separator_line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.grid3.addWidget(separator_line, 39, 0, 1, 2)
self.generate_iso_button = QtWidgets.QPushButton("%s" % _("Generate Isolation Geometry"))
self.generate_iso_button = QtWidgets.QPushButton("%s" % _("Generate Geometry"))
self.generate_iso_button.setIcon(QtGui.QIcon(self.app.resource_location + '/geometry32.png'))
self.generate_iso_button.setStyleSheet("""
QPushButton
{

View File

@ -4214,6 +4214,7 @@ class NccUI:
self.grid3.addWidget(separator_line, 32, 0, 1, 2)
self.generate_ncc_button = QtWidgets.QPushButton(_('Generate Geometry'))
self.generate_ncc_button.setIcon(QtGui.QIcon(self.app.resource_location + '/geometry32.png'))
self.generate_ncc_button.setToolTip(
_("Create the Geometry Object\n"
"for non-copper routing.")

View File

@ -3241,6 +3241,7 @@ class PaintUI:
# GO Button
self.generate_paint_button = QtWidgets.QPushButton(_('Generate Geometry'))
self.generate_paint_button.setIcon(QtGui.QIcon(self.app.resource_location + '/geometry32.png'))
self.generate_paint_button.setToolTip(
_("Create a Geometry Object which paints the polygons.")
)

View File

@ -1019,19 +1019,15 @@ class SolderPaste(AppTool):
return
try:
for line in lines:
proc_line = str(line).strip('\n')
self.text_editor_tab.code_editor.append(proc_line)
# for line in lines:
# proc_line = str(line).strip('\n')
# self.text_editor_tab.code_editor.append(proc_line)
self.text_editor_tab.load_text(lines, move_to_start=True)
except Exception as e:
log.debug('ToolSolderPaste.on_view_gcode() -->%s' % str(e))
self.app.inform.emit('[ERROR] %s --> %s' % ('ToolSolderPaste.on_view_gcode()', str(e)))
return
self.text_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
self.text_editor_tab.handleTextChanged()
# self.app.ui.show()
def on_save_gcode(self):
"""
Save solderpaste dispensing GCode to a file on HDD.

View File

@ -7668,9 +7668,6 @@ class App(QtCore.QObject):
self.ui.coords_toolbar.hide()
self.ui.delta_coords_toolbar.hide()
# first clear previous text in text editor (if any)
self.text_editor_tab.code_editor.clear()
self.text_editor_tab.code_editor.setReadOnly(False)
self.toggle_codeeditor = True
self.text_editor_tab.code_editor.completer_enable = False
self.text_editor_tab.buttonRun.hide()
@ -7722,10 +7719,6 @@ class App(QtCore.QObject):
self.ui.coords_toolbar.hide()
self.ui.delta_coords_toolbar.hide()
# first clear previous text in text editor (if any)
self.source_editor_tab.code_editor.clear()
self.source_editor_tab.code_editor.setReadOnly(False)
self.source_editor_tab.code_editor.completer_enable = False
self.source_editor_tab.buttonRun.hide()
@ -7767,20 +7760,13 @@ class App(QtCore.QObject):
self.source_editor_tab.t_frame.hide()
try:
self.source_editor_tab.code_editor.setPlainText(file.getvalue())
# for line in file:
# QtWidgets.QApplication.processEvents()
# proc_line = str(line).strip('\n')
# self.source_editor_tab.code_editor.append(proc_line)
self.source_editor_tab.load_text(file.getvalue(), clear_text=True, move_to_start=True)
except Exception as e:
log.debug('App.on_view_source() -->%s' % str(e))
self.inform.emit('[ERROR] %s: %s' % (_('Failed to load the source code for the selected object'), str(e)))
return
self.source_editor_tab.handleTextChanged()
self.source_editor_tab.t_frame.show()
self.source_editor_tab.code_editor.moveCursor(QtGui.QTextCursor.Start)
self.proc_container.view.set_idle()
# self.ui.show()
@ -9205,7 +9191,7 @@ class App(QtCore.QObject):
if f.open(QtCore.QIODevice.ReadOnly):
stream = QtCore.QTextStream(f)
code_edited = stream.readAll()
self.text_editor_tab.code_editor.setPlainText(code_edited)
self.text_editor_tab.load_text(code_edited, clear_text=True, move_to_start=True)
f.close()
except IOError:
App.log.error("Failed to open config file: %s" % filename)

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 617 B

After

Width:  |  Height:  |  Size: 862 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 732 B

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 565 B

After

Width:  |  Height:  |  Size: 686 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 870 B

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1005 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 683 B

After

Width:  |  Height:  |  Size: 719 B

BIN
assets/resources/find32.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 582 B

After

Width:  |  Height:  |  Size: 584 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 804 B

After

Width:  |  Height:  |  Size: 955 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 559 B

After

Width:  |  Height:  |  Size: 543 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 818 B

After

Width:  |  Height:  |  Size: 835 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 705 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 628 B

After

Width:  |  Height:  |  Size: 654 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 719 B