tksheet 7.4.8__py3-none-any.whl → 7.4.10__py3-none-any.whl

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.
tksheet/sorting.py CHANGED
@@ -1,13 +1,11 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Callable, Generator, Iterable, Iterator
3
+ from collections.abc import Callable, Iterator
4
4
  from datetime import datetime
5
5
  from pathlib import Path
6
6
  from re import split
7
7
  from typing import Any
8
8
 
9
- AnyIter = Iterable | Iterator
10
-
11
9
  # Possible date formats to try for the entire string
12
10
  date_formats = (
13
11
  # Common formats
@@ -298,7 +296,7 @@ def sort_selection(
298
296
 
299
297
 
300
298
  def sort_column(
301
- data: list[list[Any]] | list[Any] | AnyIter[Any],
299
+ data: list[list[Any]] | list[Any] | Iterator[Any],
302
300
  column: int = 0,
303
301
  reverse: bool = False,
304
302
  key: Callable | None = None,
@@ -316,7 +314,7 @@ def sort_column(
316
314
 
317
315
 
318
316
  def sort_row(
319
- data: list[list[Any]] | list[Any] | AnyIter[Any],
317
+ data: list[list[Any]] | list[Any] | Iterator[Any],
320
318
  row: int = 0,
321
319
  reverse: bool = False,
322
320
  key: Callable | None = None,
@@ -397,58 +395,71 @@ def sort_columns_by_row(
397
395
  return sort_indices, dict(zip(range(len(data[row])), sort_indices))
398
396
 
399
397
 
400
- def _sort_node_children(
401
- node: Any,
402
- tree: dict[str, Any],
403
- reverse: bool,
404
- key: Callable,
405
- ) -> Generator[Any, None, None]:
406
- sorted_children = sorted(
407
- (tree[child_iid] for child_iid in node.children if child_iid in tree),
408
- key=lambda child: key(child.text),
409
- reverse=reverse,
410
- )
411
- for child in sorted_children:
412
- yield child
413
- if child.children: # If the child node has children
414
- yield from _sort_node_children(child, tree, reverse, key)
415
-
416
-
417
- def sort_tree_view(
418
- _row_index: list[Any],
419
- tree_rns: dict[str, int],
420
- tree: dict[str, Any],
421
- key: Callable | None = None,
398
+ def sort_tree_rows_by_column(
399
+ data: list[list[Any]],
400
+ column: int,
401
+ index: list[Any],
402
+ rns: dict[str, int],
422
403
  reverse: bool = False,
404
+ key: Callable | None = None,
423
405
  ) -> tuple[list[Any], dict[int, int]]:
424
- if not _row_index or not tree_rns or not tree:
406
+ """
407
+ Sorts tree rows by a specified column in depth-first order, returning sorted nodes and a row mapping.
408
+
409
+ Args:
410
+ data: List of rows, where each row is a list of column values.
411
+ column: Index of the column to sort by.
412
+ index: List of nodes, where each node has 'iid', 'parent', and 'children' attributes.
413
+ rns: Dictionary mapping item IDs (iid) to original row numbers in data.
414
+ reverse: If True, sort in descending order; otherwise, ascending.
415
+ key: Optional function to compute sort keys; defaults to natural_sort_key if None.
416
+
417
+ Returns:
418
+ Tuple containing:
419
+ - List of nodes in sorted order.
420
+ - Dictionary mapping original row numbers to new row numbers.
421
+ """
422
+ if not index or not rns:
425
423
  return [], {}
426
424
 
427
425
  if key is None:
428
- # prefer version_sort_key for iid names
429
- key = version_sort_key
426
+ key = natural_sort_key # Assuming natural_sort_key is defined elsewhere
430
427
 
431
- # Create the index map and sorted nodes list
432
- mapping = {}
433
- sorted_nodes = []
434
- new_index = 0
428
+ # Define the sort_reverse parameter to avoid unnecessary reversals
429
+ sort_reverse = not reverse
435
430
 
436
- # Sort top-level nodes
437
- for node in sorted(
438
- (node for node in _row_index if node.parent == ""),
439
- key=lambda node: key(node.text),
440
- reverse=reverse,
441
- ):
442
- iid = node.iid
443
- mapping[tree_rns[iid]] = new_index
444
- sorted_nodes.append(node)
445
- new_index += 1
446
-
447
- # Sort children recursively
448
- for descendant_node in _sort_node_children(node, tree, reverse, key):
449
- mapping[tree_rns[descendant_node.iid]] = new_index
450
- sorted_nodes.append(descendant_node)
451
- new_index += 1
431
+ # Helper function to compute the sorting key for a node
432
+ def get_key(node):
433
+ row = data[rns[node.iid]]
434
+ return key(row[column] if len(row) > column else None)
435
+
436
+ # Initialize stack with sorted top-level nodes for efficiency
437
+ stack = sorted(
438
+ (node for node in index if node.parent == ""),
439
+ key=get_key,
440
+ reverse=sort_reverse,
441
+ )
442
+
443
+ # Initialize output structures
444
+ sorted_nodes = []
445
+ mapping = {}
446
+ new_rn = 0
447
+
448
+ # Process nodes iteratively in depth-first order
449
+ while stack:
450
+ current = stack.pop() # Pop from the right end
451
+ sorted_nodes.append(current)
452
+ mapping[rns[current.iid]] = new_rn
453
+ new_rn += 1
454
+ if current.children:
455
+ # Sort children
456
+ sorted_children = sorted(
457
+ (index[rns[ciid]] for ciid in current.children if ciid in rns),
458
+ key=get_key,
459
+ reverse=sort_reverse,
460
+ )
461
+ # Extend stack with sorted children
462
+ stack.extend(sorted_children) # Adds to the right end
452
463
 
453
464
  return sorted_nodes, mapping
454
465
 
tksheet/tksheet_types.py CHANGED
@@ -1,6 +1,5 @@
1
1
  from __future__ import annotations
2
2
 
3
- from collections.abc import Iterable, Iterator
4
3
  from typing import Literal, Tuple, Union
5
4
 
6
5
  from .other_classes import Span
@@ -26,8 +25,6 @@ CellPropertyKey = Literal[
26
25
  "align",
27
26
  ]
28
27
 
29
- AnyIter = Iterable | Iterator
30
-
31
28
  Binding = Literal[
32
29
  "all",
33
30
  "single_select",
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: tksheet
3
- Version: 7.4.8
3
+ Version: 7.4.10
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
@@ -0,0 +1,22 @@
1
+ tksheet/__init__.py,sha256=OgyS9wliRNfROen76H0boTTekZzt6Yx6gy05ytI54ps,2327
2
+ tksheet/colors.py,sha256=dHhmdFuQDlwohDHsAfT9VdrKoSl_R33L72a3HCin5zo,51591
3
+ tksheet/column_headers.py,sha256=tCIjq9sv5MfOfhC1hXzWU20RO1icdox1AvlYIESIQl4,103215
4
+ tksheet/constants.py,sha256=aiDvUSaPtl_TSNtRRJ_p87c9iTBz9ksMd5IsSXzz4Hk,13316
5
+ tksheet/find_window.py,sha256=TvbSqO42cw1o1AO0tQ0Q1iZogouNr4ObMo7JfkZCxgA,19877
6
+ tksheet/formatters.py,sha256=DGcRiMsDJnySNpQcjfiX84oJ7TmOSMdU6u9injIhA4g,10095
7
+ tksheet/functions.py,sha256=Lfo605jYI87KLWo6okQhfUlr-c93ZxuOR5VJKCNY6UM,51019
8
+ tksheet/main_table.py,sha256=Nxc1oALcWvYnUVqD4ryRvayW-KZwFmKLyHaxaWABLJ0,363945
9
+ tksheet/other_classes.py,sha256=pe9_Cj6d3rdeMif9nGvUz0MEUChf0l4d669RNqcNhY4,16578
10
+ tksheet/row_index.py,sha256=_lCilwJfc5Eem22S7WZH_85zWQGGLGMa1upHUGCj_Y0,140328
11
+ tksheet/sheet.py,sha256=ZgryLoqfkm2vtJDIVhXAvSUQ8G7TXztiID8Ftt3V2qo,269531
12
+ tksheet/sheet_options.py,sha256=ob-XYgGfBoi2TaFAvUUmlWUkw9xB-yXmJw17gu9__Lw,9948
13
+ tksheet/sorting.py,sha256=zcZPpRtP1h_xJGtGkG3E43H7deKQFnh9cMwZ1B2-aGc,17502
14
+ tksheet/text_editor.py,sha256=rU8Fz0-ltkM63W9io2DoZJPyzUGzCc9Z0qBtc4D1H40,7404
15
+ tksheet/themes.py,sha256=AoNAxibnQi04MN0Zpbn9-kyDnkiiV8TDNWP9FYjpuf0,18473
16
+ tksheet/tksheet_types.py,sha256=1MjXR34EmvP1KfHlLTvKKVnf0VMz_LU_WOM2q4o5hfI,4598
17
+ tksheet/top_left_rectangle.py,sha256=M52IrPIeMoYE3jSpooZmqw_0W5Fz_R-Yu1ZqA685EZ8,8557
18
+ tksheet-7.4.10.dist-info/LICENSE.txt,sha256=ndbcCPe9SlHfweE_W2RAueWUe2k7yudyxYLq6WjFdn4,1101
19
+ tksheet-7.4.10.dist-info/METADATA,sha256=pyrkLPJDMS3fT3VWRFu5jsnCXn62_E25VQ3FpaGiKCY,8006
20
+ tksheet-7.4.10.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
21
+ tksheet-7.4.10.dist-info/top_level.txt,sha256=my61PXCcck_HHAc9cq3NAlyAr3A3FXxCy9gptEOaCN8,8
22
+ tksheet-7.4.10.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- tksheet/__init__.py,sha256=l619QID9OmLzoGYKcDr2pSJsVrSSFAzG17P5JHbii5s,2326
2
- tksheet/colors.py,sha256=dHhmdFuQDlwohDHsAfT9VdrKoSl_R33L72a3HCin5zo,51591
3
- tksheet/column_headers.py,sha256=FWDiKOX4LbaNA0zj2tbnnkOBW-RE6QuDxyc3EEEur5M,103267
4
- tksheet/constants.py,sha256=aiDvUSaPtl_TSNtRRJ_p87c9iTBz9ksMd5IsSXzz4Hk,13316
5
- tksheet/find_window.py,sha256=TvbSqO42cw1o1AO0tQ0Q1iZogouNr4ObMo7JfkZCxgA,19877
6
- tksheet/formatters.py,sha256=DGcRiMsDJnySNpQcjfiX84oJ7TmOSMdU6u9injIhA4g,10095
7
- tksheet/functions.py,sha256=pCTnCniLIbJI1S9nnPauok93H2EQHEHVvTVWLWImG-I,51024
8
- tksheet/main_table.py,sha256=U95qEPjUV75jlpOF0pMBk5mas9qrG87zKeEuIUOzDXw,363142
9
- tksheet/other_classes.py,sha256=pe9_Cj6d3rdeMif9nGvUz0MEUChf0l4d669RNqcNhY4,16578
10
- tksheet/row_index.py,sha256=F7mjNJ8o0TNDGVF78JsAH0GxJAYCGx1pbjkmxTJjMbQ,134303
11
- tksheet/sheet.py,sha256=kvbmFekdwEm3hyRBILPYn3SJW905UOZJO3NUllmBUk0,272258
12
- tksheet/sheet_options.py,sha256=ob-XYgGfBoi2TaFAvUUmlWUkw9xB-yXmJw17gu9__Lw,9948
13
- tksheet/sorting.py,sha256=-x1ZBIYfaneRrQPhbb0Ehs70373o52ADXp481La3nOY,16806
14
- tksheet/text_editor.py,sha256=rU8Fz0-ltkM63W9io2DoZJPyzUGzCc9Z0qBtc4D1H40,7404
15
- tksheet/themes.py,sha256=AoNAxibnQi04MN0Zpbn9-kyDnkiiV8TDNWP9FYjpuf0,18473
16
- tksheet/tksheet_types.py,sha256=7FIDsInby1y1DZMpVINXem4Ol5RFG1ETE5fn9I9uXSk,4679
17
- tksheet/top_left_rectangle.py,sha256=M52IrPIeMoYE3jSpooZmqw_0W5Fz_R-Yu1ZqA685EZ8,8557
18
- tksheet-7.4.8.dist-info/LICENSE.txt,sha256=ndbcCPe9SlHfweE_W2RAueWUe2k7yudyxYLq6WjFdn4,1101
19
- tksheet-7.4.8.dist-info/METADATA,sha256=g03IKcPe7_orOLSvu_VQXmy_qC4Lw1Xyui75SVUoVzc,8005
20
- tksheet-7.4.8.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
21
- tksheet-7.4.8.dist-info/top_level.txt,sha256=my61PXCcck_HHAc9cq3NAlyAr3A3FXxCy9gptEOaCN8,8
22
- tksheet-7.4.8.dist-info/RECORD,,