From 6ba69b1dbc483fbcf56e392e1eac118b222c9d45 Mon Sep 17 00:00:00 2001 From: Hanjin Liu Date: Sun, 24 Sep 2023 16:02:39 +0900 Subject: [PATCH] fix sort button reset button callbacks --- tabulous/_qt/_proxy_button.py | 5 +++-- tabulous/_qt/_table/_base/_line_edit.py | 4 +++- tabulous/_sort_filter_proxy.py | 4 ++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tabulous/_qt/_proxy_button.py b/tabulous/_qt/_proxy_button.py index ca836ece..46522d94 100644 --- a/tabulous/_qt/_proxy_button.py +++ b/tabulous/_qt/_proxy_button.py @@ -117,10 +117,10 @@ def _sort(): def _reset(): if isinstance(f, ComposableSorter): with table._mgr.merging( - lambda cmds: f"Remove filter button at index {index}" + lambda cmds: f"Remove sort button at index {index}" ): table.setHorizontalHeaderWidget(index, None) - table._set_proxy(f.decompose(index)) + # table._set_proxy(f.decompose(index)) else: raise RuntimeError("Sort function is not a ComposableSorter.") @@ -137,6 +137,7 @@ def _reset(): def on_uninstalled(self, table: QBaseTable, index: int): logger.debug(f"Uninstalling sort button at index {index}") self.sortSignal.disconnect() + self.resetSignal.disconnect() f = table._proxy._obj if isinstance(f, ComposableSorter): table._set_proxy(f.decompose(index)) diff --git a/tabulous/_qt/_table/_base/_line_edit.py b/tabulous/_qt/_table/_base/_line_edit.py index fe1eb6b9..5cffa6af 100644 --- a/tabulous/_qt/_table/_base/_line_edit.py +++ b/tabulous/_qt/_table/_base/_line_edit.py @@ -19,6 +19,7 @@ construct, iter_extract, ) +from tabulous import _slice_op as _sl if TYPE_CHECKING: from types import ModuleType @@ -540,7 +541,8 @@ def _on_selection_changed(self) -> None: _df_filt = qtable_view.model().df _df_ori = qtable._data_raw rsl, csl = qtable_view._selection_model.ranges[-1] - if not qtable._proxy.is_ordered and not _is_size_one(rsl): + col_selected = len(qtable_view._selection_model._col_selection_indices) > 0 + if not (qtable._proxy.is_ordered or _sl.len_1(rsl) or col_selected): self.attachToolTip( "Table proxy is not ordered.\nCannot create cell " "references from table selection." diff --git a/tabulous/_sort_filter_proxy.py b/tabulous/_sort_filter_proxy.py index 4160338d..19a8b860 100644 --- a/tabulous/_sort_filter_proxy.py +++ b/tabulous/_sort_filter_proxy.py @@ -413,6 +413,10 @@ def __init__(self, columns: set[int] | None = None, ascending: bool = True): self._columns = columns self._ascending = ascending + def __repr__(self) -> str: + cname = type(self).__name__ + return f"{cname}<{self._columns!r}, ascending={self._ascending}>" + def __call__(self, df: pd.DataFrame) -> pd.Series: by: list[str] = [df.columns[i] for i in self._columns] if len(by) == 1: