tksheet 7.2.1__py3-none-any.whl → 7.2.3__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 +247 -201
- tksheet/main_table.py +135 -116
- tksheet/row_index.py +234 -196
- tksheet/sheet.py +86 -47
- tksheet/top_left_rectangle.py +7 -2
- {tksheet-7.2.1.dist-info → tksheet-7.2.3.dist-info}/METADATA +6 -4
- tksheet-7.2.3.dist-info/RECORD +20 -0
- tksheet-7.2.1.dist-info/RECORD +0 -20
- {tksheet-7.2.1.dist-info → tksheet-7.2.3.dist-info}/LICENSE.txt +0 -0
- {tksheet-7.2.1.dist-info → tksheet-7.2.3.dist-info}/WHEEL +0 -0
- {tksheet-7.2.1.dist-info → tksheet-7.2.3.dist-info}/top_level.txt +0 -0
tksheet/row_index.py
CHANGED
@@ -5,6 +5,9 @@ from collections import defaultdict
|
|
5
5
|
from collections.abc import (
|
6
6
|
Callable,
|
7
7
|
Generator,
|
8
|
+
Hashable,
|
9
|
+
Iterator,
|
10
|
+
Sequence,
|
8
11
|
)
|
9
12
|
from functools import (
|
10
13
|
partial,
|
@@ -13,11 +16,15 @@ from itertools import (
|
|
13
16
|
chain,
|
14
17
|
cycle,
|
15
18
|
islice,
|
19
|
+
repeat,
|
16
20
|
)
|
17
21
|
from math import (
|
18
22
|
ceil,
|
19
23
|
floor,
|
20
24
|
)
|
25
|
+
from operator import (
|
26
|
+
itemgetter,
|
27
|
+
)
|
21
28
|
from typing import Literal
|
22
29
|
|
23
30
|
from .colors import (
|
@@ -595,13 +602,13 @@ class RowIndex(tk.Canvas):
|
|
595
602
|
self.MT.main_table_redraw_grid_and_text(redraw_header=False, redraw_row_index=True)
|
596
603
|
try_binding(self.extra_b1_motion_func, event)
|
597
604
|
|
598
|
-
def get_b1_motion_box(self, start_row, end_row):
|
605
|
+
def get_b1_motion_box(self, start_row: int, end_row: int) -> tuple[int, int, int, int, Literal["rows"]]:
|
599
606
|
if end_row >= start_row:
|
600
607
|
return start_row, 0, end_row + 1, len(self.MT.col_positions) - 1, "rows"
|
601
608
|
elif end_row < start_row:
|
602
609
|
return end_row, 0, start_row + 1, len(self.MT.col_positions) - 1, "rows"
|
603
610
|
|
604
|
-
def ctrl_b1_motion(self, event: object):
|
611
|
+
def ctrl_b1_motion(self, event: object) -> None:
|
605
612
|
x1, y1, x2, y2 = self.MT.get_canvas_visible_area()
|
606
613
|
if (
|
607
614
|
self.drag_and_drop_enabled
|
@@ -655,7 +662,7 @@ class RowIndex(tk.Canvas):
|
|
655
662
|
elif not self.MT.ctrl_select_enabled:
|
656
663
|
self.b1_motion(event)
|
657
664
|
|
658
|
-
def drag_and_drop_motion(self, event: object):
|
665
|
+
def drag_and_drop_motion(self, event: object) -> float:
|
659
666
|
y = event.y
|
660
667
|
hend = self.winfo_height()
|
661
668
|
ycheck = self.yview()
|
@@ -692,11 +699,11 @@ class RowIndex(tk.Canvas):
|
|
692
699
|
|
693
700
|
def show_drag_and_drop_indicators(
|
694
701
|
self,
|
695
|
-
ypos,
|
696
|
-
x1,
|
697
|
-
x2,
|
698
|
-
rows,
|
699
|
-
):
|
702
|
+
ypos: float,
|
703
|
+
x1: float,
|
704
|
+
x2: float,
|
705
|
+
rows: Sequence[int],
|
706
|
+
) -> None:
|
700
707
|
self.hide_resize_and_ctrl_lines()
|
701
708
|
self.create_resize_line(
|
702
709
|
0,
|
@@ -717,13 +724,13 @@ class RowIndex(tk.Canvas):
|
|
717
724
|
delete_on_timer=False,
|
718
725
|
)
|
719
726
|
|
720
|
-
def hide_resize_and_ctrl_lines(self, ctrl_lines=True):
|
727
|
+
def hide_resize_and_ctrl_lines(self, ctrl_lines: bool = True) -> None:
|
721
728
|
self.delete_resize_lines()
|
722
729
|
self.MT.delete_resize_lines()
|
723
730
|
if ctrl_lines:
|
724
731
|
self.MT.delete_ctrl_outlines()
|
725
732
|
|
726
|
-
def scroll_if_event_offscreen(self, event: object):
|
733
|
+
def scroll_if_event_offscreen(self, event: object) -> bool:
|
727
734
|
ycheck = self.yview()
|
728
735
|
need_redraw = False
|
729
736
|
if event.y > self.winfo_height() and len(ycheck) > 1 and ycheck[1] < 1:
|
@@ -746,7 +753,7 @@ class RowIndex(tk.Canvas):
|
|
746
753
|
need_redraw = True
|
747
754
|
return need_redraw
|
748
755
|
|
749
|
-
def fix_yview(self):
|
756
|
+
def fix_yview(self) -> None:
|
750
757
|
ycheck = self.yview()
|
751
758
|
if ycheck and ycheck[0] < 0:
|
752
759
|
self.MT.set_yviews("moveto", 0)
|
@@ -1042,161 +1049,155 @@ class RowIndex(tk.Canvas):
|
|
1042
1049
|
w += self.get_treeview_indent(self.MT._row_index[datarn].iid) + 5
|
1043
1050
|
return w, h
|
1044
1051
|
|
1045
|
-
def
|
1052
|
+
def get_row_text_height(
|
1046
1053
|
self,
|
1047
1054
|
row: int,
|
1048
|
-
|
1049
|
-
|
1050
|
-
recreate: bool = True,
|
1051
|
-
return_new_height: bool = False,
|
1052
|
-
displayed_only: bool = False,
|
1055
|
+
visible_only: bool = False,
|
1056
|
+
only_if_too_small: bool = False,
|
1053
1057
|
) -> int:
|
1054
|
-
|
1055
|
-
r_extra = row + 2
|
1056
|
-
min_rh = self.MT.min_row_height
|
1058
|
+
h = self.MT.min_row_height
|
1057
1059
|
datarn = row if self.MT.all_rows_displayed else self.MT.displayed_rows[row]
|
1058
|
-
|
1060
|
+
# index
|
1061
|
+
_w, ih = self.get_cell_dimensions(datarn)
|
1062
|
+
# table
|
1063
|
+
if self.MT.data:
|
1059
1064
|
if self.MT.all_columns_displayed:
|
1060
|
-
if
|
1061
|
-
|
1062
|
-
start_col, end_col = self.MT.get_visible_columns(x1, x2)
|
1065
|
+
if visible_only:
|
1066
|
+
iterable = range(*self.MT.visible_text_columns)
|
1063
1067
|
else:
|
1064
1068
|
if not self.MT.data or datarn >= len(self.MT.data):
|
1065
1069
|
iterable = range(0, 0)
|
1066
1070
|
else:
|
1067
1071
|
iterable = range(0, len(self.MT.data[datarn]))
|
1068
1072
|
else:
|
1069
|
-
if
|
1070
|
-
|
1071
|
-
start_col, end_col = self.MT.get_visible_columns(x1, x2)
|
1073
|
+
if visible_only:
|
1074
|
+
start_col, end_col = self.MT.visible_text_columns
|
1072
1075
|
else:
|
1073
1076
|
start_col, end_col = 0, len(self.MT.displayed_columns)
|
1074
1077
|
iterable = self.MT.displayed_columns[start_col:end_col]
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1082
|
-
|
1083
|
-
if self.MT.data:
|
1084
|
-
for datacn in iterable:
|
1085
|
-
txt = self.MT.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True)
|
1086
|
-
if txt:
|
1087
|
-
h = self.MT.get_txt_h(txt) + 5
|
1088
|
-
else:
|
1089
|
-
h = min_rh
|
1090
|
-
if h < min_rh:
|
1091
|
-
h = int(min_rh)
|
1092
|
-
elif h > self.MT.max_row_height:
|
1093
|
-
h = int(self.MT.max_row_height)
|
1094
|
-
if h > new_height:
|
1095
|
-
new_height = h
|
1096
|
-
else:
|
1097
|
-
new_height = int(height)
|
1098
|
-
if new_height < min_rh:
|
1099
|
-
new_height = int(min_rh)
|
1100
|
-
elif new_height > self.MT.max_row_height:
|
1101
|
-
new_height = int(self.MT.max_row_height)
|
1102
|
-
if only_set_if_too_small and new_height <= self.MT.row_positions[row + 1] - self.MT.row_positions[row]:
|
1078
|
+
for datacn in iterable:
|
1079
|
+
if (txt := self.MT.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True)) and (
|
1080
|
+
th := self.MT.get_txt_h(txt) + 5
|
1081
|
+
) > h:
|
1082
|
+
h = th
|
1083
|
+
if ih > h:
|
1084
|
+
h = ih
|
1085
|
+
if only_if_too_small and h < self.MT.row_positions[row + 1] - self.MT.row_positions[row]:
|
1103
1086
|
return self.MT.row_positions[row + 1] - self.MT.row_positions[row]
|
1104
|
-
if
|
1105
|
-
|
1106
|
-
|
1107
|
-
self.MT.
|
1108
|
-
|
1109
|
-
]
|
1110
|
-
self.MT.row_positions[r_norm] = new_row_pos
|
1111
|
-
if recreate:
|
1112
|
-
self.MT.recreate_all_selection_boxes()
|
1113
|
-
return new_height
|
1087
|
+
if h < self.MT.min_row_height:
|
1088
|
+
h = int(self.MT.min_row_height)
|
1089
|
+
elif h > self.MT.max_row_height:
|
1090
|
+
h = int(self.MT.max_row_height)
|
1091
|
+
return h
|
1114
1092
|
|
1115
|
-
def
|
1093
|
+
def set_row_height(
|
1116
1094
|
self,
|
1117
|
-
|
1118
|
-
|
1119
|
-
|
1120
|
-
|
1121
|
-
|
1122
|
-
|
1123
|
-
|
1124
|
-
|
1125
|
-
|
1126
|
-
|
1095
|
+
row: int,
|
1096
|
+
height: None | int = None,
|
1097
|
+
only_if_too_small: bool = False,
|
1098
|
+
visible_only: bool = False,
|
1099
|
+
recreate: bool = True,
|
1100
|
+
) -> int:
|
1101
|
+
if height is None:
|
1102
|
+
height = self.get_row_text_height(row=row, visible_only=visible_only)
|
1103
|
+
if height < self.MT.min_row_height:
|
1104
|
+
height = int(self.MT.min_row_height)
|
1105
|
+
elif height > self.MT.max_row_height:
|
1106
|
+
height = int(self.MT.max_row_height)
|
1107
|
+
if only_if_too_small and height <= self.MT.row_positions[row + 1] - self.MT.row_positions[row]:
|
1108
|
+
return self.MT.row_positions[row + 1] - self.MT.row_positions[row]
|
1109
|
+
new_row_pos = self.MT.row_positions[row] + height
|
1110
|
+
increment = new_row_pos - self.MT.row_positions[row + 1]
|
1111
|
+
self.MT.row_positions[row + 2 :] = [
|
1112
|
+
e + increment for e in islice(self.MT.row_positions, row + 2, len(self.MT.row_positions))
|
1113
|
+
]
|
1114
|
+
self.MT.row_positions[row + 1] = new_row_pos
|
1115
|
+
if recreate:
|
1116
|
+
self.MT.recreate_all_selection_boxes()
|
1117
|
+
return height
|
1118
|
+
|
1119
|
+
def get_index_text_width(
|
1120
|
+
self,
|
1121
|
+
only_rows: Iterator[int] | None = None,
|
1122
|
+
) -> int:
|
1123
|
+
self.fix_index()
|
1124
|
+
w = self.PAR.ops.default_row_index_width
|
1125
|
+
if (not self.MT._row_index and isinstance(self.MT._row_index, list)) or (
|
1126
|
+
isinstance(self.MT._row_index, int) and self.MT._row_index >= len(self.MT.data)
|
1127
1127
|
):
|
1128
|
-
return
|
1128
|
+
return w
|
1129
1129
|
qconf = self.MT.txt_measure_canvas.itemconfig
|
1130
1130
|
qbbox = self.MT.txt_measure_canvas.bbox
|
1131
1131
|
qtxtm = self.MT.txt_measure_canvas_text
|
1132
|
-
|
1133
|
-
|
1134
|
-
|
1135
|
-
if
|
1136
|
-
|
1137
|
-
b = qbbox(qtxtm)
|
1138
|
-
w = b[2] - b[0] + 10
|
1139
|
-
if w > new_width:
|
1140
|
-
new_width = w
|
1132
|
+
if only_rows:
|
1133
|
+
iterable = only_rows
|
1134
|
+
elif self.MT.all_rows_displayed:
|
1135
|
+
if isinstance(self.MT._row_index, list):
|
1136
|
+
iterable = range(len(self.MT._row_index))
|
1141
1137
|
else:
|
1142
|
-
|
1138
|
+
iterable = range(len(self.MT.data))
|
1143
1139
|
else:
|
1144
|
-
|
1145
|
-
|
1146
|
-
|
1147
|
-
|
1148
|
-
|
1149
|
-
|
1150
|
-
|
1151
|
-
|
1152
|
-
|
1153
|
-
|
1154
|
-
|
1155
|
-
|
1156
|
-
if
|
1157
|
-
w =
|
1158
|
-
|
1159
|
-
|
1160
|
-
|
1161
|
-
new_width = w
|
1162
|
-
elif isinstance(self.MT._row_index, int):
|
1163
|
-
datacn = self.MT._row_index
|
1164
|
-
for datarn in iterable:
|
1165
|
-
txt = self.MT.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True)
|
1166
|
-
if txt:
|
1167
|
-
qconf(qtxtm, text=txt)
|
1168
|
-
b = qbbox(qtxtm)
|
1169
|
-
w = b[2] - b[0] + 10
|
1170
|
-
else:
|
1171
|
-
w = self.PAR.ops.default_row_index_width
|
1172
|
-
if w < self.MT.min_column_width:
|
1173
|
-
w = int(self.MT.min_column_width)
|
1174
|
-
elif w > self.MT.max_index_width:
|
1175
|
-
w = int(self.MT.max_index_width)
|
1176
|
-
if w > new_width:
|
1177
|
-
new_width = w
|
1178
|
-
if new_width == self.MT.min_column_width:
|
1179
|
-
new_width = self.MT.min_column_width + 10
|
1180
|
-
if set_width:
|
1181
|
-
self.set_width(new_width, set_TL=True)
|
1182
|
-
self.MT.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
|
1183
|
-
return new_width
|
1140
|
+
iterable = self.MT.displayed_rows
|
1141
|
+
if (
|
1142
|
+
isinstance(self.MT._row_index, list)
|
1143
|
+
and (tw := max(map(itemgetter(0), map(self.get_cell_dimensions, iterable)), default=w)) > w
|
1144
|
+
):
|
1145
|
+
w = tw
|
1146
|
+
elif isinstance(self.MT._row_index, int):
|
1147
|
+
datacn = self.MT._row_index
|
1148
|
+
for datarn in iterable:
|
1149
|
+
if txt := self.MT.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True):
|
1150
|
+
qconf(qtxtm, text=txt)
|
1151
|
+
b = qbbox(qtxtm)
|
1152
|
+
if (tw := b[2] - b[0] + 10) > w:
|
1153
|
+
w = tw
|
1154
|
+
if w > self.MT.max_index_width:
|
1155
|
+
w = int(self.MT.max_index_width)
|
1156
|
+
return w
|
1184
1157
|
|
1185
|
-
def
|
1158
|
+
def set_width_of_index_to_text(
|
1159
|
+
self,
|
1160
|
+
text: None | str = None,
|
1161
|
+
only_rows: list = [],
|
1162
|
+
) -> int:
|
1163
|
+
self.fix_index()
|
1164
|
+
w = self.PAR.ops.default_row_index_width
|
1165
|
+
if (text is None and isinstance(self.MT._row_index, list) and not self.MT._row_index) or (
|
1166
|
+
isinstance(self.MT._row_index, int) and self.MT._row_index >= len(self.MT.data)
|
1167
|
+
):
|
1168
|
+
return w
|
1169
|
+
if text is not None and text:
|
1170
|
+
self.MT.txt_measure_canvas.itemconfig(self.MT.txt_measure_canvas_text, text=text)
|
1171
|
+
b = self.MT.txt_measure_canvas.bbox(self.MT.txt_measure_canvas_text)
|
1172
|
+
if (tw := b[2] - b[0] + 10) > w:
|
1173
|
+
w = tw
|
1174
|
+
elif text is None:
|
1175
|
+
w = self.get_index_text_width(only_rows=only_rows)
|
1176
|
+
if w > self.MT.max_index_width:
|
1177
|
+
w = int(self.MT.max_index_width)
|
1178
|
+
self.set_width(w, set_TL=True)
|
1179
|
+
self.MT.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
|
1180
|
+
return w
|
1181
|
+
|
1182
|
+
def set_height_of_all_rows(
|
1183
|
+
self,
|
1184
|
+
height: int | None = None,
|
1185
|
+
only_if_too_small: bool = False,
|
1186
|
+
recreate: bool = True,
|
1187
|
+
) -> None:
|
1186
1188
|
if height is None:
|
1189
|
+
if self.MT.all_columns_displayed:
|
1190
|
+
iterable = range(self.MT.total_data_rows())
|
1191
|
+
else:
|
1192
|
+
iterable = range(len(self.MT.displayed_rows))
|
1187
1193
|
self.MT.set_row_positions(
|
1188
|
-
itr=(
|
1189
|
-
self.set_row_height(
|
1190
|
-
rn,
|
1191
|
-
only_set_if_too_small=only_set_if_too_small,
|
1192
|
-
recreate=False,
|
1193
|
-
return_new_height=True,
|
1194
|
-
)
|
1195
|
-
for rn in range(len(self.MT.data))
|
1196
|
-
)
|
1194
|
+
itr=(self.get_row_text_height(rn, only_if_too_small=only_if_too_small) for rn in iterable)
|
1197
1195
|
)
|
1198
|
-
|
1199
|
-
|
1196
|
+
elif height is not None:
|
1197
|
+
if self.MT.all_rows_displayed:
|
1198
|
+
self.MT.set_row_positions(itr=repeat(height, len(self.MT.data)))
|
1199
|
+
else:
|
1200
|
+
self.MT.set_row_positions(itr=repeat(height, len(self.MT.displayed_rows)))
|
1200
1201
|
if recreate:
|
1201
1202
|
self.MT.recreate_all_selection_boxes()
|
1202
1203
|
|
@@ -1209,7 +1210,7 @@ class RowIndex(tk.Canvas):
|
|
1209
1210
|
elif self.default_index == "both":
|
1210
1211
|
new_w = self.MT.get_txt_w(f"{end_row + 1} {num2alpha(end_row)}") + 20
|
1211
1212
|
elif self.PAR.ops.auto_resize_row_index is True:
|
1212
|
-
new_w = self.
|
1213
|
+
new_w = self.get_index_text_width(only_rows=only_rows)
|
1213
1214
|
else:
|
1214
1215
|
new_w = None
|
1215
1216
|
if new_w is not None and (sheet_w_x := floor(self.PAR.winfo_width() * 0.7)) < new_w:
|
@@ -1219,7 +1220,16 @@ class RowIndex(tk.Canvas):
|
|
1219
1220
|
return True
|
1220
1221
|
return False
|
1221
1222
|
|
1222
|
-
def redraw_highlight_get_text_fg(
|
1223
|
+
def redraw_highlight_get_text_fg(
|
1224
|
+
self,
|
1225
|
+
fr: float,
|
1226
|
+
sr: float,
|
1227
|
+
r: int,
|
1228
|
+
c_2: str,
|
1229
|
+
c_3: str,
|
1230
|
+
selections: dict,
|
1231
|
+
datarn: int,
|
1232
|
+
) -> tuple[str, str, bool]:
|
1223
1233
|
redrawn = False
|
1224
1234
|
kwargs = self.get_cell_kwargs(datarn, key="highlight")
|
1225
1235
|
if kwargs:
|
@@ -1280,7 +1290,16 @@ class RowIndex(tk.Canvas):
|
|
1280
1290
|
tree_arrow_fg = self.PAR.ops.tree_arrow_fg
|
1281
1291
|
return txtfg, tree_arrow_fg, redrawn
|
1282
1292
|
|
1283
|
-
def redraw_highlight(
|
1293
|
+
def redraw_highlight(
|
1294
|
+
self,
|
1295
|
+
x1: float,
|
1296
|
+
y1: float,
|
1297
|
+
x2: float,
|
1298
|
+
y2: float,
|
1299
|
+
fill: str,
|
1300
|
+
outline: str,
|
1301
|
+
tag: str | tuple[str],
|
1302
|
+
) -> bool:
|
1284
1303
|
coords = (x1, y1, x2, y2)
|
1285
1304
|
if self.hidd_high:
|
1286
1305
|
iid, showing = self.hidd_high.popitem()
|
@@ -1294,7 +1313,13 @@ class RowIndex(tk.Canvas):
|
|
1294
1313
|
self.disp_high[iid] = True
|
1295
1314
|
return True
|
1296
1315
|
|
1297
|
-
def redraw_gridline(
|
1316
|
+
def redraw_gridline(
|
1317
|
+
self,
|
1318
|
+
points: tuple[float],
|
1319
|
+
fill: str,
|
1320
|
+
width: int,
|
1321
|
+
tag: str | tuple[str],
|
1322
|
+
) -> None:
|
1298
1323
|
if self.hidd_grid:
|
1299
1324
|
t, sh = self.hidd_grid.popitem()
|
1300
1325
|
self.coords(t, points)
|
@@ -1308,11 +1333,11 @@ class RowIndex(tk.Canvas):
|
|
1308
1333
|
|
1309
1334
|
def redraw_tree_arrow(
|
1310
1335
|
self,
|
1311
|
-
x1,
|
1312
|
-
y1,
|
1313
|
-
r,
|
1314
|
-
fill,
|
1315
|
-
tag,
|
1336
|
+
x1: float,
|
1337
|
+
y1: float,
|
1338
|
+
r: int,
|
1339
|
+
fill: str,
|
1340
|
+
tag: str | tuple[str],
|
1316
1341
|
indent: float,
|
1317
1342
|
open_: bool = False,
|
1318
1343
|
) -> None:
|
@@ -1362,13 +1387,13 @@ class RowIndex(tk.Canvas):
|
|
1362
1387
|
|
1363
1388
|
def redraw_dropdown(
|
1364
1389
|
self,
|
1365
|
-
x1,
|
1366
|
-
y1,
|
1367
|
-
x2,
|
1368
|
-
y2,
|
1369
|
-
fill,
|
1370
|
-
outline,
|
1371
|
-
tag,
|
1390
|
+
x1: float,
|
1391
|
+
y1: float,
|
1392
|
+
x2: float,
|
1393
|
+
y2: float,
|
1394
|
+
fill: str,
|
1395
|
+
outline: str,
|
1396
|
+
tag: str | tuple[str],
|
1372
1397
|
draw_outline: bool = True,
|
1373
1398
|
draw_arrow: bool = True,
|
1374
1399
|
open_: bool = False,
|
@@ -1414,7 +1439,17 @@ class RowIndex(tk.Canvas):
|
|
1414
1439
|
)
|
1415
1440
|
self.disp_dropdown[t] = True
|
1416
1441
|
|
1417
|
-
def redraw_checkbox(
|
1442
|
+
def redraw_checkbox(
|
1443
|
+
self,
|
1444
|
+
x1: float,
|
1445
|
+
y1: float,
|
1446
|
+
x2: float,
|
1447
|
+
y2: float,
|
1448
|
+
fill: str,
|
1449
|
+
outline: str,
|
1450
|
+
tag: str | tuple[str],
|
1451
|
+
draw_check: bool = False,
|
1452
|
+
) -> None:
|
1418
1453
|
points = rounded_box_coords(x1, y1, x2, y2)
|
1419
1454
|
if self.hidd_checkbox:
|
1420
1455
|
t, sh = self.hidd_checkbox.popitem()
|
@@ -1461,8 +1496,10 @@ class RowIndex(tk.Canvas):
|
|
1461
1496
|
last_row_line_pos: float,
|
1462
1497
|
scrollpos_top: int,
|
1463
1498
|
y_stop: int,
|
1464
|
-
|
1465
|
-
|
1499
|
+
grid_start_row: int,
|
1500
|
+
grid_end_row: int,
|
1501
|
+
text_start_row: int,
|
1502
|
+
text_end_row: int,
|
1466
1503
|
scrollpos_bot: int,
|
1467
1504
|
row_pos_exists: bool,
|
1468
1505
|
) -> None:
|
@@ -1483,7 +1520,7 @@ class RowIndex(tk.Canvas):
|
|
1483
1520
|
self.hidd_tree_arrow.update(self.disp_tree_arrow)
|
1484
1521
|
self.disp_tree_arrow = {}
|
1485
1522
|
self.visible_row_dividers = {}
|
1486
|
-
draw_y = self.MT.row_positions[
|
1523
|
+
draw_y = self.MT.row_positions[grid_start_row]
|
1487
1524
|
xend = self.current_width - 6
|
1488
1525
|
self.row_width_resize_bbox = (
|
1489
1526
|
self.current_width - 2,
|
@@ -1500,7 +1537,7 @@ class RowIndex(tk.Canvas):
|
|
1500
1537
|
-1,
|
1501
1538
|
scrollpos_top - 1,
|
1502
1539
|
]
|
1503
|
-
for r in range(
|
1540
|
+
for r in range(grid_start_row, grid_end_row):
|
1504
1541
|
draw_y = self.MT.row_positions[r]
|
1505
1542
|
if self.height_resizing_enabled:
|
1506
1543
|
self.visible_row_dividers[r] = (1, draw_y - 2, xend, draw_y + 2)
|
@@ -1528,11 +1565,11 @@ class RowIndex(tk.Canvas):
|
|
1528
1565
|
else color_map[self.PAR.ops.index_selected_rows_bg]
|
1529
1566
|
)
|
1530
1567
|
font = self.PAR.ops.index_font
|
1531
|
-
selections = self.get_redraw_selections(
|
1568
|
+
selections = self.get_redraw_selections(text_start_row, grid_end_row)
|
1532
1569
|
dd_coords = self.dropdown.get_coords()
|
1533
1570
|
treeview = self.PAR.ops.treeview
|
1534
1571
|
|
1535
|
-
for r in range(
|
1572
|
+
for r in range(text_start_row, text_end_row):
|
1536
1573
|
rtopgridln = self.MT.row_positions[r]
|
1537
1574
|
rbotgridln = self.MT.row_positions[r + 1]
|
1538
1575
|
if rbotgridln - rtopgridln < self.MT.index_txt_height:
|
@@ -1758,7 +1795,7 @@ class RowIndex(tk.Canvas):
|
|
1758
1795
|
d[box.type_ if box.type_ != "columns" else "cells"].add(r)
|
1759
1796
|
return d
|
1760
1797
|
|
1761
|
-
def open_cell(self, event: object = None, ignore_existing_editor=False):
|
1798
|
+
def open_cell(self, event: object = None, ignore_existing_editor: bool = False) -> None:
|
1762
1799
|
if not self.MT.anything_selected() or (not ignore_existing_editor and self.text_editor.open):
|
1763
1800
|
return
|
1764
1801
|
if not self.MT.selected:
|
@@ -1777,7 +1814,7 @@ class RowIndex(tk.Canvas):
|
|
1777
1814
|
self.open_text_editor(event=event, r=r, dropdown=False)
|
1778
1815
|
|
1779
1816
|
# displayed indexes
|
1780
|
-
def get_cell_align(self, r):
|
1817
|
+
def get_cell_align(self, r: int) -> str:
|
1781
1818
|
datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
|
1782
1819
|
if datarn in self.cell_options and "align" in self.cell_options[datarn]:
|
1783
1820
|
align = self.cell_options[datarn]["align"]
|
@@ -1789,11 +1826,11 @@ class RowIndex(tk.Canvas):
|
|
1789
1826
|
def open_text_editor(
|
1790
1827
|
self,
|
1791
1828
|
event: object = None,
|
1792
|
-
r=0,
|
1793
|
-
text=None,
|
1794
|
-
state="normal",
|
1795
|
-
dropdown=False,
|
1796
|
-
):
|
1829
|
+
r: int = 0,
|
1830
|
+
text: None | str = None,
|
1831
|
+
state: str = "normal",
|
1832
|
+
dropdown: bool = False,
|
1833
|
+
) -> bool:
|
1797
1834
|
text = None
|
1798
1835
|
extra_func_key = "??"
|
1799
1836
|
if event is None or self.MT.event_opens_dropdown_or_checkbox(event):
|
@@ -1896,7 +1933,7 @@ class RowIndex(tk.Canvas):
|
|
1896
1933
|
self.text_editor.tktext.bind(key, func)
|
1897
1934
|
return True
|
1898
1935
|
|
1899
|
-
def text_editor_newline_binding(self, event: object = None, check_lines=True):
|
1936
|
+
def text_editor_newline_binding(self, event: object = None, check_lines: bool = True) -> None:
|
1900
1937
|
if not self.height_resizing_enabled:
|
1901
1938
|
return
|
1902
1939
|
curr_height = self.text_editor.window.winfo_height()
|
@@ -1938,7 +1975,7 @@ class RowIndex(tk.Canvas):
|
|
1938
1975
|
)
|
1939
1976
|
self.itemconfig(self.dropdown.canvas_id, anchor=anchor, height=win_h)
|
1940
1977
|
|
1941
|
-
def refresh_open_window_positions(self, zoom: Literal["in", "out"]):
|
1978
|
+
def refresh_open_window_positions(self, zoom: Literal["in", "out"]) -> None:
|
1942
1979
|
if self.text_editor.open:
|
1943
1980
|
r = self.text_editor.row
|
1944
1981
|
self.text_editor.window.config(height=self.MT.row_positions[r + 1] - self.MT.row_positions[r])
|
@@ -2040,7 +2077,7 @@ class RowIndex(tk.Canvas):
|
|
2040
2077
|
self.focus_set()
|
2041
2078
|
return "break"
|
2042
2079
|
|
2043
|
-
def get_dropdown_height_anchor(self, r, text_editor_h=None):
|
2080
|
+
def get_dropdown_height_anchor(self, r: int, text_editor_h: None | int = None) -> tuple[int, str]:
|
2044
2081
|
win_h = 5
|
2045
2082
|
datarn = self.MT.datarn(r)
|
2046
2083
|
for i, v in enumerate(self.get_cell_kwargs(datarn, key="dropdown")["values"]):
|
@@ -2083,7 +2120,7 @@ class RowIndex(tk.Canvas):
|
|
2083
2120
|
dd_window.search_and_see(event)
|
2084
2121
|
|
2085
2122
|
# r is displayed row
|
2086
|
-
def open_dropdown_window(self, r, event: object = None):
|
2123
|
+
def open_dropdown_window(self, r: int, event: object = None) -> None:
|
2087
2124
|
self.hide_text_editor("Escape")
|
2088
2125
|
kwargs = self.get_cell_kwargs(self.MT.datarn(r), key="dropdown")
|
2089
2126
|
if kwargs["state"] == "normal":
|
@@ -2164,7 +2201,12 @@ class RowIndex(tk.Canvas):
|
|
2164
2201
|
self.MT.main_table_redraw_grid_and_text(redraw_header=False, redraw_row_index=True, redraw_table=False)
|
2165
2202
|
|
2166
2203
|
# r is displayed row
|
2167
|
-
def close_dropdown_window(
|
2204
|
+
def close_dropdown_window(
|
2205
|
+
self,
|
2206
|
+
r: int | None = None,
|
2207
|
+
selection: object = None,
|
2208
|
+
redraw: bool = True,
|
2209
|
+
) -> None:
|
2168
2210
|
if r is not None and selection is not None:
|
2169
2211
|
datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
|
2170
2212
|
kwargs = self.get_cell_kwargs(datarn, key="dropdown")
|
@@ -2202,7 +2244,7 @@ class RowIndex(tk.Canvas):
|
|
2202
2244
|
if redraw:
|
2203
2245
|
self.MT.refresh()
|
2204
2246
|
|
2205
|
-
def mouseclick_outside_editor_or_dropdown(self, inside: bool = False):
|
2247
|
+
def mouseclick_outside_editor_or_dropdown(self, inside: bool = False) -> int | None:
|
2206
2248
|
closed_dd_coords = self.dropdown.get_coords()
|
2207
2249
|
if self.text_editor.open:
|
2208
2250
|
self.close_text_editor(new_tk_event("ButtonPress-1"))
|
@@ -2216,7 +2258,7 @@ class RowIndex(tk.Canvas):
|
|
2216
2258
|
)
|
2217
2259
|
return closed_dd_coords
|
2218
2260
|
|
2219
|
-
def mouseclick_outside_editor_or_dropdown_all_canvases(self, inside: bool = False):
|
2261
|
+
def mouseclick_outside_editor_or_dropdown_all_canvases(self, inside: bool = False) -> int | None:
|
2220
2262
|
self.CH.mouseclick_outside_editor_or_dropdown()
|
2221
2263
|
self.MT.mouseclick_outside_editor_or_dropdown()
|
2222
2264
|
return self.mouseclick_outside_editor_or_dropdown(inside)
|
@@ -2259,14 +2301,14 @@ class RowIndex(tk.Canvas):
|
|
2259
2301
|
self.set_cell_data(datarn=datarn, value=value)
|
2260
2302
|
edited = True
|
2261
2303
|
if edited and cell_resize and self.PAR.ops.cell_auto_resize_enabled:
|
2262
|
-
self.set_row_height_run_binding(r,
|
2304
|
+
self.set_row_height_run_binding(r, only_if_too_small=False)
|
2263
2305
|
if redraw:
|
2264
2306
|
self.MT.refresh()
|
2265
2307
|
if edited:
|
2266
2308
|
self.MT.sheet_modified(event_data)
|
2267
2309
|
return edited
|
2268
2310
|
|
2269
|
-
def set_cell_data(self, datarn=None, value=""):
|
2311
|
+
def set_cell_data(self, datarn: int | None = None, value: object = "") -> None:
|
2270
2312
|
if isinstance(self.MT._row_index, int):
|
2271
2313
|
self.MT.set_cell_data(datarn=datarn, datacn=self.MT._row_index, value=value)
|
2272
2314
|
else:
|
@@ -2288,7 +2330,7 @@ class RowIndex(tk.Canvas):
|
|
2288
2330
|
return False
|
2289
2331
|
return True
|
2290
2332
|
|
2291
|
-
def cell_equal_to(self, datarn, value):
|
2333
|
+
def cell_equal_to(self, datarn: int, value: object) -> bool:
|
2292
2334
|
self.fix_index(datarn)
|
2293
2335
|
if isinstance(self.MT._row_index, list):
|
2294
2336
|
return self.MT._row_index[datarn] == value
|
@@ -2297,11 +2339,11 @@ class RowIndex(tk.Canvas):
|
|
2297
2339
|
|
2298
2340
|
def get_cell_data(
|
2299
2341
|
self,
|
2300
|
-
datarn,
|
2301
|
-
get_displayed=False,
|
2302
|
-
none_to_empty_str=False,
|
2303
|
-
redirect_int=False,
|
2304
|
-
):
|
2342
|
+
datarn: int,
|
2343
|
+
get_displayed: bool = False,
|
2344
|
+
none_to_empty_str: bool = False,
|
2345
|
+
redirect_int: bool = False,
|
2346
|
+
) -> object:
|
2305
2347
|
if get_displayed:
|
2306
2348
|
return self.get_valid_cell_data_as_str(datarn, fix=False)
|
2307
2349
|
if redirect_int and isinstance(self.MT._row_index, int): # internal use
|
@@ -2315,7 +2357,7 @@ class RowIndex(tk.Canvas):
|
|
2315
2357
|
return ""
|
2316
2358
|
return self.MT._row_index[datarn]
|
2317
2359
|
|
2318
|
-
def get_valid_cell_data_as_str(self, datarn, fix=True) -> str:
|
2360
|
+
def get_valid_cell_data_as_str(self, datarn: int, fix: bool = True) -> str:
|
2319
2361
|
kwargs = self.get_cell_kwargs(datarn, key="dropdown")
|
2320
2362
|
if kwargs:
|
2321
2363
|
if kwargs["text"] is not None:
|
@@ -2336,7 +2378,7 @@ class RowIndex(tk.Canvas):
|
|
2336
2378
|
value = get_n2a(datarn, self.default_index)
|
2337
2379
|
return value
|
2338
2380
|
|
2339
|
-
def get_value_for_empty_cell(self, datarn, r_ops=True):
|
2381
|
+
def get_value_for_empty_cell(self, datarn: int, r_ops: bool = True) -> object:
|
2340
2382
|
if self.get_cell_kwargs(datarn, key="checkbox", cell=r_ops):
|
2341
2383
|
return False
|
2342
2384
|
kwargs = self.get_cell_kwargs(datarn, key="dropdown", cell=r_ops)
|
@@ -2344,10 +2386,10 @@ class RowIndex(tk.Canvas):
|
|
2344
2386
|
return kwargs["values"][0]
|
2345
2387
|
return ""
|
2346
2388
|
|
2347
|
-
def get_empty_index_seq(self, end, start=0, r_ops=True):
|
2389
|
+
def get_empty_index_seq(self, end: int, start: int = 0, r_ops: bool = True) -> list[object]:
|
2348
2390
|
return [self.get_value_for_empty_cell(datarn, r_ops=r_ops) for datarn in range(start, end)]
|
2349
2391
|
|
2350
|
-
def fix_index(self, datarn
|
2392
|
+
def fix_index(self, datarn: int | None = None) -> None:
|
2351
2393
|
if isinstance(self.MT._row_index, int):
|
2352
2394
|
return
|
2353
2395
|
if isinstance(self.MT._row_index, float):
|
@@ -2360,14 +2402,10 @@ class RowIndex(tk.Canvas):
|
|
2360
2402
|
self.MT._row_index = []
|
2361
2403
|
if isinstance(datarn, int) and datarn >= len(self.MT._row_index):
|
2362
2404
|
self.MT._row_index.extend(self.get_empty_index_seq(end=datarn + 1, start=len(self.MT._row_index)))
|
2363
|
-
if fix_values:
|
2364
|
-
for rn, v in enumerate(islice(self.MT._row_index, fix_values[0], fix_values[1])):
|
2365
|
-
if not self.input_valid_for_cell(rn, v):
|
2366
|
-
self.MT._row_index[rn] = self.get_value_for_empty_cell(rn)
|
2367
2405
|
|
2368
|
-
def set_row_height_run_binding(self, r,
|
2406
|
+
def set_row_height_run_binding(self, r: int, only_if_too_small: bool = True) -> None:
|
2369
2407
|
old_height = self.MT.row_positions[r + 1] - self.MT.row_positions[r]
|
2370
|
-
new_height = self.set_row_height(r,
|
2408
|
+
new_height = self.set_row_height(r, only_if_too_small=only_if_too_small)
|
2371
2409
|
if self.row_height_resize_func is not None and old_height != new_height:
|
2372
2410
|
self.row_height_resize_func(
|
2373
2411
|
event_dict(
|
@@ -2378,7 +2416,7 @@ class RowIndex(tk.Canvas):
|
|
2378
2416
|
)
|
2379
2417
|
|
2380
2418
|
# internal event use
|
2381
|
-
def click_checkbox(self, r, datarn=None, undo=True, redraw=True):
|
2419
|
+
def click_checkbox(self, r: int, datarn: int | None = None, undo: bool = True, redraw: bool = True) -> None:
|
2382
2420
|
if datarn is None:
|
2383
2421
|
datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
|
2384
2422
|
kwargs = self.get_cell_kwargs(datarn, key="checkbox")
|
@@ -2413,7 +2451,7 @@ class RowIndex(tk.Canvas):
|
|
2413
2451
|
if redraw:
|
2414
2452
|
self.MT.refresh()
|
2415
2453
|
|
2416
|
-
def get_cell_kwargs(self, datarn, key="dropdown", cell=
|
2454
|
+
def get_cell_kwargs(self, datarn: int, key: Hashable = "dropdown", cell: bool = True) -> dict:
|
2417
2455
|
if cell and datarn in self.cell_options and key in self.cell_options[datarn]:
|
2418
2456
|
return self.cell_options[datarn][key]
|
2419
2457
|
return {}
|