tksheet 7.4.4__py3-none-any.whl → 7.4.5__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/__init__.py +1 -1
- tksheet/column_headers.py +56 -58
- tksheet/constants.py +2 -2
- tksheet/formatters.py +20 -36
- tksheet/functions.py +13 -23
- tksheet/main_table.py +185 -334
- tksheet/other_classes.py +10 -16
- tksheet/row_index.py +87 -65
- tksheet/sheet.py +99 -105
- tksheet/sorting.py +4 -4
- tksheet/text_editor.py +9 -3
- tksheet/top_left_rectangle.py +5 -6
- {tksheet-7.4.4.dist-info → tksheet-7.4.5.dist-info}/METADATA +4 -2
- tksheet-7.4.5.dist-info/RECORD +22 -0
- {tksheet-7.4.4.dist-info → tksheet-7.4.5.dist-info}/WHEEL +1 -1
- tksheet-7.4.4.dist-info/RECORD +0 -22
- {tksheet-7.4.4.dist-info → tksheet-7.4.5.dist-info}/LICENSE.txt +0 -0
- {tksheet-7.4.4.dist-info → tksheet-7.4.5.dist-info}/top_level.txt +0 -0
tksheet/sheet.py
CHANGED
@@ -4,6 +4,7 @@ import tkinter as tk
|
|
4
4
|
from bisect import bisect_left
|
5
5
|
from collections import deque
|
6
6
|
from collections.abc import Callable, Generator, Hashable, Iterator, Sequence
|
7
|
+
from contextlib import suppress
|
7
8
|
from itertools import accumulate, chain, filterfalse, islice, product, repeat
|
8
9
|
from operator import attrgetter
|
9
10
|
from timeit import default_timer
|
@@ -123,14 +124,14 @@ class Sheet(tk.Frame):
|
|
123
124
|
header_align: str = "n",
|
124
125
|
row_index_align: str | None = None,
|
125
126
|
index_align: str = "n",
|
126
|
-
displayed_columns: list[int] =
|
127
|
+
displayed_columns: list[int] | None = None,
|
127
128
|
all_columns_displayed: bool = True,
|
128
|
-
displayed_rows: list[int] =
|
129
|
+
displayed_rows: list[int] | None = None,
|
129
130
|
all_rows_displayed: bool = True,
|
130
131
|
to_clipboard_delimiter: str = "\t",
|
131
132
|
to_clipboard_quotechar: str = '"',
|
132
133
|
to_clipboard_lineterminator: str = "\n",
|
133
|
-
from_clipboard_delimiters: list[str] | str =
|
134
|
+
from_clipboard_delimiters: list[str] | str = "\t",
|
134
135
|
show_default_header_for_empty: bool = True,
|
135
136
|
show_default_index_for_empty: bool = True,
|
136
137
|
page_up_down_select_row: bool = True,
|
@@ -734,10 +735,14 @@ class Sheet(tk.Frame):
|
|
734
735
|
- "rc_delete_row", "end_rc_delete_row", "end_delete_rows", "delete_rows"
|
735
736
|
- "begin_rc_delete_column", "begin_delete_columns"
|
736
737
|
- "rc_delete_column", "end_rc_delete_column","end_delete_columns", "delete_columns"
|
737
|
-
- "begin_rc_insert_column", "begin_insert_column", "begin_insert_columns", "begin_add_column",
|
738
|
-
|
739
|
-
- "
|
740
|
-
|
738
|
+
- "begin_rc_insert_column", "begin_insert_column", "begin_insert_columns", "begin_add_column",
|
739
|
+
"begin_rc_add_column", "begin_add_columns"
|
740
|
+
- "rc_insert_column", "end_rc_insert_column", "end_insert_column", "end_insert_columns", "rc_add_column",
|
741
|
+
"end_rc_add_column", "end_add_column", "end_add_columns", "add_columns"
|
742
|
+
- "begin_rc_insert_row", "begin_insert_row", "begin_insert_rows", "begin_rc_add_row", "begin_add_row",
|
743
|
+
"begin_add_rows"
|
744
|
+
- "rc_insert_row", "end_rc_insert_row", "end_insert_row", "end_insert_rows", "rc_add_row", "end_rc_add_row",
|
745
|
+
"end_add_row", "end_add_rows", "add_rows"
|
741
746
|
- "row_height_resize"
|
742
747
|
- "column_width_resize"
|
743
748
|
- "cell_select"
|
@@ -1613,10 +1618,7 @@ class Sheet(tk.Frame):
|
|
1613
1618
|
res = list(chain.from_iterable(res))
|
1614
1619
|
elif span.ndim == 1:
|
1615
1620
|
# flatten sublists
|
1616
|
-
if len(res) == 1 and len(res[0]) == 1
|
1617
|
-
res = res[0]
|
1618
|
-
else:
|
1619
|
-
res = list(chain.from_iterable(res))
|
1621
|
+
res = res[0] if len(res) == 1 and len(res[0]) == 1 else list(chain.from_iterable(res))
|
1620
1622
|
# if span.ndim == 2 res keeps its current
|
1621
1623
|
# dimensions as a list of lists
|
1622
1624
|
if span.convert is not None:
|
@@ -2208,10 +2210,7 @@ class Sheet(tk.Frame):
|
|
2208
2210
|
c_ops=False,
|
2209
2211
|
)
|
2210
2212
|
numrows = len(data)
|
2211
|
-
if self.MT.all_rows_displayed
|
2212
|
-
displayed_ins_idx = idx
|
2213
|
-
else:
|
2214
|
-
displayed_ins_idx = bisect_left(self.MT.displayed_rows, idx)
|
2213
|
+
displayed_ins_idx = idx if self.MT.all_rows_displayed else bisect_left(self.MT.displayed_rows, idx)
|
2215
2214
|
event_data = self.MT.add_rows(
|
2216
2215
|
*self.MT.get_args_for_add_rows(
|
2217
2216
|
data_ins_row=idx,
|
@@ -2599,7 +2598,8 @@ class Sheet(tk.Frame):
|
|
2599
2598
|
"""
|
2600
2599
|
Sort the data within specified box regions in the table.
|
2601
2600
|
|
2602
|
-
This method sorts the data within one or multiple box regions defined by their coordinates.
|
2601
|
+
This method sorts the data within one or multiple box regions defined by their coordinates.
|
2602
|
+
Each box's columns are sorted independently.
|
2603
2603
|
|
2604
2604
|
Args:
|
2605
2605
|
boxes (CreateSpanTypes): A type that can create a Span.
|
@@ -2617,7 +2617,8 @@ class Sheet(tk.Frame):
|
|
2617
2617
|
Note: Performance might be slow with the natural sort for very large datasets.
|
2618
2618
|
|
2619
2619
|
Returns:
|
2620
|
-
EventDataDict: A dictionary containing information about the sorting event,
|
2620
|
+
EventDataDict: A dictionary containing information about the sorting event,
|
2621
|
+
including changes made to the table.
|
2621
2622
|
|
2622
2623
|
Raises:
|
2623
2624
|
ValueError: If the input boxes are not in the expected format or if the data cannot be sorted.
|
@@ -2758,9 +2759,9 @@ class Sheet(tk.Frame):
|
|
2758
2759
|
def dropdown(
|
2759
2760
|
self,
|
2760
2761
|
*key: CreateSpanTypes,
|
2761
|
-
values: list =
|
2762
|
+
values: list[object] | None = None,
|
2762
2763
|
edit_data: bool = True,
|
2763
|
-
set_values: dict[tuple[int, int], object] =
|
2764
|
+
set_values: dict[tuple[int, int], object] | None = None,
|
2764
2765
|
set_value: object = None,
|
2765
2766
|
state: Literal["normal", "readonly", "disabled"] = "normal",
|
2766
2767
|
redraw: bool = True,
|
@@ -2770,6 +2771,10 @@ class Sheet(tk.Frame):
|
|
2770
2771
|
validate_input: bool = True,
|
2771
2772
|
text: None | str = None,
|
2772
2773
|
) -> Span:
|
2774
|
+
if values is None:
|
2775
|
+
values = []
|
2776
|
+
if set_values is None:
|
2777
|
+
set_values = {}
|
2773
2778
|
if not search_function:
|
2774
2779
|
search_function = dropdown_search_function
|
2775
2780
|
v = set_value if set_value is not None else values[0] if values else ""
|
@@ -2794,13 +2799,13 @@ class Sheet(tk.Frame):
|
|
2794
2799
|
self.del_index_cell_options_dropdown_and_checkbox(r)
|
2795
2800
|
add_to_options(self.RI.cell_options, r, "dropdown", d)
|
2796
2801
|
if edit_data:
|
2797
|
-
set_idata(r, value=set_values
|
2802
|
+
set_idata(r, value=set_values.get(r, v))
|
2798
2803
|
if header:
|
2799
2804
|
for c in cols:
|
2800
2805
|
self.del_header_cell_options_dropdown_and_checkbox(c)
|
2801
2806
|
add_to_options(self.CH.cell_options, c, "dropdown", d)
|
2802
2807
|
if edit_data:
|
2803
|
-
set_hdata(c, value=set_values
|
2808
|
+
set_hdata(c, value=set_values.get(c, v))
|
2804
2809
|
if table:
|
2805
2810
|
if span.kind == "cell":
|
2806
2811
|
for r in rows:
|
@@ -2808,21 +2813,21 @@ class Sheet(tk.Frame):
|
|
2808
2813
|
self.del_cell_options_dropdown_and_checkbox(r, c)
|
2809
2814
|
add_to_options(self.MT.cell_options, (r, c), "dropdown", d)
|
2810
2815
|
if edit_data:
|
2811
|
-
set_tdata(r, c, value=set_values
|
2816
|
+
set_tdata(r, c, value=set_values.get((r, c), v))
|
2812
2817
|
elif span.kind == "row":
|
2813
2818
|
for r in rows:
|
2814
2819
|
self.del_row_options_dropdown_and_checkbox(r)
|
2815
2820
|
add_to_options(self.MT.row_options, r, "dropdown", d)
|
2816
2821
|
if edit_data:
|
2817
2822
|
for c in cols:
|
2818
|
-
set_tdata(r, c, value=set_values
|
2823
|
+
set_tdata(r, c, value=set_values.get((r, c), v))
|
2819
2824
|
elif span.kind == "column":
|
2820
2825
|
for c in cols:
|
2821
2826
|
self.del_column_options_dropdown_and_checkbox(c)
|
2822
2827
|
add_to_options(self.MT.col_options, c, "dropdown", d)
|
2823
2828
|
if edit_data:
|
2824
2829
|
for r in rows:
|
2825
|
-
set_tdata(r, c, value=set_values
|
2830
|
+
set_tdata(r, c, value=set_values.get((r, c), v))
|
2826
2831
|
self.set_refresh_timer(redraw)
|
2827
2832
|
return span
|
2828
2833
|
|
@@ -3002,11 +3007,13 @@ class Sheet(tk.Frame):
|
|
3002
3007
|
def format(
|
3003
3008
|
self,
|
3004
3009
|
*key: CreateSpanTypes,
|
3005
|
-
formatter_options: dict =
|
3010
|
+
formatter_options: dict | None = None,
|
3006
3011
|
formatter_class: object = None,
|
3007
3012
|
redraw: bool = True,
|
3008
3013
|
**kwargs,
|
3009
3014
|
) -> Span:
|
3015
|
+
if formatter_options is None:
|
3016
|
+
formatter_options = {}
|
3010
3017
|
span = self.span_from_key(*key)
|
3011
3018
|
rows, cols = self.ranges_from_span(span)
|
3012
3019
|
kwargs = fix_format_kwargs({"formatter": formatter_class, **formatter_options, **kwargs})
|
@@ -4034,7 +4041,7 @@ class Sheet(tk.Frame):
|
|
4034
4041
|
column: int = 0,
|
4035
4042
|
keep_yscroll: bool = False,
|
4036
4043
|
keep_xscroll: bool = False,
|
4037
|
-
bottom_right_corner: bool =
|
4044
|
+
bottom_right_corner: bool | None = None,
|
4038
4045
|
check_cell_visibility: bool = True,
|
4039
4046
|
redraw: bool = True,
|
4040
4047
|
) -> Sheet:
|
@@ -4053,7 +4060,11 @@ class Sheet(tk.Frame):
|
|
4053
4060
|
return self.MT.cell_visible(r, c)
|
4054
4061
|
|
4055
4062
|
def cell_completely_visible(self, r: int, c: int, seperate_axes: bool = False) -> bool:
|
4056
|
-
|
4063
|
+
if seperate_axes:
|
4064
|
+
d = self.MT.cell_visibility_info(r, c)
|
4065
|
+
return d["yvis"], d["xvis"]
|
4066
|
+
else:
|
4067
|
+
return self.MT.cell_completely_visible(r, c)
|
4057
4068
|
|
4058
4069
|
def set_xview(self, position: None | float = None, option: str = "moveto") -> Sheet | tuple[float, float]:
|
4059
4070
|
if position is not None:
|
@@ -4507,18 +4518,14 @@ class Sheet(tk.Frame):
|
|
4507
4518
|
def unbind_key_text_editor(self, key: str) -> Sheet:
|
4508
4519
|
if key == "all":
|
4509
4520
|
for key in self.MT.text_editor_user_bound_keys:
|
4510
|
-
|
4521
|
+
with suppress(Exception):
|
4511
4522
|
self.MT.text_editor.tktext.unbind(key)
|
4512
|
-
except Exception:
|
4513
|
-
pass
|
4514
4523
|
self.MT.text_editor_user_bound_keys = {}
|
4515
4524
|
else:
|
4516
4525
|
if key in self.MT.text_editor_user_bound_keys:
|
4517
4526
|
del self.MT.text_editor_user_bound_keys[key]
|
4518
|
-
|
4527
|
+
with suppress(Exception):
|
4519
4528
|
self.MT.text_editor.tktext.unbind(key)
|
4520
|
-
except Exception:
|
4521
|
-
pass
|
4522
4529
|
return self
|
4523
4530
|
|
4524
4531
|
def get_text_editor_value(self) -> str | None:
|
@@ -4977,9 +4984,9 @@ class Sheet(tk.Frame):
|
|
4977
4984
|
columns=set(),
|
4978
4985
|
)
|
4979
4986
|
for tag in unpack(tags):
|
4980
|
-
res.cells.update(self.MT.tagged_cells
|
4981
|
-
res.rows.update(self.MT.tagged_rows
|
4982
|
-
res.columns.update(self.MT.tagged_columns
|
4987
|
+
res.cells.update(self.MT.tagged_cells.get(tag, set()))
|
4988
|
+
res.rows.update(self.MT.tagged_rows.get(tag, set()))
|
4989
|
+
res.columns.update(self.MT.tagged_columns.get(tag, set()))
|
4983
4990
|
return res
|
4984
4991
|
|
4985
4992
|
# Treeview Mode
|
@@ -5073,10 +5080,7 @@ class Sheet(tk.Frame):
|
|
5073
5080
|
"""
|
5074
5081
|
If used without args all items are opened
|
5075
5082
|
"""
|
5076
|
-
if items := set(unpack(items))
|
5077
|
-
to_open = self._tree_open(items)
|
5078
|
-
else:
|
5079
|
-
to_open = self._tree_open(set(self.get_children()))
|
5083
|
+
to_open = self._tree_open(items) if (items := set(unpack(items))) else self._tree_open(set(self.get_children()))
|
5080
5084
|
return self.show_rows(
|
5081
5085
|
rows=to_open,
|
5082
5086
|
redraw=redraw,
|
@@ -5103,10 +5107,7 @@ class Sheet(tk.Frame):
|
|
5103
5107
|
"""
|
5104
5108
|
If used without args all items are closed
|
5105
5109
|
"""
|
5106
|
-
if items
|
5107
|
-
to_close = self._tree_close(unpack(items))
|
5108
|
-
else:
|
5109
|
-
to_close = self._tree_close(self.get_children())
|
5110
|
+
to_close = self._tree_close(unpack(items)) if items else self._tree_close(self.get_children())
|
5110
5111
|
return self.hide_rows(
|
5111
5112
|
rows=to_close,
|
5112
5113
|
redraw=redraw,
|
@@ -5164,13 +5165,10 @@ class Sheet(tk.Frame):
|
|
5164
5165
|
self.RI.tree_rns[parent]
|
5165
5166
|
+ index
|
5166
5167
|
+ 1
|
5167
|
-
+ sum(
|
5168
|
-
sum(1 for _ in self.RI.get_iid_descendants(cid))
|
5169
|
-
for cid in islice(self.get_children(parent), index)
|
5170
|
-
)
|
5168
|
+
+ sum(self.RI.num_descendants(cid) for cid in islice(self.get_children(parent), index))
|
5171
5169
|
)
|
5172
5170
|
else:
|
5173
|
-
datarn = self.RI.tree_rns[parent] +
|
5171
|
+
datarn = self.RI.tree_rns[parent] + self.RI.num_descendants(parent) + 1
|
5174
5172
|
else:
|
5175
5173
|
if isinstance(index, int):
|
5176
5174
|
datarn = index
|
@@ -5206,10 +5204,7 @@ class Sheet(tk.Frame):
|
|
5206
5204
|
datarn = self._get_id_insert_row(index=index, parent=parent)
|
5207
5205
|
rns_to_add = {}
|
5208
5206
|
for rn, r in enumerate(data, start=datarn):
|
5209
|
-
if iid_column is None
|
5210
|
-
iid = self.RI.new_iid()
|
5211
|
-
else:
|
5212
|
-
iid = r[iid_column]
|
5207
|
+
iid = self.RI.new_iid() if iid_column is None else r[iid_column]
|
5213
5208
|
new_node = Node(
|
5214
5209
|
r[text_column] if isinstance(text_column, int) else text_column if isinstance(text_column, str) else "",
|
5215
5210
|
iid,
|
@@ -5302,8 +5297,8 @@ class Sheet(tk.Frame):
|
|
5302
5297
|
def itemrow(self, item: str) -> int:
|
5303
5298
|
try:
|
5304
5299
|
return self.RI.tree_rns[item]
|
5305
|
-
except
|
5306
|
-
raise ValueError(f"item '{item}' does not exist.")
|
5300
|
+
except ValueError as error:
|
5301
|
+
raise ValueError(f"item '{item}' does not exist.") from error
|
5307
5302
|
|
5308
5303
|
def rowitem(self, row: int, data_index: bool = False) -> str | None:
|
5309
5304
|
try:
|
@@ -5524,7 +5519,7 @@ class Sheet(tk.Frame):
|
|
5524
5519
|
return self.set_refresh_timer(redraw)
|
5525
5520
|
|
5526
5521
|
def selection_toggle(self, *items, redraw: bool = True) -> Sheet:
|
5527
|
-
selected =
|
5522
|
+
selected = {self.MT._row_index[self.displayed_row_to_data(rn)].iid for rn in self.get_selected_rows()}
|
5528
5523
|
add = []
|
5529
5524
|
remove = []
|
5530
5525
|
for item in unpack(items):
|
@@ -5892,14 +5887,12 @@ class Sheet(tk.Frame):
|
|
5892
5887
|
|
5893
5888
|
def readonly_rows(
|
5894
5889
|
self,
|
5895
|
-
rows: list | int
|
5890
|
+
rows: list[int] | int,
|
5896
5891
|
readonly: bool = True,
|
5897
5892
|
redraw: bool = False,
|
5898
5893
|
) -> Sheet:
|
5899
5894
|
if isinstance(rows, int):
|
5900
5895
|
rows = [rows]
|
5901
|
-
else:
|
5902
|
-
rows = rows
|
5903
5896
|
if not readonly:
|
5904
5897
|
for r in rows:
|
5905
5898
|
if r in self.MT.row_options and "readonly" in self.MT.row_options[r]:
|
@@ -5913,14 +5906,12 @@ class Sheet(tk.Frame):
|
|
5913
5906
|
|
5914
5907
|
def readonly_columns(
|
5915
5908
|
self,
|
5916
|
-
columns: list | int
|
5909
|
+
columns: list[int] | int,
|
5917
5910
|
readonly: bool = True,
|
5918
5911
|
redraw: bool = False,
|
5919
5912
|
) -> Sheet:
|
5920
5913
|
if isinstance(columns, int):
|
5921
5914
|
columns = [columns]
|
5922
|
-
else:
|
5923
|
-
columns = columns
|
5924
5915
|
if not readonly:
|
5925
5916
|
for c in columns:
|
5926
5917
|
if c in self.MT.col_options and "readonly" in self.MT.col_options[c]:
|
@@ -5936,7 +5927,7 @@ class Sheet(tk.Frame):
|
|
5936
5927
|
self,
|
5937
5928
|
row: int = 0,
|
5938
5929
|
column: int = 0,
|
5939
|
-
cells: list =
|
5930
|
+
cells: list[tuple[int, int]] | None = None,
|
5940
5931
|
readonly: bool = True,
|
5941
5932
|
redraw: bool = False,
|
5942
5933
|
) -> Sheet:
|
@@ -5965,7 +5956,7 @@ class Sheet(tk.Frame):
|
|
5965
5956
|
|
5966
5957
|
def readonly_header(
|
5967
5958
|
self,
|
5968
|
-
columns: list
|
5959
|
+
columns: list[int],
|
5969
5960
|
readonly: bool = True,
|
5970
5961
|
redraw: bool = False,
|
5971
5962
|
) -> Sheet:
|
@@ -5974,7 +5965,7 @@ class Sheet(tk.Frame):
|
|
5974
5965
|
|
5975
5966
|
def readonly_index(
|
5976
5967
|
self,
|
5977
|
-
rows: list
|
5968
|
+
rows: list[int],
|
5978
5969
|
readonly: bool = True,
|
5979
5970
|
redraw: bool = False,
|
5980
5971
|
) -> Sheet:
|
@@ -5983,7 +5974,7 @@ class Sheet(tk.Frame):
|
|
5983
5974
|
|
5984
5975
|
def dehighlight_rows(
|
5985
5976
|
self,
|
5986
|
-
rows: list[int] | Literal["all"]
|
5977
|
+
rows: list[int] | Literal["all"],
|
5987
5978
|
redraw: bool = True,
|
5988
5979
|
) -> Sheet:
|
5989
5980
|
if isinstance(rows, int):
|
@@ -5998,19 +5989,15 @@ class Sheet(tk.Frame):
|
|
5998
5989
|
del self.RI.cell_options[r]["highlight"]
|
5999
5990
|
else:
|
6000
5991
|
for r in rows:
|
6001
|
-
|
5992
|
+
with suppress(Exception):
|
6002
5993
|
del self.MT.row_options[r]["highlight"]
|
6003
|
-
|
6004
|
-
pass
|
6005
|
-
try:
|
5994
|
+
with suppress(Exception):
|
6006
5995
|
del self.RI.cell_options[r]["highlight"]
|
6007
|
-
except Exception:
|
6008
|
-
pass
|
6009
5996
|
return self.set_refresh_timer(redraw)
|
6010
5997
|
|
6011
5998
|
def dehighlight_columns(
|
6012
5999
|
self,
|
6013
|
-
columns: list[int] | Literal["all"]
|
6000
|
+
columns: list[int] | Literal["all"],
|
6014
6001
|
redraw: bool = True,
|
6015
6002
|
) -> Sheet:
|
6016
6003
|
if isinstance(columns, int):
|
@@ -6025,14 +6012,10 @@ class Sheet(tk.Frame):
|
|
6025
6012
|
del self.CH.cell_options[c]["highlight"]
|
6026
6013
|
else:
|
6027
6014
|
for c in columns:
|
6028
|
-
|
6015
|
+
with suppress(Exception):
|
6029
6016
|
del self.MT.col_options[c]["highlight"]
|
6030
|
-
|
6031
|
-
pass
|
6032
|
-
try:
|
6017
|
+
with suppress(Exception):
|
6033
6018
|
del self.CH.cell_options[c]["highlight"]
|
6034
|
-
except Exception:
|
6035
|
-
pass
|
6036
6019
|
return self.set_refresh_timer(redraw)
|
6037
6020
|
|
6038
6021
|
def highlight_rows(
|
@@ -6074,7 +6057,7 @@ class Sheet(tk.Frame):
|
|
6074
6057
|
self,
|
6075
6058
|
row: int | Literal["all"] = 0,
|
6076
6059
|
column: int | Literal["all"] = 0,
|
6077
|
-
cells: list[tuple[int, int]] =
|
6060
|
+
cells: list[tuple[int, int]] | None = None,
|
6078
6061
|
canvas: Literal["table", "index", "header"] = "table",
|
6079
6062
|
bg: bool | None | str = False,
|
6080
6063
|
fg: bool | None | str = False,
|
@@ -6128,7 +6111,7 @@ class Sheet(tk.Frame):
|
|
6128
6111
|
self,
|
6129
6112
|
row: int | Literal["all"] = 0,
|
6130
6113
|
column: int = 0,
|
6131
|
-
cells: list[tuple[int, int]] =
|
6114
|
+
cells: list[tuple[int, int]] | None = None,
|
6132
6115
|
canvas: Literal["table", "row_index", "index", "header"] = "table",
|
6133
6116
|
all_: bool = False,
|
6134
6117
|
redraw: bool = True,
|
@@ -6207,7 +6190,7 @@ class Sheet(tk.Frame):
|
|
6207
6190
|
self,
|
6208
6191
|
row: int = 0,
|
6209
6192
|
column: int = 0,
|
6210
|
-
cells: list
|
6193
|
+
cells: list[tuple[int, int]] | dict[tuple[int, int], str] | None = None,
|
6211
6194
|
align: str | None = "global",
|
6212
6195
|
redraw: bool = True,
|
6213
6196
|
) -> Sheet:
|
@@ -6224,7 +6207,7 @@ class Sheet(tk.Frame):
|
|
6224
6207
|
|
6225
6208
|
def align_rows(
|
6226
6209
|
self,
|
6227
|
-
rows: list | dict | int
|
6210
|
+
rows: list[int] | dict[int, str] | int,
|
6228
6211
|
align: str | None = "global",
|
6229
6212
|
align_index: bool = False,
|
6230
6213
|
redraw: bool = True,
|
@@ -6249,7 +6232,7 @@ class Sheet(tk.Frame):
|
|
6249
6232
|
|
6250
6233
|
def align_columns(
|
6251
6234
|
self,
|
6252
|
-
columns: list | dict | int
|
6235
|
+
columns: list[int] | dict[int, str] | int,
|
6253
6236
|
align: str | None = "global",
|
6254
6237
|
align_header: bool = False,
|
6255
6238
|
redraw: bool = True,
|
@@ -6274,7 +6257,7 @@ class Sheet(tk.Frame):
|
|
6274
6257
|
|
6275
6258
|
def align_header(
|
6276
6259
|
self,
|
6277
|
-
columns: list | dict | int
|
6260
|
+
columns: list[int] | dict[int, str] | int,
|
6278
6261
|
align: str | None = "global",
|
6279
6262
|
redraw: bool = True,
|
6280
6263
|
) -> Sheet:
|
@@ -6291,7 +6274,7 @@ class Sheet(tk.Frame):
|
|
6291
6274
|
|
6292
6275
|
def align_index(
|
6293
6276
|
self,
|
6294
|
-
rows: list | dict | int
|
6277
|
+
rows: list[int] | dict[int, str] | int,
|
6295
6278
|
align: str | None = "global",
|
6296
6279
|
redraw: bool = True,
|
6297
6280
|
) -> Sheet:
|
@@ -6457,11 +6440,11 @@ class Sheet(tk.Frame):
|
|
6457
6440
|
c: int | Literal["all"] = 0,
|
6458
6441
|
) -> None:
|
6459
6442
|
if isinstance(r, str) and r.lower() == "all" and isinstance(c, int):
|
6460
|
-
for r_,
|
6443
|
+
for r_, _ in self.MT.cell_options:
|
6461
6444
|
if "checkbox" in self.MT.cell_options[(r_, c)]:
|
6462
6445
|
self.del_cell_options_checkbox(r_, c)
|
6463
6446
|
elif isinstance(c, str) and c.lower() == "all" and isinstance(r, int):
|
6464
|
-
for
|
6447
|
+
for _, c_ in self.MT.cell_options:
|
6465
6448
|
if "checkbox" in self.MT.cell_options[(r, c_)]:
|
6466
6449
|
self.del_cell_options_checkbox(r, c_)
|
6467
6450
|
elif isinstance(r, str) and r.lower() == "all" and isinstance(c, str) and c.lower() == "all":
|
@@ -6712,11 +6695,11 @@ class Sheet(tk.Frame):
|
|
6712
6695
|
c: int | Literal["all"] = 0,
|
6713
6696
|
) -> None:
|
6714
6697
|
if isinstance(r, str) and r.lower() == "all" and isinstance(c, int):
|
6715
|
-
for r_,
|
6698
|
+
for r_, _ in self.MT.cell_options:
|
6716
6699
|
if "dropdown" in self.MT.cell_options[(r_, c)]:
|
6717
6700
|
self.del_cell_options_dropdown(r_, c)
|
6718
6701
|
elif isinstance(c, str) and c.lower() == "all" and isinstance(r, int):
|
6719
|
-
for
|
6702
|
+
for _, c_ in self.MT.cell_options:
|
6720
6703
|
if "dropdown" in self.MT.cell_options[(r, c_)]:
|
6721
6704
|
self.del_cell_options_dropdown(r, c_)
|
6722
6705
|
elif isinstance(r, str) and r.lower() == "all" and isinstance(c, str) and c.lower() == "all":
|
@@ -6810,9 +6793,11 @@ class Sheet(tk.Frame):
|
|
6810
6793
|
r: int = 0,
|
6811
6794
|
c: int = 0,
|
6812
6795
|
set_existing_dropdown: bool = False,
|
6813
|
-
values: list[object] =
|
6796
|
+
values: list[object] | None = None,
|
6814
6797
|
set_value: object = None,
|
6815
6798
|
) -> Sheet:
|
6799
|
+
if values is None:
|
6800
|
+
values = []
|
6816
6801
|
if set_existing_dropdown:
|
6817
6802
|
if self.MT.dropdown.open:
|
6818
6803
|
r_, c_ = self.MT.dropdown.get_coords()
|
@@ -6835,9 +6820,11 @@ class Sheet(tk.Frame):
|
|
6835
6820
|
self,
|
6836
6821
|
c: int = 0,
|
6837
6822
|
set_existing_dropdown: bool = False,
|
6838
|
-
values: list[object] =
|
6823
|
+
values: list[object] | None = None,
|
6839
6824
|
set_value: object = None,
|
6840
6825
|
) -> Sheet:
|
6826
|
+
if values is None:
|
6827
|
+
values = []
|
6841
6828
|
if set_existing_dropdown:
|
6842
6829
|
if self.CH.dropdown.open:
|
6843
6830
|
c_ = self.CH.dropdown.get_coords()
|
@@ -6859,9 +6846,11 @@ class Sheet(tk.Frame):
|
|
6859
6846
|
self,
|
6860
6847
|
r: int = 0,
|
6861
6848
|
set_existing_dropdown: bool = False,
|
6862
|
-
values: list[object] =
|
6849
|
+
values: list[object] | None = None,
|
6863
6850
|
set_value: object = None,
|
6864
6851
|
) -> Sheet:
|
6852
|
+
if values is None:
|
6853
|
+
values = []
|
6865
6854
|
if set_existing_dropdown:
|
6866
6855
|
if self.RI.current_dropdown_window is not None:
|
6867
6856
|
r_ = self.RI.current_dropdown_window.r
|
@@ -6950,11 +6939,13 @@ class Sheet(tk.Frame):
|
|
6950
6939
|
self,
|
6951
6940
|
r: int | Literal["all"],
|
6952
6941
|
c: int | Literal["all"],
|
6953
|
-
formatter_options: dict =
|
6942
|
+
formatter_options: dict | None = None,
|
6954
6943
|
formatter_class: object = None,
|
6955
6944
|
redraw: bool = True,
|
6956
6945
|
**kwargs,
|
6957
6946
|
) -> Sheet:
|
6947
|
+
if formatter_options is None:
|
6948
|
+
formatter_options = {}
|
6958
6949
|
kwargs = fix_format_kwargs({"formatter": formatter_class, **formatter_options, **kwargs})
|
6959
6950
|
if isinstance(r, str) and r.lower() == "all" and isinstance(c, int):
|
6960
6951
|
for r_ in range(self.MT.total_data_rows()):
|
@@ -6983,11 +6974,11 @@ class Sheet(tk.Frame):
|
|
6983
6974
|
clear_values: bool = False,
|
6984
6975
|
) -> Sheet:
|
6985
6976
|
if isinstance(r, str) and r.lower() == "all" and isinstance(c, int):
|
6986
|
-
for r_,
|
6977
|
+
for r_, _ in self.MT.cell_options:
|
6987
6978
|
if "format" in self.MT.cell_options[(r_, c)]:
|
6988
6979
|
self.MT.delete_cell_format(r_, c, clear_values=clear_values)
|
6989
6980
|
elif isinstance(c, str) and c.lower() == "all" and isinstance(r, int):
|
6990
|
-
for
|
6981
|
+
for _, c_ in self.MT.cell_options:
|
6991
6982
|
if "format" in self.MT.cell_options[(r, c_)]:
|
6992
6983
|
self.MT.delete_cell_format(r, c_, clear_values=clear_values)
|
6993
6984
|
elif isinstance(r, str) and r.lower() == "all" and isinstance(c, str) and c.lower() == "all":
|
@@ -7001,11 +6992,13 @@ class Sheet(tk.Frame):
|
|
7001
6992
|
def format_row(
|
7002
6993
|
self,
|
7003
6994
|
r: AnyIter[int] | int | Literal["all"],
|
7004
|
-
formatter_options: dict =
|
6995
|
+
formatter_options: dict | None = None,
|
7005
6996
|
formatter_class: object = None,
|
7006
6997
|
redraw: bool = True,
|
7007
6998
|
**kwargs,
|
7008
6999
|
) -> Sheet:
|
7000
|
+
if formatter_options is None:
|
7001
|
+
formatter_options = {}
|
7009
7002
|
kwargs = fix_format_kwargs({"formatter": formatter_class, **formatter_options, **kwargs})
|
7010
7003
|
if isinstance(r, str) and r.lower() == "all":
|
7011
7004
|
for r_ in range(len(self.MT.data)):
|
@@ -7043,11 +7036,13 @@ class Sheet(tk.Frame):
|
|
7043
7036
|
def format_column(
|
7044
7037
|
self,
|
7045
7038
|
c: AnyIter[int] | int | Literal["all"],
|
7046
|
-
formatter_options: dict =
|
7039
|
+
formatter_options: dict | None = None,
|
7047
7040
|
formatter_class: object = None,
|
7048
7041
|
redraw: bool = True,
|
7049
7042
|
**kwargs,
|
7050
7043
|
) -> Sheet:
|
7044
|
+
if formatter_options is None:
|
7045
|
+
formatter_options = {}
|
7051
7046
|
kwargs = fix_format_kwargs({"formatter": formatter_class, **formatter_options, **kwargs})
|
7052
7047
|
if isinstance(c, str) and c.lower() == "all":
|
7053
7048
|
for c_ in range(self.MT.total_data_cols()):
|
@@ -7099,7 +7094,7 @@ class Dropdown(Sheet):
|
|
7099
7094
|
height: int | None = None,
|
7100
7095
|
font: None | tuple[str, int, str] = None,
|
7101
7096
|
outline_thickness: int = 2,
|
7102
|
-
values: list[object] =
|
7097
|
+
values: list[object] | None = None,
|
7103
7098
|
close_dropdown_window: Callable | None = None,
|
7104
7099
|
search_function: Callable = dropdown_search_function,
|
7105
7100
|
modified_function: None | Callable = None,
|
@@ -7157,7 +7152,7 @@ class Dropdown(Sheet):
|
|
7157
7152
|
ops=ops,
|
7158
7153
|
outline_color=outline_color,
|
7159
7154
|
align=align,
|
7160
|
-
values=values,
|
7155
|
+
values=[] if values is None else values,
|
7161
7156
|
search_function=search_function,
|
7162
7157
|
modified_function=modified_function,
|
7163
7158
|
)
|
@@ -7245,10 +7240,7 @@ class Dropdown(Sheet):
|
|
7245
7240
|
row = None
|
7246
7241
|
elif event.keysym == "Return":
|
7247
7242
|
row = self.get_selected_rows()
|
7248
|
-
if not row
|
7249
|
-
row = None
|
7250
|
-
else:
|
7251
|
-
row = next(iter(row))
|
7243
|
+
row = None if not row else next(iter(row))
|
7252
7244
|
else:
|
7253
7245
|
row = self.identify_row(event, exclude_index=True, allow_end=False)
|
7254
7246
|
if self.single_index:
|
@@ -7274,10 +7266,12 @@ class Dropdown(Sheet):
|
|
7274
7266
|
|
7275
7267
|
def values(
|
7276
7268
|
self,
|
7277
|
-
values: list =
|
7269
|
+
values: list[object] | None = None,
|
7278
7270
|
redraw: bool = True,
|
7279
7271
|
width: int | None = None,
|
7280
7272
|
) -> None:
|
7273
|
+
if values is None:
|
7274
|
+
values = []
|
7281
7275
|
self.set_sheet_data(
|
7282
7276
|
[[v] for v in values],
|
7283
7277
|
reset_col_positions=False,
|
tksheet/sorting.py
CHANGED
@@ -67,7 +67,7 @@ def _string_fallback(item: str) -> tuple[int, ...]:
|
|
67
67
|
5,
|
68
68
|
len(components),
|
69
69
|
tuple(int(e) if e.isdigit() else e.lower() for comp in components[:-1] for e in split(r"(\d+)", comp) if e),
|
70
|
-
|
70
|
+
(),
|
71
71
|
)
|
72
72
|
|
73
73
|
|
@@ -117,7 +117,7 @@ def version_sort_key(item: object) -> tuple[int, ...]:
|
|
117
117
|
for e in split(r"(\d+)", comp)
|
118
118
|
if e
|
119
119
|
),
|
120
|
-
|
120
|
+
(),
|
121
121
|
)
|
122
122
|
else:
|
123
123
|
return (1, item)
|
@@ -195,7 +195,7 @@ def natural_sort_key(item: object) -> tuple[int, ...]:
|
|
195
195
|
for e in split(r"(\d+)", comp)
|
196
196
|
if e
|
197
197
|
),
|
198
|
-
|
198
|
+
(),
|
199
199
|
)
|
200
200
|
else:
|
201
201
|
return (1, item)
|
@@ -393,7 +393,7 @@ def sort_columns_by_row(
|
|
393
393
|
unsorted_part = [elem for idx, elem in enumerate(row_data) if idx not in sort_indices_set]
|
394
394
|
new_data.append(sorted_part + unsorted_part)
|
395
395
|
|
396
|
-
return sort_indices,
|
396
|
+
return sort_indices, dict(zip(range(len(data[row])), sort_indices))
|
397
397
|
|
398
398
|
|
399
399
|
def _sort_node_children(
|
tksheet/text_editor.py
CHANGED
@@ -111,9 +111,15 @@ class TextEditorTkText(tk.Text):
|
|
111
111
|
):
|
112
112
|
self.tag_add("align", 1.0, "end")
|
113
113
|
self.event_generate("<<TextModified>>")
|
114
|
-
if
|
115
|
-
|
116
|
-
|
114
|
+
if (
|
115
|
+
args
|
116
|
+
and len(args) > 1
|
117
|
+
and args[1] != "\n"
|
118
|
+
and args != ("1.0", "end")
|
119
|
+
and self.yview() != (0.0, 1.0)
|
120
|
+
and self.newline_bindng is not None
|
121
|
+
):
|
122
|
+
self.newline_bindng(check_lines=False)
|
117
123
|
return result
|
118
124
|
|
119
125
|
def rc(self, event: object) -> None:
|