Skip to content

Commit

Permalink
fix incorrect drop index, set_all_cell_sizes_to_text() incorrect widths
Browse files Browse the repository at this point in the history
  • Loading branch information
ragardner committed Jun 4, 2024
1 parent 79c8414 commit cb77779
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
8 changes: 8 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
### Version 7.2.6
#### Fixed:
- Drag and drop incorrect drop index
- `set_all_cell_sizes_to_text()` incorrect widths

#### Changed:
- Functions that move rows/columns such as `move_rows()`/`move_columns()` have had their move to indexes changed slightly, you may need to check yours still work as intended if using these functions

### Version 7.2.5
#### Fixed:
- `StopIteration` on drag and drop
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
name = "tksheet"
description = "Tkinter table / sheet widget"
readme = "README.md"
version = "7.2.5"
version = "7.2.6"
authors = [{ name = "ragardner", email = "[email protected]" }]
requires-python = ">=3.8"
license = {file = "LICENSE.txt"}
Expand Down
2 changes: 1 addition & 1 deletion tksheet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
tksheet - A Python tkinter table widget
"""

__version__ = "7.2.5"
__version__ = "7.2.6"

from .colors import (
color_map,
Expand Down
10 changes: 7 additions & 3 deletions tksheet/column_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,8 +847,10 @@ def b1_release(self, event: object) -> None:
and is_contiguous(self.dragged_col.to_move)
)
):
if c >= len(self.MT.col_positions) - 1:
c -= 1
if c > self.dragged_col.to_move[-1]:
c += 1
if c > len(self.MT.col_positions) - 1:
c = len(self.MT.col_positions) - 1
event_data = event_dict(
name="move_columns",
sheet=self.PAR.name,
Expand Down Expand Up @@ -1010,7 +1012,9 @@ def get_cell_dimensions(self, datacn: int) -> tuple[int, int]:
txt = self.get_valid_cell_data_as_str(datacn, fix=False)
if txt:
self.MT.txt_measure_canvas.itemconfig(
self.MT.txt_measure_canvas_text, text=txt, font=self.PAR.ops.header_font
self.MT.txt_measure_canvas_text,
text=txt,
font=self.PAR.ops.header_font,
)
b = self.MT.txt_measure_canvas.bbox(self.MT.txt_measure_canvas_text)
w = b[2] - b[0] + 7
Expand Down
16 changes: 11 additions & 5 deletions tksheet/main_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,11 @@ def get_args_for_move_columns(
disp_new_idxs = get_new_indexes(move_to=move_to, to_move=to_move)
else:
disp_new_idxs = {}
# at_least_cols should not be len in this case as move_to can be len
if not self.all_columns_displayed and not data_indexes:
totalcols = self.equalize_data_row_lengths(at_least_cols=self.datacn(move_to) + 1)
totalcols = self.equalize_data_row_lengths(at_least_cols=self.datacn(move_to))
else:
totalcols = self.equalize_data_row_lengths(at_least_cols=move_to + 1)
totalcols = self.equalize_data_row_lengths(at_least_cols=move_to)
data_new_idxs = get_new_indexes(move_to=move_to, to_move=to_move)
if not self.all_columns_displayed and not data_indexes:
moved = {self.displayed_columns[i] for i in to_move}
Expand Down Expand Up @@ -1233,7 +1234,12 @@ def get_args_for_move_rows(
disp_new_idxs = get_new_indexes(move_to=move_to, to_move=to_move)
else:
disp_new_idxs = {}
self.fix_data_len(self.datarn(move_to) if not self.all_rows_displayed and not data_indexes else move_to)
# move_to can be len and fix_data_len() takes index so - 1
if not self.all_rows_displayed and not data_indexes:
fix_len = self.datarn(move_to) - 1
else:
fix_len = move_to - 1
self.fix_data_len(fix_len)
totalrows = max(self.total_data_rows(), len(self.row_positions) - 1)
data_new_idxs = get_new_indexes(move_to=move_to, to_move=to_move)
if not self.all_rows_displayed and not data_indexes:
Expand Down Expand Up @@ -3691,10 +3697,9 @@ def set_cell_size_to_text(self, r, c, only_if_too_small=False, redraw: bool = Tr
else:
return False

def set_all_cell_sizes_to_text(self, w: int | None = None, slim: bool = False) -> tuple[list[float], list[float]]:
def set_all_cell_sizes_to_text(self, width: int | None = None, slim: bool = False) -> tuple[list[float], list[float]]:
min_column_width = int(self.min_column_width)
min_rh = int(self.min_row_height)
w = min_column_width if w is None else w
h = min_rh
rhs = defaultdict(lambda: int(min_rh))
cws = []
Expand Down Expand Up @@ -3724,6 +3729,7 @@ def set_all_cell_sizes_to_text(self, w: int | None = None, slim: bool = False) -
rhs[datarn] = h
added_w_space = 1 if slim else 7
for datacn in itercols:
w = min_column_width if width is None else width
if (hw := self.CH.get_cell_dimensions(datacn)[0]) > w:
w = hw
else:
Expand Down
6 changes: 4 additions & 2 deletions tksheet/row_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -846,8 +846,10 @@ def b1_release(self, event: object) -> None:
and is_contiguous(self.dragged_row.to_move)
)
):
if r >= len(self.MT.row_positions) - 1:
r -= 1
if r > self.dragged_row.to_move[-1]:
r += 1
if r > len(self.MT.row_positions) - 1:
r = len(self.MT.row_positions) - 1
event_data = event_dict(
name="move_rows",
sheet=self.PAR.name,
Expand Down
2 changes: 1 addition & 1 deletion tksheet/sheet.py
Original file line number Diff line number Diff line change
Expand Up @@ -3362,7 +3362,7 @@ def set_all_cell_sizes_to_text(
width: int | None = None,
slim: bool = False,
) -> tuple[list[float], list[float]]:
self.MT.set_all_cell_sizes_to_text(w=width, slim=slim)
self.MT.set_all_cell_sizes_to_text(width=width, slim=slim)
self.set_refresh_timer(redraw)
return self.MT.row_positions, self.MT.col_positions

Expand Down

0 comments on commit cb77779

Please sign in to comment.