tksheet 7.3.3__py3-none-any.whl → 7.3.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
tksheet/main_table.py CHANGED
@@ -3,42 +3,17 @@ from __future__ import annotations
3
3
  import csv as csv
4
4
  import io
5
5
  import tkinter as tk
6
- from bisect import (
7
- bisect_left,
8
- bisect_right,
9
- )
10
- from collections import (
11
- defaultdict,
12
- deque,
13
- )
14
- from collections.abc import (
15
- Callable,
16
- Generator,
17
- Hashable,
18
- Sequence,
19
- )
20
- from functools import (
21
- partial,
22
- )
23
- from itertools import (
24
- accumulate,
25
- chain,
26
- cycle,
27
- filterfalse,
28
- islice,
29
- repeat,
30
- )
31
- from math import (
32
- ceil,
33
- floor,
34
- )
6
+ from bisect import bisect_left, bisect_right
7
+ from collections import defaultdict, deque
8
+ from collections.abc import Callable, Generator, Hashable, Sequence
9
+ from functools import partial
10
+ from itertools import accumulate, chain, cycle, filterfalse, islice, repeat
11
+ from math import ceil, floor
35
12
  from operator import itemgetter
36
13
  from tkinter import TclError
37
14
  from typing import Literal
38
15
 
39
- from .colors import (
40
- color_map,
41
- )
16
+ from .colors import color_map
42
17
  from .constants import (
43
18
  USER_OS,
44
19
  bind_add_columns,
@@ -52,9 +27,7 @@ from .constants import (
52
27
  text_editor_to_unbind,
53
28
  val_modifying_options,
54
29
  )
55
- from .find_window import (
56
- FindWindow,
57
- )
30
+ from .find_window import FindWindow
58
31
  from .formatters import (
59
32
  data_to_str,
60
33
  format_data,
@@ -119,12 +92,8 @@ from .other_classes import (
119
92
  SelectionBox,
120
93
  TextEditorStorage,
121
94
  )
122
- from .text_editor import (
123
- TextEditor,
124
- )
125
- from .types import (
126
- AnyIter,
127
- )
95
+ from .text_editor import TextEditor
96
+ from .types import AnyIter
128
97
 
129
98
 
130
99
  class MainTable(tk.Canvas):
@@ -362,10 +331,8 @@ class MainTable(tk.Canvas):
362
331
  reset_col_positions=False,
363
332
  deselect_all=False,
364
333
  )
334
+ self.rc_popup_menu, self.empty_rc_popup_menu = None, None
365
335
  self.reset_col_positions()
366
-
367
- self.rc_popup_menu = None
368
- self.empty_rc_popup_menu = None
369
336
  self.basic_bindings()
370
337
  self.create_rc_menus()
371
338
 
@@ -649,6 +616,8 @@ class MainTable(tk.Canvas):
649
616
  find: str,
650
617
  reverse: bool = False,
651
618
  ) -> tuple[int, int, int] | None:
619
+ if not self.selected:
620
+ return None
652
621
  current_box = self.selection_boxes[self.selected.fill_iid]
653
622
  current_id = self.selected.fill_iid
654
623
  if is_last_cell(*current_box.coords, self.selected.row, self.selected.column, reverse=reverse):
@@ -2014,9 +1983,9 @@ class MainTable(tk.Canvas):
2014
1983
  need_redraw = True
2015
1984
  else:
2016
1985
  if r is not None and not keep_yscroll:
2017
- y = int(self.row_positions[r] + ((self.row_positions[r + 1] - self.row_positions[r]) * r_pc)) - 2
2018
- if y < 0:
2019
- y = 0
1986
+ y = max(
1987
+ 0, int(self.row_positions[r] + ((self.row_positions[r + 1] - self.row_positions[r]) * r_pc)) - 2
1988
+ )
2020
1989
  y = y / (self.row_positions[-1] + self.PAR.ops.empty_vertical)
2021
1990
  args = [
2022
1991
  "moveto",
@@ -2041,9 +2010,9 @@ class MainTable(tk.Canvas):
2041
2010
  need_redraw = True
2042
2011
  else:
2043
2012
  if c is not None and not keep_xscroll:
2044
- x = int(self.col_positions[c] + ((self.col_positions[c + 1] - self.col_positions[c]) * c_pc)) - 2
2045
- if x < 0:
2046
- x = 0
2013
+ x = max(
2014
+ 0, int(self.col_positions[c] + ((self.col_positions[c + 1] - self.col_positions[c]) * c_pc)) - 2
2015
+ )
2047
2016
  x = x / (self.col_positions[-1] + self.PAR.ops.empty_horizontal)
2048
2017
  args = [
2049
2018
  "moveto",
@@ -2394,15 +2363,11 @@ class MainTable(tk.Canvas):
2394
2363
  def page_UP(self, event: object = None) -> None:
2395
2364
  height = self.winfo_height()
2396
2365
  top = self.canvasy(0)
2397
- scrollto_y = top - height
2398
- if scrollto_y < 0:
2399
- scrollto_y = 0
2366
+ scrollto_y = max(0, top - height)
2400
2367
  if self.PAR.ops.page_up_down_select_row:
2401
2368
  r = bisect_left(self.row_positions, scrollto_y)
2402
2369
  if self.selected and self.selected.row == r:
2403
- r -= 1
2404
- if r < 0:
2405
- r = 0
2370
+ r = max(0, r - 1)
2406
2371
  if self.RI.row_selection_enabled and (
2407
2372
  self.anything_selected(exclude_columns=True, exclude_cells=True) or not self.anything_selected()
2408
2373
  ):
@@ -5495,7 +5460,7 @@ class MainTable(tk.Canvas):
5495
5460
  can_width: int | None,
5496
5461
  dont_blend: bool,
5497
5462
  alternate_color: Highlight | None,
5498
- ) -> str:
5463
+ ) -> tuple[str, bool]:
5499
5464
  redrawn = False
5500
5465
  if (datarn, datacn) in self.progress_bars:
5501
5466
  kwargs = self.progress_bars[(datarn, datacn)]
@@ -5574,7 +5539,6 @@ class MainTable(tk.Canvas):
5574
5539
  if self.get_cell_kwargs(datarn, datacn, key="dropdown") and self.PAR.ops.show_dropdown_borders
5575
5540
  else ""
5576
5541
  ),
5577
- tag="hi",
5578
5542
  )
5579
5543
  if isinstance(kwargs, ProgressBar):
5580
5544
  if kwargs.del_when_done and kwargs.percent >= 100:
@@ -5600,7 +5564,17 @@ class MainTable(tk.Canvas):
5600
5564
  txtfg = self.PAR.ops.table_fg
5601
5565
  return txtfg, redrawn
5602
5566
 
5603
- def redraw_highlight(self, x1, y1, x2, y2, fill, outline, tag, can_width=None, pc=None):
5567
+ def redraw_highlight(
5568
+ self,
5569
+ x1: int | float,
5570
+ y1: int | float,
5571
+ x2: int | float,
5572
+ y2: int | float,
5573
+ fill: str,
5574
+ outline: str,
5575
+ can_width: None | float = None,
5576
+ pc: None | float = None,
5577
+ ) -> bool:
5604
5578
  if not is_type_int(pc) or pc >= 100:
5605
5579
  coords = (
5606
5580
  x1 - 1 if outline else x1,
@@ -5618,66 +5592,61 @@ class MainTable(tk.Canvas):
5618
5592
  if showing:
5619
5593
  self.itemconfig(iid, fill=fill, outline=outline)
5620
5594
  else:
5621
- self.itemconfig(iid, fill=fill, outline=outline, tag=tag, state="normal")
5595
+ self.itemconfig(iid, fill=fill, outline=outline, state="normal")
5596
+ self.tag_raise(iid)
5622
5597
  else:
5623
- iid = self.create_rectangle(coords, fill=fill, outline=outline, tag=tag)
5598
+ iid = self.create_rectangle(coords, fill=fill, outline=outline)
5624
5599
  self.disp_high[iid] = True
5625
5600
  return True
5626
5601
 
5627
- def redraw_gridline(
5628
- self,
5629
- points,
5630
- fill,
5631
- width,
5632
- tag,
5633
- ):
5634
- if self.hidd_grid:
5635
- iid, sh = self.hidd_grid.popitem()
5636
- self.coords(iid, points)
5637
- if sh:
5638
- self.itemconfig(
5639
- iid,
5640
- fill=fill,
5641
- width=width,
5642
- capstyle=tk.BUTT,
5643
- joinstyle=tk.ROUND,
5644
- )
5602
+ def redraw_gridline(self, points: list[float]) -> None:
5603
+ if points:
5604
+ if self.hidd_grid:
5605
+ iid, sh = self.hidd_grid.popitem()
5606
+ self.coords(iid, points)
5607
+ if sh:
5608
+ self.itemconfig(
5609
+ iid,
5610
+ fill=self.PAR.ops.table_grid_fg,
5611
+ width=1,
5612
+ capstyle=tk.BUTT,
5613
+ joinstyle=tk.ROUND,
5614
+ )
5615
+ else:
5616
+ self.itemconfig(
5617
+ iid,
5618
+ fill=self.PAR.ops.table_grid_fg,
5619
+ width=1,
5620
+ capstyle=tk.BUTT,
5621
+ joinstyle=tk.ROUND,
5622
+ state="normal",
5623
+ )
5624
+ self.tag_raise(iid)
5645
5625
  else:
5646
- self.itemconfig(
5647
- iid,
5648
- fill=fill,
5649
- width=width,
5626
+ iid = self.create_line(
5627
+ points,
5628
+ fill=self.PAR.ops.table_grid_fg,
5629
+ width=1,
5650
5630
  capstyle=tk.BUTT,
5651
5631
  joinstyle=tk.ROUND,
5652
- state="normal",
5632
+ tag="g",
5653
5633
  )
5654
- else:
5655
- iid = self.create_line(
5656
- points,
5657
- fill=fill,
5658
- width=width,
5659
- capstyle=tk.BUTT,
5660
- joinstyle=tk.ROUND,
5661
- tag=tag,
5662
- )
5663
- self.disp_grid[iid] = True
5664
- return iid
5634
+ self.disp_grid[iid] = True
5665
5635
 
5666
5636
  def redraw_dropdown(
5667
5637
  self,
5668
- x1,
5669
- y1,
5670
- x2,
5671
- y2,
5672
- fill,
5673
- outline,
5674
- tag,
5675
- draw_outline=True,
5676
- draw_arrow=True,
5677
- open_=False,
5678
- ):
5638
+ x1: int | float,
5639
+ y1: int | float,
5640
+ x2: int | float,
5641
+ y2: int | float,
5642
+ fill: str,
5643
+ outline: str,
5644
+ draw_outline: bool = True,
5645
+ draw_arrow: bool = True,
5646
+ open_: bool = False,
5647
+ ) -> None:
5679
5648
  if draw_outline and self.PAR.ops.show_dropdown_borders:
5680
- self.redraw_highlight(x1 + 1, y1 + 1, x2, y2, fill="", outline=self.PAR.ops.table_fg, tag=tag)
5649
+ self.redraw_highlight(x1 + 1, y1 + 1, x2, y2, fill="", outline=self.PAR.ops.table_fg)
5681
5650
  if draw_arrow:
5682
5651
  mod = (self.table_txt_height - 1) if self.table_txt_height % 2 else self.table_txt_height
5683
5652
  small_mod = int(mod / 5)
@@ -5708,13 +5677,12 @@ class MainTable(tk.Canvas):
5708
5677
  if sh:
5709
5678
  self.itemconfig(t, fill=fill)
5710
5679
  else:
5711
- self.itemconfig(t, fill=fill, tag=tag, state="normal")
5680
+ self.itemconfig(t, fill=fill, state="normal")
5712
5681
  self.lift(t)
5713
5682
  else:
5714
5683
  t = self.create_line(
5715
5684
  points,
5716
5685
  fill=fill,
5717
- tag=tag,
5718
5686
  width=2,
5719
5687
  capstyle=tk.ROUND,
5720
5688
  joinstyle=tk.BEVEL,
@@ -5729,7 +5697,6 @@ class MainTable(tk.Canvas):
5729
5697
  y2: int | float,
5730
5698
  fill: str,
5731
5699
  outline: str,
5732
- tag: str | tuple,
5733
5700
  draw_check: bool = False,
5734
5701
  ) -> None:
5735
5702
  points = rounded_box_coords(x1, y1, x2, y2)
@@ -5739,10 +5706,10 @@ class MainTable(tk.Canvas):
5739
5706
  if sh:
5740
5707
  self.itemconfig(t, fill=outline, outline=fill)
5741
5708
  else:
5742
- self.itemconfig(t, fill=outline, outline=fill, tag=tag, state="normal")
5709
+ self.itemconfig(t, fill=outline, outline=fill, state="normal")
5743
5710
  self.lift(t)
5744
5711
  else:
5745
- t = self.create_polygon(points, fill=outline, outline=fill, tag=tag, smooth=True)
5712
+ t = self.create_polygon(points, fill=outline, outline=fill, smooth=True)
5746
5713
  self.disp_checkbox[t] = True
5747
5714
  if draw_check:
5748
5715
  x1 = x1 + 4
@@ -5756,28 +5723,13 @@ class MainTable(tk.Canvas):
5756
5723
  if sh:
5757
5724
  self.itemconfig(t, fill=fill, outline=outline)
5758
5725
  else:
5759
- self.itemconfig(t, fill=fill, outline=outline, tag=tag, state="normal")
5726
+ self.itemconfig(t, fill=fill, outline=outline, state="normal")
5760
5727
  self.lift(t)
5761
5728
  else:
5762
- t = self.create_polygon(points, fill=fill, outline=outline, tag=tag, smooth=True)
5729
+ t = self.create_polygon(points, fill=fill, outline=outline, smooth=True)
5763
5730
  self.disp_checkbox[t] = True
5764
5731
 
5765
- def main_table_redraw_grid_and_text(
5766
- self,
5767
- redraw_header: bool = False,
5768
- redraw_row_index: bool = False,
5769
- redraw_table: bool = True,
5770
- setting_views: bool = False,
5771
- ) -> bool:
5772
- try:
5773
- can_width = self.winfo_width()
5774
- can_height = self.winfo_height()
5775
- except Exception:
5776
- return False
5777
- row_pos_exists = self.row_positions != [0] and self.row_positions
5778
- col_pos_exists = self.col_positions != [0] and self.col_positions
5779
- resized_cols = False
5780
- resized_rows = False
5732
+ def _auto_resize_columns(self, can_width: float, col_pos_exists: bool) -> bool:
5781
5733
  if self.PAR.ops.auto_resize_columns and self.allow_auto_resize_columns and col_pos_exists:
5782
5734
  max_w = can_width - self.PAR.ops.empty_horizontal
5783
5735
  if self.PAR.ops.auto_resize_columns < self.PAR.ops.min_column_width:
@@ -5785,7 +5737,6 @@ class MainTable(tk.Canvas):
5785
5737
  else:
5786
5738
  min_column_width = self.PAR.ops.auto_resize_columns
5787
5739
  if (len(self.col_positions) - 1) * min_column_width < max_w:
5788
- resized_cols = True
5789
5740
  change = int((max_w - self.col_positions[-1]) / (len(self.col_positions) - 1))
5790
5741
  widths = [
5791
5742
  int(b - a) + change - 1
@@ -5802,6 +5753,10 @@ class MainTable(tk.Canvas):
5802
5753
  if i not in diffs:
5803
5754
  widths[i] -= change
5804
5755
  self.col_positions = list(accumulate(chain([0], widths)))
5756
+ return True
5757
+ return False
5758
+
5759
+ def _auto_resize_rows(self, can_height: float, row_pos_exists: bool) -> bool:
5805
5760
  if self.PAR.ops.auto_resize_rows and self.allow_auto_resize_rows and row_pos_exists:
5806
5761
  max_h = can_height - self.PAR.ops.empty_vertical
5807
5762
  if self.PAR.ops.auto_resize_rows < self.min_row_height:
@@ -5809,7 +5764,6 @@ class MainTable(tk.Canvas):
5809
5764
  else:
5810
5765
  min_row_height = self.PAR.ops.auto_resize_rows
5811
5766
  if (len(self.row_positions) - 1) * min_row_height < max_h:
5812
- resized_rows = True
5813
5767
  change = int((max_h - self.row_positions[-1]) / (len(self.row_positions) - 1))
5814
5768
  heights = [
5815
5769
  int(b - a) + change - 1
@@ -5826,6 +5780,10 @@ class MainTable(tk.Canvas):
5826
5780
  if i not in diffs:
5827
5781
  heights[i] -= change
5828
5782
  self.row_positions = list(accumulate(chain([0], heights)))
5783
+ return True
5784
+ return False
5785
+
5786
+ def _manage_scroll_bars(self, can_height: float, can_width: float) -> None:
5829
5787
  if (
5830
5788
  self.PAR.ops.auto_resize_row_index is not True
5831
5789
  and can_width >= self.col_positions[-1] + self.PAR.ops.empty_horizontal
@@ -5852,6 +5810,26 @@ class MainTable(tk.Canvas):
5852
5810
  ):
5853
5811
  self.PAR.yscroll.grid(row=0, column=2, rowspan=3, sticky="nswe")
5854
5812
  self.PAR.yscroll_showing = True
5813
+
5814
+ def main_table_redraw_grid_and_text(
5815
+ self,
5816
+ redraw_header: bool = False,
5817
+ redraw_row_index: bool = False,
5818
+ redraw_table: bool = True,
5819
+ setting_views: bool = False,
5820
+ ) -> bool:
5821
+ try:
5822
+ can_width = self.winfo_width()
5823
+ can_height = self.winfo_height()
5824
+ except Exception:
5825
+ return False
5826
+ row_pos_exists = self.row_positions != [0] and self.row_positions
5827
+ col_pos_exists = self.col_positions != [0] and self.col_positions
5828
+
5829
+ resized_cols = self._auto_resize_columns(can_width=can_width, col_pos_exists=col_pos_exists)
5830
+ resized_rows = self._auto_resize_rows(can_height=can_height, row_pos_exists=row_pos_exists)
5831
+ self._manage_scroll_bars(can_height=can_height, can_width=can_width)
5832
+
5855
5833
  last_col_line_pos = self.col_positions[-1] + 1
5856
5834
  last_row_line_pos = self.row_positions[-1] + 1
5857
5835
  scrollregion = (
@@ -5867,6 +5845,7 @@ class MainTable(tk.Canvas):
5867
5845
  self.RI.configure_scrollregion(last_row_line_pos)
5868
5846
  if setting_views:
5869
5847
  return False
5848
+
5870
5849
  scrollpos_top = self.canvasy(0)
5871
5850
  scrollpos_bot = self.canvasy(can_height)
5872
5851
  scrollpos_left = self.canvasx(0)
@@ -5894,6 +5873,7 @@ class MainTable(tk.Canvas):
5894
5873
  for widget in (self, self.RI, self.CH, self.TL):
5895
5874
  widget.update_idletasks()
5896
5875
  return False
5876
+
5897
5877
  if self.find_window.open:
5898
5878
  w, h, x, y = self.get_find_window_dimensions_coords(w_width=self.winfo_width())
5899
5879
  self.coords(self.find_window.canvas_id, x, y)
@@ -5913,79 +5893,11 @@ class MainTable(tk.Canvas):
5913
5893
  self.disp_dropdown = {}
5914
5894
  self.hidd_checkbox.update(self.disp_checkbox)
5915
5895
  self.disp_checkbox = {}
5916
- if last_col_line_pos > scrollpos_right:
5917
- x_stop = scrollpos_right
5918
- else:
5919
- x_stop = last_col_line_pos
5920
- if last_row_line_pos > scrollpos_bot:
5921
- y_stop = scrollpos_bot
5922
- else:
5923
- y_stop = last_row_line_pos
5924
- if redraw_table and self.PAR.ops.show_horizontal_grid and row_pos_exists:
5925
- if self.PAR.ops.horizontal_grid_to_end_of_window:
5926
- x_grid_stop = scrollpos_right + can_width
5927
- else:
5928
- if last_col_line_pos > scrollpos_right:
5929
- x_grid_stop = x_stop + 1
5930
- else:
5931
- x_grid_stop = x_stop - 1
5932
- points = list(
5933
- chain.from_iterable(
5934
- [
5935
- (
5936
- scrollpos_left - 1,
5937
- self.row_positions[r],
5938
- x_grid_stop,
5939
- self.row_positions[r],
5940
- scrollpos_left - 1,
5941
- self.row_positions[r],
5942
- scrollpos_left - 1,
5943
- self.row_positions[r + 1] if len(self.row_positions) - 1 > r else self.row_positions[r],
5944
- )
5945
- for r in range(grid_start_row, grid_end_row)
5946
- ]
5947
- )
5948
- )
5949
- if points:
5950
- self.redraw_gridline(
5951
- points=points,
5952
- fill=self.PAR.ops.table_grid_fg,
5953
- width=1,
5954
- tag="g",
5955
- )
5956
- if redraw_table and self.PAR.ops.show_vertical_grid and col_pos_exists:
5957
- if self.PAR.ops.vertical_grid_to_end_of_window:
5958
- y_grid_stop = scrollpos_bot + can_height
5959
- else:
5960
- if last_row_line_pos > scrollpos_bot:
5961
- y_grid_stop = y_stop + 1
5962
- else:
5963
- y_grid_stop = y_stop - 1
5964
- points = list(
5965
- chain.from_iterable(
5966
- [
5967
- (
5968
- self.col_positions[c],
5969
- scrollpos_top - 1,
5970
- self.col_positions[c],
5971
- y_grid_stop,
5972
- self.col_positions[c],
5973
- scrollpos_top - 1,
5974
- self.col_positions[c + 1] if len(self.col_positions) - 1 > c else self.col_positions[c],
5975
- scrollpos_top - 1,
5976
- )
5977
- for c in range(grid_start_col, grid_end_col)
5978
- ]
5979
- )
5980
- )
5981
- if points:
5982
- self.redraw_gridline(
5983
- points=points,
5984
- fill=self.PAR.ops.table_grid_fg,
5985
- width=1,
5986
- tag="g",
5987
- )
5896
+ x_stop = min(last_col_line_pos, scrollpos_right)
5897
+ y_stop = min(last_row_line_pos, scrollpos_bot)
5988
5898
  if redraw_table:
5899
+ font = self.PAR.ops.table_font
5900
+ dd_coords = self.dropdown.get_coords()
5989
5901
  selections = self.get_redraw_selections(text_start_row, grid_end_row, text_start_col, grid_end_col)
5990
5902
  sel_cells_bg = color_tup(self.PAR.ops.table_selected_cells_bg)
5991
5903
  sel_cols_bg = color_tup(self.PAR.ops.table_selected_columns_bg)
@@ -6007,7 +5919,6 @@ class MainTable(tk.Canvas):
6007
5919
  else:
6008
5920
  alternate_color = None
6009
5921
  dont_blend = tuple()
6010
-
6011
5922
  if not self.PAR.ops.show_selected_cells_border:
6012
5923
  override = (
6013
5924
  color_tup(self.PAR.ops.table_selected_cells_fg),
@@ -6016,22 +5927,17 @@ class MainTable(tk.Canvas):
6016
5927
  )
6017
5928
  else:
6018
5929
  override = tuple()
5930
+ for r in range(text_start_row, text_end_row):
5931
+ rtopgridln = self.row_positions[r]
5932
+ rbotgridln = self.row_positions[r + 1]
5933
+ if rbotgridln - rtopgridln < self.table_txt_height:
5934
+ continue
5935
+ datarn = self.datarn(r)
6019
5936
 
6020
- rows_ = tuple(range(text_start_row, text_end_row))
6021
- font = self.PAR.ops.table_font
6022
- dd_coords = self.dropdown.get_coords()
6023
- for c in range(text_start_col, text_end_col):
6024
- for r in rows_:
6025
- rtopgridln = self.row_positions[r]
6026
- rbotgridln = self.row_positions[r + 1]
6027
- if rbotgridln - rtopgridln < self.table_txt_height:
6028
- continue
5937
+ for c in range(text_start_col, text_end_col):
6029
5938
  cleftgridln = self.col_positions[c]
6030
5939
  crightgridln = self.col_positions[c + 1]
6031
-
6032
- datarn = self.datarn(r)
6033
5940
  datacn = self.datacn(c)
6034
-
6035
5941
  fill, dd_drawn = self.redraw_highlight_get_text_fg(
6036
5942
  r=r,
6037
5943
  c=c,
@@ -6049,69 +5955,35 @@ class MainTable(tk.Canvas):
6049
5955
  dont_blend=(r, c) == dont_blend,
6050
5956
  alternate_color=alternate_color,
6051
5957
  )
6052
- align = self.get_cell_kwargs(datarn, datacn, key="align")
6053
- if align:
6054
- align = align
6055
- else:
5958
+ if not (align := self.get_cell_kwargs(datarn, datacn, key="align")):
6056
5959
  align = self.align
6057
- kwargs = self.get_cell_kwargs(datarn, datacn, key="dropdown")
6058
- if align == "w":
6059
- draw_x = cleftgridln + 3
6060
- if kwargs:
6061
- mw = crightgridln - cleftgridln - self.table_txt_height - 2
6062
- self.redraw_dropdown(
6063
- cleftgridln,
6064
- rtopgridln,
6065
- crightgridln,
6066
- self.row_positions[r + 1],
6067
- fill=fill if kwargs["state"] != "disabled" else self.PAR.ops.table_grid_fg,
6068
- outline=fill,
6069
- tag=f"dd_{r}_{c}",
6070
- draw_outline=not dd_drawn,
6071
- draw_arrow=mw >= 5,
6072
- open_=dd_coords == (r, c),
6073
- )
6074
- else:
6075
- mw = crightgridln - cleftgridln - 1
6076
- elif align == "e":
6077
- if kwargs:
6078
- mw = crightgridln - cleftgridln - self.table_txt_height - 2
5960
+ if kwargs := self.get_cell_kwargs(datarn, datacn, key="dropdown"):
5961
+ mw = crightgridln - cleftgridln - self.table_txt_height - 2
5962
+ if align == "w":
5963
+ draw_x = cleftgridln + 3
5964
+ elif align == "e":
6079
5965
  draw_x = crightgridln - 5 - self.table_txt_height
6080
- self.redraw_dropdown(
6081
- cleftgridln,
6082
- rtopgridln,
6083
- crightgridln,
6084
- self.row_positions[r + 1],
6085
- fill=fill if kwargs["state"] != "disabled" else self.PAR.ops.table_grid_fg,
6086
- outline=fill,
6087
- tag=f"dd_{r}_{c}",
6088
- draw_outline=not dd_drawn,
6089
- draw_arrow=mw >= 5,
6090
- open_=dd_coords == (r, c),
6091
- )
6092
- else:
6093
- mw = crightgridln - cleftgridln - 1
6094
- draw_x = crightgridln - 3
6095
- elif align == "center":
6096
- if kwargs:
6097
- mw = crightgridln - cleftgridln - self.table_txt_height - 2
5966
+ elif align == "center":
6098
5967
  draw_x = cleftgridln + ceil((crightgridln - cleftgridln - self.table_txt_height) / 2)
6099
- self.redraw_dropdown(
6100
- cleftgridln,
6101
- rtopgridln,
6102
- crightgridln,
6103
- self.row_positions[r + 1],
6104
- fill=fill if kwargs["state"] != "disabled" else self.PAR.ops.table_grid_fg,
6105
- outline=fill,
6106
- tag=f"dd_{r}_{c}",
6107
- draw_outline=not dd_drawn,
6108
- draw_arrow=mw >= 5,
6109
- open_=dd_coords == (r, c),
6110
- )
6111
- else:
6112
- mw = crightgridln - cleftgridln - 1
5968
+ self.redraw_dropdown(
5969
+ cleftgridln,
5970
+ rtopgridln,
5971
+ crightgridln,
5972
+ self.row_positions[r + 1],
5973
+ fill=fill if kwargs["state"] != "disabled" else self.PAR.ops.table_grid_fg,
5974
+ outline=fill,
5975
+ draw_outline=not dd_drawn,
5976
+ draw_arrow=mw >= 5,
5977
+ open_=dd_coords == (r, c),
5978
+ )
5979
+ else:
5980
+ mw = crightgridln - cleftgridln - 1
5981
+ if align == "w":
5982
+ draw_x = cleftgridln + 3
5983
+ elif align == "e":
5984
+ draw_x = crightgridln - 3
5985
+ elif align == "center":
6113
5986
  draw_x = cleftgridln + floor((crightgridln - cleftgridln) / 2)
6114
- if not kwargs:
6115
5987
  kwargs = self.get_cell_kwargs(datarn, datacn, key="checkbox")
6116
5988
  if kwargs and mw > self.table_txt_height + 1:
6117
5989
  box_w = self.table_txt_height + 1
@@ -6121,7 +5993,7 @@ class MainTable(tk.Canvas):
6121
5993
  draw_x += ceil(box_w / 2) + 1
6122
5994
  mw -= box_w + 3
6123
5995
  try:
6124
- draw_check = self.data[datarn][datacn]
5996
+ draw_check = bool(self.data[datarn][datacn])
6125
5997
  except Exception:
6126
5998
  draw_check = False
6127
5999
  self.redraw_checkbox(
@@ -6131,92 +6003,137 @@ class MainTable(tk.Canvas):
6131
6003
  rtopgridln + self.table_txt_height + 3,
6132
6004
  fill=fill if kwargs["state"] == "normal" else self.PAR.ops.table_grid_fg,
6133
6005
  outline="",
6134
- tag="cb",
6135
6006
  draw_check=draw_check,
6136
6007
  )
6137
- lns = self.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True).split("\n")
6008
+ lines = self.get_valid_cell_data_as_str(datarn, datacn, get_displayed=True)
6138
6009
  if (
6139
- lns != [""]
6140
- and mw > self.table_txt_width
6141
- and not (
6142
- (align == "w" and draw_x > scrollpos_right)
6143
- or (align == "e" and cleftgridln + 5 > scrollpos_right)
6144
- or (align == "center" and cleftgridln + 5 > scrollpos_right)
6145
- )
6010
+ not lines
6011
+ or mw < self.table_txt_width
6012
+ or (align == "w" and draw_x > scrollpos_right)
6013
+ or (align == "e" and cleftgridln + 5 > scrollpos_right)
6014
+ or (align == "center" and cleftgridln + 5 > scrollpos_right)
6146
6015
  ):
6147
- draw_y = rtopgridln + self.table_first_ln_ins
6148
- start_ln = int((scrollpos_top - rtopgridln) / self.table_xtra_lines_increment)
6149
- if start_ln < 0:
6150
- start_ln = 0
6151
- draw_y += start_ln * self.table_xtra_lines_increment
6152
- if draw_y + self.table_half_txt_height - 1 <= rbotgridln and len(lns) > start_ln:
6153
- for txt in islice(lns, start_ln, None):
6154
- if self.hidd_text:
6155
- iid, showing = self.hidd_text.popitem()
6156
- self.coords(iid, draw_x, draw_y)
6157
- if showing:
6158
- self.itemconfig(
6159
- iid,
6160
- text=txt,
6161
- fill=fill,
6162
- font=font,
6163
- anchor=align,
6164
- )
6165
- else:
6166
- self.itemconfig(
6167
- iid,
6168
- text=txt,
6169
- fill=fill,
6170
- font=font,
6171
- anchor=align,
6172
- state="normal",
6173
- )
6174
- self.tag_raise(iid)
6016
+ continue
6017
+ lines = lines.split("\n")
6018
+ start_ln = max(0, int((scrollpos_top - rtopgridln) / self.table_xtra_lines_increment))
6019
+ draw_y = rtopgridln + self.table_first_ln_ins + start_ln * self.table_xtra_lines_increment
6020
+ if draw_y + self.table_half_txt_height - 1 <= rbotgridln and len(lines) >= start_ln:
6021
+ for txt in islice(lines, start_ln, None):
6022
+ if self.hidd_text:
6023
+ iid, showing = self.hidd_text.popitem()
6024
+ self.coords(iid, draw_x, draw_y)
6025
+ if showing:
6026
+ self.itemconfig(
6027
+ iid,
6028
+ text=txt,
6029
+ fill=fill,
6030
+ font=font,
6031
+ anchor=align,
6032
+ )
6175
6033
  else:
6176
- iid = self.create_text(
6177
- draw_x,
6178
- draw_y,
6034
+ self.itemconfig(
6035
+ iid,
6179
6036
  text=txt,
6180
6037
  fill=fill,
6181
6038
  font=font,
6182
6039
  anchor=align,
6183
- tag="t",
6040
+ state="normal",
6184
6041
  )
6185
- self.disp_text[iid] = True
6186
- wd = self.bbox(iid)
6187
- wd = wd[2] - wd[0]
6188
- if wd > mw:
6189
- if align == "w":
6190
- txt = txt[: int(len(txt) * (mw / wd))]
6042
+ self.tag_raise(iid)
6043
+ else:
6044
+ iid = self.create_text(
6045
+ draw_x,
6046
+ draw_y,
6047
+ text=txt,
6048
+ fill=fill,
6049
+ font=font,
6050
+ anchor=align,
6051
+ tag="t",
6052
+ )
6053
+ self.disp_text[iid] = True
6054
+ wd = self.bbox(iid)
6055
+ if (wd := wd[2] - wd[0]) > mw:
6056
+ if align == "w":
6057
+ txt = txt[: int(len(txt) * (mw / wd))]
6058
+ self.itemconfig(iid, text=txt)
6059
+ wd = self.bbox(iid)
6060
+ while wd[2] - wd[0] > mw:
6061
+ txt = txt[:-1]
6191
6062
  self.itemconfig(iid, text=txt)
6192
6063
  wd = self.bbox(iid)
6193
- while wd[2] - wd[0] > mw:
6194
- txt = txt[:-1]
6195
- self.itemconfig(iid, text=txt)
6196
- wd = self.bbox(iid)
6197
- elif align == "e":
6198
- txt = txt[len(txt) - int(len(txt) * (mw / wd)) :]
6064
+ elif align == "e":
6065
+ txt = txt[len(txt) - int(len(txt) * (mw / wd)) :]
6066
+ self.itemconfig(iid, text=txt)
6067
+ wd = self.bbox(iid)
6068
+ while wd[2] - wd[0] > mw:
6069
+ txt = txt[1:]
6199
6070
  self.itemconfig(iid, text=txt)
6200
6071
  wd = self.bbox(iid)
6201
- while wd[2] - wd[0] > mw:
6202
- txt = txt[1:]
6203
- self.itemconfig(iid, text=txt)
6204
- wd = self.bbox(iid)
6205
- elif align == "center":
6206
- self.c_align_cyc = cycle(self.centre_alignment_text_mod_indexes)
6207
- tmod = ceil((len(txt) - int(len(txt) * (mw / wd))) / 2)
6208
- txt = txt[tmod - 1 : -tmod]
6072
+ elif align == "center":
6073
+ tmod = ceil((len(txt) - int(len(txt) * (mw / wd))) / 2)
6074
+ txt = txt[tmod - 1 : -tmod]
6075
+ self.itemconfig(iid, text=txt)
6076
+ wd = self.bbox(iid)
6077
+ while wd[2] - wd[0] > mw:
6078
+ txt = txt[next(self.c_align_cyc)]
6209
6079
  self.itemconfig(iid, text=txt)
6210
6080
  wd = self.bbox(iid)
6211
- while wd[2] - wd[0] > mw:
6212
- txt = txt[next(self.c_align_cyc)]
6213
- self.itemconfig(iid, text=txt)
6214
- wd = self.bbox(iid)
6215
- self.coords(iid, draw_x, draw_y)
6216
- draw_y += self.table_xtra_lines_increment
6217
- if draw_y + self.table_half_txt_height - 1 > rbotgridln:
6218
- break
6219
- if redraw_table:
6081
+ self.coords(iid, draw_x, draw_y)
6082
+ draw_y += self.table_xtra_lines_increment
6083
+ if draw_y + self.table_half_txt_height - 1 > rbotgridln:
6084
+ break
6085
+ # manage horizontal grid lines
6086
+ if self.PAR.ops.show_horizontal_grid and row_pos_exists:
6087
+ if self.PAR.ops.horizontal_grid_to_end_of_window:
6088
+ x_grid_stop = scrollpos_right + can_width
6089
+ else:
6090
+ if last_col_line_pos > scrollpos_right:
6091
+ x_grid_stop = x_stop + 1
6092
+ else:
6093
+ x_grid_stop = x_stop - 1
6094
+ self.redraw_gridline(
6095
+ points=tuple(
6096
+ chain.from_iterable(
6097
+ (
6098
+ scrollpos_left - 1,
6099
+ self.row_positions[r],
6100
+ x_grid_stop,
6101
+ self.row_positions[r],
6102
+ scrollpos_left - 1,
6103
+ self.row_positions[r],
6104
+ scrollpos_left - 1,
6105
+ self.row_positions[r + 1] if len(self.row_positions) - 1 > r else self.row_positions[r],
6106
+ )
6107
+ for r in range(grid_start_row, grid_end_row)
6108
+ )
6109
+ )
6110
+ )
6111
+ # manage vertical grid lines
6112
+ if self.PAR.ops.show_vertical_grid and col_pos_exists:
6113
+ if self.PAR.ops.vertical_grid_to_end_of_window:
6114
+ y_grid_stop = scrollpos_bot + can_height
6115
+ else:
6116
+ if last_row_line_pos > scrollpos_bot:
6117
+ y_grid_stop = y_stop + 1
6118
+ else:
6119
+ y_grid_stop = y_stop - 1
6120
+ self.redraw_gridline(
6121
+ points=tuple(
6122
+ chain.from_iterable(
6123
+ (
6124
+ self.col_positions[c],
6125
+ scrollpos_top - 1,
6126
+ self.col_positions[c],
6127
+ y_grid_stop,
6128
+ self.col_positions[c],
6129
+ scrollpos_top - 1,
6130
+ self.col_positions[c + 1] if len(self.col_positions) - 1 > c else self.col_positions[c],
6131
+ scrollpos_top - 1,
6132
+ )
6133
+ for c in range(grid_start_col, grid_end_col)
6134
+ )
6135
+ ),
6136
+ )
6220
6137
  for dct in (
6221
6138
  self.hidd_text,
6222
6139
  self.hidd_high,
@@ -6234,6 +6151,10 @@ class MainTable(tk.Canvas):
6234
6151
  self.tag_raise(box.bd_iid)
6235
6152
  if self.selected:
6236
6153
  self.tag_raise(self.selected.iid)
6154
+ if self.RI.disp_resize_lines:
6155
+ self.tag_raise("rh")
6156
+ if self.CH.disp_resize_lines:
6157
+ self.tag_raise("rw")
6237
6158
  if redraw_header and self.show_header:
6238
6159
  self.CH.redraw_grid_and_text(
6239
6160
  last_col_line_pos=last_col_line_pos,
@@ -6313,7 +6234,7 @@ class MainTable(tk.Canvas):
6313
6234
  # set current to a particular existing selection box
6314
6235
  if isinstance(item, int) and item in self.selection_boxes:
6315
6236
  selection_box = self.selection_boxes[item]
6316
- r1, c1, r2, c2 = selection_box.coords
6237
+ r1, c1, _, _ = selection_box.coords
6317
6238
  if box_created(r1 if r is None else r, c1 if c is None else c, selection_box):
6318
6239
  return
6319
6240
 
@@ -6732,7 +6653,7 @@ class MainTable(tk.Canvas):
6732
6653
 
6733
6654
  def get_redraw_selections(self, startr: int, endr: int, startc: int, endc: int) -> dict:
6734
6655
  d = defaultdict(set)
6735
- for item, box in self.get_selection_items():
6656
+ for _, box in self.get_selection_items():
6736
6657
  r1, c1, r2, c2 = box.coords
6737
6658
  if box.type_ == "cells":
6738
6659
  for r in range(startr, endr):
@@ -6770,7 +6691,7 @@ class MainTable(tk.Canvas):
6770
6691
  if get_cells:
6771
6692
  s = {
6772
6693
  (r, c)
6773
- for item, box in self.get_selection_items(cells=False, columns=False)
6694
+ for _, box in self.get_selection_items(cells=False, columns=False)
6774
6695
  for r in range(box.coords.from_r, box.coords.upto_r)
6775
6696
  for c in range(0, len(self.col_positions) - 1)
6776
6697
  }
@@ -6779,7 +6700,7 @@ class MainTable(tk.Canvas):
6779
6700
  else:
6780
6701
  s = {
6781
6702
  r
6782
- for item, box in self.get_selection_items(cells=False, columns=False)
6703
+ for _, box in self.get_selection_items(cells=False, columns=False)
6783
6704
  for r in range(box.coords.from_r, box.coords.upto_r)
6784
6705
  }
6785
6706
  if get_cells_as_rows:
@@ -6794,7 +6715,7 @@ class MainTable(tk.Canvas):
6794
6715
  if get_cells:
6795
6716
  s = {
6796
6717
  (r, c)
6797
- for item, box in self.get_selection_items(cells=False, rows=False)
6718
+ for _, box in self.get_selection_items(cells=False, rows=False)
6798
6719
  for r in range(0, len(self.row_positions) - 1)
6799
6720
  for c in range(box.coords.from_c, box.coords.upto_c)
6800
6721
  }
@@ -6803,7 +6724,7 @@ class MainTable(tk.Canvas):
6803
6724
  else:
6804
6725
  s = {
6805
6726
  c
6806
- for item, box in self.get_selection_items(cells=False, rows=False)
6727
+ for _, box in self.get_selection_items(cells=False, rows=False)
6807
6728
  for c in range(box.coords.from_c, box.coords.upto_c)
6808
6729
  }
6809
6730
  if get_cells_as_cols:
@@ -6817,7 +6738,7 @@ class MainTable(tk.Canvas):
6817
6738
  ) -> set[tuple[int, int]]:
6818
6739
  return {
6819
6740
  (r, c)
6820
- for item, box in self.get_selection_items(rows=get_rows, columns=get_cols)
6741
+ for _, box in self.get_selection_items(rows=get_rows, columns=get_cols)
6821
6742
  for r in range(box.coords.from_r, box.coords.upto_r)
6822
6743
  for c in range(box.coords.from_c, box.coords.upto_c)
6823
6744
  }
@@ -6829,16 +6750,16 @@ class MainTable(tk.Canvas):
6829
6750
  ) -> Generator[tuple[int, int]]:
6830
6751
  yield from (
6831
6752
  (r, c)
6832
- for item, box in self.get_selection_items(rows=get_rows, columns=get_cols)
6753
+ for _, box in self.get_selection_items(rows=get_rows, columns=get_cols)
6833
6754
  for r in range(box.coords.from_r, box.coords.upto_r)
6834
6755
  for c in range(box.coords.from_c, box.coords.upto_c)
6835
6756
  )
6836
6757
 
6837
6758
  def get_all_selection_boxes(self) -> tuple[tuple[int, int, int, int]]:
6838
- return tuple(box.coords for item, box in self.get_selection_items())
6759
+ return tuple(box.coords for _, box in self.get_selection_items())
6839
6760
 
6840
6761
  def get_all_selection_boxes_with_types(self) -> list[tuple[tuple[int, int, int, int], str]]:
6841
- return [Box_st(box.coords, box.type_) for item, box in self.get_selection_items()]
6762
+ return [Box_st(box.coords, box.type_) for _, box in self.get_selection_items()]
6842
6763
 
6843
6764
  def all_selected(self) -> bool:
6844
6765
  return any(
@@ -6858,7 +6779,7 @@ class MainTable(tk.Canvas):
6858
6779
  and isinstance(c, int)
6859
6780
  and any(
6860
6781
  box.coords.from_r <= r and box.coords.upto_r > r and box.coords.from_c <= c and box.coords.upto_c > c
6861
- for item, box in self.get_selection_items(
6782
+ for _, box in self.get_selection_items(
6862
6783
  rows=inc_rows,
6863
6784
  columns=inc_cols,
6864
6785
  )
@@ -6868,7 +6789,7 @@ class MainTable(tk.Canvas):
6868
6789
  def col_selected(self, c: int, cells: bool = False) -> bool:
6869
6790
  return isinstance(c, int) and any(
6870
6791
  box.coords.from_c <= c and box.coords.upto_c > c
6871
- for item, box in self.get_selection_items(
6792
+ for _, box in self.get_selection_items(
6872
6793
  cells=cells,
6873
6794
  rows=False,
6874
6795
  )
@@ -6877,7 +6798,7 @@ class MainTable(tk.Canvas):
6877
6798
  def row_selected(self, r: int, cells: bool = False) -> bool:
6878
6799
  return isinstance(r, int) and any(
6879
6800
  box.coords.from_r <= r and box.coords.upto_r > r
6880
- for item, box in self.get_selection_items(
6801
+ for _, box in self.get_selection_items(
6881
6802
  cells=cells,
6882
6803
  columns=False,
6883
6804
  )
@@ -6891,7 +6812,7 @@ class MainTable(tk.Canvas):
6891
6812
  ) -> list[int]:
6892
6813
  return [
6893
6814
  item
6894
- for item, box in self.get_selection_items(
6815
+ for item, _ in self.get_selection_items(
6895
6816
  columns=not exclude_columns,
6896
6817
  rows=not exclude_rows,
6897
6818
  cells=not exclude_cells,
@@ -7049,10 +6970,10 @@ class MainTable(tk.Canvas):
7049
6970
  )
7050
6971
  > curr_height
7051
6972
  ):
7052
- new_height = curr_height + self.table_xtra_lines_increment
7053
- space_bot = self.get_space_bot(r)
7054
- if new_height > space_bot:
7055
- new_height = space_bot
6973
+ new_height = min(
6974
+ curr_height + self.table_xtra_lines_increment,
6975
+ self.scrollregion[3] - self.scrollregion[1] - self.row_positions[r],
6976
+ )
7056
6977
  if new_height != curr_height:
7057
6978
  self.text_editor.window.config(height=new_height)
7058
6979
  if self.dropdown.open and self.dropdown.get_coords() == (r, c):
@@ -7287,10 +7208,8 @@ class MainTable(tk.Canvas):
7287
7208
  sheet_h = int(
7288
7209
  self.row_positions[-1] + 1 + self.PAR.ops.empty_vertical - (self.row_positions[r] + text_editor_h)
7289
7210
  )
7290
- if win_h > 0:
7291
- win_h -= 1
7292
- if sheet_h > 0:
7293
- sheet_h -= 1
7211
+ win_h = max(0, win_h - 1)
7212
+ sheet_h = max(0, sheet_h - 1)
7294
7213
  return win_h if win_h >= sheet_h else sheet_h
7295
7214
 
7296
7215
  def get_dropdown_height_anchor(self, r: int, c: int, text_editor_h: int | None = None) -> tuple:
@@ -7304,8 +7223,7 @@ class MainTable(tk.Canvas):
7304
7223
  win_h += self.min_row_height
7305
7224
  if i == 5:
7306
7225
  break
7307
- if win_h > 500:
7308
- win_h = 500
7226
+ win_h = min(win_h, 500)
7309
7227
  space_bot = self.get_space_bot(r, text_editor_h)
7310
7228
  space_top = int(self.row_positions[r])
7311
7229
  anchor = "nw"
@@ -7395,7 +7313,7 @@ class MainTable(tk.Canvas):
7395
7313
  self.itemconfig(self.dropdown.canvas_id, state="normal", anchor=anchor)
7396
7314
  self.dropdown.window.tkraise()
7397
7315
  else:
7398
- self.dropdown.window = self.PAR.dropdown_class(
7316
+ self.dropdown.window = self.PAR._dropdown_cls(
7399
7317
  self.winfo_toplevel(),
7400
7318
  **reset_kwargs,
7401
7319
  close_dropdown_window=self.close_dropdown_window,
@@ -7440,12 +7358,11 @@ class MainTable(tk.Canvas):
7440
7358
  datacn = self.datacn(c)
7441
7359
  datarn = self.datarn(r)
7442
7360
  kwargs = self.get_cell_kwargs(datarn, datacn, key="dropdown")
7443
- pre_edit_value = self.get_cell_data(datarn, datacn)
7444
7361
  event_data = event_dict(
7445
7362
  name="end_edit_table",
7446
7363
  sheet=self.PAR.name,
7447
7364
  widget=self,
7448
- cells_table={(datarn, datacn): pre_edit_value},
7365
+ cells_table={(datarn, datacn): self.get_cell_data(datarn, datacn)},
7449
7366
  key="??",
7450
7367
  value=selection,
7451
7368
  loc=Loc(r, c),
@@ -7454,30 +7371,12 @@ class MainTable(tk.Canvas):
7454
7371
  boxes=self.get_boxes(),
7455
7372
  selected=self.selected,
7456
7373
  )
7457
- if kwargs["select_function"] is not None:
7458
- kwargs["select_function"](event_data)
7459
- if self.edit_validation_func:
7460
- selection, edited = self.edit_validation_func(event_data), False
7461
- if selection is not None:
7462
- edited = self.set_cell_data_undo(
7463
- r,
7464
- c,
7465
- datarn=datarn,
7466
- datacn=datacn,
7467
- value=selection,
7468
- redraw=not redraw,
7469
- )
7470
- else:
7471
- edited = self.set_cell_data_undo(
7472
- r,
7473
- c,
7474
- datarn=datarn,
7475
- datacn=datacn,
7476
- value=selection,
7477
- redraw=not redraw,
7478
- )
7479
- if edited:
7480
- try_binding(self.extra_end_edit_cell_func, event_data)
7374
+ try_binding(kwargs["select_function"], event_data)
7375
+ selection = selection if not self.edit_validation_func else self.edit_validation_func(event_data)
7376
+ if selection is not None:
7377
+ edited = self.set_cell_data_undo(r, c, datarn=datarn, datacn=datacn, value=selection, redraw=not redraw)
7378
+ if edited:
7379
+ try_binding(self.extra_end_edit_cell_func, event_data)
7481
7380
  self.recreate_all_selection_boxes()
7482
7381
  self.focus_set()
7483
7382
  self.hide_text_editor_and_dropdown(redraw=redraw)