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/main_table.py CHANGED
@@ -15,7 +15,6 @@ from collections.abc import (
15
15
  Callable,
16
16
  Generator,
17
17
  Hashable,
18
- Iterator,
19
18
  Sequence,
20
19
  )
21
20
  from functools import (
@@ -59,6 +58,7 @@ from .functions import (
59
58
  diff_list,
60
59
  down_cell_within_box,
61
60
  event_dict,
61
+ float_to_int,
62
62
  gen_formatted,
63
63
  get_data_from_clipboard,
64
64
  get_new_indexes,
@@ -98,6 +98,9 @@ from .other_classes import (
98
98
  from .text_editor import (
99
99
  TextEditor,
100
100
  )
101
+ from .types import (
102
+ AnyIter,
103
+ )
101
104
  from .vars import (
102
105
  USER_OS,
103
106
  bind_add_columns,
@@ -257,8 +260,6 @@ class MainTable(tk.Canvas):
257
260
  self.rc_insert_row_enabled = False
258
261
  self.rc_popup_menus_enabled = False
259
262
  self.edit_cell_enabled = False
260
- self.new_row_width = 0
261
- self.new_header_height = 0
262
263
  self.CH = kwargs["column_headers_canvas"]
263
264
  self.CH.MT = self
264
265
  self.CH.RI = kwargs["row_index_canvas"]
@@ -297,11 +298,6 @@ class MainTable(tk.Canvas):
297
298
  self.txt_measure_canvas = tk.Canvas(self)
298
299
  self.txt_measure_canvas_text = self.txt_measure_canvas.create_text(0, 0, text="", font=self.PAR.ops.table_font)
299
300
 
300
- self.max_row_height = float(kwargs["max_row_height"])
301
- self.max_index_width = float(kwargs["max_index_width"])
302
- self.max_column_width = float(kwargs["max_column_width"])
303
- self.max_header_height = float(kwargs["max_header_height"])
304
-
305
301
  self.RI.set_width(self.PAR.ops.default_row_index_width)
306
302
  self.set_table_font_help()
307
303
  self.set_header_font_help()
@@ -411,7 +407,9 @@ class MainTable(tk.Canvas):
411
407
  ("<Control-MouseWheel>", self.ctrl_mousewheel),
412
408
  ("<Control-plus>", self.zoom_in),
413
409
  ("<Control-equal>", self.zoom_in),
410
+ ("<Meta-Command-equal>", self.zoom_in),
414
411
  ("<Control-minus>", self.zoom_out),
412
+ ("<Meta-Command-minus>", self.zoom_out),
415
413
  )
416
414
  mt_ri_canvas_linux_bindings = {
417
415
  ("<Button-4>", self.mousewheel),
@@ -1850,14 +1848,43 @@ class MainTable(tk.Canvas):
1850
1848
  if redraw:
1851
1849
  self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
1852
1850
  if run_binding_func:
1853
- if self.select_all_binding_func:
1854
- self.select_all_binding_func(
1855
- self.get_select_event(being_drawn_item=self.being_drawn_item),
1856
- )
1857
1851
  event_data = self.get_select_event(self.being_drawn_item)
1852
+ try_binding(self.select_all_binding_func, event_data)
1858
1853
  self.PAR.emit_event("<<SheetSelect>>", data=event_data)
1859
1854
  self.PAR.emit_event("<<SelectAll>>", data=event_data)
1860
1855
 
1856
+ def select_columns(self, event: object) -> None:
1857
+ if not self.selected:
1858
+ return
1859
+ r1, c1, r2, c2 = self.selection_boxes[self.selected.fill_iid].coords
1860
+ r, c = self.selected.row, self.selected.column
1861
+ self.set_currently_selected(
1862
+ r=r,
1863
+ c=c,
1864
+ item=self.CH.select_col(range(c1, c2), redraw=True),
1865
+ )
1866
+
1867
+ def select_rows(self, event: object) -> None:
1868
+ if not self.selected:
1869
+ return
1870
+ r1, c1, r2, c2 = self.selection_boxes[self.selected.fill_iid].coords
1871
+ r, c = self.selected.row, self.selected.column
1872
+ self.set_currently_selected(
1873
+ r=r,
1874
+ c=c,
1875
+ item=self.RI.select_row(range(r1, r2), redraw=True),
1876
+ )
1877
+
1878
+ def select_row_start(self, event: object) -> None:
1879
+ if self.selected:
1880
+ self.select_cell(self.selected.row, 0)
1881
+ self.see(self.selected.row, 0)
1882
+
1883
+ def select_a1(self, event: object) -> None:
1884
+ if len(self.row_positions) > 1 and len(self.col_positions) > 1:
1885
+ self.select_cell(0, 0)
1886
+ self.see(0, 0)
1887
+
1861
1888
  def select_cell(
1862
1889
  self,
1863
1890
  r: int,
@@ -1940,7 +1967,9 @@ class MainTable(tk.Canvas):
1940
1967
  ) -> None:
1941
1968
  if not self.selected:
1942
1969
  return
1970
+ curr_box = self.selected.fill_iid
1943
1971
  if r == "all" or (r is None and c is None and cell is None):
1972
+ self.hide_dropdown_editor_all_canvases()
1944
1973
  for item, box in self.get_selection_items():
1945
1974
  self.hide_selection_box(item)
1946
1975
  elif r in ("allrows", "allcols"):
@@ -1950,6 +1979,8 @@ class MainTable(tk.Canvas):
1950
1979
  cells=False,
1951
1980
  ):
1952
1981
  self.hide_selection_box(item)
1982
+ if item == curr_box:
1983
+ self.hide_dropdown_editor_all_canvases()
1953
1984
  elif isinstance(r, int) and c is None and cell is None:
1954
1985
  for item, box in self.get_selection_items(columns=False, cells=False):
1955
1986
  r1, c1, r2, c2 = box.coords
@@ -1957,6 +1988,8 @@ class MainTable(tk.Canvas):
1957
1988
  resel = self.selected.fill_iid == item
1958
1989
  to_sel = self.selected.row
1959
1990
  self.hide_selection_box(item)
1991
+ if item == curr_box:
1992
+ self.hide_dropdown_editor_all_canvases()
1960
1993
  if r2 - r1 != 1:
1961
1994
  if r == r1:
1962
1995
  self.create_selection_box(
@@ -2000,6 +2033,8 @@ class MainTable(tk.Canvas):
2000
2033
  resel = self.selected.fill_iid == item
2001
2034
  to_sel = self.selected.column
2002
2035
  self.hide_selection_box(item)
2036
+ if item == curr_box:
2037
+ self.hide_dropdown_editor_all_canvases()
2003
2038
  if c2 - c1 != 1:
2004
2039
  if c == c1:
2005
2040
  self.create_selection_box(
@@ -2043,6 +2078,8 @@ class MainTable(tk.Canvas):
2043
2078
  r1, c1, r2, c2 = box.coords
2044
2079
  if r >= r1 and c >= c1 and r < r2 and c < c2:
2045
2080
  self.hide_selection_box(item)
2081
+ if item == curr_box:
2082
+ self.hide_text_editor_and_dropdown(redraw=False)
2046
2083
  if redraw:
2047
2084
  self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
2048
2085
  sel_event = self.get_select_event(being_drawn_item=self.being_drawn_item)
@@ -2052,12 +2089,15 @@ class MainTable(tk.Canvas):
2052
2089
 
2053
2090
  def deselect_any(
2054
2091
  self,
2055
- rows: Iterator[int] | int | None = None,
2056
- columns: Iterator[int] | int | None = None,
2092
+ rows: AnyIter[int] | int | None = None,
2093
+ columns: AnyIter[int] | int | None = None,
2057
2094
  redraw: bool = True,
2058
2095
  ) -> None:
2096
+ if not self.selected:
2097
+ return
2059
2098
  rows = int_x_iter(rows)
2060
2099
  columns = int_x_iter(columns)
2100
+ curr_box = self.selected.fill_iid
2061
2101
  if is_iterable(rows) and is_iterable(columns):
2062
2102
  rows = tuple(consecutive_ranges(sorted(rows)))
2063
2103
  columns = tuple(consecutive_ranges(sorted(columns)))
@@ -2072,6 +2112,8 @@ class MainTable(tk.Canvas):
2072
2112
  (cols_end >= c1 and cols_end <= c2) or (cols_st >= c1 and cols_st < c2)
2073
2113
  ):
2074
2114
  hidden = self.hide_selection_box(item)
2115
+ if item == curr_box:
2116
+ self.hide_dropdown_editor_all_canvases()
2075
2117
  break
2076
2118
  elif is_iterable(rows):
2077
2119
  rows = tuple(consecutive_ranges(sorted(rows)))
@@ -2080,6 +2122,8 @@ class MainTable(tk.Canvas):
2080
2122
  for rows_st, rows_end in rows:
2081
2123
  if (rows_end >= r1 and rows_end <= r2) or (rows_st >= r1 and rows_st < r2):
2082
2124
  self.hide_selection_box(item)
2125
+ if item == curr_box:
2126
+ self.hide_dropdown_editor_all_canvases()
2083
2127
  break
2084
2128
  elif is_iterable(columns):
2085
2129
  columns = tuple(consecutive_ranges(sorted(columns)))
@@ -2088,6 +2132,8 @@ class MainTable(tk.Canvas):
2088
2132
  for cols_st, cols_end in columns:
2089
2133
  if (cols_end >= c1 and cols_end <= c2) or (cols_st >= c1 and cols_st < c2):
2090
2134
  self.hide_selection_box(item)
2135
+ if item == curr_box:
2136
+ self.hide_dropdown_editor_all_canvases()
2091
2137
  break
2092
2138
  else:
2093
2139
  self.deselect()
@@ -2678,7 +2724,7 @@ class MainTable(tk.Canvas):
2678
2724
  self._enable_binding(bindings.lower())
2679
2725
  self.create_rc_menus()
2680
2726
 
2681
- def disable_bindings(self, bindings):
2727
+ def disable_bindings(self, bindings: object) -> None:
2682
2728
  if not bindings:
2683
2729
  self._disable_binding("all")
2684
2730
  elif isinstance(bindings, (list, tuple)):
@@ -2692,21 +2738,33 @@ class MainTable(tk.Canvas):
2692
2738
  self._disable_binding(bindings)
2693
2739
  self.create_rc_menus()
2694
2740
 
2695
- def _enable_binding(self, binding):
2741
+ def _enable_binding(self, binding: str) -> None:
2696
2742
  if binding == "enable_all":
2697
2743
  binding = "all"
2698
- if binding in ("all", "single", "single_selection_mode", "single_select"):
2699
- self.single_selection_enabled = True
2700
- self.toggle_selection_enabled = False
2701
- elif binding in ("toggle", "toggle_selection_mode", "toggle_select"):
2702
- self.toggle_selection_enabled = True
2703
- self.single_selection_enabled = False
2744
+ if binding in (
2745
+ "all",
2746
+ "single",
2747
+ "single_selection_mode",
2748
+ "single_select",
2749
+ "toggle",
2750
+ "toggle_selection_mode",
2751
+ "toggle_select",
2752
+ ):
2753
+ self._tksheet_bind("row_start_bindings", self.select_row_start)
2754
+ self._tksheet_bind("table_start_bindings", self.select_a1)
2755
+ if binding in ("all", "single", "single_selection_mode", "single_select"):
2756
+ self.single_selection_enabled = True
2757
+ self.toggle_selection_enabled = False
2758
+ elif binding in ("toggle", "toggle_selection_mode", "toggle_select"):
2759
+ self.toggle_selection_enabled = True
2760
+ self.single_selection_enabled = False
2704
2761
  if binding in ("all", "drag_select"):
2705
2762
  self.drag_selection_enabled = True
2706
2763
  if binding in ("all", "column_width_resize"):
2707
2764
  self.CH.width_resizing_enabled = True
2708
2765
  if binding in ("all", "column_select"):
2709
2766
  self.CH.col_selection_enabled = True
2767
+ self._tksheet_bind("select_columns_bindings", self.select_columns)
2710
2768
  if binding in ("all", "column_height_resize"):
2711
2769
  self.CH.height_resizing_enabled = True
2712
2770
  self.TL.rh_state()
@@ -2723,6 +2781,7 @@ class MainTable(tk.Canvas):
2723
2781
  self.TL.rw_state()
2724
2782
  if binding in ("all", "row_select"):
2725
2783
  self.RI.row_selection_enabled = True
2784
+ self._tksheet_bind("select_rows_bindings", self.select_rows)
2726
2785
  if binding in ("all", "row_drag_and_drop", "move_rows"):
2727
2786
  self.RI.drag_and_drop_enabled = True
2728
2787
  if binding in ("all", "select_all"):
@@ -2808,21 +2867,29 @@ class MainTable(tk.Canvas):
2808
2867
  for binding in self.PAR.ops[bindings_key]:
2809
2868
  widget.bind(binding, func)
2810
2869
 
2811
- def _disable_binding(self, binding):
2870
+ def _disable_binding(self, binding: str) -> None:
2812
2871
  if binding == "disable_all":
2813
2872
  binding = "all"
2814
- if binding in ("all", "single", "single_selection_mode", "single_select"):
2873
+ if binding in (
2874
+ "all",
2875
+ "single",
2876
+ "single_selection_mode",
2877
+ "single_select",
2878
+ "toggle",
2879
+ "toggle_selection_mode",
2880
+ "toggle_select",
2881
+ ):
2882
+ self._tksheet_unbind("row_start_bindings")
2883
+ self._tksheet_unbind("table_start_bindings")
2815
2884
  self.single_selection_enabled = False
2816
2885
  self.toggle_selection_enabled = False
2817
- elif binding in ("toggle", "toggle_selection_mode", "toggle_select"):
2818
- self.toggle_selection_enabled = False
2819
- self.single_selection_enabled = False
2820
2886
  if binding in ("all", "drag_select"):
2821
2887
  self.drag_selection_enabled = False
2822
2888
  if binding in ("all", "column_width_resize"):
2823
2889
  self.CH.width_resizing_enabled = False
2824
2890
  if binding in ("all", "column_select"):
2825
2891
  self.CH.col_selection_enabled = False
2892
+ self._tksheet_unbind("select_columns_bindings")
2826
2893
  if binding in ("all", "column_height_resize"):
2827
2894
  self.CH.height_resizing_enabled = False
2828
2895
  self.TL.rh_state("hidden")
@@ -2839,6 +2906,7 @@ class MainTable(tk.Canvas):
2839
2906
  self.TL.rw_state("hidden")
2840
2907
  if binding in ("all", "row_select"):
2841
2908
  self.RI.row_selection_enabled = False
2909
+ self._tksheet_unbind("select_rows_bindings")
2842
2910
  if binding in ("all", "row_drag_and_drop", "move_rows"):
2843
2911
  self.RI.drag_and_drop_enabled = False
2844
2912
  if binding in bind_del_columns:
@@ -3210,20 +3278,6 @@ class MainTable(tk.Canvas):
3210
3278
  run_binding=False,
3211
3279
  )
3212
3280
  self.hide_selection_box(to_hide)
3213
- if self.RI.width_resizing_enabled and self.RI.rsz_w is not None and self.RI.currently_resizing_width:
3214
- self.delete_resize_lines()
3215
- self.RI.delete_resize_lines()
3216
- self.RI.currently_resizing_width = False
3217
- self.RI.set_width(self.new_row_width, set_TL=True)
3218
- self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
3219
- self.b1_pressed_loc = None
3220
- elif self.CH.height_resizing_enabled and self.CH.rsz_h is not None and self.CH.currently_resizing_height:
3221
- self.delete_resize_lines()
3222
- self.CH.delete_resize_lines()
3223
- self.CH.currently_resizing_height = False
3224
- self.CH.set_height(self.new_header_height, set_TL=True)
3225
- self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
3226
- self.b1_pressed_loc = None
3227
3281
  self.RI.rsz_w = None
3228
3282
  self.CH.rsz_h = None
3229
3283
  if self.b1_pressed_loc is not None:
@@ -3546,7 +3600,7 @@ class MainTable(tk.Canvas):
3546
3600
  c_pc=c_pc,
3547
3601
  )
3548
3602
 
3549
- def get_txt_w(self, txt, font=None):
3603
+ def get_txt_w(self, txt: str, font: None | FontTuple = None) -> int:
3550
3604
  self.txt_measure_canvas.itemconfig(
3551
3605
  self.txt_measure_canvas_text,
3552
3606
  text=txt,
@@ -3555,7 +3609,7 @@ class MainTable(tk.Canvas):
3555
3609
  b = self.txt_measure_canvas.bbox(self.txt_measure_canvas_text)
3556
3610
  return b[2] - b[0]
3557
3611
 
3558
- def get_txt_h(self, txt, font=None):
3612
+ def get_txt_h(self, txt: str, font: None | FontTuple = None) -> int:
3559
3613
  self.txt_measure_canvas.itemconfig(
3560
3614
  self.txt_measure_canvas_text,
3561
3615
  text=txt,
@@ -3564,7 +3618,7 @@ class MainTable(tk.Canvas):
3564
3618
  b = self.txt_measure_canvas.bbox(self.txt_measure_canvas_text)
3565
3619
  return b[3] - b[1]
3566
3620
 
3567
- def get_txt_dimensions(self, txt, font=None):
3621
+ def get_txt_dimensions(self, txt: str, font: None | FontTuple = None) -> int:
3568
3622
  self.txt_measure_canvas.itemconfig(
3569
3623
  self.txt_measure_canvas_text,
3570
3624
  text=txt,
@@ -3573,7 +3627,7 @@ class MainTable(tk.Canvas):
3573
3627
  b = self.txt_measure_canvas.bbox(self.txt_measure_canvas_text)
3574
3628
  return b[2] - b[0], b[3] - b[1]
3575
3629
 
3576
- def get_lines_cell_height(self, n, font=None):
3630
+ def get_lines_cell_height(self, n: int, font: None | FontTuple = None) -> int:
3577
3631
  return (
3578
3632
  self.get_txt_h(
3579
3633
  txt="\n".join("|" for _ in range(n)) if n > 1 else "|",
@@ -3582,15 +3636,17 @@ class MainTable(tk.Canvas):
3582
3636
  + 5
3583
3637
  )
3584
3638
 
3585
- def set_min_column_width(self):
3586
- self.min_column_width = 1
3587
- if self.min_column_width > self.max_column_width:
3588
- self.max_column_width = self.min_column_width + 20
3639
+ def set_min_column_width(self, width: int) -> None:
3640
+ if width:
3641
+ self.PAR.ops.min_column_width = width
3642
+
3643
+ if self.PAR.ops.min_column_width > self.PAR.ops.max_column_width:
3644
+ self.PAR.ops.max_column_width = self.PAR.ops.min_column_width + 20
3589
3645
  if (
3590
3646
  isinstance(self.PAR.ops.auto_resize_columns, (int, float))
3591
- and self.PAR.ops.auto_resize_columns < self.min_column_width
3647
+ and self.PAR.ops.auto_resize_columns < self.PAR.ops.min_column_width
3592
3648
  ):
3593
- self.PAR.ops.auto_resize_columns = self.min_column_width
3649
+ self.PAR.ops.auto_resize_columns = self.PAR.ops.min_column_width
3594
3650
 
3595
3651
  def get_default_row_height(self) -> int:
3596
3652
  if isinstance(self.PAR.ops.default_row_height, str):
@@ -3641,7 +3697,6 @@ class MainTable(tk.Canvas):
3641
3697
  self.table_xtra_lines_increment = int(self.table_txt_height)
3642
3698
  if self.min_row_height < 12:
3643
3699
  self.min_row_height = 12
3644
- self.set_min_column_width()
3645
3700
 
3646
3701
  def set_header_font(self, newfont: tuple | None = None) -> tuple[str, int, str]:
3647
3702
  if newfont:
@@ -3672,7 +3727,6 @@ class MainTable(tk.Canvas):
3672
3727
  and self.PAR.ops.default_header_height < self.min_header_height
3673
3728
  ):
3674
3729
  self.PAR.ops.default_header_height = int(self.min_header_height)
3675
- self.set_min_column_width()
3676
3730
  self.CH.set_height(self.get_default_header_height(), set_TL=True)
3677
3731
 
3678
3732
  def set_index_font(self, newfont: tuple | None = None) -> tuple[str, int, str]:
@@ -3742,15 +3796,15 @@ class MainTable(tk.Canvas):
3742
3796
  w = b[2] - b[0] + 7
3743
3797
  h = b[3] - b[1] + 5
3744
3798
  else:
3745
- w = self.min_column_width
3799
+ w = self.PAR.ops.min_column_width
3746
3800
  h = self.min_row_height
3747
3801
  if self.get_cell_kwargs(datarn, datacn, key="dropdown") or self.get_cell_kwargs(datarn, datacn, key="checkbox"):
3748
3802
  return w + self.table_txt_height, h
3749
3803
  return w, h
3750
3804
 
3751
3805
  def set_cell_size_to_text(self, r, c, only_if_too_small=False, redraw: bool = True, run_binding=False):
3752
- min_column_width = int(self.min_column_width)
3753
- min_rh = int(self.min_row_height)
3806
+ min_column_width = self.PAR.ops.min_column_width
3807
+ min_rh = self.min_row_height
3754
3808
  w = min_column_width
3755
3809
  h = min_rh
3756
3810
  datacn = self.datacn(c)
@@ -3759,13 +3813,13 @@ class MainTable(tk.Canvas):
3759
3813
  if tw > w:
3760
3814
  w = tw
3761
3815
  if h < min_rh:
3762
- h = int(min_rh)
3763
- elif h > self.max_row_height:
3764
- h = int(self.max_row_height)
3816
+ h = min_rh
3817
+ elif h > self.PAR.ops.max_row_height:
3818
+ h = int(self.PAR.ops.max_row_height)
3765
3819
  if w < min_column_width:
3766
- w = int(min_column_width)
3767
- elif w > self.max_column_width:
3768
- w = int(self.max_column_width)
3820
+ w = min_column_width
3821
+ elif w > self.PAR.ops.max_column_width:
3822
+ w = int(self.PAR.ops.max_column_width)
3769
3823
  cell_needs_resize_w = False
3770
3824
  cell_needs_resize_h = False
3771
3825
  if only_if_too_small:
@@ -3825,8 +3879,10 @@ class MainTable(tk.Canvas):
3825
3879
  width: int | None = None,
3826
3880
  slim: bool = False,
3827
3881
  ) -> tuple[list[float], list[float]]:
3828
- min_column_width = int(self.min_column_width)
3829
- min_rh = int(self.min_row_height)
3882
+ min_column_width = self.PAR.ops.min_column_width
3883
+ max_column_width = float_to_int(self.PAR.ops.max_column_width)
3884
+ max_row_height = float_to_int(self.PAR.ops.max_row_height)
3885
+ min_rh = self.min_row_height
3830
3886
  h = min_rh
3831
3887
  rhs = defaultdict(lambda: int(min_rh))
3832
3888
  cws = []
@@ -3849,9 +3905,9 @@ class MainTable(tk.Canvas):
3849
3905
  for datarn in iterrows:
3850
3906
  w_, h = self.RI.get_cell_dimensions(datarn)
3851
3907
  if h < min_rh:
3852
- h = int(min_rh)
3853
- elif h > self.max_row_height:
3854
- h = int(self.max_row_height)
3908
+ h = min_rh
3909
+ elif h > max_row_height:
3910
+ h = max_row_height
3855
3911
  if h > rhs[datarn]:
3856
3912
  rhs[datarn] = h
3857
3913
  added_w_space = 1 if slim else 7
@@ -3883,22 +3939,22 @@ class MainTable(tk.Canvas):
3883
3939
  if tw > w:
3884
3940
  w = tw
3885
3941
  if h < min_rh:
3886
- h = int(min_rh)
3887
- elif h > self.max_row_height:
3888
- h = int(self.max_row_height)
3942
+ h = min_rh
3943
+ elif h > max_row_height:
3944
+ h = max_row_height
3889
3945
  if h > rhs[datarn]:
3890
3946
  rhs[datarn] = h
3891
3947
  if w < min_column_width:
3892
- w = int(min_column_width)
3893
- elif w > self.max_column_width:
3894
- w = int(self.max_column_width)
3948
+ w = min_column_width
3949
+ elif w > max_column_width:
3950
+ w = max_column_width
3895
3951
  cws.append(w)
3896
3952
  self.set_row_positions(itr=rhs.values())
3897
3953
  self.set_col_positions(itr=cws)
3898
3954
  self.recreate_all_selection_boxes()
3899
3955
  return self.row_positions, self.col_positions
3900
3956
 
3901
- def set_col_positions(self, itr: Iterator[float]) -> None:
3957
+ def set_col_positions(self, itr: AnyIter[float]) -> None:
3902
3958
  self.col_positions = list(accumulate(chain([0], itr)))
3903
3959
 
3904
3960
  def reset_col_positions(self, ncols: int | None = None):
@@ -3910,7 +3966,7 @@ class MainTable(tk.Canvas):
3910
3966
  else:
3911
3967
  self.set_col_positions(itr=repeat(colpos, len(self.displayed_columns)))
3912
3968
 
3913
- def set_row_positions(self, itr: Iterator[float]) -> None:
3969
+ def set_row_positions(self, itr: AnyIter[float]) -> None:
3914
3970
  self.row_positions = list(accumulate(chain([0], itr)))
3915
3971
 
3916
3972
  def reset_row_positions(self, nrows: int | None = None):
@@ -3944,7 +4000,7 @@ class MainTable(tk.Canvas):
3944
4000
  del self.row_positions[idx]
3945
4001
  self.row_positions[idx:] = [e - w for e in islice(self.row_positions, idx, len(self.row_positions))]
3946
4002
 
3947
- def del_col_positions(self, idxs: Iterator[int] | None = None):
4003
+ def del_col_positions(self, idxs: AnyIter[int] | None = None):
3948
4004
  if idxs is None:
3949
4005
  del self.col_positions[-1]
3950
4006
  else:
@@ -3952,7 +4008,7 @@ class MainTable(tk.Canvas):
3952
4008
  idxs = set(idxs)
3953
4009
  self.set_col_positions(itr=(w for i, w in enumerate(self.gen_column_widths()) if i not in idxs))
3954
4010
 
3955
- def del_row_positions(self, idxs: Iterator[int] | None = None):
4011
+ def del_row_positions(self, idxs: AnyIter[int] | None = None):
3956
4012
  if idxs is None:
3957
4013
  del self.row_positions[-1]
3958
4014
  else:
@@ -4952,7 +5008,7 @@ class MainTable(tk.Canvas):
4952
5008
 
4953
5009
  def display_rows(
4954
5010
  self,
4955
- rows: int | Iterator | None = None,
5011
+ rows: int | AnyIter | None = None,
4956
5012
  all_rows_displayed: bool | None = None,
4957
5013
  reset_row_positions: bool = True,
4958
5014
  deselect_all: bool = True,
@@ -4981,7 +5037,7 @@ class MainTable(tk.Canvas):
4981
5037
 
4982
5038
  def display_columns(
4983
5039
  self,
4984
- columns: int | Iterator | None = None,
5040
+ columns: int | AnyIter | None = None,
4985
5041
  all_columns_displayed: bool | None = None,
4986
5042
  reset_col_positions: bool = True,
4987
5043
  deselect_all: bool = True,
@@ -5475,8 +5531,8 @@ class MainTable(tk.Canvas):
5475
5531
  resized_rows = False
5476
5532
  if self.PAR.ops.auto_resize_columns and self.allow_auto_resize_columns and col_pos_exists:
5477
5533
  max_w = can_width - self.PAR.ops.empty_horizontal
5478
- if self.PAR.ops.auto_resize_columns < self.min_column_width:
5479
- min_column_width = self.column_width
5534
+ if self.PAR.ops.auto_resize_columns < self.PAR.ops.min_column_width:
5535
+ min_column_width = self.PAR.ops.min_column_width
5480
5536
  else:
5481
5537
  min_column_width = self.PAR.ops.auto_resize_columns
5482
5538
  if (len(self.col_positions) - 1) * min_column_width < max_w:
@@ -5956,7 +6012,7 @@ class MainTable(tk.Canvas):
5956
6012
  rows: bool = True,
5957
6013
  columns: bool = True,
5958
6014
  reverse: bool = False,
5959
- ) -> Generator[int]:
6015
+ ) -> tuple[tuple[int, SelectionBox]]:
5960
6016
  """
5961
6017
  Most recent selection box should be last
5962
6018
  """
@@ -6409,31 +6465,55 @@ class MainTable(tk.Canvas):
6409
6465
  def recreate_all_selection_boxes(self) -> None:
6410
6466
  if not self.selected:
6411
6467
  return
6468
+ modified = False
6412
6469
  for item, box in self.get_selection_items():
6413
6470
  r1, c1, r2, c2 = box.coords
6471
+ if not modified:
6472
+ modified = (
6473
+ r1 >= len(self.row_positions) - 1
6474
+ or c1 >= len(self.col_positions) - 1
6475
+ or r2 > len(self.row_positions) - 1
6476
+ or c2 > len(self.col_positions) - 1
6477
+ )
6414
6478
  if r1 >= len(self.row_positions) - 1:
6415
6479
  if len(self.row_positions) > 1:
6416
6480
  r1 = len(self.row_positions) - 2
6417
6481
  else:
6418
- r1 = len(self.row_positions) - 1
6482
+ r1 = 0
6419
6483
  if c1 >= len(self.col_positions) - 1:
6420
6484
  if len(self.col_positions) > 1:
6421
6485
  c1 = len(self.col_positions) - 2
6422
6486
  else:
6423
- c1 = len(self.col_positions) - 1
6487
+ c1 = 0
6424
6488
  if r2 > len(self.row_positions) - 1:
6425
6489
  r2 = len(self.row_positions) - 1
6426
6490
  if c2 > len(self.col_positions) - 1:
6427
6491
  c2 = len(self.col_positions) - 1
6428
- self.recreate_selection_box(r1, c1, r2, c2, item)
6492
+ self.recreate_selection_box(r1, c1, r2, c2, item, run_binding=False)
6493
+
6429
6494
  if self.selected:
6430
6495
  r = self.selected.row
6431
6496
  c = self.selected.column
6432
6497
  if r < len(self.row_positions) - 1 and c < len(self.col_positions) - 1:
6433
- self.set_currently_selected(r, c, item=self.selected.fill_iid)
6498
+ self.set_currently_selected(
6499
+ r,
6500
+ c,
6501
+ item=self.selected.fill_iid,
6502
+ run_binding=False,
6503
+ )
6434
6504
  else:
6435
6505
  box = self.selection_boxes[self.selected.fill_iid]
6436
- self.set_currently_selected(box.coords.from_r, box.coords.from_c, item=box.fill_iid)
6506
+ self.set_currently_selected(
6507
+ box.coords.from_r,
6508
+ box.coords.from_c,
6509
+ item=box.fill_iid,
6510
+ run_binding=False,
6511
+ )
6512
+ if modified:
6513
+ self.PAR.emit_event(
6514
+ "<<SheetSelect>>",
6515
+ data=self.get_select_event(self.being_drawn_item),
6516
+ )
6437
6517
 
6438
6518
  def get_redraw_selections(self, startr: int, endr: int, startc: int, endc: int) -> dict:
6439
6519
  d = defaultdict(set)
@@ -6891,7 +6971,7 @@ class MainTable(tk.Canvas):
6891
6971
  name="end_edit_table",
6892
6972
  sheet=self.PAR.name,
6893
6973
  widget=self,
6894
- cells_table={(datarn, datacn): text_editor_value},
6974
+ cells_table={(datarn, datacn): self.get_cell_data(datarn, datacn)},
6895
6975
  key=event.keysym,
6896
6976
  value=text_editor_value,
6897
6977
  loc=Loc(r, c),