From 8f0b591d74f362a4809e5b4400bfedad234ad8fe Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Mon, 22 Nov 2021 03:26:09 +0200 Subject: [PATCH] - in AppTextEditor made some changes (added some placeholders and a message popup when reaching the end of document) - when viewing GCode the Find field can now keep the focus --- CHANGELOG.md | 5 +++++ appEditors/AppTextEditor.py | 23 +++++++++++++++++++++-- appGUI/GUIElements.py | 26 ++++++++++++++++++++++++-- appObjects/FlatCAMCNCJob.py | 3 +++ 4 files changed, 53 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 74449fae..673b0197 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ CHANGELOG for FlatCAM beta ================================================= +22.11.2021 + +- in AppTextEditor made some changes (added some placeholders and a message popup when reaching the end of document) +- when viewing GCode the Find field can now keep the focus + 21.11.2021 - updated the language strings diff --git a/appEditors/AppTextEditor.py b/appEditors/AppTextEditor.py index e466c7ca..49276f24 100644 --- a/appEditors/AppTextEditor.py +++ b/appEditors/AppTextEditor.py @@ -91,6 +91,7 @@ class AppTextEditor(QtWidgets.QWidget): # Entry FIND self.entryFind = FCEntry() + self.entryFind.setPlaceholderText(_("Find box. Enter here the strings to be searched in the text.")) self.entryFind.setToolTip(_("Find box. Enter here the strings to be searched in the text.")) control_lay.addWidget(self.entryFind) @@ -102,6 +103,7 @@ class AppTextEditor(QtWidgets.QWidget): # Entry REPLACE self.entryReplace = FCEntry() + self.entryReplace.setPlaceholderText(_("String to replace the one in the Find box throughout the text.")) self.entryReplace.setToolTip(_("String to replace the one in the Find box throughout the text.")) control_lay.addWidget(self.entryReplace) @@ -163,6 +165,7 @@ class AppTextEditor(QtWidgets.QWidget): self.buttonPrint.clicked.connect(self.handlePrint) self.buttonPreview.clicked.connect(self.handlePreview) self.buttonFind.clicked.connect(self.handleFindGCode) + self.entryFind.editingFinished.connect(self.handleFindGCode) self.buttonReplace.clicked.connect(self.handleReplaceGCode) # self.button_copy_all.clicked.connect(self.handleCopyAll) @@ -333,9 +336,25 @@ class AppTextEditor(QtWidgets.QWidget): text_to_be_found = self.entryFind.get_value() r = self.code_editor.find(str(text_to_be_found), flags) + if r is False: - self.code_editor.moveCursor(QtGui.QTextCursor.MoveOperation.Start) - self.code_editor.find(str(text_to_be_found), flags) + msgbox = QtWidgets.QMessageBox() + msgbox.setWindowTitle(_('Find')) + msgbox.setWindowIcon(QtGui.QIcon(self.app.resource_location + '/find32.png')) + msgbox.setIcon(QtWidgets.QMessageBox.Icon.Question) + + msgbox.setText(_("End of document.")) + msgbox.setInformativeText('%s' % _("Start from beginning?")) + bt_ok = msgbox.addButton(_('Ok'), QtWidgets.QMessageBox.ButtonRole.AcceptRole) + bt_cancel = msgbox.addButton(_('Cancel'), QtWidgets.QMessageBox.ButtonRole.RejectRole) + + msgbox.setDefaultButton(bt_cancel) + msgbox.exec() + response = msgbox.clickedButton() + + if response == bt_ok: + self.code_editor.moveCursor(QtGui.QTextCursor.MoveOperation.Start) + self.code_editor.find(str(text_to_be_found), flags) def handleReplaceGCode(self): diff --git a/appGUI/GUIElements.py b/appGUI/GUIElements.py index a5c5d750..282ea8b7 100644 --- a/appGUI/GUIElements.py +++ b/appGUI/GUIElements.py @@ -626,10 +626,13 @@ class IntEntry(FCLineEdit): class FCEntry(FCLineEdit): - def __init__(self, decimals=None, alignment=None, border_color=None, parent=None): + def __init__(self, decimals=None, alignment=None, border_color=None, parent=None, keep_focus=False): super(FCEntry, self).__init__(parent) self.readyToEdit = True - self.editingFinished.connect(self.on_edit_finished) + self._keep_focus = keep_focus + if self._keep_focus is False: + self.editingFinished.connect(self.on_edit_finished) + self.decimals = decimals if decimals is not None else 4 if border_color: @@ -644,6 +647,25 @@ class FCEntry(FCLineEdit): align_val = QtCore.Qt.AlignmentFlag.AlignLeft self.setAlignment(align_val) + @property + def keep_focus(self): + return self._keep_focus + + @keep_focus.setter + def keep_focus(self, val): + self._keep_focus = val + if val is True: + try: + self.editingFinished.disconnect(self.on_edit_finished) + except (AttributeError, TypeError): + pass + self.editingFinished.connect(self.on_edit_finished) + else: + try: + self.editingFinished.disconnect(self.on_edit_finished) + except (AttributeError, TypeError): + pass + def on_edit_finished(self): self.clearFocus() diff --git a/appObjects/FlatCAMCNCJob.py b/appObjects/FlatCAMCNCJob.py index 74279f17..7cbdfb0f 100644 --- a/appObjects/FlatCAMCNCJob.py +++ b/appObjects/FlatCAMCNCJob.py @@ -793,6 +793,9 @@ class CNCJobObject(FlatCAMObj, CNCjob): self.gcode_editor_tab.entryReplace.hide() self.gcode_editor_tab.code_editor.setReadOnly(True) + # make sure that the Find entry keeps the focus on the line + self.gcode_editor_tab.entryFind.keep_focus = False + self.app.inform.emit('[success] %s...' % _('Loaded Machine Code into Code Editor')) def on_update_source_file(self):