tksheet 7.2.15__py3-none-any.whl → 7.2.17__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 CHANGED
@@ -4,7 +4,7 @@
4
4
  tksheet - A Python tkinter table widget
5
5
  """
6
6
 
7
- __version__ = "7.2.15"
7
+ __version__ = "7.2.17"
8
8
 
9
9
  from .colors import (
10
10
  color_map,
tksheet/row_index.py CHANGED
@@ -921,11 +921,12 @@ class RowIndex(tk.Canvas):
921
921
  eventx: int,
922
922
  ) -> bool:
923
923
  if self.PAR.ops.treeview and (
924
- canvasy < self.MT.row_positions[r] + self.MT.index_txt_height + 3
924
+ canvasy < self.MT.row_positions[r] + self.MT.index_txt_height + 5
925
925
  and isinstance(self.MT._row_index, list)
926
926
  and (datarn := self.MT.datarn(r)) < len(self.MT._row_index)
927
927
  and eventx
928
- < self.get_treeview_indent((iid := self.MT._row_index[datarn].iid)) + self.MT.index_txt_height + 1
928
+ < (indent := self.get_iid_indent((iid := self.MT._row_index[datarn].iid))) + self.MT.index_txt_height + 4
929
+ and eventx >= indent + 1
929
930
  ):
930
931
  return iid
931
932
  return None
@@ -1056,7 +1057,7 @@ class RowIndex(tk.Canvas):
1056
1057
  align = self.align
1057
1058
  if align == "w":
1058
1059
  w += self.MT.index_txt_height
1059
- w += self.get_treeview_indent(self.MT._row_index[datarn].iid) + 10
1060
+ w += self.get_iid_indent(self.MT._row_index[datarn].iid) + 10
1060
1061
  return w, h
1061
1062
 
1062
1063
  def get_row_text_height(
@@ -1331,12 +1332,13 @@ class RowIndex(tk.Canvas):
1331
1332
  self,
1332
1333
  x1: float,
1333
1334
  y1: float,
1334
- r: int,
1335
+ y2: float,
1335
1336
  fill: str,
1336
1337
  tag: str | tuple[str],
1337
1338
  indent: float,
1338
1339
  has_children: bool = False,
1339
1340
  open_: bool = False,
1341
+ level: int = 1,
1340
1342
  ) -> None:
1341
1343
  mod = (self.MT.index_txt_height - 1) if self.MT.index_txt_height % 2 else self.MT.index_txt_height
1342
1344
  small_mod = int(mod / 5)
@@ -1369,14 +1371,36 @@ class RowIndex(tk.Canvas):
1369
1371
  y1 + mid_y + small_mod + small_mod,
1370
1372
  )
1371
1373
  else:
1374
+ # POINTS FOR A LINE THAT STOPS BELOW FIRST LINE OF TEXT
1375
+ # points = (
1376
+ # # the upper point
1377
+ # x1 + 5 + indent + small_mod + small_mod,
1378
+ # y1 + mid_y - small_mod - small_mod,
1379
+ # # the bottom point
1380
+ # x1 + 5 + indent + small_mod + small_mod,
1381
+ # y1 + mid_y + small_mod + small_mod,
1382
+ # )
1383
+
1384
+ # POINTS FOR A LINE THAT STOPS AT ROW LINE
1385
+ # points = (
1386
+ # # the upper point
1387
+ # x1 + 5 + indent + small_mod + small_mod,
1388
+ # y1 + mid_y - small_mod - small_mod,
1389
+ # # the bottom point
1390
+ # x1 + 5 + indent + small_mod + small_mod,
1391
+ # y2 - mid_y + small_mod + small_mod,
1392
+ # )
1393
+
1394
+ # POINTS FOR A HORIZONTAL LINE
1372
1395
  points = (
1373
- # the upper point
1374
- x1 + 5 + indent + small_mod + small_mod,
1375
- y1 + mid_y - small_mod - small_mod,
1376
- # the bottom point
1377
- x1 + 5 + indent + small_mod + small_mod,
1378
- y1 + mid_y + small_mod + small_mod,
1396
+ # the left point
1397
+ x1 + 5 + indent,
1398
+ y1 + mid_y,
1399
+ # the right point
1400
+ x1 + 5 + indent + small_mod + small_mod + small_mod + small_mod,
1401
+ y1 + mid_y,
1379
1402
  )
1403
+
1380
1404
  if self.hidd_tree_arrow:
1381
1405
  t, sh = self.hidd_tree_arrow.popitem()
1382
1406
  self.coords(t, points)
@@ -1696,17 +1720,18 @@ class RowIndex(tk.Canvas):
1696
1720
  mw -= self.MT.index_txt_height
1697
1721
  if align == "w":
1698
1722
  draw_x += self.MT.index_txt_height + 3
1699
- indent = self.get_treeview_indent(iid)
1723
+ level, indent = self.get_iid_level_indent(iid)
1700
1724
  draw_x += indent + 5
1701
1725
  self.redraw_tree_arrow(
1702
1726
  2,
1703
1727
  rtopgridln,
1704
- r=r,
1728
+ rbotgridln - 1,
1705
1729
  fill=tree_arrow_fg,
1706
1730
  tag="ta",
1707
1731
  indent=indent,
1708
1732
  has_children=bool(self.tree[iid].children),
1709
1733
  open_=self.MT._row_index[datarn].iid in self.tree_open_ids,
1734
+ level=level,
1710
1735
  )
1711
1736
  lns = self.get_valid_cell_data_as_str(datarn, fix=False)
1712
1737
  if not lns:
@@ -2517,13 +2542,21 @@ class RowIndex(tk.Canvas):
2517
2542
  def gen_top_nodes(self) -> Generator[Node]:
2518
2543
  yield from (node for node in self.MT._row_index if node.parent == "")
2519
2544
 
2520
- def get_treeview_indent(self, iid: str) -> int:
2545
+ def get_iid_indent(self, iid: str) -> int:
2521
2546
  if isinstance(self.PAR.ops.treeview_indent, str):
2522
2547
  indent = self.MT.index_txt_width * int(self.PAR.ops.treeview_indent)
2523
2548
  else:
2524
2549
  indent = self.PAR.ops.treeview_indent
2525
2550
  return indent * max(self.get_node_level(self.tree[iid]))
2526
2551
 
2552
+ def get_iid_level_indent(self, iid: str) -> tuple[int, int]:
2553
+ if isinstance(self.PAR.ops.treeview_indent, str):
2554
+ indent = self.MT.index_txt_width * int(self.PAR.ops.treeview_indent)
2555
+ else:
2556
+ indent = self.PAR.ops.treeview_indent
2557
+ level = max(self.get_node_level(self.tree[iid]))
2558
+ return level, indent * level
2559
+
2527
2560
  def remove_node_from_parents_children(self, node: Node) -> None:
2528
2561
  if node.parent:
2529
2562
  node.parent.children.remove(node)
tksheet/sheet.py CHANGED
@@ -10,6 +10,7 @@ from collections.abc import (
10
10
  Iterator,
11
11
  Sequence,
12
12
  )
13
+ from functools import partial
13
14
  from itertools import (
14
15
  accumulate,
15
16
  chain,
@@ -192,7 +193,7 @@ class Sheet(tk.Frame):
192
193
  edit_cell_return: Literal["right", "down", ""] = "down",
193
194
  editor_del_key: Literal["forward", "backward", ""] = "forward",
194
195
  treeview: bool = False,
195
- treeview_indent: str | int = "6",
196
+ treeview_indent: str | int = "5",
196
197
  rounded_boxes: bool = True,
197
198
  alternate_color: str = "",
198
199
  # colors
@@ -4708,12 +4709,14 @@ class Sheet(tk.Frame):
4708
4709
  data: list[list[object]],
4709
4710
  iid_column: int,
4710
4711
  parent_column: int,
4711
- text_column: None | int = None,
4712
+ text_column: None | int | list[str] = None,
4712
4713
  push_ops: bool = False,
4713
4714
  row_heights: Sequence[int] | None | False = None,
4714
4715
  open_ids: Iterator[str] | None = None,
4715
4716
  safety: bool = True,
4716
4717
  ncols: int | None = None,
4718
+ include_iid_column: bool = True,
4719
+ include_parent_column: bool = True,
4717
4720
  ) -> Sheet:
4718
4721
  self.reset(cell_options=False, column_widths=False, header=False, redraw=False)
4719
4722
  if text_column is None:
@@ -4738,15 +4741,15 @@ class Sheet(tk.Frame):
4738
4741
  tally_of_ids[iid] += 1
4739
4742
  row[iid_column] = new
4740
4743
  if iid in self.RI.tree:
4741
- self.RI.tree[iid].text = row[text_column]
4744
+ self.RI.tree[iid].text = row[text_column] if isinstance(text_column, int) else text_column[rn]
4742
4745
  else:
4743
- self.RI.tree[iid] = Node(row[text_column], iid, "")
4746
+ self.RI.tree[iid] = Node(row[text_column] if isinstance(text_column, int) else text_column[rn], iid, "")
4744
4747
  if safety and (iid == pid or self.RI.build_pid_causes_recursive_loop(iid, pid)):
4745
4748
  row[parent_column] = ""
4746
4749
  pid = ""
4747
4750
  if pid:
4748
4751
  if pid not in self.RI.tree:
4749
- self.RI.tree[pid] = Node(row[text_column], pid)
4752
+ self.RI.tree[pid] = Node(row[text_column] if isinstance(text_column, int) else text_column[rn], pid)
4750
4753
  self.RI.tree[iid].parent = self.RI.tree[pid]
4751
4754
  self.RI.tree[pid].children.append(self.RI.tree[iid])
4752
4755
  else:
@@ -4759,8 +4762,9 @@ class Sheet(tk.Frame):
4759
4762
  newrow[iid_column] = n.iid
4760
4763
  self.RI.tree_rns[n.iid] = len(data)
4761
4764
  data.append(newrow)
4762
- self.insert_rows(
4763
- rows=[[self.RI.tree[iid]] + data[self.RI.tree_rns[iid]] for iid in self.get_children()],
4765
+
4766
+ insert_rows = partial(
4767
+ self.insert_rows,
4764
4768
  idx=0,
4765
4769
  heights={} if row_heights is False else row_heights,
4766
4770
  row_index=True,
@@ -4769,6 +4773,37 @@ class Sheet(tk.Frame):
4769
4773
  push_ops=push_ops,
4770
4774
  redraw=False,
4771
4775
  )
4776
+
4777
+ if include_iid_column and include_parent_column:
4778
+ insert_rows(rows=[[self.RI.tree[iid]] + data[self.RI.tree_rns[iid]] for iid in self.get_children()])
4779
+
4780
+ elif include_iid_column and not include_parent_column:
4781
+ exclude = {parent_column}
4782
+ insert_rows(
4783
+ rows=[
4784
+ [self.RI.tree[iid]] + [e for i, e in enumerate(data[self.RI.tree_rns[iid]]) if i not in exclude]
4785
+ for iid in self.get_children()
4786
+ ]
4787
+ )
4788
+
4789
+ elif include_parent_column and not include_iid_column:
4790
+ exclude = {iid_column}
4791
+ insert_rows(
4792
+ rows=[
4793
+ [self.RI.tree[iid]] + [e for i, e in enumerate(data[self.RI.tree_rns[iid]]) if i not in exclude]
4794
+ for iid in self.get_children()
4795
+ ]
4796
+ )
4797
+
4798
+ elif not include_iid_column and not include_parent_column:
4799
+ exclude = {iid_column, parent_column}
4800
+ insert_rows(
4801
+ rows=[
4802
+ [self.RI.tree[iid]] + [e for i, e in enumerate(data[self.RI.tree_rns[iid]]) if i not in exclude]
4803
+ for iid in self.get_children()
4804
+ ]
4805
+ )
4806
+
4772
4807
  self.MT.all_rows_displayed = False
4773
4808
  self.MT.displayed_rows = list(range(len(self.MT._row_index)))
4774
4809
  self.RI.tree_rns = {n.iid: i for i, n in enumerate(self.MT._row_index)}
@@ -4886,12 +4921,12 @@ class Sheet(tk.Frame):
4886
4921
  index: None | int | Literal["end"] = None,
4887
4922
  iid: None | str = None,
4888
4923
  text: None | str = None,
4889
- values: None | list = None,
4924
+ values: None | list[object] = None,
4890
4925
  create_selections: bool = False,
4891
4926
  ) -> str:
4892
4927
  if iid is None:
4893
4928
  i = 0
4894
- while (iid := f"{i}") in self.RI.tree:
4929
+ while (iid := f"{num2alpha(i)}") in self.RI.tree:
4895
4930
  i += 1
4896
4931
  iid, pid = iid.lower(), parent.lower()
4897
4932
  if not iid:
@@ -5214,7 +5249,7 @@ class Sheet(tk.Frame):
5214
5249
  raise ValueError(f"Item '{item}' does not exist.")
5215
5250
  return self.RI.tree_rns[item] in self.MT.displayed_rows
5216
5251
 
5217
- def display_item(self, item: str, redraw=False) -> Sheet:
5252
+ def display_item(self, item: str, redraw: bool = False) -> Sheet:
5218
5253
  """
5219
5254
  Ensure that item is displayed in the tree
5220
5255
  - Opens all of an item's ancestors
@@ -5231,7 +5266,7 @@ class Sheet(tk.Frame):
5231
5266
  )
5232
5267
  return self.set_refresh_timer(redraw)
5233
5268
 
5234
- def scroll_to_item(self, item: str, redraw=False) -> Sheet:
5269
+ def scroll_to_item(self, item: str, redraw: bool = False) -> Sheet:
5235
5270
  """
5236
5271
  Scrolls to an item and ensures that it is displayed
5237
5272
  """
tksheet/sheet_options.py CHANGED
@@ -242,7 +242,7 @@ def new_sheet_options() -> DotDict:
242
242
  "edit_cell_return": "down",
243
243
  "editor_del_key": "forward",
244
244
  "treeview": False,
245
- "treeview_indent": "6",
245
+ "treeview_indent": "5",
246
246
  "rounded_boxes": True,
247
247
  "alternate_color": "",
248
248
  }
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tksheet
3
- Version: 7.2.15
3
+ Version: 7.2.17
4
4
  Summary: Tkinter table / sheet widget
5
5
  Author-email: ragardner <github@ragardner.simplelogin.com>
6
6
  License: Copyright (c) 2019 ragardner and open source contributors
@@ -83,6 +83,7 @@ This library is maintained with the help of **[others](https://github.com/ragard
83
83
  - Change fonts and font size (not for individual cells)
84
84
  - Change any colors in the sheet
85
85
  - Dropdowns, check boxes, progress bars
86
+ - [Treeview mode](https://github.com/ragardner/tksheet/wiki/Version-7#treeview-mode)
86
87
  - [Hide rows and/or columns](https://github.com/ragardner/tksheet/wiki/Version-7#example-header-dropdown-boxes-and-row-filtering)
87
88
  - Left `"w"`, Center `"center"` or Right `"e"` text alignment for any cell/row/column
88
89
 
@@ -110,3 +111,10 @@ sheet.delete_columns(columns=[0, 3], undo=True)
110
111
  ### **dark theme**
111
112
 
112
113
  ![tksheet dark theme](https://github.com/user-attachments/assets/288453d6-5ac1-4d45-827f-45b24a3d05ed)
114
+
115
+ ### **treeview mode**
116
+
117
+ ![tksheet treeview](https://github.com/user-attachments/assets/159ab987-7612-4db7-98de-1f30c9680247)
118
+
119
+
120
+
@@ -1,20 +1,20 @@
1
- tksheet/__init__.py,sha256=7DsA4dnRJU4f9UyzWDd0-lHkvu9HCT28y5A2n7g4z3g,2165
1
+ tksheet/__init__.py,sha256=TDIJBK7_SlAbZEGQyaWByzoFyx9741bcSAEQHnD_Rms,2165
2
2
  tksheet/colors.py,sha256=1k06VorynLmnC4FdJg8H4reIA6rXaeXBpdMwXLhN8oc,51594
3
3
  tksheet/column_headers.py,sha256=bHv67vRhRYxw_qyrw5akJo-b77vtN4y-mEO617FEqxE,102222
4
4
  tksheet/formatters.py,sha256=DXif00aq9DgFpXwkbiqD86KxtDg0Meop51hLY-KcGNQ,10037
5
5
  tksheet/functions.py,sha256=wTWsTFZkTMJH-2qz--9qNaprWqhA7sYVzCEhuw_PRhs,42369
6
6
  tksheet/main_table.py,sha256=WeSemTwFb8zEu0v2QabPNGZqM06kkCs-IvP1HLSR1oM,328843
7
7
  tksheet/other_classes.py,sha256=HIKIDNXJRv0H5qbftcCtLVWW8NKSBAwyNXQOlmPWTDQ,15633
8
- tksheet/row_index.py,sha256=docjegBsQIO0qfPE7_zgTPkdTOHBMRJBpA9t6wqslj0,109630
9
- tksheet/sheet.py,sha256=ffaVQmjBEFtDiDDif7L1ze7XIT2jMmFHhPerC4AqubU,275549
10
- tksheet/sheet_options.py,sha256=d6o2TxGrHEJbdeFYfD67QPXM9irKSnLyNIiJI46gaw0,12442
8
+ tksheet/row_index.py,sha256=kEdlyPaSeTFGhEwKMN57jH61WMN5fX91Xi3EnR1x8Ws,110974
9
+ tksheet/sheet.py,sha256=3U5E7k9_LdRKmTmEX_WBuPVPuTWYY5SzRY0OTiRIgXQ,277075
10
+ tksheet/sheet_options.py,sha256=hA4Gi2spLmltq3HrgfzetUaqvT_FaVI8PrSQkgdoyEE,12442
11
11
  tksheet/text_editor.py,sha256=lmmHOPb11S8tlNtC10vijF1QqVB5Ts2hUKnGJd_JkWA,7103
12
12
  tksheet/themes.py,sha256=ZO4RqnAhEpApsoA5ZGUkYvb7huaNHSmrV_ug2TWWzOE,14474
13
13
  tksheet/top_left_rectangle.py,sha256=ri7hb9CC5l37ynmxceprq11UuWWRpWEI_0AI42wzv0A,8444
14
14
  tksheet/types.py,sha256=IgoEHMbceKpakcZtanxKaKJ4RdCq7UW6EoEIIz5O59k,340
15
15
  tksheet/vars.py,sha256=86ubZZElsnQuC6Lv6bW2lt2NhD9wAp6PxtkK7ufKqq0,3452
16
- tksheet-7.2.15.dist-info/LICENSE.txt,sha256=ndbcCPe9SlHfweE_W2RAueWUe2k7yudyxYLq6WjFdn4,1101
17
- tksheet-7.2.15.dist-info/METADATA,sha256=LvqFaxqVU3rN2hYis6Ur4XO_AehkY4bBjuhbkb5rvt8,6263
18
- tksheet-7.2.15.dist-info/WHEEL,sha256=UvcQYKBHoFqaQd6LKyqHw9fxEolWLQnlzP0h_LgJAfI,91
19
- tksheet-7.2.15.dist-info/top_level.txt,sha256=my61PXCcck_HHAc9cq3NAlyAr3A3FXxCy9gptEOaCN8,8
20
- tksheet-7.2.15.dist-info/RECORD,,
16
+ tksheet-7.2.17.dist-info/LICENSE.txt,sha256=ndbcCPe9SlHfweE_W2RAueWUe2k7yudyxYLq6WjFdn4,1101
17
+ tksheet-7.2.17.dist-info/METADATA,sha256=9Alc-s77Mb9MEJR4TIcAUQ8zM4h1hJCztLUEEB7uxMw,6476
18
+ tksheet-7.2.17.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
19
+ tksheet-7.2.17.dist-info/top_level.txt,sha256=my61PXCcck_HHAc9cq3NAlyAr3A3FXxCy9gptEOaCN8,8
20
+ tksheet-7.2.17.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.0.0)
2
+ Generator: setuptools (75.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5