Skip to content

Commit

Permalink
show results on the ctrl+f highlighter without clicking (#1696)
Browse files Browse the repository at this point in the history
* pin werkzeug to >=2.2.3

* Added requested feature

* Added requested feature

* Added new checkbox functionality

* Test fail fixed

* flake8 Test failing fix

* filter_shortcuts parameter changed
  • Loading branch information
sratslla authored Mar 14, 2023
1 parent 4f412bd commit 31d5e31
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
21 changes: 20 additions & 1 deletion mslib/msui/msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ def __init__(self):
self.label.setVisible(i),
self.label_2.setVisible(i),
self.line.setVisible(i)))
self.cbHighlight.stateChanged.connect(self.filter_shortcuts)
self.cbDisplayType.currentTextChanged.connect(self.fill_list)
self.cbAdvanced.stateChanged.emit(self.cbAdvanced.checkState())
self.oldReject = self.reject
Expand Down Expand Up @@ -294,10 +295,18 @@ def get_shortcuts(self):

return shortcuts

def filter_shortcuts(self, text):
def filter_shortcuts(self, text="Nothing", rerun=True):
"""
Hides all shortcuts not containing the text
"""
text = self.leShortcutFilter.text()
self.reset_highlight()

window_count = 0
for window in self.treeWidget.findItems("", QtCore.Qt.MatchContains):
if not window.isHidden():
window_count += 1

for window in self.treeWidget.findItems("", QtCore.Qt.MatchContains):
wms_hits = 0

Expand All @@ -308,12 +317,22 @@ def filter_shortcuts(self, text):
wms_hits += 1
else:
widget.setHidden(True)

if wms_hits == 1 and (self.cbHighlight.isChecked() or window_count == 1):
for child_index in range(window.childCount()):
widget = window.child(child_index)
if (not widget.isHidden()) and hasattr(widget.source_object, "setStyleSheet"):
widget.source_object.setStyleSheet("background-color: yellow;")
break

if wms_hits == 0 and len(text) > 0:
window.setHidden(True)
else:
window.setHidden(False)

self.filterRemoveAction.setVisible(len(text) > 0)
if rerun:
self.filter_shortcuts(text, False)


class MSUI_AboutDialog(QtWidgets.QDialog, ui_ab.Ui_AboutMSUIDialog):
Expand Down
6 changes: 5 additions & 1 deletion mslib/msui/qt5/ui_shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'mslib/msui/ui/ui_shortcuts.ui'
# Form implementation generated from reading ui file 'ui_shortcuts.ui'
#
# Created by: PyQt5 UI code generator 5.12.3
#
Expand Down Expand Up @@ -58,6 +58,9 @@ def setupUi(self, ShortcutsDialog):
self.cbAdvanced = QtWidgets.QCheckBox(ShortcutsDialog)
self.cbAdvanced.setObjectName("cbAdvanced")
self.horizontalLayout_2.addWidget(self.cbAdvanced)
self.cbHighlight = QtWidgets.QCheckBox(ShortcutsDialog)
self.cbHighlight.setObjectName("cbHighlight")
self.horizontalLayout_2.addWidget(self.cbHighlight)
self.buttonBox = QtWidgets.QDialogButtonBox(ShortcutsDialog)
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Close)
Expand All @@ -80,3 +83,4 @@ def retranslateUi(self, ShortcutsDialog):
self.cbDisplayType.setItemText(1, _translate("ShortcutsDialog", "Text"))
self.cbDisplayType.setItemText(2, _translate("ShortcutsDialog", "ObjectName"))
self.cbAdvanced.setText(_translate("ShortcutsDialog", "Advanced Settings"))
self.cbHighlight.setText(_translate("ShortcutsDialog", "Highlight on all Windows"))
7 changes: 7 additions & 0 deletions mslib/msui/ui/ui_shortcuts.ui
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbHighlight">
<property name="text">
<string>Highlight on all Windows</string>
</property>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
Expand Down
3 changes: 2 additions & 1 deletion tests/_test_msui/test_msui.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ def test_shortcuts_present(self):
# Assert list gets filled properly
self.shortcuts.fill_list()
assert self.shortcuts.treeWidget.topLevelItemCount() == 1
self.shortcuts.filter_shortcuts("Nothing")
self.shortcuts.leShortcutFilter.setText("Nothing")
self.shortcuts.filter_shortcuts()
assert self.shortcuts.treeWidget.topLevelItem(0).isHidden()

# Assert changing display type works
Expand Down

0 comments on commit 31d5e31

Please sign in to comment.