Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sort button behavior #127

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions tabulous/_qt/_proxy_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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))
Expand Down
4 changes: 3 additions & 1 deletion tabulous/_qt/_table/_base/_line_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
construct,
iter_extract,
)
from tabulous import _slice_op as _sl

if TYPE_CHECKING:
from types import ModuleType
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 4 additions & 0 deletions tabulous/_sort_filter_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down