Skip to content

Commit

Permalink
WIP: Replace prints with text insert
Browse files Browse the repository at this point in the history
This prevents part of the results being printed to stdout.
  • Loading branch information
MHendricks committed Mar 6, 2024
1 parent da2b96a commit 126a0af
Showing 1 changed file with 46 additions and 44 deletions.
90 changes: 46 additions & 44 deletions preditor/gui/find_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}")
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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)

0 comments on commit 126a0af

Please sign in to comment.