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/main_table.py CHANGED
@@ -1851,9 +1851,10 @@ class MainTable(tk.Canvas):
1851
1851
  c: int,
1852
1852
  redraw: bool = False,
1853
1853
  run_binding_func: bool = True,
1854
+ ext: bool = False,
1854
1855
  ) -> int:
1855
1856
  self.deselect("all", redraw=False)
1856
- fill_iid = self.create_selection_box(r, c, r + 1, c + 1, state="hidden")
1857
+ fill_iid = self.create_selection_box(r, c, r + 1, c + 1, state="hidden", ext=ext)
1857
1858
  if redraw:
1858
1859
  self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
1859
1860
  if run_binding_func:
@@ -1867,8 +1868,9 @@ class MainTable(tk.Canvas):
1867
1868
  redraw: bool = False,
1868
1869
  run_binding_func: bool = True,
1869
1870
  set_as_current: bool = False,
1871
+ ext: bool = False,
1870
1872
  ) -> int:
1871
- fill_iid = self.create_selection_box(r, c, r + 1, c + 1, state="hidden", set_current=set_as_current)
1873
+ fill_iid = self.create_selection_box(r, c, r + 1, c + 1, state="hidden", set_current=set_as_current, ext=ext)
1872
1874
  if redraw:
1873
1875
  self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True)
1874
1876
  if run_binding_func:
@@ -1883,6 +1885,7 @@ class MainTable(tk.Canvas):
1883
1885
  redraw: bool = True,
1884
1886
  run_binding_func: bool = True,
1885
1887
  set_as_current: bool = True,
1888
+ ext: bool = False,
1886
1889
  ) -> int | None:
1887
1890
  if add_selection:
1888
1891
  if self.cell_selected(row, column, inc_rows=True, inc_cols=True):
@@ -1894,12 +1897,13 @@ class MainTable(tk.Canvas):
1894
1897
  redraw=redraw,
1895
1898
  run_binding_func=run_binding_func,
1896
1899
  set_as_current=set_as_current,
1900
+ ext=ext,
1897
1901
  )
1898
1902
  else:
1899
1903
  if self.cell_selected(row, column, inc_rows=True, inc_cols=True):
1900
1904
  fill_iid = self.deselect(r=row, c=column, redraw=redraw)
1901
1905
  else:
1902
- fill_iid = self.select_cell(row, column, redraw=redraw)
1906
+ fill_iid = self.select_cell(row, column, redraw=redraw, ext=ext)
1903
1907
  return fill_iid
1904
1908
 
1905
1909
  def get_select_event(self, being_drawn_item: None | int = None) -> EventDataDict:
@@ -3527,7 +3531,7 @@ class MainTable(tk.Canvas):
3527
3531
  self.table_first_ln_ins = self.table_half_txt_height + 2
3528
3532
  else:
3529
3533
  self.table_first_ln_ins = self.table_half_txt_height + 3
3530
- self.min_row_height = int(self.table_first_ln_ins * 2.25)
3534
+ self.min_row_height = int(self.table_first_ln_ins * 2.22)
3531
3535
  self.table_xtra_lines_increment = int(self.table_txt_height)
3532
3536
  if self.min_row_height < 12:
3533
3537
  self.min_row_height = 12
@@ -3556,7 +3560,7 @@ class MainTable(tk.Canvas):
3556
3560
  else:
3557
3561
  self.header_first_ln_ins = self.header_half_txt_height + 3
3558
3562
  self.header_xtra_lines_increment = self.header_txt_height
3559
- self.min_header_height = int(self.header_first_ln_ins * 2.25)
3563
+ self.min_header_height = int(self.header_first_ln_ins * 2.22)
3560
3564
  if (
3561
3565
  isinstance(self.PAR.ops.default_header_height, int)
3562
3566
  and self.PAR.ops.default_header_height < self.min_header_height
@@ -3638,7 +3642,7 @@ class MainTable(tk.Canvas):
3638
3642
  return w + self.table_txt_height, h
3639
3643
  return w, h
3640
3644
 
3641
- def set_cell_size_to_text(self, r, c, only_set_if_too_small=False, redraw: bool = True, run_binding=False):
3645
+ def set_cell_size_to_text(self, r, c, only_if_too_small=False, redraw: bool = True, run_binding=False):
3642
3646
  min_column_width = int(self.min_column_width)
3643
3647
  min_rh = int(self.min_row_height)
3644
3648
  w = min_column_width
@@ -3658,7 +3662,7 @@ class MainTable(tk.Canvas):
3658
3662
  w = int(self.max_column_width)
3659
3663
  cell_needs_resize_w = False
3660
3664
  cell_needs_resize_h = False
3661
- if only_set_if_too_small:
3665
+ if only_if_too_small:
3662
3666
  if w > self.col_positions[c + 1] - self.col_positions[c]:
3663
3667
  cell_needs_resize_w = True
3664
3668
  if h > self.row_positions[r + 1] - self.row_positions[r]:
@@ -3788,24 +3792,26 @@ class MainTable(tk.Canvas):
3788
3792
 
3789
3793
  def reset_col_positions(self, ncols: int | None = None):
3790
3794
  colpos = self.PAR.ops.default_column_width
3791
- if self.all_columns_displayed:
3792
- self.set_col_positions(itr=(colpos for c in range(ncols if ncols is not None else self.total_data_cols())))
3795
+ if isinstance(ncols, int):
3796
+ self.set_col_positions(itr=repeat(colpos, ncols))
3793
3797
  else:
3794
- self.set_col_positions(
3795
- itr=(colpos for c in range(ncols if ncols is not None else len(self.displayed_columns)))
3796
- )
3798
+ if self.all_columns_displayed:
3799
+ self.set_col_positions(itr=repeat(colpos, self.total_data_cols()))
3800
+ else:
3801
+ self.set_col_positions(itr=repeat(colpos, len(self.displayed_columns)))
3797
3802
 
3798
3803
  def set_row_positions(self, itr: Iterator[float]) -> None:
3799
3804
  self.row_positions = list(accumulate(chain([0], itr)))
3800
3805
 
3801
3806
  def reset_row_positions(self, nrows: int | None = None):
3802
3807
  rowpos = self.get_default_row_height()
3803
- if self.all_rows_displayed:
3804
- self.set_row_positions(itr=(rowpos for r in range(nrows if nrows is not None else self.total_data_rows())))
3808
+ if isinstance(nrows, int):
3809
+ self.set_row_positions(itr=repeat(rowpos, nrows))
3805
3810
  else:
3806
- self.set_row_positions(
3807
- itr=(rowpos for r in range(nrows if nrows is not None else len(self.displayed_rows)))
3808
- )
3811
+ if self.all_rows_displayed:
3812
+ self.set_row_positions(itr=repeat(rowpos, self.total_data_rows()))
3813
+ else:
3814
+ self.set_row_positions(itr=repeat(rowpos, len(self.displayed_rows)))
3809
3815
 
3810
3816
  def del_col_position(self, idx: int, deselect_all: bool = False):
3811
3817
  if deselect_all:
@@ -4335,7 +4341,7 @@ class MainTable(tk.Canvas):
4335
4341
  self.set_row_positions(
4336
4342
  itr=chain(
4337
4343
  self.gen_row_heights(),
4338
- (default_row_height for i in range(len(self.row_positions) - 1, maxrn + 1)),
4344
+ repeat(default_row_height, len(self.row_positions) - 1, maxrn + 1),
4339
4345
  )
4340
4346
  )
4341
4347
  if isinstance(self._headers, list) and header:
@@ -4470,7 +4476,7 @@ class MainTable(tk.Canvas):
4470
4476
  self.set_col_positions(
4471
4477
  itr=chain(
4472
4478
  self.gen_column_widths(),
4473
- (self.PAR.ops.default_column_width for i in range(len(self.col_positions) - 1, maxcn + 1)),
4479
+ repeat(self.PAR.ops.default_column_width, len(self.col_positions) - 1, maxcn + 1),
4474
4480
  )
4475
4481
  )
4476
4482
  if push_ops:
@@ -5011,19 +5017,21 @@ class MainTable(tk.Canvas):
5011
5017
  self.canvasy(self.winfo_height()),
5012
5018
  )
5013
5019
 
5014
- def get_visible_rows(self, y1: int | float, y2: int | float) -> tuple[int, int]:
5015
- start_row = bisect_left(self.row_positions, y1)
5016
- end_row = bisect_right(self.row_positions, y2)
5017
- if not y2 >= self.row_positions[-1]:
5018
- end_row += 1
5019
- return start_row, end_row
5020
-
5021
- def get_visible_columns(self, x1: int | float, x2: int | float) -> tuple[int, int]:
5022
- start_col = bisect_left(self.col_positions, x1)
5023
- end_col = bisect_right(self.col_positions, x2)
5024
- if not x2 >= self.col_positions[-1]:
5025
- end_col += 1
5026
- return start_col, end_col
5020
+ @property
5021
+ def visible_text_rows(self) -> tuple[int, int]:
5022
+ start = bisect_left(self.row_positions, self.canvasy(0))
5023
+ end = bisect_right(self.row_positions, self.canvasy(self.winfo_height()))
5024
+ start = start - 1 if start else start
5025
+ end = end - 1 if end == len(self.row_positions) else end
5026
+ return start, end
5027
+
5028
+ @property
5029
+ def visible_text_columns(self) -> tuple[int, int]:
5030
+ start = bisect_left(self.col_positions, self.canvasx(0))
5031
+ end = bisect_right(self.col_positions, self.canvasx(self.winfo_width()))
5032
+ start = start - 1 if start else start
5033
+ end = end - 1 if end == len(self.col_positions) else end
5034
+ return start, end
5027
5035
 
5028
5036
  def redraw_highlight_get_text_fg(
5029
5037
  self,
@@ -5370,21 +5378,26 @@ class MainTable(tk.Canvas):
5370
5378
  self.RI.configure_scrollregion(last_row_line_pos)
5371
5379
  if setting_views:
5372
5380
  return False
5381
+ scrollpos_top = self.canvasy(0)
5373
5382
  scrollpos_bot = self.canvasy(can_height)
5374
- end_row = bisect_right(self.row_positions, scrollpos_bot)
5375
- if not scrollpos_bot >= self.row_positions[-1]:
5376
- end_row += 1
5377
5383
  scrollpos_left = self.canvasx(0)
5378
- scrollpos_top = self.canvasy(0)
5379
5384
  scrollpos_right = self.canvasx(can_width)
5380
- start_row = bisect_left(self.row_positions, scrollpos_top)
5381
- start_col = bisect_left(self.col_positions, scrollpos_left)
5382
- end_col = bisect_right(self.col_positions, scrollpos_right)
5385
+
5386
+ grid_start_row = bisect_left(self.row_positions, scrollpos_top)
5387
+ grid_end_row = bisect_right(self.row_positions, scrollpos_bot)
5388
+ grid_start_col = bisect_left(self.col_positions, scrollpos_left)
5389
+ grid_end_col = bisect_right(self.col_positions, scrollpos_right)
5390
+
5391
+ text_start_row = grid_start_row - 1 if grid_start_row else grid_start_row
5392
+ text_end_row = grid_end_row - 1 if grid_end_row == len(self.row_positions) else grid_end_row
5393
+ text_start_col = grid_start_col - 1 if grid_start_col else grid_start_col
5394
+ text_end_col = grid_end_col - 1 if grid_end_col == len(self.col_positions) else grid_end_col
5395
+
5383
5396
  changed_w = False
5384
5397
  if self.PAR.ops.auto_resize_row_index and redraw_row_index and self.show_index:
5385
5398
  changed_w = self.RI.auto_set_index_width(
5386
- end_row=end_row - 1,
5387
- only_rows=[self.datarn(r) for r in range(start_row if not start_row else start_row - 1, end_row - 1)],
5399
+ end_row=grid_end_row,
5400
+ only_rows=[self.datarn(r) for r in range(text_start_row, text_end_row)],
5388
5401
  )
5389
5402
  if resized_cols or resized_rows or changed_w:
5390
5403
  self.recreate_all_selection_boxes()
@@ -5404,8 +5417,6 @@ class MainTable(tk.Canvas):
5404
5417
  self.disp_dropdown = {}
5405
5418
  self.hidd_checkbox.update(self.disp_checkbox)
5406
5419
  self.disp_checkbox = {}
5407
- if not scrollpos_right >= self.col_positions[-1]:
5408
- end_col += 1
5409
5420
  if last_col_line_pos > scrollpos_right:
5410
5421
  x_stop = scrollpos_right
5411
5422
  else:
@@ -5435,7 +5446,7 @@ class MainTable(tk.Canvas):
5435
5446
  self.canvasx(0) - 1,
5436
5447
  self.row_positions[r + 1] if len(self.row_positions) - 1 > r else self.row_positions[r],
5437
5448
  )
5438
- for r in range(start_row - 1, end_row)
5449
+ for r in range(grid_start_row, grid_end_row)
5439
5450
  ]
5440
5451
  )
5441
5452
  )
@@ -5467,7 +5478,7 @@ class MainTable(tk.Canvas):
5467
5478
  self.col_positions[c + 1] if len(self.col_positions) - 1 > c else self.col_positions[c],
5468
5479
  scrollpos_top - 1,
5469
5480
  )
5470
- for c in range(start_col - 1, end_col)
5481
+ for c in range(grid_start_col, grid_end_col)
5471
5482
  ]
5472
5483
  )
5473
5484
  )
@@ -5478,13 +5489,8 @@ class MainTable(tk.Canvas):
5478
5489
  width=1,
5479
5490
  tag="g",
5480
5491
  )
5481
- if start_row > 0:
5482
- start_row -= 1
5483
- if start_col > 0:
5484
- start_col -= 1
5485
- end_row -= 1
5486
5492
  if redraw_table:
5487
- selections = self.get_redraw_selections(start_row, end_row, start_col, end_col)
5493
+ selections = self.get_redraw_selections(text_start_row, grid_end_row, text_start_col, grid_end_col)
5488
5494
  c_2 = (
5489
5495
  self.PAR.ops.table_selected_cells_bg
5490
5496
  if self.PAR.ops.table_selected_cells_bg.startswith("#")
@@ -5503,10 +5509,10 @@ class MainTable(tk.Canvas):
5503
5509
  else color_map[self.PAR.ops.table_selected_rows_bg]
5504
5510
  )
5505
5511
  c_4_ = (int(c_4[1:3], 16), int(c_4[3:5], 16), int(c_4[5:], 16))
5506
- rows_ = tuple(range(start_row, end_row))
5512
+ rows_ = tuple(range(text_start_row, text_end_row))
5507
5513
  font = self.PAR.ops.table_font
5508
5514
  dd_coords = self.dropdown.get_coords()
5509
- for c in range(start_col, end_col - 1):
5515
+ for c in range(text_start_col, text_end_col):
5510
5516
  for r in rows_:
5511
5517
  rtopgridln = self.row_positions[r]
5512
5518
  rbotgridln = self.row_positions[r + 1]
@@ -5714,23 +5720,27 @@ class MainTable(tk.Canvas):
5714
5720
  self.tag_raise(self.selected.iid)
5715
5721
  if redraw_header and self.show_header:
5716
5722
  self.CH.redraw_grid_and_text(
5717
- last_col_line_pos,
5718
- scrollpos_left,
5719
- x_stop,
5720
- start_col,
5721
- end_col,
5722
- scrollpos_right,
5723
- col_pos_exists,
5723
+ last_col_line_pos=last_col_line_pos,
5724
+ scrollpos_left=scrollpos_left,
5725
+ x_stop=x_stop,
5726
+ grid_start_col=grid_start_col,
5727
+ grid_end_col=grid_end_col,
5728
+ text_start_col=text_start_col,
5729
+ text_end_col=text_end_col,
5730
+ scrollpos_right=scrollpos_right,
5731
+ col_pos_exists=col_pos_exists,
5724
5732
  )
5725
5733
  if redraw_row_index and self.show_index:
5726
5734
  self.RI.redraw_grid_and_text(
5727
- last_row_line_pos,
5728
- scrollpos_top,
5729
- y_stop,
5730
- start_row,
5731
- end_row + 1,
5732
- scrollpos_bot,
5733
- row_pos_exists,
5735
+ last_row_line_pos=last_row_line_pos,
5736
+ scrollpos_top=scrollpos_top,
5737
+ y_stop=y_stop,
5738
+ grid_start_row=grid_start_row,
5739
+ grid_end_row=grid_end_row,
5740
+ text_start_row=text_start_row,
5741
+ text_end_row=text_end_row,
5742
+ scrollpos_bot=scrollpos_bot,
5743
+ row_pos_exists=row_pos_exists,
5734
5744
  )
5735
5745
  event_data = {"sheetname": "", "header": redraw_header, "row_index": redraw_row_index, "table": redraw_table}
5736
5746
  self.PAR.emit_event("<<SheetRedrawn>>", data=event_data)
@@ -5935,7 +5945,7 @@ class MainTable(tk.Canvas):
5935
5945
  self.hidd_boxes.add(item)
5936
5946
  self.itemconfig(item, state="hidden")
5937
5947
 
5938
- def hide_selection_box(self, item: int | None, set_current: bool = True) -> bool:
5948
+ def hide_selection_box(self, item: int | None) -> bool:
5939
5949
  if item is None or item is True:
5940
5950
  return
5941
5951
  box = self.selection_boxes.pop(item)
@@ -5948,6 +5958,10 @@ class MainTable(tk.Canvas):
5948
5958
  self.set_current_to_last()
5949
5959
  if item == self.being_drawn_item:
5950
5960
  self.being_drawn_item = None
5961
+ elif item == self.RI.being_drawn_item:
5962
+ self.RI.being_drawn_item = None
5963
+ elif item == self.CH.being_drawn_item:
5964
+ self.CH.being_drawn_item = None
5951
5965
  return True
5952
5966
 
5953
5967
  def hide_selected(self) -> None:
@@ -5965,6 +5979,7 @@ class MainTable(tk.Canvas):
5965
5979
  state: str = "normal",
5966
5980
  set_current: bool | tuple[int, int] = True,
5967
5981
  run_binding: bool = False,
5982
+ ext: bool = False,
5968
5983
  ) -> int:
5969
5984
  if self.col_positions == [0]:
5970
5985
  c1 = 0
@@ -6019,7 +6034,8 @@ class MainTable(tk.Canvas):
6019
6034
  )
6020
6035
  bd_iid = None
6021
6036
  if self.PAR.ops.show_selected_cells_border and (
6022
- (self.being_drawn_item is None and self.RI.being_drawn_item is None and self.CH.being_drawn_item is None)
6037
+ ext
6038
+ or (self.being_drawn_item is None and self.RI.being_drawn_item is None and self.CH.being_drawn_item is None)
6023
6039
  or self.selection_boxes
6024
6040
  ):
6025
6041
  bd_iid = self.display_box(
@@ -6479,7 +6495,7 @@ class MainTable(tk.Canvas):
6479
6495
  text = text if isinstance(text, str) else f"{text}"
6480
6496
  text = "" if text is None else text
6481
6497
  if self.PAR.ops.cell_auto_resize_enabled:
6482
- self.set_cell_size_to_text(r, c, only_set_if_too_small=True, redraw=True, run_binding=True)
6498
+ self.set_cell_size_to_text(r, c, only_if_too_small=True, redraw=True, run_binding=True)
6483
6499
  if self.text_editor.open and (r, c) == self.text_editor.coords:
6484
6500
  self.text_editor.window.set_text(self.text_editor.get() + "" if not isinstance(text, str) else text)
6485
6501
  return
@@ -7096,7 +7112,7 @@ class MainTable(tk.Canvas):
7096
7112
  self.undo_stack.append(pickled_event_dict(event_data))
7097
7113
  self.set_cell_data(datarn, datacn, value)
7098
7114
  if cell_resize and self.PAR.ops.cell_auto_resize_enabled:
7099
- self.set_cell_size_to_text(r, c, only_set_if_too_small=True, redraw=redraw, run_binding=True)
7115
+ self.set_cell_size_to_text(r, c, only_if_too_small=True, redraw=redraw, run_binding=True)
7100
7116
  self.sheet_modified(event_data)
7101
7117
  return True
7102
7118
  return False