tksheet 7.3.2__py3-none-any.whl → 7.3.4__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/functions.py CHANGED
@@ -5,39 +5,17 @@ import io
5
5
  import pickle
6
6
  import re
7
7
  import tkinter as tk
8
- from bisect import (
9
- bisect_left,
10
- )
8
+ from bisect import bisect_left
11
9
  from collections import deque
12
- from collections.abc import (
13
- Callable,
14
- Generator,
15
- Hashable,
16
- Iterable,
17
- Iterator,
18
- Sequence,
19
- )
10
+ from collections.abc import Callable, Generator, Hashable, Iterable, Iterator, Sequence
20
11
  from itertools import islice, repeat
21
12
  from typing import Literal
22
13
 
23
14
  from .colors import color_map
24
- from .formatters import (
25
- to_bool,
26
- )
27
- from .other_classes import (
28
- Box_nt,
29
- DotDict,
30
- EventDataDict,
31
- Highlight,
32
- Loc,
33
- Span,
34
- )
35
- from .types import (
36
- AnyIter,
37
- )
38
- from .constants import (
39
- symbols_set,
40
- )
15
+ from .constants import symbols_set
16
+ from .formatters import to_bool
17
+ from .other_classes import Box_nt, DotDict, EventDataDict, Highlight, Loc, Span
18
+ from .types import AnyIter
41
19
 
42
20
  unpickle_obj = pickle.loads
43
21
 
@@ -590,17 +568,8 @@ def move_elements_by_mapping(
590
568
  # old_idxs = {new index: old index, ...}
591
569
  if old_idxs is None:
592
570
  old_idxs = dict(zip(new_idxs.values(), new_idxs))
593
-
594
- res = [0] * len(seq)
595
-
596
571
  remaining_values = (e for i, e in enumerate(seq) if i not in new_idxs)
597
- for i in range(len(res)):
598
- if i in old_idxs:
599
- res[i] = seq[old_idxs[i]]
600
- else:
601
- res[i] = next(remaining_values)
602
-
603
- return res
572
+ return [seq[old_idxs[i]] if i in old_idxs else next(remaining_values) for i in range(len(seq))]
604
573
 
605
574
 
606
575
  def move_elements_to(
@@ -734,6 +703,105 @@ def diff_gen(seq: list[float]) -> Generator[int]:
734
703
  )
735
704
 
736
705
 
706
+ def gen_coords(
707
+ start_row: int,
708
+ start_col: int,
709
+ end_row: int,
710
+ end_col: int,
711
+ reverse: bool = False,
712
+ ) -> Generator[tuple[int, int]]:
713
+ if reverse:
714
+ for r in reversed(range(start_row, end_row)):
715
+ for c in reversed(range(start_col, end_col)):
716
+ yield (r, c)
717
+ else:
718
+ for r in range(start_row, end_row):
719
+ for c in range(start_col, end_col):
720
+ yield (r, c)
721
+
722
+
723
+ def box_gen_coords(
724
+ start_row: int,
725
+ start_col: int,
726
+ total_cols: int,
727
+ total_rows: int,
728
+ reverse: bool = False,
729
+ ) -> Generator[tuple[int, int]]:
730
+ if reverse:
731
+ # yield start cell
732
+ yield (start_row, start_col)
733
+ # yield any remaining cells in the starting row before the start column
734
+ if start_col:
735
+ for col in reversed(range(start_col)):
736
+ yield (start_row, col)
737
+ # yield any cells above start row
738
+ for row in reversed(range(start_row)):
739
+ for col in reversed(range(total_cols)):
740
+ yield (row, col)
741
+ # yield cells from bottom of table upward
742
+ for row in range(total_rows - 1, start_row, -1):
743
+ for col in reversed(range(total_cols)):
744
+ yield (row, col)
745
+ # yield any remaining cells in start row
746
+ for col in range(total_cols - 1, start_col, -1):
747
+ yield (start_row, col)
748
+ else:
749
+ # Yield cells from the start position to the end of the current row
750
+ for col in range(start_col, total_cols):
751
+ yield (start_row, col)
752
+ # yield from the next row to the last row
753
+ for row in range(start_row + 1, total_rows):
754
+ for col in range(total_cols):
755
+ yield (row, col)
756
+ # yield from the beginning up to the start
757
+ for row in range(start_row):
758
+ for col in range(total_cols):
759
+ yield (row, col)
760
+ # yield any remaining cells in the starting row before the start column
761
+ for col in range(start_col):
762
+ yield (start_row, col)
763
+
764
+
765
+ def next_cell(
766
+ start_row: int,
767
+ start_col: int,
768
+ end_row: int,
769
+ end_col: int,
770
+ row: int,
771
+ col: int,
772
+ reverse: bool = False,
773
+ ) -> tuple[int, int]:
774
+ if reverse:
775
+ col -= 1
776
+ if col < start_col:
777
+ col = end_col - 1
778
+ row -= 1
779
+ if row < start_row:
780
+ row = end_row - 1
781
+ else:
782
+ col += 1
783
+ if col == end_col:
784
+ col = start_col
785
+ row += 1
786
+ if row == end_row:
787
+ row = start_row
788
+ return row, col
789
+
790
+
791
+ def is_last_cell(
792
+ start_row: int,
793
+ start_col: int,
794
+ end_row: int,
795
+ end_col: int,
796
+ row: int,
797
+ col: int,
798
+ reverse: bool = False,
799
+ ) -> bool:
800
+ if reverse:
801
+ return row == start_row and col == start_col
802
+ return row == end_row - 1 and col == end_col - 1
803
+
804
+
737
805
  def zip_fill_2nd_value(x: AnyIter[object], o: object) -> Generator[object, object]:
738
806
  return zip(x, repeat(o))
739
807