tksheet 7.4.1__tar.gz → 7.4.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. {tksheet-7.4.1/tksheet.egg-info → tksheet-7.4.2}/PKG-INFO +2 -2
  2. {tksheet-7.4.1 → tksheet-7.4.2}/README.md +1 -1
  3. {tksheet-7.4.1 → tksheet-7.4.2}/pyproject.toml +1 -1
  4. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/__init__.py +1 -1
  5. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/column_headers.py +3 -3
  6. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/row_index.py +3 -3
  7. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/sorting.py +92 -44
  8. {tksheet-7.4.1 → tksheet-7.4.2/tksheet.egg-info}/PKG-INFO +2 -2
  9. {tksheet-7.4.1 → tksheet-7.4.2}/LICENSE.txt +0 -0
  10. {tksheet-7.4.1 → tksheet-7.4.2}/setup.cfg +0 -0
  11. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/colors.py +0 -0
  12. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/constants.py +0 -0
  13. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/find_window.py +0 -0
  14. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/formatters.py +0 -0
  15. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/functions.py +0 -0
  16. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/main_table.py +0 -0
  17. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/other_classes.py +0 -0
  18. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/sheet.py +0 -0
  19. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/sheet_options.py +0 -0
  20. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/text_editor.py +0 -0
  21. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/themes.py +0 -0
  22. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/tksheet_types.py +0 -0
  23. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet/top_left_rectangle.py +0 -0
  24. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet.egg-info/SOURCES.txt +0 -0
  25. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet.egg-info/dependency_links.txt +0 -0
  26. {tksheet-7.4.1 → tksheet-7.4.2}/tksheet.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tksheet
3
- Version: 7.4.1
3
+ Version: 7.4.2
4
4
  Summary: Tkinter table / sheet and treeview widget
5
5
  Author-email: ragardner <github@ragardner.simplelogin.com>
6
6
  License: Copyright (c) 2019 ragardner and open source contributors
@@ -77,7 +77,7 @@ License-File: LICENSE.txt
77
77
  <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#issues">Issues</a></td>
78
78
  </tr>
79
79
  <tr>
80
- <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#enhancements-or-suggestions">Suggestions</a></td>
80
+ <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#enhancements-or-suggestions">Suggestions and Contributors</a></td>
81
81
  </tr>
82
82
  </tbody>
83
83
  </table>
@@ -34,7 +34,7 @@
34
34
  <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#issues">Issues</a></td>
35
35
  </tr>
36
36
  <tr>
37
- <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#enhancements-or-suggestions">Suggestions</a></td>
37
+ <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#enhancements-or-suggestions">Suggestions and Contributors</a></td>
38
38
  </tr>
39
39
  </tbody>
40
40
  </table>
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
  name = "tksheet"
7
7
  description = "Tkinter table / sheet and treeview widget"
8
8
  readme = "README.md"
9
- version = "7.4.1"
9
+ version = "7.4.2"
10
10
  authors = [{ name = "ragardner", email = "github@ragardner.simplelogin.com" }]
11
11
  requires-python = ">=3.8"
12
12
  license = {file = "LICENSE.txt"}
@@ -4,7 +4,7 @@
4
4
  tksheet - A Python tkinter table widget
5
5
  """
6
6
 
7
- __version__ = "7.4.1"
7
+ __version__ = "7.4.2"
8
8
 
9
9
  from .colors import (
10
10
  color_map,
@@ -915,14 +915,14 @@ class ColumnHeaders(tk.Canvas):
915
915
  key: Callable | None = None,
916
916
  undo: bool = True,
917
917
  ) -> EventDataDict:
918
- event_data = self.MT.new_event_dict("sort_rows", state=True)
918
+ event_data = self.MT.new_event_dict("move_rows", state=True)
919
919
  if not self.MT.data:
920
920
  return event_data
921
921
  if column is None:
922
922
  if not self.MT.selected:
923
923
  return event_data
924
924
  column = self.MT.selected.column
925
- if try_binding(self.ch_extra_begin_sort_rows_func, event_data, "begin_sort_rows"):
925
+ if try_binding(self.ch_extra_begin_sort_rows_func, event_data, "begin_move_rows"):
926
926
  disp_new_idxs, disp_row_ctr = {}, 0
927
927
  if self.ops.treeview:
928
928
  new_nodes_order, data_new_idxs = sort_tree_view(
@@ -973,7 +973,7 @@ class ColumnHeaders(tk.Canvas):
973
973
  }
974
974
  if undo and self.MT.undo_enabled:
975
975
  self.MT.undo_stack.append(stored_event_dict(event_data))
976
- try_binding(self.ch_extra_end_sort_rows_func, event_data, "end_sort_rows")
976
+ try_binding(self.ch_extra_end_sort_rows_func, event_data, "end_move_rows")
977
977
  self.MT.sheet_modified(event_data)
978
978
  self.PAR.emit_event("<<SheetModified>>", event_data)
979
979
  self.MT.refresh()
@@ -936,14 +936,14 @@ class RowIndex(tk.Canvas):
936
936
  key: Callable | None = None,
937
937
  undo: bool = True,
938
938
  ) -> EventDataDict:
939
- event_data = self.MT.new_event_dict("sort_columns", state=True)
939
+ event_data = self.MT.new_event_dict("move_columns", state=True)
940
940
  if not self.MT.data:
941
941
  return event_data
942
942
  if row is None:
943
943
  if not self.MT.selected:
944
944
  return event_data
945
945
  row = self.MT.selected.row
946
- if try_binding(self.ri_extra_begin_sort_cols_func, event_data, "begin_sort_columns"):
946
+ if try_binding(self.ri_extra_begin_sort_cols_func, event_data, "begin_move_columns"):
947
947
  sorted_indices, data_new_idxs = sort_columns_by_row(self.MT.data, row=row, reverse=reverse, key=key)
948
948
  disp_new_idxs = {}
949
949
  if self.MT.all_columns_displayed:
@@ -970,7 +970,7 @@ class RowIndex(tk.Canvas):
970
970
  }
971
971
  if undo and self.MT.undo_enabled:
972
972
  self.MT.undo_stack.append(stored_event_dict(event_data))
973
- try_binding(self.ri_extra_end_sort_cols_func, event_data, "end_sort_columns")
973
+ try_binding(self.ri_extra_end_sort_cols_func, event_data, "end_move_columns")
974
974
  self.MT.sheet_modified(event_data)
975
975
  self.PAR.emit_event("<<SheetModified>>", event_data)
976
976
  self.MT.refresh()
@@ -1,11 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Callable, Generator
3
+ from collections.abc import Callable, Generator, Iterable, Iterator
4
4
  from datetime import datetime
5
+ from pathlib import Path
5
6
  from re import finditer
6
7
 
7
- from .other_classes import Node
8
- from .tksheet_types import AnyIter
8
+ AnyIter = Iterable | Iterator
9
9
 
10
10
  # Possible date formats to try for the entire string
11
11
  date_formats = [
@@ -45,24 +45,27 @@ date_formats = [
45
45
  ]
46
46
 
47
47
 
48
- def natural_sort_key(item: object) -> tuple[int, object]:
48
+ def natural_sort_key(
49
+ item: object,
50
+ ) -> tuple[int, ...]:
49
51
  """
50
- A key function for natural sorting that handles various Python types, including
51
- date-like strings in multiple formats.
52
-
53
- This function aims to sort elements in a human-readable order:
54
- - None values first
55
- - Booleans (False before True)
56
- - Numbers (integers, floats combined)
57
- - Datetime objects
58
- - Strings with natural sorting for embedded numbers and dates
59
- - Unknown types treated as strings or left at the end
60
-
61
- Args:
62
- item: Any Python object to be sorted.
63
-
64
- Returns:
65
- A tuple or value that can be used for sorting.
52
+ A key for natural sorting of various Python types.
53
+
54
+ This function returns a tuple where the first element is an integer
55
+ ranking the type, followed by type-specific comparison values.
56
+
57
+ 1. None
58
+ 2. bool
59
+ 3. int, float
60
+ 4. datetime
61
+ 5. filepaths
62
+ 6. empty strings
63
+ 7. strings
64
+ 8. unknown objects with __str__ method
65
+ 9. unknown objects
66
+
67
+ :param item: Any Python object to be sorted.
68
+ :return: A tuple for sorting, with type indicator and comparison values.
66
69
  """
67
70
  if item is None:
68
71
  return (0,)
@@ -76,31 +79,39 @@ def natural_sort_key(item: object) -> tuple[int, object]:
76
79
  elif isinstance(item, datetime):
77
80
  return (3, item.timestamp())
78
81
 
82
+ elif isinstance(item, Path):
83
+ return (4, item.as_posix())
84
+
79
85
  elif isinstance(item, str):
80
- for date_format in date_formats:
86
+ if not item:
87
+ return (5, item)
88
+
89
+ else:
90
+ for date_format in date_formats:
91
+ try:
92
+ return (3, datetime.strptime(item, date_format).timestamp())
93
+ except ValueError:
94
+ continue
95
+
81
96
  try:
82
- return (3, datetime.strptime(item, date_format).timestamp())
83
- except ValueError:
84
- continue
97
+ return (2, float(item))
98
+ except Exception:
99
+ pass
85
100
 
86
- try:
87
- return (2, float(item))
88
- except Exception:
89
- n = []
90
- s = []
91
- for match in finditer(r"\d+|[^\d\s]+", item):
92
- if (m := match.group()).isdigit():
93
- n.append(int(m))
94
- else:
95
- s.append(m.lower())
96
- return (5, s, n)
101
+ if "/" in item or "\\" in item:
102
+ try:
103
+ return (4, Path(item).as_posix())
104
+ except Exception:
105
+ pass
106
+
107
+ return (6, item.lower(), tuple(int(match.group()) for match in finditer(r"\d+", item)))
97
108
 
109
+ # For unknown types, attempt to convert to string, or place at end
98
110
  else:
99
- # For unknown types, attempt to convert to string, or place at end
100
111
  try:
101
- return (6, f"{item}".lower())
112
+ return (7, f"{item}".lower())
102
113
  except Exception:
103
- return (7, item)
114
+ return (8, item)
104
115
 
105
116
 
106
117
  def sort_selection(
@@ -233,11 +244,11 @@ def sort_columns_by_row(
233
244
 
234
245
 
235
246
  def _sort_node_children(
236
- node: Node,
237
- tree: dict[str, Node],
247
+ node: object,
248
+ tree: dict[str, object],
238
249
  reverse: bool,
239
250
  key: Callable,
240
- ) -> Generator[Node, None, None]:
251
+ ) -> Generator[object, None, None]:
241
252
  sorted_children = sorted(
242
253
  (tree[child_iid] for child_iid in node.children if child_iid in tree),
243
254
  key=lambda child: key(child.text),
@@ -250,12 +261,12 @@ def _sort_node_children(
250
261
 
251
262
 
252
263
  def sort_tree_view(
253
- _row_index: list[Node],
264
+ _row_index: list[object],
254
265
  tree_rns: dict[str, int],
255
- tree: dict[str, Node],
266
+ tree: dict[str, object],
256
267
  key: Callable = natural_sort_key,
257
268
  reverse: bool = False,
258
- ) -> tuple[list[Node], dict[int, int]]:
269
+ ) -> tuple[list[object], dict[int, int]]:
259
270
  if not _row_index or not tree_rns or not tree:
260
271
  return [], {}
261
272
 
@@ -285,3 +296,40 @@ def sort_tree_view(
285
296
  new_index += 1
286
297
 
287
298
  return sorted_nodes, mapping
299
+
300
+
301
+ # def test_natural_sort_key():
302
+ # test_items = [
303
+ # None,
304
+ # False,
305
+ # True,
306
+ # 5,
307
+ # 3.14,
308
+ # datetime(2023, 1, 1),
309
+ # "abc123",
310
+ # "123abc",
311
+ # "abc123def",
312
+ # "998zzz",
313
+ # "10-01-2023",
314
+ # "01-10-2023",
315
+ # "fi1le_0.txt",
316
+ # "file_2.txt",
317
+ # "file_10.txt",
318
+ # "file_1.txt",
319
+ # "path/to/file_2.txt",
320
+ # "path/to/file_10.txt",
321
+ # "path/to/file_1.txt",
322
+ # "/another/path/file_2.log",
323
+ # "/another/path/file_10.log",
324
+ # "/another/path/file_1.log",
325
+ # "C:\\Windows\\System32\\file_2.dll",
326
+ # "C:\\Windows\\System32\\file_10.dll",
327
+ # "C:\\Windows\\System32\\file_1.dll",
328
+ # ]
329
+ # print("Sort objects:", [natural_sort_key(e) for e in test_items])
330
+ # sorted_items = sorted(test_items, key=natural_sort_key)
331
+ # print("\nNatural Sort Order:", sorted_items)
332
+
333
+
334
+ # if __name__ == "__main__":
335
+ # test_natural_sort_key()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tksheet
3
- Version: 7.4.1
3
+ Version: 7.4.2
4
4
  Summary: Tkinter table / sheet and treeview widget
5
5
  Author-email: ragardner <github@ragardner.simplelogin.com>
6
6
  License: Copyright (c) 2019 ragardner and open source contributors
@@ -77,7 +77,7 @@ License-File: LICENSE.txt
77
77
  <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#issues">Issues</a></td>
78
78
  </tr>
79
79
  <tr>
80
- <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#enhancements-or-suggestions">Suggestions</a></td>
80
+ <td align="right" colspan="2"><a href="https://github.com/ragardner/tksheet/wiki/Version-7#enhancements-or-suggestions">Suggestions and Contributors</a></td>
81
81
  </tr>
82
82
  </tbody>
83
83
  </table>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes