From 9b08c51bbadd5a82f3de18a0772709e440c8043a Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Wed, 25 Nov 2020 18:32:18 +0200 Subject: [PATCH] - added Find function in Tcl Shell (will search for either the selected text in the command line or for the one stored on the clipboard) --- CHANGELOG.md | 2 ++ appGUI/GUIElements.py | 10 ++++++++++ appTools/ToolShell.py | 17 ++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60572af4..c8ebf070 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ CHANGELOG for FlatCAM beta - some changes in the Tools visibility in the Tools ToolBar - added confirmation status messages for clearing the recent files/projects lists - moved around portions of code in the App.__init__ for optimization; added a control in Preferences for usage of Log in Tcl Shell +- added a text placeholder in the Tcl Shell +- added Find function in Tcl Shell (will search for either the selected text in the command line or for the one stored on the clipboard) 24.11.2020 diff --git a/appGUI/GUIElements.py b/appGUI/GUIElements.py index ca9a7eb2..ac52b897 100644 --- a/appGUI/GUIElements.py +++ b/appGUI/GUIElements.py @@ -3865,6 +3865,7 @@ class _BrowserTextEdit(QTextEdit): self.menu = None self.version = version self.app = app + self.find_text = lambda: None def contextMenuEvent(self, event): # self.menu = self.createStandardContextMenu(event.pos()) @@ -3884,6 +3885,12 @@ class _BrowserTextEdit(QTextEdit): self.menu.addAction(sel_all_action) sel_all_action.triggered.connect(self.selectAll) + find_action = QAction('%s\t%s' % (_("Find"), _('Ctrl+F')), self) + self.menu.addAction(find_action) + find_action.triggered.connect(self.find_text) + + self.menu.addSeparator() + if self.app: save_action = QAction('%s\t%s' % (_("Save Log"), _('Ctrl+S')), self) # save_action.setShortcut(QKeySequence(Qt.Key_S)) @@ -3913,6 +3920,9 @@ class _BrowserTextEdit(QTextEdit): # Copy Text elif key == QtCore.Qt.Key_C: self.copy_text() + # Copy Text + elif key == QtCore.Qt.Key_F: + self.find_text() # Save Log elif key == QtCore.Qt.Key_S: if self.app: diff --git a/appTools/ToolShell.py b/appTools/ToolShell.py index e3a6f5d2..7f00dbed 100644 --- a/appTools/ToolShell.py +++ b/appTools/ToolShell.py @@ -7,7 +7,7 @@ # ########################################################## -from PyQt5 import QtCore, QtGui +from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QTextCursor, QPixmap from PyQt5.QtWidgets import QVBoxLayout, QWidget, QHBoxLayout, QLabel from appGUI.GUIElements import _BrowserTextEdit, _ExpandableTextEdit, FCLabel @@ -48,6 +48,7 @@ class TermWidget(QWidget): "span {white-space:pre;}") self._edit = _ExpandableTextEdit(self, self) + self._edit.setPlaceholderText(_("Type a command to be executed ...")) self._edit.historyNext.connect(self._on_history_next) self._edit.historyPrev.connect(self._on_history_prev) self._edit.setFocus() @@ -320,6 +321,20 @@ class FCShell(TermWidget): self.app.inform_shell[str].connect(self.app.info_shell) self.app.inform_shell[str, bool].connect(self.app.info_shell) + self._browser.find_text = self.find_text + + def find_text(self): + edit_cursor = self._edit.textCursor() + txt = edit_cursor.selectedText() + clipboard = QtWidgets.QApplication.clipboard() + + searched_txt = txt if txt != '' else clipboard.text() + + r = self._browser.find(str(searched_txt)) + if r is False: + self._browser.moveCursor(QtGui.QTextCursor.Start) + self._browser.find(str(searched_txt)) + def init_tcl(self): if hasattr(self, 'tcl') and self.tcl is not None: # self.tcl = None