From 626f2778430ac624bf2c12edeb4beea64a1420da Mon Sep 17 00:00:00 2001 From: Mike Hendricks Date: Tue, 5 Mar 2024 22:53:55 -0800 Subject: [PATCH] WIP: Replace prints with text insert This prevents part of the results being printed to stdout. --- preditor/gui/find_files.py | 90 +++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 44 deletions(-) diff --git a/preditor/gui/find_files.py b/preditor/gui/find_files.py index 7571944d..d31e4cd0 100644 --- a/preditor/gui/find_files.py +++ b/preditor/gui/find_files.py @@ -28,28 +28,21 @@ def activate(self): self.show() self.uiFindTXT.setFocus() - def insert_found_text(self, found_text, href, tool_tip): - cursor = self.console.textCursor() - # Insert hyperlink - fmt = cursor.charFormat() - fmt.setAnchor(True) - fmt.setAnchorHref(href) - fmt.setFontUnderline(True) - fmt.setToolTip(tool_tip) - cursor.insertText(found_text, fmt) - # Show the updated text output - QApplication.instance().processEvents() + def find(self): + find_text = self.uiFindTXT.text() + self.insert_text("\nFind in workboxs: {}\n\n".format(find_text)) - def insert_text(self, text): - cursor = self.console.textCursor() - fmt = cursor.charFormat() - fmt.setAnchor(False) - fmt.setAnchorHref('') - fmt.setFontUnderline(False) - fmt.setToolTip('') - cursor.insertText(text, fmt) - # Show the updated text output - QApplication.instance().processEvents() + for manager in self.managers: + for ( + editor, + group_name, + tab_name, + group_index, + tab_index, + ) in manager.all_widgets(): + path = "/".join((group_name, tab_name)) + workbox_id = '{},{}'.format(group_index, tab_index) + self.search_file_simple(editor, path, workbox_id) def indicate_results( self, @@ -84,7 +77,19 @@ def indicate_results( if end < find_len: self.insert_text(line[start:]) - def print_lines(self, start, *lines, info=None): + def insert_found_text(self, found_text, href, tool_tip): + cursor = self.console.textCursor() + # Insert hyperlink + fmt = cursor.charFormat() + fmt.setAnchor(True) + fmt.setAnchorHref(href) + fmt.setFontUnderline(True) + fmt.setToolTip(tool_tip) + cursor.insertText(found_text, fmt) + # Show the updated text output + QApplication.instance().processEvents() + + def insert_lines(self, start, *lines, info=None): if info is None: info = {} info.setdefault("fmt", " {num: 4d}{split} {line}") @@ -96,6 +101,17 @@ def print_lines(self, start, *lines, info=None): # print(line) self.indicate_results(line + "\n", start + i, **info) + def insert_text(self, text): + cursor = self.console.textCursor() + fmt = cursor.charFormat() + fmt.setAnchor(False) + fmt.setAnchorHref('') + fmt.setFontUnderline(False) + fmt.setToolTip('') + cursor.insertText(text, fmt) + # Show the updated text output + QApplication.instance().processEvents() + def search_file_simple(self, editor, path, workbox_id): # print('search_file_simple', path) context = self.uiContextSPN.value() @@ -120,15 +136,17 @@ def search_file_simple(self, editor, path, workbox_id): ii = i - context if first: # Print the filename on the first find - print("# File: {}".format(path)) + # print("# File: {}".format(path)) + self.insert_text("# File: {}\n".format(path)) first = False else: - print( - " {dot: >{padding}} ".format( + # print( + self.insert_text( + " {dot: >{padding}} \n".format( dot='.' * len(str(ii)), padding=padding ) ) - self.print_lines(ii, *pre_history, line, info=info) + self.insert_lines(ii, *pre_history, line, info=info) # print(" xxx:", *pre_history, line, sep='') # Clear history so if two errors seen in close proximity, we don't # echo some lines twice @@ -145,26 +163,10 @@ def search_file_simple(self, editor, path, workbox_id): # Once we exceed context without finding another result, # print the post text and stop tracking post_history if len(post_history) >= context: - self.print_lines(post_line, *post_history, info=info) + self.insert_lines(post_line, *post_history, info=info) post_history = None post_line = None if post_history: print('# --------') - self.print_lines(post_line, *post_history, info=info) - - def find(self): - find_text = self.uiFindTXT.text() - print("Find:", find_text) - - for manager in self.managers: - for ( - editor, - group_name, - tab_name, - group_index, - tab_index, - ) in manager.all_widgets(): - path = "/".join((group_name, tab_name)) - workbox_id = '{},{}'.format(group_index, tab_index) - self.search_file_simple(editor, path, workbox_id) + self.insert_lines(post_line, *post_history, info=info)