Skip to content

Commit

Permalink
'ctrl+f' hotkey to focus on filter line editor
Browse files Browse the repository at this point in the history
  • Loading branch information
swillisart committed Nov 7, 2022
1 parent b6c077f commit ea50dc8
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 56 deletions.
14 changes: 8 additions & 6 deletions capture/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,8 @@ def appendItem(self, item_type, in_file):

def change_count(self, operation, item_type, number):
group = item_type.group
count = group.countSpinBox.value()

total = operation(count, number)
group.countSpinBox.setValue(total)
total = operation(group.count, number)
group.setCount(total)

def closeEvent(self, event):
self.hide()
Expand All @@ -601,8 +599,12 @@ def _close(self):
def searchChanged(self, text):
regex = QRegularExpression(text, QRegularExpression.CaseInsensitiveOption)
for item_type in Types:
view_proxy_model = item_type.group.content.model()
view_proxy_model.setFilterRegularExpression(regex)
group = item_type.group
proxy_model = group.content.model()
proxy_model.setFilterRegularExpression(regex)
proxy_model.endResetModel()
rows = proxy_model.rowCount()
group.setCount(total=group.count, filtered=rows)

@Slot()
def openInViewer(self, index):
Expand Down
25 changes: 23 additions & 2 deletions library/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

# -- Third-party --
from PySide6.QtCore import (QItemSelectionModel, QModelIndex, QThreadPool,
QTimer, Slot, QSize)
from PySide6.QtGui import QIcon, QPixmap, Qt, QImage
QTimer, Slot, QSize, QPoint)
from PySide6.QtGui import QIcon, QPixmap, Qt, QImage, QShortcut, QKeySequence, QCursor
from PySide6.QtWidgets import (QApplication, QMainWindow, QSizePolicy,
QSystemTrayIcon, QToolButton, QWidget, QLabel)

Expand Down Expand Up @@ -144,6 +144,27 @@ def __init__(self, *args, **kwargs):
self._ingester = None
self.preferences_dialog = None
self.block_search = False
QShortcut(QKeySequence('ctrl+f'), self, self.toFilterBox)

@Slot()
def toFilterBox(self):
position = self.mapFromGlobal(QCursor.pos())
mapping = {
self.categoryDock: self.categoryDock.titleBarWidget().filter_line,
self.attributeDock: self.attributeDock.titleBarWidget().filter_line,
self.linksDock: self.linksDock.titleBarWidget().filter_line,
}
for widget, search in mapping.items():
if not widget.isVisible():
continue
rect = widget.rect()
g = widget.mapTo(self, rect.topLeft())
rect = rect.translated(g)
if rect.contains(position):
search.setFocus()
return

self.searchBox.setFocus()

@Slot(list)
def installLinkViewSlots(self, views):
Expand Down
23 changes: 14 additions & 9 deletions library/widgets/description.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import re
import os
import operator
import os
import re
from functools import partial
import markdown

from PySide6.QtCore import Slot, QUrl, Signal, QFile, QTextStream, QEvent, QObject, QTimer
from PySide6.QtGui import QImage, Qt, QTextDocument, QTextCursor, QMovie, QColor, QFontMetrics
from PySide6.QtWidgets import QDialogButtonBox, QTextBrowser, QTextEdit, QApplication, QInputDialog, QLineEdit, QWidget, QAbstractButton, QDialog

from library.config import peakLoad, RELIC_PREFS
import markdown
from library.config import RELIC_PREFS, peakLoad
from library.io.util import readMovieFrames
from sequence_path.main import SequencePath as Path
from PySide6.QtCore import (QEvent, QFile, QObject, QTextStream, QTimer, QUrl,
Signal, Slot)
from PySide6.QtGui import (QColor, QFontMetrics, QImage, QKeySequence, QMovie,
QShortcut, Qt, QTextCursor, QTextDocument)
from PySide6.QtWidgets import (QAbstractButton, QApplication, QDialog,
QDialogButtonBox, QInputDialog, QLineEdit,
QTextBrowser, QTextEdit, QWidget)
from relic.qt.widgets import FilterBox
from sequence_path.main import SequencePath as Path

URL_REGEX = re.compile(r'\(\.(\/.+)\)')

Expand Down Expand Up @@ -208,6 +211,7 @@ def onPlainTextEditChanged(self):

from library.ui.description import Ui_DescriptionDialog


class Window(Ui_DescriptionDialog, QDialog):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
Expand All @@ -220,6 +224,7 @@ def __init__(self, *args, **kwargs):
self.filter_layout.insertWidget(0, self.filter_box)
self.button_box.clicked.connect(self.onDescriptionButtonClicked)
self.text_edit.textChanged.connect(self.text_browser.onPlainTextEditChanged)
QShortcut(QKeySequence('ctrl+f'), self, self.filter_box.editor.setFocus)

@Slot(Path)
def keyPressEvent(self, event):
Expand Down
55 changes: 16 additions & 39 deletions library/widgets/subcategoriesViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,39 +23,16 @@
class recursiveTreeFilter(QSortFilterProxyModel):
def __init__(self, parent=None):
super(recursiveTreeFilter, self).__init__(parent)
self.text = ""

def _accept_index(self, idx):
if idx.isValid():
text = idx.data(role=Qt.DisplayRole)

if text:
condition = text.lower().find(self.text.lower()) >= 0
else:
return False
if condition:
return True
for childnum in range(idx.model().rowCount(parent=idx)):
if self._accept_index(idx.model().index(childnum, 0, parent=idx)):
return True
return False
self.setSortCaseSensitivity(Qt.CaseInsensitive)
self.setFilterCaseSensitivity(Qt.CaseInsensitive)
self.setRecursiveFilteringEnabled(True)
self.setAutoAcceptChildRows(True)

def lessThan(self, left, right):
leftData = self.sourceModel().data(left)
rightData = self.sourceModel().data(right)
return leftData > rightData

def filterAcceptsRow(self, sourceRow, sourceParent):
"""Only first column in model for search
Args:
sourceRow ([type]): [description]
sourceParent ([type]): [description]
"""

idx = self.sourceModel().index(sourceRow, 0, sourceParent)
return self._accept_index(idx)


class subcategoryDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
Expand Down Expand Up @@ -109,8 +86,6 @@ def __init__(self, category=None):
proto_item = polymorphicItem(fields=subcategory(name='', count=0))
self.model.setItemPrototype(proto_item)
self.proxyModel = recursiveTreeFilter()
self.proxyModel.setSortCaseSensitivity(Qt.CaseInsensitive)
self.proxyModel.setSortRole(Qt.DisplayRole)
self.proxyModel.setSourceModel(self.model)
self.setModel(self.proxyModel)
self.subcategoryListView = ListViewFocus(self)
Expand Down Expand Up @@ -649,7 +624,7 @@ def receiveNewCounts(self, count_data):
set_counter(tree_item, tree_view, count_data)
item_model.dataChanged.emit(index, index, [Qt.UserRole])
full_count += root_item.count
cat.tab.countSpinBox.setValue(full_count)
cat.tab.setCount(full_count)

@staticmethod
def setCountData(tree_item, tree_view, count_data):
Expand Down Expand Up @@ -715,15 +690,18 @@ def clearAllModels(self):
category.tree.clear()

def filterAll(self, text):
role = Qt.UserRole
for category in self.all_categories:
self._filterTree(category.tree, text)
tree = category.tree
proxy = tree.proxyModel
proxy.setFilterFixedString(text)
tree.expandAll()
rows = range(proxy.rowCount())
filtered = sum([proxy.index(i, 0).data(role).count for i in rows])
category.tab.setCount(category.count, filtered)

@staticmethod
def _filterTree(tree, text):
tree.proxyModel.text = text
regex = QRegularExpression(text, QRegularExpression.CaseInsensitiveOption)
tree.proxyModel.setFilterRegularExpression(regex)
tree.expandAll()
if text == '':
[x.tab.show() for x in self.all_categories]


class ExpandableTab(ExpandableGroup):
Expand All @@ -737,8 +715,7 @@ def __init__(self, category):
icon = QIcon(category.icon)
self.iconButton.setIcon(icon)
self.nameLabel.setText(category.name)
self.countSpinBox.setValue(category.count)

self.setCount(category.count)
for widget in (self.styledLine, self.styledLine_1):
color = CategoryColor(category.id).data
widget.setStyleSheet(
Expand Down

0 comments on commit ea50dc8

Please sign in to comment.