Skip to content

Commit

Permalink
WIP: Find Files
Browse files Browse the repository at this point in the history
  • Loading branch information
MHendricks committed Jan 2, 2024
1 parent 0d294b5 commit 5fb0def
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 23 deletions.
22 changes: 19 additions & 3 deletions preditor/gui/find_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,32 @@

from collections import deque

from Qt.QtWidgets import QWidget
from Qt.QtCore import Qt
from Qt.QtWidgets import QApplication, QShortcut, QWidget

from ..gui import loadUi


class FindFiles(QWidget):
def __init__(self, managers=None, parent=None):
def __init__(self, parent=None, managers=None, console=None):
super(FindFiles, self).__init__(parent=parent)
if managers is None:
managers = []
self.managers = managers
self.console = console

loadUi(__file__, self)

self.uiCloseSCT = QShortcut(
Qt.Key_Escape, self, context=Qt.WidgetWithChildrenShortcut
)
self.uiCloseSCT.activated.connect(self.hide)

def activate(self):
"""Called to make this widget ready for the user to interact with."""
self.show()
self.uiFindTXT.setFocus()

def insert_found_text(self, found_text, href, tool_tip):
cursor = self.console.textCursor()
# Insert hyperlink
Expand All @@ -25,6 +37,8 @@ def insert_found_text(self, found_text, href, tool_tip):
fmt.setFontUnderline(True)
fmt.setToolTip(tool_tip)
cursor.insertText(found_text, fmt)
# Show the updated text output
QApplication.instance().processEvents()

def insert_text(self, text):
cursor = self.console.textCursor()
Expand All @@ -34,6 +48,8 @@ def insert_text(self, text):
fmt.setFontUnderline(False)
fmt.setToolTip('')
cursor.insertText(text, fmt)
# Show the updated text output
QApplication.instance().processEvents()

def indicate_results(
self,
Expand All @@ -44,7 +60,7 @@ def indicate_results(
workbox_id="undefined",
fmt="",
):
href = '{}, {}, {}'.format(path, workbox_id, line_num)
href = ', {}, {}'.format(workbox_id, line_num)
tool_tip = "Open {} at line number {}".format(path, line_num)
find_len = len(find_text)

Expand Down
10 changes: 10 additions & 0 deletions preditor/gui/loggerwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ def __init__(self, parent, name=None, run_workbox=False, standalone=False):
)
self.uiConsoleTOOLBAR.insertSeparator(self.uiRunSelectedACT)

# Configure Find in Workboxes
self.uiFindInWorkboxesWGT.hide()
self.uiFindInWorkboxesWGT.managers.append(self.uiWorkboxTAB)
self.uiFindInWorkboxesWGT.console = self.console()

# Initial configuration of the logToFile feature
self._logToFilePath = None
self._stds = None
Expand Down Expand Up @@ -1022,6 +1027,11 @@ def showEvent(self, event):
def show_workbox_options(self):
self.uiWorkboxSTACK.setCurrentIndex(WorkboxPages.Options)

@Slot()
def show_find_in_workboxes(self):
"""Ensure the find workboxes widget is visible and has focus."""
self.uiFindInWorkboxesWGT.activate()

@Slot()
def show_focus_name(self):
model = WorkboxListItemModel(manager=self.uiWorkboxTAB)
Expand Down
66 changes: 48 additions & 18 deletions preditor/gui/ui/find_files.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>636</width>
<height>41</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -21,13 +21,6 @@
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QPushButton" name="uiFindBTN">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="uiFindOptionsLYT">
<item>
Expand Down Expand Up @@ -68,13 +61,18 @@
<item row="0" column="2">
<widget class="QLineEdit" name="uiFindTXT"/>
</item>
<item row="1" column="0" colspan="4">
<widget class="QTreeWidget" name="uiResultsTREE">
<column>
<property name="text">
<string notr="true">1</string>
</property>
</column>
<item row="0" column="3">
<widget class="QPushButton" name="uiFindBTN">
<property name="text">
<string>Find</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QToolButton" name="uiCloseBTN">
<property name="text">
<string>x</string>
</property>
</widget>
</item>
</layout>
Expand All @@ -88,15 +86,47 @@
<slot>find()</slot>
<hints>
<hint type="sourcelabel">
<x>382</x>
<y>25</y>
<x>601</x>
<y>31</y>
</hint>
<hint type="destinationlabel">
<x>421</x>
<y>29</y>
</hint>
</hints>
</connection>
<connection>
<sender>uiFindTXT</sender>
<signal>returnPressed()</signal>
<receiver>uiFindFilesWGT</receiver>
<slot>find()</slot>
<hints>
<hint type="sourcelabel">
<x>488</x>
<y>23</y>
</hint>
<hint type="destinationlabel">
<x>501</x>
<y>65</y>
</hint>
</hints>
</connection>
<connection>
<sender>uiCloseBTN</sender>
<signal>released()</signal>
<receiver>uiFindFilesWGT</receiver>
<slot>hide()</slot>
<hints>
<hint type="sourcelabel">
<x>620</x>
<y>19</y>
</hint>
<hint type="destinationlabel">
<x>676</x>
<y>24</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>find()</slot>
Expand Down
40 changes: 38 additions & 2 deletions preditor/gui/ui/loggerwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@
</widget>
</widget>
</item>
<item>
<widget class="FindFiles" name="uiFindInWorkboxesWGT" native="true"/>
</item>
</layout>
</widget>
<widget class="QMenuBar" name="uiMenuBar">
Expand Down Expand Up @@ -323,6 +326,8 @@
<addaction name="menuFocus_to_Group"/>
<addaction name="menuFocus_to_Tab"/>
<addaction name="uiFocusNameACT"/>
<addaction name="separator"/>
<addaction name="uiFindInWorkboxesACT"/>
</widget>
<addaction name="uiScriptingMENU"/>
<addaction name="menuEdit"/>
Expand Down Expand Up @@ -951,6 +956,14 @@ at the indicated line in the specified text editor.
<string>Ctrl+Alt+Shift+R</string>
</property>
</action>
<action name="uiFindInWorkboxesACT">
<property name="text">
<string>Find in Workboxes</string>
</property>
<property name="shortcut">
<string>Ctrl+Shift+F</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand All @@ -969,6 +982,12 @@ at the indicated line in the specified text editor.
<extends>QWidget</extends>
<header>preditor.gui.editor_chooser.h</header>
</customwidget>
<customwidget>
<class>FindFiles</class>
<extends>QWidget</extends>
<header>preditor.gui.find_files.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
Expand Down Expand Up @@ -1011,20 +1030,37 @@ at the indicated line in the specified text editor.
<slot>update_workbox_stack()</slot>
<hints>
<hint type="sourcelabel">
<x>754</x>
<y>377</y>
<x>763</x>
<y>371</y>
</hint>
<hint type="destinationlabel">
<x>747</x>
<y>401</y>
</hint>
</hints>
</connection>
<connection>
<sender>uiFindInWorkboxesACT</sender>
<signal>triggered()</signal>
<receiver>PrEditorWindow</receiver>
<slot>show_find_in_workboxes()</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>397</x>
<y>202</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>apply_options()</slot>
<slot>reset_options()</slot>
<slot>show_workbox_options()</slot>
<slot>update_workbox_stack()</slot>
<slot>show_find_in_workboxes()</slot>
</slots>
</ui>

0 comments on commit 5fb0def

Please sign in to comment.