tksheet 7.2.23__py3-none-any.whl → 7.3.1__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/__init__.py +1 -1
- tksheet/column_headers.py +53 -48
- tksheet/functions.py +26 -9
- tksheet/main_table.py +168 -88
- tksheet/row_index.py +52 -48
- tksheet/sheet.py +107 -79
- tksheet/sheet_options.py +19 -0
- tksheet/top_left_rectangle.py +14 -7
- tksheet/types.py +8 -0
- {tksheet-7.2.23.dist-info → tksheet-7.3.1.dist-info}/METADATA +36 -12
- tksheet-7.3.1.dist-info/RECORD +20 -0
- {tksheet-7.2.23.dist-info → tksheet-7.3.1.dist-info}/WHEEL +1 -1
- tksheet-7.2.23.dist-info/RECORD +0 -20
- {tksheet-7.2.23.dist-info → tksheet-7.3.1.dist-info}/LICENSE.txt +0 -0
- {tksheet-7.2.23.dist-info → tksheet-7.3.1.dist-info}/top_level.txt +0 -0
tksheet/row_index.py
CHANGED
@@ -5,7 +5,6 @@ from collections import defaultdict
|
|
5
5
|
from collections.abc import (
|
6
6
|
Generator,
|
7
7
|
Hashable,
|
8
|
-
Iterator,
|
9
8
|
Sequence,
|
10
9
|
)
|
11
10
|
from functools import (
|
@@ -35,13 +34,15 @@ from .formatters import (
|
|
35
34
|
)
|
36
35
|
from .functions import (
|
37
36
|
consecutive_chunks,
|
37
|
+
consecutive_ranges,
|
38
38
|
event_dict,
|
39
39
|
get_n2a,
|
40
|
+
int_x_tuple,
|
40
41
|
is_contiguous,
|
41
42
|
new_tk_event,
|
42
43
|
num2alpha,
|
43
|
-
stored_event_dict,
|
44
44
|
rounded_box_coords,
|
45
|
+
stored_event_dict,
|
45
46
|
try_binding,
|
46
47
|
)
|
47
48
|
from .other_classes import (
|
@@ -54,6 +55,9 @@ from .other_classes import (
|
|
54
55
|
from .text_editor import (
|
55
56
|
TextEditor,
|
56
57
|
)
|
58
|
+
from .types import (
|
59
|
+
AnyIter,
|
60
|
+
)
|
57
61
|
from .vars import (
|
58
62
|
rc_binding,
|
59
63
|
symbols_set,
|
@@ -74,6 +78,7 @@ class RowIndex(tk.Canvas):
|
|
74
78
|
self.MT = None # is set from within MainTable() __init__
|
75
79
|
self.CH = None # is set from within MainTable() __init__
|
76
80
|
self.TL = None # is set from within TopLeftRectangle() __init__
|
81
|
+
self.current_width = None
|
77
82
|
self.popup_menu_loc = None
|
78
83
|
self.extra_begin_edit_cell_func = None
|
79
84
|
self.extra_end_edit_cell_func = None
|
@@ -95,7 +100,6 @@ class RowIndex(tk.Canvas):
|
|
95
100
|
self.ri_extra_end_drag_drop_func = None
|
96
101
|
self.extra_double_b1_func = None
|
97
102
|
self.row_height_resize_func = None
|
98
|
-
self.new_row_width = 0
|
99
103
|
self.cell_options = {}
|
100
104
|
self.drag_and_drop_enabled = False
|
101
105
|
self.dragged_row = None
|
@@ -178,13 +182,15 @@ class RowIndex(tk.Canvas):
|
|
178
182
|
self.MT.saved_row_heights = {}
|
179
183
|
|
180
184
|
def set_width(self, new_width: int, set_TL: bool = False, recreate_selection_boxes: bool = True) -> None:
|
181
|
-
self.current_width = new_width
|
182
185
|
try:
|
183
186
|
self.config(width=new_width)
|
184
187
|
except Exception:
|
185
188
|
return
|
186
189
|
if set_TL:
|
187
|
-
self.TL.set_dimensions(new_w=new_width
|
190
|
+
self.TL.set_dimensions(new_w=new_width)
|
191
|
+
if isinstance(self.current_width, int) and new_width > self.current_width and recreate_selection_boxes:
|
192
|
+
self.MT.recreate_all_selection_boxes()
|
193
|
+
self.current_width = new_width
|
188
194
|
|
189
195
|
def rc(self, event: object) -> None:
|
190
196
|
self.mouseclick_outside_editor_or_dropdown_all_canvases(inside=True)
|
@@ -480,11 +486,6 @@ class RowIndex(tk.Canvas):
|
|
480
486
|
self.MT.create_resize_line(x1, line2y, x2, line2y, width=1, fill=self.PAR.ops.resizing_line_fg, tag="rhl2")
|
481
487
|
elif self.width_resizing_enabled and self.rsz_h is None and self.rsz_w is True:
|
482
488
|
self.currently_resizing_width = True
|
483
|
-
x1, y1, x2, y2 = self.MT.get_canvas_visible_area()
|
484
|
-
x = int(event.x)
|
485
|
-
if x < self.MT.min_column_width:
|
486
|
-
x = int(self.MT.min_column_width)
|
487
|
-
self.new_row_width = x
|
488
489
|
elif self.MT.identify_row(y=event.y, allow_end=False) is None:
|
489
490
|
self.MT.deselect("all")
|
490
491
|
elif self.row_selection_enabled and self.rsz_h is None and self.rsz_w is None:
|
@@ -513,7 +514,7 @@ class RowIndex(tk.Canvas):
|
|
513
514
|
if self.height_resizing_enabled and self.rsz_h is not None and self.currently_resizing_height:
|
514
515
|
y = self.canvasy(event.y)
|
515
516
|
size = y - self.MT.row_positions[self.rsz_h - 1]
|
516
|
-
if size >= self.MT.min_row_height and size < self.
|
517
|
+
if size >= self.MT.min_row_height and size < self.PAR.ops.max_row_height:
|
517
518
|
self.hide_resize_and_ctrl_lines(ctrl_lines=False)
|
518
519
|
line2y = self.MT.row_positions[self.rsz_h - 1]
|
519
520
|
self.create_resize_line(
|
@@ -548,18 +549,14 @@ class RowIndex(tk.Canvas):
|
|
548
549
|
elif self.width_resizing_enabled and self.rsz_w is not None and self.currently_resizing_width:
|
549
550
|
evx = event.x
|
550
551
|
if evx > self.current_width:
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
x = self.MT.canvasx(evx - self.current_width)
|
555
|
-
self.new_row_width = evx
|
552
|
+
if evx > self.PAR.ops.max_index_width:
|
553
|
+
evx = int(self.PAR.ops.max_index_width)
|
554
|
+
self.drag_width_resize(evx)
|
556
555
|
else:
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
self.drag_width_resize()
|
562
|
-
if (
|
556
|
+
if evx < self.PAR.ops.min_column_width:
|
557
|
+
evx = self.PAR.ops.min_column_width
|
558
|
+
self.drag_width_resize(evx)
|
559
|
+
elif (
|
563
560
|
self.drag_and_drop_enabled
|
564
561
|
and self.row_selection_enabled
|
565
562
|
and self.MT.anything_selected(exclude_cells=True, exclude_columns=True)
|
@@ -777,9 +774,9 @@ class RowIndex(tk.Canvas):
|
|
777
774
|
and event.x < self.MT.index_txt_height + 4
|
778
775
|
)
|
779
776
|
|
780
|
-
def drag_width_resize(self) -> None:
|
781
|
-
self.set_width(
|
782
|
-
self.MT.main_table_redraw_grid_and_text(redraw_header=
|
777
|
+
def drag_width_resize(self, width: int) -> None:
|
778
|
+
self.set_width(width, set_TL=True)
|
779
|
+
self.MT.main_table_redraw_grid_and_text(redraw_header=False, redraw_row_index=True, redraw_table=False)
|
783
780
|
|
784
781
|
def drag_height_resize(self) -> None:
|
785
782
|
new_row_pos = int(self.coords("rhl")[1])
|
@@ -787,8 +784,8 @@ class RowIndex(tk.Canvas):
|
|
787
784
|
size = new_row_pos - self.MT.row_positions[self.rsz_h - 1]
|
788
785
|
if size < self.MT.min_row_height:
|
789
786
|
new_row_pos = ceil(self.MT.row_positions[self.rsz_h - 1] + self.MT.min_row_height)
|
790
|
-
elif size > self.
|
791
|
-
new_row_pos = floor(self.MT.row_positions[self.rsz_h - 1] + self.
|
787
|
+
elif size > self.PAR.ops.max_row_height:
|
788
|
+
new_row_pos = floor(self.MT.row_positions[self.rsz_h - 1] + self.PAR.ops.max_row_height)
|
792
789
|
increment = new_row_pos - self.MT.row_positions[self.rsz_h]
|
793
790
|
self.MT.row_positions[self.rsz_h + 1 :] = [
|
794
791
|
e + increment for e in islice(self.MT.row_positions, self.rsz_h + 1, None)
|
@@ -822,12 +819,8 @@ class RowIndex(tk.Canvas):
|
|
822
819
|
self.MT.bind("<MouseWheel>", self.MT.mousewheel)
|
823
820
|
if self.height_resizing_enabled and self.rsz_h is not None and self.currently_resizing_height:
|
824
821
|
self.drag_height_resize()
|
825
|
-
self.currently_resizing_height = False
|
826
822
|
self.hide_resize_and_ctrl_lines(ctrl_lines=False)
|
827
|
-
elif
|
828
|
-
self.currently_resizing_width = False
|
829
|
-
self.drag_width_resize()
|
830
|
-
if (
|
823
|
+
elif (
|
831
824
|
self.drag_and_drop_enabled
|
832
825
|
and self.MT.anything_selected(exclude_cells=True, exclude_columns=True)
|
833
826
|
and self.row_selection_enabled
|
@@ -955,20 +948,31 @@ class RowIndex(tk.Canvas):
|
|
955
948
|
|
956
949
|
def select_row(
|
957
950
|
self,
|
958
|
-
r: int,
|
951
|
+
r: int | AnyIter[int],
|
959
952
|
redraw: bool = False,
|
960
953
|
run_binding_func: bool = True,
|
961
954
|
ext: bool = False,
|
962
955
|
) -> int:
|
963
956
|
boxes_to_hide = tuple(self.MT.selection_boxes)
|
964
|
-
|
957
|
+
fill_iids = [
|
958
|
+
self.MT.create_selection_box(
|
959
|
+
start,
|
960
|
+
0,
|
961
|
+
end,
|
962
|
+
len(self.MT.col_positions) - 1,
|
963
|
+
"rows",
|
964
|
+
set_current=True,
|
965
|
+
ext=ext,
|
966
|
+
)
|
967
|
+
for start, end in consecutive_ranges(int_x_tuple(r))
|
968
|
+
]
|
965
969
|
for iid in boxes_to_hide:
|
966
970
|
self.MT.hide_selection_box(iid)
|
967
971
|
if redraw:
|
968
972
|
self.MT.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
|
969
973
|
if run_binding_func:
|
970
974
|
self.MT.run_selection_binding("rows")
|
971
|
-
return
|
975
|
+
return fill_iids[0] if len(fill_iids) == 1 else fill_iids
|
972
976
|
|
973
977
|
def add_selection(
|
974
978
|
self,
|
@@ -1092,8 +1096,8 @@ class RowIndex(tk.Canvas):
|
|
1092
1096
|
return self.MT.row_positions[row + 1] - self.MT.row_positions[row]
|
1093
1097
|
if h < self.MT.min_row_height:
|
1094
1098
|
h = int(self.MT.min_row_height)
|
1095
|
-
elif h > self.
|
1096
|
-
h = int(self.
|
1099
|
+
elif h > self.PAR.ops.max_row_height:
|
1100
|
+
h = int(self.PAR.ops.max_row_height)
|
1097
1101
|
return h
|
1098
1102
|
|
1099
1103
|
def set_row_height(
|
@@ -1108,8 +1112,8 @@ class RowIndex(tk.Canvas):
|
|
1108
1112
|
height = self.get_row_text_height(row=row, visible_only=visible_only)
|
1109
1113
|
if height < self.MT.min_row_height:
|
1110
1114
|
height = int(self.MT.min_row_height)
|
1111
|
-
elif height > self.
|
1112
|
-
height = int(self.
|
1115
|
+
elif height > self.PAR.ops.max_row_height:
|
1116
|
+
height = int(self.PAR.ops.max_row_height)
|
1113
1117
|
if only_if_too_small and height <= self.MT.row_positions[row + 1] - self.MT.row_positions[row]:
|
1114
1118
|
return self.MT.row_positions[row + 1] - self.MT.row_positions[row]
|
1115
1119
|
new_row_pos = self.MT.row_positions[row] + height
|
@@ -1124,7 +1128,7 @@ class RowIndex(tk.Canvas):
|
|
1124
1128
|
|
1125
1129
|
def get_index_text_width(
|
1126
1130
|
self,
|
1127
|
-
only_rows:
|
1131
|
+
only_rows: AnyIter[int] | None = None,
|
1128
1132
|
) -> int:
|
1129
1133
|
self.fix_index()
|
1130
1134
|
w = self.PAR.ops.default_row_index_width
|
@@ -1143,8 +1147,8 @@ class RowIndex(tk.Canvas):
|
|
1143
1147
|
iterable = self.MT.displayed_rows
|
1144
1148
|
if (new_w := max(map(itemgetter(0), map(self.get_cell_dimensions, iterable)), default=w)) > w:
|
1145
1149
|
w = new_w
|
1146
|
-
if w > self.
|
1147
|
-
w = int(self.
|
1150
|
+
if w > self.PAR.ops.max_index_width:
|
1151
|
+
w = int(self.PAR.ops.max_index_width)
|
1148
1152
|
return w
|
1149
1153
|
|
1150
1154
|
def set_width_of_index_to_text(
|
@@ -1165,8 +1169,8 @@ class RowIndex(tk.Canvas):
|
|
1165
1169
|
w = tw
|
1166
1170
|
elif text is None:
|
1167
1171
|
w = self.get_index_text_width(only_rows=only_rows)
|
1168
|
-
if w > self.
|
1169
|
-
w = int(self.
|
1172
|
+
if w > self.PAR.ops.max_index_width:
|
1173
|
+
w = int(self.PAR.ops.max_index_width)
|
1170
1174
|
self.set_width(w, set_TL=True)
|
1171
1175
|
self.MT.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
|
1172
1176
|
return w
|
@@ -1637,7 +1641,7 @@ class RowIndex(tk.Canvas):
|
|
1637
1641
|
outline=fill,
|
1638
1642
|
tag="dd",
|
1639
1643
|
draw_outline=not dd_drawn,
|
1640
|
-
draw_arrow=
|
1644
|
+
draw_arrow=True,
|
1641
1645
|
open_=dd_coords == r,
|
1642
1646
|
)
|
1643
1647
|
else:
|
@@ -1656,7 +1660,7 @@ class RowIndex(tk.Canvas):
|
|
1656
1660
|
outline=fill,
|
1657
1661
|
tag="dd",
|
1658
1662
|
draw_outline=not dd_drawn,
|
1659
|
-
draw_arrow=
|
1663
|
+
draw_arrow=True,
|
1660
1664
|
open_=dd_coords == r,
|
1661
1665
|
)
|
1662
1666
|
else:
|
@@ -1676,7 +1680,7 @@ class RowIndex(tk.Canvas):
|
|
1676
1680
|
outline=fill,
|
1677
1681
|
tag="dd",
|
1678
1682
|
draw_outline=not dd_drawn,
|
1679
|
-
draw_arrow=
|
1683
|
+
draw_arrow=True,
|
1680
1684
|
open_=dd_coords == r,
|
1681
1685
|
)
|
1682
1686
|
else:
|
@@ -1785,7 +1789,7 @@ class RowIndex(tk.Canvas):
|
|
1785
1789
|
txt = txt[:-1]
|
1786
1790
|
self.itemconfig(iid, text=txt)
|
1787
1791
|
wd = self.bbox(iid)
|
1788
|
-
elif align == "e" and
|
1792
|
+
elif align == "e" and checkbox_kwargs:
|
1789
1793
|
txt = txt[len(txt) - int(len(txt) * (mw / wd)) :]
|
1790
1794
|
self.itemconfig(iid, text=txt)
|
1791
1795
|
wd = self.bbox(iid)
|