Skip to content

Commit

Permalink
Merge pull request #15 from altendky/fix/GT-96/parameters_tab_search_…
Browse files Browse the repository at this point in the history
…past_first

fix (GT-96): parameters tab search past first
  • Loading branch information
gordon-epc authored Apr 2, 2021
2 parents d0ceeee + a993444 commit 7338d3e
Showing 1 changed file with 33 additions and 20 deletions.
53 changes: 33 additions & 20 deletions epyqlib/utils/qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap
import time
import traceback
import typing
import uuid
import weakref

Expand Down Expand Up @@ -153,6 +154,10 @@ def message_handler(mode, context, message):
)
)
print(" {}: {}\n".format(mode, message))
# Output stack track, minus the last entry which unnecesarily points to the next line.
tb_stack = traceback.extract_stack()
tb_format = traceback.format_list(tb_stack[:-1])
print("".join(tb_format))


class Progress(QtCore.QObject):
Expand Down Expand Up @@ -631,14 +636,14 @@ def dialog_from_file(parent, title, file_name):
)


@attr.s(auto_attribs=True)
class PySortFilterProxyModel(QtCore.QSortFilterProxyModel):
def __init__(self, *args, filter_column, **kwargs):
super().__init__(*args, **kwargs)

# TODO: replace with filterKeyColumn
self.filter_column = filter_column
_parent: QtCore.QObject = None
filter_column: int = 0
wildcard: QtCore.QRegExp = attr.Factory(QtCore.QRegExp)

self.wildcard = QtCore.QRegExp()
def __attrs_post_init__(self):
super().__init__(self._parent)
self.wildcard.setPatternSyntax(QtCore.QRegExp.Wildcard)

def lessThan(self, left, right):
Expand Down Expand Up @@ -750,17 +755,21 @@ def set_row_column(index, row=None, column=None):
return None


@attr.s
@attr.s(auto_attribs=True)
class DiffProxyModel(QtCore.QIdentityProxyModel):
parent = attr.ib(default=None)
columns = attr.ib(factory=set, converter=set)
_reference_column = attr.ib(default=None)
diff_highlights = attr.ib(factory=dict)
reference_highlights = attr.ib(factory=dict)
diff_role = attr.ib(default=QtCore.Qt.ItemDataRole.DisplayRole)
_parent: QtCore.QObject = None
columns: typing.Set[int] = attr.ib(factory=set, converter=set)
_reference_column: int = None
diff_highlights: typing.Dict[
QtCore.Qt.ItemDataRole, PyQt5.QtGui.QColor
] = attr.Factory(dict)
reference_highlights: typing.Dict[
QtCore.Qt.ItemDataRole, PyQt5.QtGui.QColor
] = attr.Factory(dict)
diff_role: QtCore.Qt.ItemDataRole = QtCore.Qt.ItemDataRole.DisplayRole

def __attrs_post_init__(self):
super().__init__(self.parent)
super().__init__(self._parent)

def data(self, index, role):
column = index.column()
Expand Down Expand Up @@ -857,23 +866,27 @@ def search_view(view, text, column):
return

model = view.model()

index = view.currentIndex()
models = []

while model is not None:
while True:
models.append(model)
search = getattr(model, "search", None)
if search is not None:
break

model = model.sourceModel()
else:
raise Exception("ack")
next_model = model.sourceModel()

if next_model is None:
raise Exception("ack")

index = model.mapToSource(index)
model = next_model

index = search(
text=text,
column=column,
search_from=view.currentIndex(),
search_from=index,
)

if index is not None:
Expand Down

0 comments on commit 7338d3e

Please sign in to comment.