Rendi ordinabili le griglie diagnostica
This commit is contained in:
@@ -165,6 +165,9 @@ class DiagnosticaWindow(ctk.CTkToplevel):
|
|||||||
self.var_status = tk.StringVar(value="")
|
self.var_status = tk.StringVar(value="")
|
||||||
self._last_export_slug = "diagnostica"
|
self._last_export_slug = "diagnostica"
|
||||||
self._current_columns = SHIPPED_NOT_DISASSOCIATED_COLUMNS
|
self._current_columns = SHIPPED_NOT_DISASSOCIATED_COLUMNS
|
||||||
|
self._column_titles: dict[str, str] = {}
|
||||||
|
self._sort_column = ""
|
||||||
|
self._sort_descending = False
|
||||||
|
|
||||||
self.title(
|
self.title(
|
||||||
versioned_title(
|
versioned_title(
|
||||||
@@ -284,13 +287,55 @@ class DiagnosticaWindow(ctk.CTkToplevel):
|
|||||||
self.tree.delete(*self.tree.get_children(""))
|
self.tree.delete(*self.tree.get_children(""))
|
||||||
keys = tuple(str(col[0]) for col in columns)
|
keys = tuple(str(col[0]) for col in columns)
|
||||||
self.tree.configure(columns=keys, show="headings")
|
self.tree.configure(columns=keys, show="headings")
|
||||||
|
self._sort_column = ""
|
||||||
|
self._sort_descending = False
|
||||||
|
self._column_titles = {}
|
||||||
for key, locale_key, default, width, anchor in columns:
|
for key, locale_key, default, width, anchor in columns:
|
||||||
|
title = loc_text(str(locale_key), catalog=self._locale_catalog, default=str(default))
|
||||||
|
self._column_titles[str(key)] = title
|
||||||
self.tree.heading(
|
self.tree.heading(
|
||||||
key,
|
key,
|
||||||
text=loc_text(str(locale_key), catalog=self._locale_catalog, default=str(default)),
|
text=title,
|
||||||
|
command=lambda col=str(key): self._sort_by_column(col),
|
||||||
)
|
)
|
||||||
self.tree.column(key, width=int(width), anchor=str(anchor), stretch=True)
|
self.tree.column(key, width=int(width), anchor=str(anchor), stretch=True)
|
||||||
|
|
||||||
|
def _refresh_sort_headings(self) -> None:
|
||||||
|
for key, title in self._column_titles.items():
|
||||||
|
suffix = ""
|
||||||
|
if key == self._sort_column:
|
||||||
|
suffix = " v" if self._sort_descending else " ^"
|
||||||
|
self.tree.heading(key, text=f"{title}{suffix}", command=lambda col=key: self._sort_by_column(col))
|
||||||
|
|
||||||
|
def _sort_key(self, value: Any) -> tuple[int, Any]:
|
||||||
|
text = str(value or "").strip()
|
||||||
|
if not text:
|
||||||
|
return (2, "")
|
||||||
|
normalized = text.replace(".", "").replace(",", ".")
|
||||||
|
try:
|
||||||
|
return (0, float(normalized))
|
||||||
|
except ValueError:
|
||||||
|
return (1, text.casefold())
|
||||||
|
|
||||||
|
def _sort_by_column(self, column: str) -> None:
|
||||||
|
columns = list(self.tree["columns"])
|
||||||
|
if column not in columns:
|
||||||
|
return
|
||||||
|
descending = not self._sort_descending if self._sort_column == column else False
|
||||||
|
col_index = columns.index(column)
|
||||||
|
rows = []
|
||||||
|
for iid in self.tree.get_children(""):
|
||||||
|
values = self.tree.item(iid, "values")
|
||||||
|
value = values[col_index] if col_index < len(values) else ""
|
||||||
|
rows.append((self._sort_key(value), iid))
|
||||||
|
rows.sort(key=lambda item: item[0], reverse=descending)
|
||||||
|
for index, (_key, iid) in enumerate(rows):
|
||||||
|
self.tree.move(iid, "", index)
|
||||||
|
self.tree.item(iid, tags=(zebra_tag(index),))
|
||||||
|
self._sort_column = column
|
||||||
|
self._sort_descending = descending
|
||||||
|
self._refresh_sort_headings()
|
||||||
|
|
||||||
def _load_shipped_not_disassociated(self) -> None:
|
def _load_shipped_not_disassociated(self) -> None:
|
||||||
self._run_check(
|
self._run_check(
|
||||||
key="shipped_not_disassociated",
|
key="shipped_not_disassociated",
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ MODULE_VERSIONS: dict[str, str] = {
|
|||||||
"barcode_service": "1.0.24",
|
"barcode_service": "1.0.24",
|
||||||
"busy_overlay": "1.0.0",
|
"busy_overlay": "1.0.0",
|
||||||
"db_config": "1.0.0",
|
"db_config": "1.0.0",
|
||||||
"diagnostica": "1.0.3",
|
"diagnostica": "1.0.4",
|
||||||
"gestione_aree": "1.0.1",
|
"gestione_aree": "1.0.1",
|
||||||
"gestione_layout": "1.0.2",
|
"gestione_layout": "1.0.2",
|
||||||
"gestione_pickinglist": "1.0.4",
|
"gestione_pickinglist": "1.0.4",
|
||||||
|
|||||||
Reference in New Issue
Block a user