From 9be9e09417c96cc5e000a973c3cc1bd1c53caa8b Mon Sep 17 00:00:00 2001 From: Marius Stanciu Date: Fri, 29 Mar 2024 09:54:43 +0200 Subject: [PATCH] - continue refactoring methods from the appMain --- CHANGELOG.md | 4 ++++ appGUI/MainGUI.py | 36 ++++++++++++++++++++++++++++++++++-- appMain.py | 26 -------------------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb85e2a3..c2246097 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ CHANGELOG for FlatCAM Evo beta ================================================= +29.03.2024 + +- continue refactoring methods from the appMain + 28.03.2024 - major refactoring: started to move the methods connected to the Edit menu to their own class to clean up the App mega class diff --git a/appGUI/MainGUI.py b/appGUI/MainGUI.py index 2b85af0c..8c6c69ab 100644 --- a/appGUI/MainGUI.py +++ b/appGUI/MainGUI.py @@ -3021,7 +3021,7 @@ class MainGUI(QtWidgets.QMainWindow): if key == QtCore.Qt.Key.Key_G: widget_name = self.plot_tab_area.currentWidget().objectName() if 'editor' in widget_name.lower(): - self.app.goto_text_line() + self.goto_text_line() else: self.app.f_handlers.on_file_open_gerber() @@ -4466,10 +4466,42 @@ class MainGUI(QtWidgets.QMainWindow): if key == QtCore.Qt.Key.Key_G: self.app.ui.grid_snap_btn.trigger() - # Jump to coords + # Jump to coordinates if key == QtCore.Qt.Key.Key_J: self.app.on_jump_to() + def goto_text_line(self): + """ + Will scroll a text to the specified text line. + + :return: None + """ + editor_widget = self.plot_tab_area.currentWidget() + try: + c_editor = editor_widget.code_editor # noqa + except AttributeError: + return + + dia_box = Dialog_box(title=_("Go to Line ..."), + label='%s:' % _("Line"), + icon=QtGui.QIcon(self.app.resource_location + '/jump_to32.png'), + initial_text='') + try: + line = int(dia_box.location) - 1 + except (ValueError, TypeError): + line = 0 + + if dia_box.ok: + # make sure to move first the cursor at the end so after finding the line, the line will be positioned + # at the top of the window + c_editor.moveCursor(QTextCursor.MoveOperation.End) + # get the document() of the AppTextEditor + doc = c_editor.document() + # create a Text Cursor based on the searched line + cursor = QTextCursor(doc.findBlockByLineNumber(line)) + # set cursor of the code editor with the cursor at the searched line + c_editor.setTextCursor(cursor) + def eventFilter(self, obj, event): """ Filter the ToolTips display based on a Preferences setting diff --git a/appMain.py b/appMain.py index bf1540fe..3d8942de 100644 --- a/appMain.py +++ b/appMain.py @@ -6848,32 +6848,6 @@ class App(QtCore.QObject): def on_code_editor_close(self): self.toggle_codeeditor = False - def goto_text_line(self): - """ - Will scroll a text to the specified text line. - - :return: None - """ - dia_box = Dialog_box(title=_("Go to Line ..."), - label='%s:' % _("Line"), - icon=QtGui.QIcon(self.resource_location + '/jump_to32.png'), - initial_text='') - try: - line = int(dia_box.location) - 1 - except (ValueError, TypeError): - line = 0 - - if dia_box.ok: - # make sure to move first the cursor at the end so after finding the line, the line will be positioned - # at the top of the window - self.ui.plot_tab_area.currentWidget().code_editor.moveCursor(QTextCursor.MoveOperation.End) - # get the document() of the AppTextEditor - doc = self.ui.plot_tab_area.currentWidget().code_editor.document() - # create a Text Cursor based on the searched line - cursor = QTextCursor(doc.findBlockByLineNumber(line)) - # set cursor of the code editor with the cursor at the searcehd line - self.ui.plot_tab_area.currentWidget().code_editor.setTextCursor(cursor) - def plot_all(self, fit_view=True, muted=False, use_thread=True): """ Re-generates all plots from all objects.