tksheet 7.2.0__py3-none-any.whl → 7.2.2__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/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)
@@ -921,6 +928,7 @@ class RowIndex(tk.Canvas):
921
928
  redraw: bool = True,
922
929
  run_binding_func: bool = True,
923
930
  set_as_current: bool = True,
931
+ ext: bool = False,
924
932
  ) -> int | None:
925
933
  if add_selection:
926
934
  if self.MT.row_selected(row):
@@ -931,18 +939,25 @@ class RowIndex(tk.Canvas):
931
939
  redraw=redraw,
932
940
  run_binding_func=run_binding_func,
933
941
  set_as_current=set_as_current,
942
+ ext=ext,
934
943
  )
935
944
  else:
936
945
  if self.MT.row_selected(row):
937
946
  fill_iid = self.MT.deselect(r=row, redraw=redraw)
938
947
  else:
939
- fill_iid = self.select_row(row, redraw=redraw)
948
+ fill_iid = self.select_row(row, redraw=redraw, ext=ext)
940
949
  return fill_iid
941
950
 
942
- def select_row(self, r: int, redraw: bool = False, run_binding_func: bool = True) -> int:
951
+ def select_row(
952
+ self,
953
+ r: int,
954
+ redraw: bool = False,
955
+ run_binding_func: bool = True,
956
+ ext: bool = False,
957
+ ) -> int:
943
958
  self.MT.deselect("all", redraw=False)
944
959
  box = (r, 0, r + 1, len(self.MT.col_positions) - 1, "rows")
945
- fill_iid = self.MT.create_selection_box(*box)
960
+ fill_iid = self.MT.create_selection_box(*box, ext=ext)
946
961
  if redraw:
947
962
  self.MT.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
948
963
  if run_binding_func:
@@ -955,9 +970,10 @@ class RowIndex(tk.Canvas):
955
970
  redraw: bool = False,
956
971
  run_binding_func: bool = True,
957
972
  set_as_current: bool = True,
973
+ ext: bool = False,
958
974
  ) -> int:
959
975
  box = (r, 0, r + 1, len(self.MT.col_positions) - 1, "rows")
960
- fill_iid = self.MT.create_selection_box(*box, set_current=set_as_current)
976
+ fill_iid = self.MT.create_selection_box(*box, set_current=set_as_current, ext=ext)
961
977
  if redraw:
962
978
  self.MT.main_table_redraw_grid_and_text(redraw_header=False, redraw_row_index=True)
963
979
  if run_binding_func:
@@ -1033,161 +1049,155 @@ class RowIndex(tk.Canvas):
1033
1049
  w += self.get_treeview_indent(self.MT._row_index[datarn].iid) + 5
1034
1050
  return w, h
1035
1051
 
1036
- def set_row_height(
1052
+ def get_row_text_height(
1037
1053
  self,
1038
1054
  row: int,
1039
- height: None | int = None,
1040
- only_set_if_too_small: bool = False,
1041
- recreate: bool = True,
1042
- return_new_height: bool = False,
1043
- displayed_only: bool = False,
1055
+ visible_only: bool = False,
1056
+ only_if_too_small: bool = False,
1044
1057
  ) -> int:
1045
- r_norm = row + 1
1046
- r_extra = row + 2
1047
- min_rh = self.MT.min_row_height
1058
+ h = self.MT.min_row_height
1048
1059
  datarn = row if self.MT.all_rows_displayed else self.MT.displayed_rows[row]
1049
- if height is None:
1060
+ # index
1061
+ _w, ih = self.get_cell_dimensions(datarn)
1062
+ # table
1063
+ if self.MT.data:
1050
1064
  if self.MT.all_columns_displayed:
1051
- if displayed_only:
1052
- x1, y1, x2, y2 = self.MT.get_canvas_visible_area()
1053
- start_col, end_col = self.MT.get_visible_columns(x1, x2)
1065
+ if visible_only:
1066
+ iterable = range(*self.MT.visible_text_columns)
1054
1067
  else:
1055
1068
  if not self.MT.data or datarn >= len(self.MT.data):
1056
1069
  iterable = range(0, 0)
1057
1070
  else:
1058
1071
  iterable = range(0, len(self.MT.data[datarn]))
1059
1072
  else:
1060
- if displayed_only:
1061
- x1, y1, x2, y2 = self.MT.get_canvas_visible_area()
1062
- 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
1063
1075
  else:
1064
1076
  start_col, end_col = 0, len(self.MT.displayed_columns)
1065
1077
  iterable = self.MT.displayed_columns[start_col:end_col]
1066
- new_height = int(min_rh)
1067
- w_, h = self.get_cell_dimensions(datarn)
1068
- if h < min_rh:
1069
- h = int(min_rh)
1070
- elif h > self.MT.max_row_height:
1071
- h = int(self.MT.max_row_height)
1072
- if h > new_height:
1073
- new_height = h
1074
- if self.MT.data:
1075
- for datacn in iterable:
1076
- txt = self.MT.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True)
1077
- if txt:
1078
- h = self.MT.get_txt_h(txt) + 5
1079
- else:
1080
- h = min_rh
1081
- if h < min_rh:
1082
- h = int(min_rh)
1083
- elif h > self.MT.max_row_height:
1084
- h = int(self.MT.max_row_height)
1085
- if h > new_height:
1086
- new_height = h
1087
- else:
1088
- new_height = int(height)
1089
- if new_height < min_rh:
1090
- new_height = int(min_rh)
1091
- elif new_height > self.MT.max_row_height:
1092
- new_height = int(self.MT.max_row_height)
1093
- 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]:
1094
1086
  return self.MT.row_positions[row + 1] - self.MT.row_positions[row]
1095
- if not return_new_height:
1096
- new_row_pos = self.MT.row_positions[row] + new_height
1097
- increment = new_row_pos - self.MT.row_positions[r_norm]
1098
- self.MT.row_positions[r_extra:] = [
1099
- e + increment for e in islice(self.MT.row_positions, r_extra, len(self.MT.row_positions))
1100
- ]
1101
- self.MT.row_positions[r_norm] = new_row_pos
1102
- if recreate:
1103
- self.MT.recreate_all_selection_boxes()
1104
- 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
1105
1092
 
1106
- def set_width_of_index_to_text(
1093
+ def set_row_height(
1107
1094
  self,
1108
- text: None | str = None,
1109
- only_rows: list = [],
1110
- set_width: bool = True,
1111
- ) -> None | int:
1112
- if (
1113
- text is None
1114
- and not self.MT._row_index
1115
- and isinstance(self.MT._row_index, list)
1116
- or isinstance(self.MT._row_index, int)
1117
- and self.MT._row_index >= len(self.MT.data)
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)
1118
1127
  ):
1119
- return
1128
+ return w
1120
1129
  qconf = self.MT.txt_measure_canvas.itemconfig
1121
1130
  qbbox = self.MT.txt_measure_canvas.bbox
1122
1131
  qtxtm = self.MT.txt_measure_canvas_text
1123
- new_width = int(self.MT.min_column_width)
1124
- self.fix_index()
1125
- if text is not None:
1126
- if text:
1127
- qconf(qtxtm, text=text)
1128
- b = qbbox(qtxtm)
1129
- w = b[2] - b[0] + 10
1130
- if w > new_width:
1131
- 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))
1132
1137
  else:
1133
- w = self.PAR.ops.default_row_index_width
1138
+ iterable = range(len(self.MT.data))
1134
1139
  else:
1135
- if only_rows:
1136
- iterable = only_rows
1137
- elif self.MT.all_rows_displayed:
1138
- if isinstance(self.MT._row_index, list):
1139
- iterable = range(len(self.MT._row_index))
1140
- else:
1141
- iterable = range(len(self.MT.data))
1142
- else:
1143
- iterable = self.MT.displayed_rows
1144
- if isinstance(self.MT._row_index, list):
1145
- for datarn in iterable:
1146
- w, h_ = self.get_cell_dimensions(datarn)
1147
- if w < self.MT.min_column_width:
1148
- w = int(self.MT.min_column_width)
1149
- elif w > self.MT.max_index_width:
1150
- w = int(self.MT.max_index_width)
1151
- if w > new_width:
1152
- new_width = w
1153
- elif isinstance(self.MT._row_index, int):
1154
- datacn = self.MT._row_index
1155
- for datarn in iterable:
1156
- txt = self.MT.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True)
1157
- if txt:
1158
- qconf(qtxtm, text=txt)
1159
- b = qbbox(qtxtm)
1160
- w = b[2] - b[0] + 10
1161
- else:
1162
- w = self.PAR.ops.default_row_index_width
1163
- if w < self.MT.min_column_width:
1164
- w = int(self.MT.min_column_width)
1165
- elif w > self.MT.max_index_width:
1166
- w = int(self.MT.max_index_width)
1167
- if w > new_width:
1168
- new_width = w
1169
- if new_width == self.MT.min_column_width:
1170
- new_width = self.MT.min_column_width + 10
1171
- if set_width:
1172
- self.set_width(new_width, set_TL=True)
1173
- self.MT.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
1174
- 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
1175
1157
 
1176
- def set_height_of_all_rows(self, height=None, only_set_if_too_small=False, recreate=True):
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:
1177
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))
1178
1193
  self.MT.set_row_positions(
1179
- itr=(
1180
- self.set_row_height(
1181
- rn,
1182
- only_set_if_too_small=only_set_if_too_small,
1183
- recreate=False,
1184
- return_new_height=True,
1185
- )
1186
- for rn in range(len(self.MT.data))
1187
- )
1194
+ itr=(self.get_row_text_height(rn, only_if_too_small=only_if_too_small) for rn in iterable)
1188
1195
  )
1189
- else:
1190
- self.MT.set_row_positions(itr=(height for r in range(len(self.MT.data))))
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)))
1191
1201
  if recreate:
1192
1202
  self.MT.recreate_all_selection_boxes()
1193
1203
 
@@ -1200,7 +1210,7 @@ class RowIndex(tk.Canvas):
1200
1210
  elif self.default_index == "both":
1201
1211
  new_w = self.MT.get_txt_w(f"{end_row + 1} {num2alpha(end_row)}") + 20
1202
1212
  elif self.PAR.ops.auto_resize_row_index is True:
1203
- new_w = self.set_width_of_index_to_text(only_rows=only_rows, set_width=False)
1213
+ new_w = self.get_index_text_width(only_rows=only_rows)
1204
1214
  else:
1205
1215
  new_w = None
1206
1216
  if new_w is not None and (sheet_w_x := floor(self.PAR.winfo_width() * 0.7)) < new_w:
@@ -1210,7 +1220,16 @@ class RowIndex(tk.Canvas):
1210
1220
  return True
1211
1221
  return False
1212
1222
 
1213
- def redraw_highlight_get_text_fg(self, fr, sr, r, c_2, c_3, selections, datarn):
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]:
1214
1233
  redrawn = False
1215
1234
  kwargs = self.get_cell_kwargs(datarn, key="highlight")
1216
1235
  if kwargs:
@@ -1271,7 +1290,16 @@ class RowIndex(tk.Canvas):
1271
1290
  tree_arrow_fg = self.PAR.ops.tree_arrow_fg
1272
1291
  return txtfg, tree_arrow_fg, redrawn
1273
1292
 
1274
- def redraw_highlight(self, x1, y1, x2, y2, fill, outline, tag):
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:
1275
1303
  coords = (x1, y1, x2, y2)
1276
1304
  if self.hidd_high:
1277
1305
  iid, showing = self.hidd_high.popitem()
@@ -1285,7 +1313,13 @@ class RowIndex(tk.Canvas):
1285
1313
  self.disp_high[iid] = True
1286
1314
  return True
1287
1315
 
1288
- def redraw_gridline(self, points, fill, width, tag):
1316
+ def redraw_gridline(
1317
+ self,
1318
+ points: tuple[float],
1319
+ fill: str,
1320
+ width: int,
1321
+ tag: str | tuple[str],
1322
+ ) -> None:
1289
1323
  if self.hidd_grid:
1290
1324
  t, sh = self.hidd_grid.popitem()
1291
1325
  self.coords(t, points)
@@ -1299,11 +1333,11 @@ class RowIndex(tk.Canvas):
1299
1333
 
1300
1334
  def redraw_tree_arrow(
1301
1335
  self,
1302
- x1,
1303
- y1,
1304
- r,
1305
- fill,
1306
- tag,
1336
+ x1: float,
1337
+ y1: float,
1338
+ r: int,
1339
+ fill: str,
1340
+ tag: str | tuple[str],
1307
1341
  indent: float,
1308
1342
  open_: bool = False,
1309
1343
  ) -> None:
@@ -1353,13 +1387,13 @@ class RowIndex(tk.Canvas):
1353
1387
 
1354
1388
  def redraw_dropdown(
1355
1389
  self,
1356
- x1,
1357
- y1,
1358
- x2,
1359
- y2,
1360
- fill,
1361
- outline,
1362
- tag,
1390
+ x1: float,
1391
+ y1: float,
1392
+ x2: float,
1393
+ y2: float,
1394
+ fill: str,
1395
+ outline: str,
1396
+ tag: str | tuple[str],
1363
1397
  draw_outline: bool = True,
1364
1398
  draw_arrow: bool = True,
1365
1399
  open_: bool = False,
@@ -1405,7 +1439,17 @@ class RowIndex(tk.Canvas):
1405
1439
  )
1406
1440
  self.disp_dropdown[t] = True
1407
1441
 
1408
- def redraw_checkbox(self, x1, y1, x2, y2, fill, outline, tag, draw_check=False):
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:
1409
1453
  points = rounded_box_coords(x1, y1, x2, y2)
1410
1454
  if self.hidd_checkbox:
1411
1455
  t, sh = self.hidd_checkbox.popitem()
@@ -1452,8 +1496,10 @@ class RowIndex(tk.Canvas):
1452
1496
  last_row_line_pos: float,
1453
1497
  scrollpos_top: int,
1454
1498
  y_stop: int,
1455
- start_row: int,
1456
- end_row: int,
1499
+ grid_start_row: int,
1500
+ grid_end_row: int,
1501
+ text_start_row: int,
1502
+ text_end_row: int,
1457
1503
  scrollpos_bot: int,
1458
1504
  row_pos_exists: bool,
1459
1505
  ) -> None:
@@ -1474,7 +1520,7 @@ class RowIndex(tk.Canvas):
1474
1520
  self.hidd_tree_arrow.update(self.disp_tree_arrow)
1475
1521
  self.disp_tree_arrow = {}
1476
1522
  self.visible_row_dividers = {}
1477
- draw_y = self.MT.row_positions[start_row]
1523
+ draw_y = self.MT.row_positions[grid_start_row]
1478
1524
  xend = self.current_width - 6
1479
1525
  self.row_width_resize_bbox = (
1480
1526
  self.current_width - 2,
@@ -1491,7 +1537,7 @@ class RowIndex(tk.Canvas):
1491
1537
  -1,
1492
1538
  scrollpos_top - 1,
1493
1539
  ]
1494
- for r in range(start_row + 1, end_row):
1540
+ for r in range(grid_start_row, grid_end_row):
1495
1541
  draw_y = self.MT.row_positions[r]
1496
1542
  if self.height_resizing_enabled:
1497
1543
  self.visible_row_dividers[r] = (1, draw_y - 2, xend, draw_y + 2)
@@ -1519,11 +1565,11 @@ class RowIndex(tk.Canvas):
1519
1565
  else color_map[self.PAR.ops.index_selected_rows_bg]
1520
1566
  )
1521
1567
  font = self.PAR.ops.index_font
1522
- selections = self.get_redraw_selections(start_row, end_row)
1568
+ selections = self.get_redraw_selections(text_start_row, grid_end_row)
1523
1569
  dd_coords = self.dropdown.get_coords()
1524
1570
  treeview = self.PAR.ops.treeview
1525
1571
 
1526
- for r in range(start_row, end_row - 1):
1572
+ for r in range(text_start_row, text_end_row):
1527
1573
  rtopgridln = self.MT.row_positions[r]
1528
1574
  rbotgridln = self.MT.row_positions[r + 1]
1529
1575
  if rbotgridln - rtopgridln < self.MT.index_txt_height:
@@ -1749,7 +1795,7 @@ class RowIndex(tk.Canvas):
1749
1795
  d[box.type_ if box.type_ != "columns" else "cells"].add(r)
1750
1796
  return d
1751
1797
 
1752
- 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:
1753
1799
  if not self.MT.anything_selected() or (not ignore_existing_editor and self.text_editor.open):
1754
1800
  return
1755
1801
  if not self.MT.selected:
@@ -1768,7 +1814,7 @@ class RowIndex(tk.Canvas):
1768
1814
  self.open_text_editor(event=event, r=r, dropdown=False)
1769
1815
 
1770
1816
  # displayed indexes
1771
- def get_cell_align(self, r):
1817
+ def get_cell_align(self, r: int) -> str:
1772
1818
  datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
1773
1819
  if datarn in self.cell_options and "align" in self.cell_options[datarn]:
1774
1820
  align = self.cell_options[datarn]["align"]
@@ -1780,11 +1826,11 @@ class RowIndex(tk.Canvas):
1780
1826
  def open_text_editor(
1781
1827
  self,
1782
1828
  event: object = None,
1783
- r=0,
1784
- text=None,
1785
- state="normal",
1786
- dropdown=False,
1787
- ):
1829
+ r: int = 0,
1830
+ text: None | str = None,
1831
+ state: str = "normal",
1832
+ dropdown: bool = False,
1833
+ ) -> bool:
1788
1834
  text = None
1789
1835
  extra_func_key = "??"
1790
1836
  if event is None or self.MT.event_opens_dropdown_or_checkbox(event):
@@ -1887,7 +1933,7 @@ class RowIndex(tk.Canvas):
1887
1933
  self.text_editor.tktext.bind(key, func)
1888
1934
  return True
1889
1935
 
1890
- 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:
1891
1937
  if not self.height_resizing_enabled:
1892
1938
  return
1893
1939
  curr_height = self.text_editor.window.winfo_height()
@@ -1929,7 +1975,7 @@ class RowIndex(tk.Canvas):
1929
1975
  )
1930
1976
  self.itemconfig(self.dropdown.canvas_id, anchor=anchor, height=win_h)
1931
1977
 
1932
- def refresh_open_window_positions(self, zoom: Literal["in", "out"]):
1978
+ def refresh_open_window_positions(self, zoom: Literal["in", "out"]) -> None:
1933
1979
  if self.text_editor.open:
1934
1980
  r = self.text_editor.row
1935
1981
  self.text_editor.window.config(height=self.MT.row_positions[r + 1] - self.MT.row_positions[r])
@@ -2031,7 +2077,7 @@ class RowIndex(tk.Canvas):
2031
2077
  self.focus_set()
2032
2078
  return "break"
2033
2079
 
2034
- 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]:
2035
2081
  win_h = 5
2036
2082
  datarn = self.MT.datarn(r)
2037
2083
  for i, v in enumerate(self.get_cell_kwargs(datarn, key="dropdown")["values"]):
@@ -2074,7 +2120,7 @@ class RowIndex(tk.Canvas):
2074
2120
  dd_window.search_and_see(event)
2075
2121
 
2076
2122
  # r is displayed row
2077
- def open_dropdown_window(self, r, event: object = None):
2123
+ def open_dropdown_window(self, r: int, event: object = None) -> None:
2078
2124
  self.hide_text_editor("Escape")
2079
2125
  kwargs = self.get_cell_kwargs(self.MT.datarn(r), key="dropdown")
2080
2126
  if kwargs["state"] == "normal":
@@ -2155,7 +2201,12 @@ class RowIndex(tk.Canvas):
2155
2201
  self.MT.main_table_redraw_grid_and_text(redraw_header=False, redraw_row_index=True, redraw_table=False)
2156
2202
 
2157
2203
  # r is displayed row
2158
- def close_dropdown_window(self, r=None, selection=None, redraw=True):
2204
+ def close_dropdown_window(
2205
+ self,
2206
+ r: int | None = None,
2207
+ selection: object = None,
2208
+ redraw: bool = True,
2209
+ ) -> None:
2159
2210
  if r is not None and selection is not None:
2160
2211
  datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
2161
2212
  kwargs = self.get_cell_kwargs(datarn, key="dropdown")
@@ -2193,7 +2244,7 @@ class RowIndex(tk.Canvas):
2193
2244
  if redraw:
2194
2245
  self.MT.refresh()
2195
2246
 
2196
- def mouseclick_outside_editor_or_dropdown(self, inside: bool = False):
2247
+ def mouseclick_outside_editor_or_dropdown(self, inside: bool = False) -> int | None:
2197
2248
  closed_dd_coords = self.dropdown.get_coords()
2198
2249
  if self.text_editor.open:
2199
2250
  self.close_text_editor(new_tk_event("ButtonPress-1"))
@@ -2207,7 +2258,7 @@ class RowIndex(tk.Canvas):
2207
2258
  )
2208
2259
  return closed_dd_coords
2209
2260
 
2210
- 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:
2211
2262
  self.CH.mouseclick_outside_editor_or_dropdown()
2212
2263
  self.MT.mouseclick_outside_editor_or_dropdown()
2213
2264
  return self.mouseclick_outside_editor_or_dropdown(inside)
@@ -2250,14 +2301,14 @@ class RowIndex(tk.Canvas):
2250
2301
  self.set_cell_data(datarn=datarn, value=value)
2251
2302
  edited = True
2252
2303
  if edited and cell_resize and self.PAR.ops.cell_auto_resize_enabled:
2253
- self.set_row_height_run_binding(r, only_set_if_too_small=False)
2304
+ self.set_row_height_run_binding(r, only_if_too_small=False)
2254
2305
  if redraw:
2255
2306
  self.MT.refresh()
2256
2307
  if edited:
2257
2308
  self.MT.sheet_modified(event_data)
2258
2309
  return edited
2259
2310
 
2260
- def set_cell_data(self, datarn=None, value=""):
2311
+ def set_cell_data(self, datarn: int | None = None, value: object = "") -> None:
2261
2312
  if isinstance(self.MT._row_index, int):
2262
2313
  self.MT.set_cell_data(datarn=datarn, datacn=self.MT._row_index, value=value)
2263
2314
  else:
@@ -2279,7 +2330,7 @@ class RowIndex(tk.Canvas):
2279
2330
  return False
2280
2331
  return True
2281
2332
 
2282
- def cell_equal_to(self, datarn, value):
2333
+ def cell_equal_to(self, datarn: int, value: object) -> bool:
2283
2334
  self.fix_index(datarn)
2284
2335
  if isinstance(self.MT._row_index, list):
2285
2336
  return self.MT._row_index[datarn] == value
@@ -2288,11 +2339,11 @@ class RowIndex(tk.Canvas):
2288
2339
 
2289
2340
  def get_cell_data(
2290
2341
  self,
2291
- datarn,
2292
- get_displayed=False,
2293
- none_to_empty_str=False,
2294
- redirect_int=False,
2295
- ):
2342
+ datarn: int,
2343
+ get_displayed: bool = False,
2344
+ none_to_empty_str: bool = False,
2345
+ redirect_int: bool = False,
2346
+ ) -> object:
2296
2347
  if get_displayed:
2297
2348
  return self.get_valid_cell_data_as_str(datarn, fix=False)
2298
2349
  if redirect_int and isinstance(self.MT._row_index, int): # internal use
@@ -2306,7 +2357,7 @@ class RowIndex(tk.Canvas):
2306
2357
  return ""
2307
2358
  return self.MT._row_index[datarn]
2308
2359
 
2309
- 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:
2310
2361
  kwargs = self.get_cell_kwargs(datarn, key="dropdown")
2311
2362
  if kwargs:
2312
2363
  if kwargs["text"] is not None:
@@ -2327,7 +2378,7 @@ class RowIndex(tk.Canvas):
2327
2378
  value = get_n2a(datarn, self.default_index)
2328
2379
  return value
2329
2380
 
2330
- 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:
2331
2382
  if self.get_cell_kwargs(datarn, key="checkbox", cell=r_ops):
2332
2383
  return False
2333
2384
  kwargs = self.get_cell_kwargs(datarn, key="dropdown", cell=r_ops)
@@ -2335,10 +2386,10 @@ class RowIndex(tk.Canvas):
2335
2386
  return kwargs["values"][0]
2336
2387
  return ""
2337
2388
 
2338
- 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]:
2339
2390
  return [self.get_value_for_empty_cell(datarn, r_ops=r_ops) for datarn in range(start, end)]
2340
2391
 
2341
- def fix_index(self, datarn=None, fix_values=tuple()):
2392
+ def fix_index(self, datarn: int | None = None) -> None:
2342
2393
  if isinstance(self.MT._row_index, int):
2343
2394
  return
2344
2395
  if isinstance(self.MT._row_index, float):
@@ -2351,14 +2402,10 @@ class RowIndex(tk.Canvas):
2351
2402
  self.MT._row_index = []
2352
2403
  if isinstance(datarn, int) and datarn >= len(self.MT._row_index):
2353
2404
  self.MT._row_index.extend(self.get_empty_index_seq(end=datarn + 1, start=len(self.MT._row_index)))
2354
- if fix_values:
2355
- for rn, v in enumerate(islice(self.MT._row_index, fix_values[0], fix_values[1])):
2356
- if not self.input_valid_for_cell(rn, v):
2357
- self.MT._row_index[rn] = self.get_value_for_empty_cell(rn)
2358
2405
 
2359
- def set_row_height_run_binding(self, r, only_set_if_too_small=True):
2406
+ def set_row_height_run_binding(self, r: int, only_if_too_small: bool = True) -> None:
2360
2407
  old_height = self.MT.row_positions[r + 1] - self.MT.row_positions[r]
2361
- new_height = self.set_row_height(r, only_set_if_too_small=only_set_if_too_small)
2408
+ new_height = self.set_row_height(r, only_if_too_small=only_if_too_small)
2362
2409
  if self.row_height_resize_func is not None and old_height != new_height:
2363
2410
  self.row_height_resize_func(
2364
2411
  event_dict(
@@ -2369,7 +2416,7 @@ class RowIndex(tk.Canvas):
2369
2416
  )
2370
2417
 
2371
2418
  # internal event use
2372
- 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:
2373
2420
  if datarn is None:
2374
2421
  datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
2375
2422
  kwargs = self.get_cell_kwargs(datarn, key="checkbox")
@@ -2404,7 +2451,7 @@ class RowIndex(tk.Canvas):
2404
2451
  if redraw:
2405
2452
  self.MT.refresh()
2406
2453
 
2407
- def get_cell_kwargs(self, datarn, key="dropdown", cell=True, entire=True):
2454
+ def get_cell_kwargs(self, datarn: int, key: Hashable = "dropdown", cell: bool = True) -> dict:
2408
2455
  if cell and datarn in self.cell_options and key in self.cell_options[datarn]:
2409
2456
  return self.cell_options[datarn][key]
2410
2457
  return {}