tksheet 7.2.1__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
@@ -3642,7 +3642,7 @@ class MainTable(tk.Canvas):
3642
3642
  return w + self.table_txt_height, h
3643
3643
  return w, h
3644
3644
 
3645
- 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):
3646
3646
  min_column_width = int(self.min_column_width)
3647
3647
  min_rh = int(self.min_row_height)
3648
3648
  w = min_column_width
@@ -3662,7 +3662,7 @@ class MainTable(tk.Canvas):
3662
3662
  w = int(self.max_column_width)
3663
3663
  cell_needs_resize_w = False
3664
3664
  cell_needs_resize_h = False
3665
- if only_set_if_too_small:
3665
+ if only_if_too_small:
3666
3666
  if w > self.col_positions[c + 1] - self.col_positions[c]:
3667
3667
  cell_needs_resize_w = True
3668
3668
  if h > self.row_positions[r + 1] - self.row_positions[r]:
@@ -3792,24 +3792,26 @@ class MainTable(tk.Canvas):
3792
3792
 
3793
3793
  def reset_col_positions(self, ncols: int | None = None):
3794
3794
  colpos = self.PAR.ops.default_column_width
3795
- if self.all_columns_displayed:
3796
- 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))
3797
3797
  else:
3798
- self.set_col_positions(
3799
- itr=(colpos for c in range(ncols if ncols is not None else len(self.displayed_columns)))
3800
- )
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)))
3801
3802
 
3802
3803
  def set_row_positions(self, itr: Iterator[float]) -> None:
3803
3804
  self.row_positions = list(accumulate(chain([0], itr)))
3804
3805
 
3805
3806
  def reset_row_positions(self, nrows: int | None = None):
3806
3807
  rowpos = self.get_default_row_height()
3807
- if self.all_rows_displayed:
3808
- 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))
3809
3810
  else:
3810
- self.set_row_positions(
3811
- itr=(rowpos for r in range(nrows if nrows is not None else len(self.displayed_rows)))
3812
- )
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)))
3813
3815
 
3814
3816
  def del_col_position(self, idx: int, deselect_all: bool = False):
3815
3817
  if deselect_all:
@@ -4339,7 +4341,7 @@ class MainTable(tk.Canvas):
4339
4341
  self.set_row_positions(
4340
4342
  itr=chain(
4341
4343
  self.gen_row_heights(),
4342
- (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),
4343
4345
  )
4344
4346
  )
4345
4347
  if isinstance(self._headers, list) and header:
@@ -4474,7 +4476,7 @@ class MainTable(tk.Canvas):
4474
4476
  self.set_col_positions(
4475
4477
  itr=chain(
4476
4478
  self.gen_column_widths(),
4477
- (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),
4478
4480
  )
4479
4481
  )
4480
4482
  if push_ops:
@@ -5015,19 +5017,21 @@ class MainTable(tk.Canvas):
5015
5017
  self.canvasy(self.winfo_height()),
5016
5018
  )
5017
5019
 
5018
- def get_visible_rows(self, y1: int | float, y2: int | float) -> tuple[int, int]:
5019
- start_row = bisect_left(self.row_positions, y1)
5020
- end_row = bisect_right(self.row_positions, y2)
5021
- if not y2 >= self.row_positions[-1]:
5022
- end_row += 1
5023
- return start_row, end_row
5024
-
5025
- def get_visible_columns(self, x1: int | float, x2: int | float) -> tuple[int, int]:
5026
- start_col = bisect_left(self.col_positions, x1)
5027
- end_col = bisect_right(self.col_positions, x2)
5028
- if not x2 >= self.col_positions[-1]:
5029
- end_col += 1
5030
- 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
5031
5035
 
5032
5036
  def redraw_highlight_get_text_fg(
5033
5037
  self,
@@ -5374,21 +5378,26 @@ class MainTable(tk.Canvas):
5374
5378
  self.RI.configure_scrollregion(last_row_line_pos)
5375
5379
  if setting_views:
5376
5380
  return False
5381
+ scrollpos_top = self.canvasy(0)
5377
5382
  scrollpos_bot = self.canvasy(can_height)
5378
- end_row = bisect_right(self.row_positions, scrollpos_bot)
5379
- if not scrollpos_bot >= self.row_positions[-1]:
5380
- end_row += 1
5381
5383
  scrollpos_left = self.canvasx(0)
5382
- scrollpos_top = self.canvasy(0)
5383
5384
  scrollpos_right = self.canvasx(can_width)
5384
- start_row = bisect_left(self.row_positions, scrollpos_top)
5385
- start_col = bisect_left(self.col_positions, scrollpos_left)
5386
- 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
+
5387
5396
  changed_w = False
5388
5397
  if self.PAR.ops.auto_resize_row_index and redraw_row_index and self.show_index:
5389
5398
  changed_w = self.RI.auto_set_index_width(
5390
- end_row=end_row - 1,
5391
- 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)],
5392
5401
  )
5393
5402
  if resized_cols or resized_rows or changed_w:
5394
5403
  self.recreate_all_selection_boxes()
@@ -5408,8 +5417,6 @@ class MainTable(tk.Canvas):
5408
5417
  self.disp_dropdown = {}
5409
5418
  self.hidd_checkbox.update(self.disp_checkbox)
5410
5419
  self.disp_checkbox = {}
5411
- if not scrollpos_right >= self.col_positions[-1]:
5412
- end_col += 1
5413
5420
  if last_col_line_pos > scrollpos_right:
5414
5421
  x_stop = scrollpos_right
5415
5422
  else:
@@ -5439,7 +5446,7 @@ class MainTable(tk.Canvas):
5439
5446
  self.canvasx(0) - 1,
5440
5447
  self.row_positions[r + 1] if len(self.row_positions) - 1 > r else self.row_positions[r],
5441
5448
  )
5442
- for r in range(start_row - 1, end_row)
5449
+ for r in range(grid_start_row, grid_end_row)
5443
5450
  ]
5444
5451
  )
5445
5452
  )
@@ -5471,7 +5478,7 @@ class MainTable(tk.Canvas):
5471
5478
  self.col_positions[c + 1] if len(self.col_positions) - 1 > c else self.col_positions[c],
5472
5479
  scrollpos_top - 1,
5473
5480
  )
5474
- for c in range(start_col - 1, end_col)
5481
+ for c in range(grid_start_col, grid_end_col)
5475
5482
  ]
5476
5483
  )
5477
5484
  )
@@ -5482,13 +5489,8 @@ class MainTable(tk.Canvas):
5482
5489
  width=1,
5483
5490
  tag="g",
5484
5491
  )
5485
- if start_row > 0:
5486
- start_row -= 1
5487
- if start_col > 0:
5488
- start_col -= 1
5489
- end_row -= 1
5490
5492
  if redraw_table:
5491
- 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)
5492
5494
  c_2 = (
5493
5495
  self.PAR.ops.table_selected_cells_bg
5494
5496
  if self.PAR.ops.table_selected_cells_bg.startswith("#")
@@ -5507,10 +5509,10 @@ class MainTable(tk.Canvas):
5507
5509
  else color_map[self.PAR.ops.table_selected_rows_bg]
5508
5510
  )
5509
5511
  c_4_ = (int(c_4[1:3], 16), int(c_4[3:5], 16), int(c_4[5:], 16))
5510
- rows_ = tuple(range(start_row, end_row))
5512
+ rows_ = tuple(range(text_start_row, text_end_row))
5511
5513
  font = self.PAR.ops.table_font
5512
5514
  dd_coords = self.dropdown.get_coords()
5513
- for c in range(start_col, end_col - 1):
5515
+ for c in range(text_start_col, text_end_col):
5514
5516
  for r in rows_:
5515
5517
  rtopgridln = self.row_positions[r]
5516
5518
  rbotgridln = self.row_positions[r + 1]
@@ -5718,23 +5720,27 @@ class MainTable(tk.Canvas):
5718
5720
  self.tag_raise(self.selected.iid)
5719
5721
  if redraw_header and self.show_header:
5720
5722
  self.CH.redraw_grid_and_text(
5721
- last_col_line_pos,
5722
- scrollpos_left,
5723
- x_stop,
5724
- start_col,
5725
- end_col,
5726
- scrollpos_right,
5727
- 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,
5728
5732
  )
5729
5733
  if redraw_row_index and self.show_index:
5730
5734
  self.RI.redraw_grid_and_text(
5731
- last_row_line_pos,
5732
- scrollpos_top,
5733
- y_stop,
5734
- start_row,
5735
- end_row + 1,
5736
- scrollpos_bot,
5737
- 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,
5738
5744
  )
5739
5745
  event_data = {"sheetname": "", "header": redraw_header, "row_index": redraw_row_index, "table": redraw_table}
5740
5746
  self.PAR.emit_event("<<SheetRedrawn>>", data=event_data)
@@ -6489,7 +6495,7 @@ class MainTable(tk.Canvas):
6489
6495
  text = text if isinstance(text, str) else f"{text}"
6490
6496
  text = "" if text is None else text
6491
6497
  if self.PAR.ops.cell_auto_resize_enabled:
6492
- 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)
6493
6499
  if self.text_editor.open and (r, c) == self.text_editor.coords:
6494
6500
  self.text_editor.window.set_text(self.text_editor.get() + "" if not isinstance(text, str) else text)
6495
6501
  return
@@ -7106,7 +7112,7 @@ class MainTable(tk.Canvas):
7106
7112
  self.undo_stack.append(pickled_event_dict(event_data))
7107
7113
  self.set_cell_data(datarn, datacn, value)
7108
7114
  if cell_resize and self.PAR.ops.cell_auto_resize_enabled:
7109
- 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)
7110
7116
  self.sheet_modified(event_data)
7111
7117
  return True
7112
7118
  return False