Skip to content

Commit

Permalink
add sort order indicators to tabular preview labels
Browse files Browse the repository at this point in the history
  • Loading branch information
nickzoic committed Mar 27, 2024
1 parent 561f39d commit aefe93d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
Binary file added countess/gui/icons/sort_dn.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added countess/gui/icons/sort_un.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added countess/gui/icons/sort_up.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion countess/gui/tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import pandas as pd
from pandas.api.types import is_integer_dtype, is_numeric_dtype

from countess.gui.widgets import get_bitmap_image

# XXX columns should automatically resize based on information
# from _column_xscrollcommand which can tell if they're
# overflowing. Or maybe use
Expand Down Expand Up @@ -147,7 +149,7 @@ def set_dataframe(self, dataframe: pd.DataFrame):
else:
name = str(name)
is_index = " (index)" if num < self.index_cols else ""
label = tk.Label(self.subframe, text=f"{name}\n{dtype}{is_index}")
label = tk.Label(self.subframe, text=f"{name}\n{dtype}{is_index}", image=get_bitmap_image(self, "sort_un"), compound=tk.RIGHT)
label.grid(row=1, column=num, sticky=tk.EW)
label.bind("<Button-1>", partial(self._label_button_1, num))
label.bind("<B1-Motion>", partial(self._label_b1_motion, num))
Expand Down Expand Up @@ -251,6 +253,11 @@ def set_sort_order(self, column_num: int, descending: Optional[bool]=None):
self.dataframe = self.dataframe.sort_values(
self.dataframe.columns[column_num - self.index_cols], ascending=self.sort_ascending
)

for n, label in enumerate(self.labels):
icon = "sort_un" if n != column_num else "sort_up" if self.sort_ascending else "sort_dn"
label.configure(image=get_bitmap_image(self.winfo_toplevel(), icon))

self.refresh()

def scrollto(self, new_offset):
Expand Down

0 comments on commit aefe93d

Please sign in to comment.