Skip to content

Commit

Permalink
7.2.12 -> 7.2.13
Browse files Browse the repository at this point in the history
#### Fixed:
- [245](#245)

#### Changed:
- Moved variable `default_index` to sheet options as `default_row_index`
- Moved variable `default_header` to sheet options

#### Improved:
- Documentation
  • Loading branch information
ragardner committed Aug 1, 2024
1 parent 1a6a39c commit d911a2a
Show file tree
Hide file tree
Showing 11 changed files with 118 additions and 57 deletions.
11 changes: 11 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
### Version 7.2.13
#### Fixed:
- [245](https://github.com/ragardner/tksheet/issues/245)

#### Changed:
- Moved variable `default_index` to sheet options as `default_row_index`
- Moved variable `default_header` to sheet options

#### Improved:
- Documentation

### Version 7.2.12
#### Pull Requests:
- [237](https://github.com/ragardner/tksheet/pull/237)
Expand Down
17 changes: 16 additions & 1 deletion docs/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -3941,9 +3941,15 @@ get_column_alignments() -> dict
---
# **Getting Selected Cells**

All selected cell/box getting functions return or generate **displayed** cell coordinates.
- Displayed cell coordinates ignore hidden rows/columns when indexing cells.
- Data cell coordinates include hidden rows/columns in indexing cells.

#### **Get the currently selected cell**

This is always a single cell, the one, for example, in which the cell text editor opens when making single edits.
This is always a single cell of displayed indices. If you have hidden rows or columns you can change the integers to data indices using the following functions:
- [Change a row](https://github.com/ragardner/tksheet/wiki/Version-7#displayed-row-index-to-data)
- [Change a column](https://github.com/ragardner/tksheet/wiki/Version-7#displayed-column-index-to-data)

```python
get_currently_selected() -> tuple | Selected
Expand Down Expand Up @@ -3982,6 +3988,7 @@ get_selected_rows(
return_tuple: bool = False,
) -> tuple[int] | tuple[tuple[int, int]] | set[int] | set[tuple[int, int]]
```
- Returns displayed indexes.

___

Expand All @@ -3994,6 +4001,7 @@ get_selected_columns(
return_tuple: bool = False,
) -> tuple[int] | tuple[tuple[int, int]] | set[int] | set[tuple[int, int]]
```
- Returns displayed indexes.

___

Expand All @@ -4007,6 +4015,7 @@ get_selected_cells(
sort_by_column: bool = False,
) -> list[tuple[int, int]] | set[tuple[int, int]]
```
- Returns displayed coordinates.

___

Expand All @@ -4018,6 +4027,7 @@ gen_selected_cells(
get_columns: bool = False,
) -> Generator[tuple[int, int]]
```
- Generates displayed coordinates.

___

Expand All @@ -4026,6 +4036,7 @@ ___
```python
get_all_selection_boxes() -> tuple[tuple[int, int, int, int]]
```
- Returns displayed coordinates.

___

Expand Down Expand Up @@ -4118,6 +4129,10 @@ get_selected_min_max() -> tuple[int, int, int, int] | tuple[None, None, None, No
---
# **Modifying Selected Cells**

All selected cell/box setting functions use **displayed** cell coordinates.
- Displayed cell coordinates ignore hidden rows/columns when indexing cells.
- Data cell coordinates include hidden rows/columns in indexing cells.

```python
set_currently_selected(row: int | None = None, column: int | None = None) -> Sheet
```
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.12"
version = "7.2.13"
authors = [{ name = "ragardner", email = "[email protected]" }]
requires-python = ">=3.8"
license = {file = "LICENSE.txt"}
Expand Down
1 change: 1 addition & 0 deletions tksheet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
alpha2num,
consecutive_chunks,
consecutive_ranges,
convert_align,
data_to_displayed_idxs,
displayed_to_data_idxs,
dropdown_search_function,
Expand Down
3 changes: 1 addition & 2 deletions tksheet/column_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ def __init__(self, *args, **kwargs):
self.hidd_checkbox = {}
self.hidd_boxes = set()

self.default_header = kwargs["default_header"].lower()
self.align = kwargs["header_align"]
self.basic_bindings()

Expand Down Expand Up @@ -2270,7 +2269,7 @@ def get_valid_cell_data_as_str(self, datacn: int, fix: bool = True) -> str:
except Exception:
value = ""
if not value and self.PAR.ops.show_default_header_for_empty:
value = get_n2a(datacn, self.default_header)
value = get_n2a(datacn, self.PAR.ops.default_header)
return value

def get_value_for_empty_cell(self, datacn: int, c_ops: bool = True) -> object:
Expand Down
11 changes: 10 additions & 1 deletion tksheet/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@


def get_csv_str_dialect(s: str, delimiters: str) -> csv.Dialect:
if len(s) > 6000:
try:
_upto = next(
match.start() + 1 for i, match in enumerate(re.finditer("\n", s), 1) if i == 300 or match.start() > 6000
)
except Exception:
_upto = len(s)
else:
_upto = len(s)
try:
return csv.Sniffer().sniff(s[:5000] if len(s) > 5000 else s, delimiters=delimiters)
return csv.Sniffer().sniff(s[:_upto] if len(s) > 6000 else s, delimiters=delimiters)
except Exception:
return csv.excel_tab

Expand Down
4 changes: 2 additions & 2 deletions tksheet/main_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -6345,7 +6345,7 @@ def get_selected_rows(
for r in range(box.coords.from_r, box.coords.upto_r)
}
if get_cells_as_rows:
return s | set(tup[0] for tup in self.get_selected_cells())
return s | set(map(itemgetter(0), self.gen_selected_cells()))
return s

def get_selected_cols(
Expand All @@ -6369,7 +6369,7 @@ def get_selected_cols(
for c in range(box.coords.from_c, box.coords.upto_c)
}
if get_cells_as_cols:
return s | set(tup[1] for tup in self.get_selected_cells())
return s | set(map(itemgetter(1), self.gen_selected_cells()))
return s

def get_selected_cells(
Expand Down
80 changes: 45 additions & 35 deletions tksheet/row_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ def __init__(self, *args, **kwargs):
self.hidd_boxes = set()

self.align = kwargs["row_index_align"]
self.default_index = kwargs["default_row_index"].lower()

self.tree_reset()
self.basic_bindings()
Expand Down Expand Up @@ -1200,11 +1199,11 @@ def set_height_of_all_rows(

def auto_set_index_width(self, end_row: int, only_rows: list) -> bool:
if not isinstance(self.MT._row_index, int) and not self.MT._row_index:
if self.default_index == "letters":
if self.PAR.ops.default_row_index == "letters":
new_w = self.MT.get_txt_w(f"{num2alpha(end_row)}") + 20
elif self.default_index == "numbers":
elif self.PAR.ops.default_row_index == "numbers":
new_w = self.MT.get_txt_w(f"{end_row}") + 20
elif self.default_index == "both":
elif self.PAR.ops.default_row_index == "both":
new_w = self.MT.get_txt_w(f"{end_row + 1} {num2alpha(end_row)}") + 20
elif self.PAR.ops.auto_resize_row_index is True:
new_w = self.get_index_text_width(only_rows=only_rows)
Expand Down Expand Up @@ -1336,33 +1335,44 @@ def redraw_tree_arrow(
fill: str,
tag: str | tuple[str],
indent: float,
has_children: bool = False,
open_: bool = False,
) -> None:
mod = (self.MT.index_txt_height - 1) if self.MT.index_txt_height % 2 else self.MT.index_txt_height
small_mod = int(mod / 5)
mid_y = floor(self.MT.min_row_height / 2)
# up arrow
if open_:
points = (
# the left hand downward point
x1 + 5 + indent,
y1 + mid_y + small_mod,
# the middle upward point
x1 + 5 + indent + small_mod + small_mod,
y1 + mid_y - small_mod,
# the right hand downward point
x1 + 5 + indent + small_mod + small_mod + small_mod + small_mod,
y1 + mid_y + small_mod,
)
# right pointing arrow
if has_children:
# up arrow
if open_:
points = (
# the left hand downward point
x1 + 5 + indent,
y1 + mid_y + small_mod,
# the middle upward point
x1 + 5 + indent + small_mod + small_mod,
y1 + mid_y - small_mod,
# the right hand downward point
x1 + 5 + indent + small_mod + small_mod + small_mod + small_mod,
y1 + mid_y + small_mod,
)
# right pointing arrow
else:
points = (
# the upper point
x1 + 5 + indent + small_mod + small_mod,
y1 + mid_y - small_mod - small_mod,
# the middle point
x1 + 5 + indent + small_mod + small_mod + small_mod + small_mod,
y1 + mid_y,
# the bottom point
x1 + 5 + indent + small_mod + small_mod,
y1 + mid_y + small_mod + small_mod,
)
else:
points = (
# the upper point
x1 + 5 + indent + small_mod + small_mod,
y1 + mid_y - small_mod - small_mod,
# the middle point
x1 + 5 + indent + small_mod + small_mod + small_mod + small_mod,
y1 + mid_y,
# the bottom point
x1 + 5 + indent + small_mod + small_mod,
y1 + mid_y + small_mod + small_mod,
Expand All @@ -1371,14 +1381,14 @@ def redraw_tree_arrow(
t, sh = self.hidd_tree_arrow.popitem()
self.coords(t, points)
if sh:
self.itemconfig(t, fill=fill)
self.itemconfig(t, fill=fill if has_children else self.PAR.ops.index_grid_fg)
else:
self.itemconfig(t, fill=fill, tag=tag, state="normal")
self.itemconfig(t, fill=fill if has_children else self.PAR.ops.index_grid_fg, tag=tag, state="normal")
self.lift(t)
else:
t = self.create_line(
points,
fill=fill,
fill=fill if has_children else self.PAR.ops.index_grid_fg,
tag=tag,
width=2,
capstyle=tk.ROUND,
Expand Down Expand Up @@ -1689,16 +1699,16 @@ def redraw_grid_and_text(
draw_x += self.MT.index_txt_height + 3
indent = self.get_treeview_indent(iid)
draw_x += indent + 5
if self.tree[iid].children:
self.redraw_tree_arrow(
2,
rtopgridln,
r=r,
fill=tree_arrow_fg,
tag="ta",
indent=indent,
open_=self.MT._row_index[datarn].iid in self.tree_open_ids,
)
self.redraw_tree_arrow(
2,
rtopgridln,
r=r,
fill=tree_arrow_fg,
tag="ta",
indent=indent,
has_children=bool(self.tree[iid].children),
open_=self.MT._row_index[datarn].iid in self.tree_open_ids,
)
lns = self.get_valid_cell_data_as_str(datarn, fix=False)
if not lns:
continue
Expand Down Expand Up @@ -2388,7 +2398,7 @@ def get_valid_cell_data_as_str(self, datarn: int, fix: bool = True) -> str:
except Exception:
value = ""
if not value and self.PAR.ops.show_default_index_for_empty:
value = get_n2a(datarn, self.default_index)
value = get_n2a(datarn, self.PAR.ops.default_row_index)
return value

def get_value_for_empty_cell(self, datarn: int, r_ops: bool = True) -> object:
Expand Down
Loading

0 comments on commit d911a2a

Please sign in to comment.