tksheet 7.1.6__py3-none-any.whl → 7.1.8__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/other_classes.py CHANGED
@@ -17,10 +17,8 @@ Box_t = namedtuple(
17
17
  "Box_t",
18
18
  "from_r from_c upto_r upto_c type_",
19
19
  )
20
- Box_st = namedtuple(
21
- "Box_st",
22
- "coords type_"
23
- )
20
+ Box_st = namedtuple("Box_st", "coords type_")
21
+ Loc = namedtuple("Loc", "row column")
24
22
 
25
23
  Highlight = namedtuple(
26
24
  "Highlight",
@@ -472,4 +470,3 @@ Selected = namedtuple(
472
470
  None,
473
471
  ),
474
472
  )
475
-
tksheet/row_index.py CHANGED
@@ -31,10 +31,10 @@ from .functions import (
31
31
  consecutive_chunks,
32
32
  ev_stack_dict,
33
33
  event_dict,
34
- get_checkbox_points,
35
34
  get_n2a,
36
35
  is_contiguous,
37
36
  num2alpha,
37
+ rounded_box_coords,
38
38
  try_binding,
39
39
  )
40
40
  from .other_classes import (
@@ -51,6 +51,7 @@ from .vars import (
51
51
  USER_OS,
52
52
  rc_binding,
53
53
  symbols_set,
54
+ text_editor_to_unbind,
54
55
  )
55
56
 
56
57
 
@@ -405,7 +406,7 @@ class RowIndex(tk.Canvas):
405
406
  ):
406
407
  self.open_cell(event)
407
408
  elif (iid := self.event_over_tree_arrow(r, self.canvasy(event.y), event.x)) is not None:
408
- self.PAR.item(iid, open_=iid not in self.tree_open_ids)
409
+ self.PAR.item(iid, open_=iid not in self.tree_open_ids, redraw=False)
409
410
  self.rsz_h = None
410
411
  self.mouse_motion(event)
411
412
  try_binding(self.extra_double_b1_func, event)
@@ -869,7 +870,7 @@ class RowIndex(tk.Canvas):
869
870
  elif (iid := self.event_over_tree_arrow(r, canvasy, event.x)) is not None:
870
871
  if self.MT.selection_boxes:
871
872
  self.select_row(r, redraw=False)
872
- self.PAR.item(iid, open_=iid not in self.tree_open_ids)
873
+ self.PAR.item(iid, open_=iid not in self.tree_open_ids, redraw=False)
873
874
  else:
874
875
  self.mouseclick_outside_editor_or_dropdown_all_canvases(inside=True)
875
876
  self.b1_pressed_loc = None
@@ -958,14 +959,33 @@ class RowIndex(tk.Canvas):
958
959
  outline: str,
959
960
  state: str,
960
961
  tags: str | tuple[str],
962
+ iid: None | int = None,
961
963
  ) -> int:
962
- if self.hidd_boxes:
963
- iid = self.hidd_boxes.pop()
964
- self.coords(iid, x1, y1, x2, y2)
964
+ coords = rounded_box_coords(
965
+ x1,
966
+ y1,
967
+ x2,
968
+ y2,
969
+ radius=8 if self.PAR.ops.rounded_boxes else 0,
970
+ )
971
+ if isinstance(iid, int):
972
+ self.coords(iid, coords)
965
973
  self.itemconfig(iid, fill=fill, outline=outline, state=state, tags=tags)
966
974
  else:
967
- iid = self.create_rectangle(x1, y1, x2, y2, fill=fill, outline=outline, state=state, tags=tags)
968
- self.disp_boxes.add(iid)
975
+ if self.hidd_boxes:
976
+ iid = self.hidd_boxes.pop()
977
+ self.coords(iid, coords)
978
+ self.itemconfig(iid, fill=fill, outline=outline, state=state, tags=tags)
979
+ else:
980
+ iid = self.create_polygon(
981
+ coords,
982
+ fill=fill,
983
+ outline=outline,
984
+ state=state,
985
+ tags=tags,
986
+ smooth=True,
987
+ )
988
+ self.disp_boxes.add(iid)
969
989
  return iid
970
990
 
971
991
  def hide_box(self, item: int | None) -> None:
@@ -1341,7 +1361,7 @@ class RowIndex(tk.Canvas):
1341
1361
  self.disp_dropdown[t] = True
1342
1362
 
1343
1363
  def redraw_checkbox(self, x1, y1, x2, y2, fill, outline, tag, draw_check=False):
1344
- points = get_checkbox_points(x1, y1, x2, y2)
1364
+ points = rounded_box_coords(x1, y1, x2, y2)
1345
1365
  if self.hidd_checkbox:
1346
1366
  t, sh = self.hidd_checkbox.popitem()
1347
1367
  self.coords(t, points)
@@ -1359,7 +1379,7 @@ class RowIndex(tk.Canvas):
1359
1379
  y1 = y1 + 4
1360
1380
  x2 = x2 - 3
1361
1381
  y2 = y2 - 3
1362
- points = get_checkbox_points(x1, y1, x2, y2, radius=4)
1382
+ points = rounded_box_coords(x1, y1, x2, y2, radius=4)
1363
1383
  if self.hidd_checkbox:
1364
1384
  t, sh = self.hidd_checkbox.popitem()
1365
1385
  self.coords(t, points)
@@ -1659,16 +1679,14 @@ class RowIndex(tk.Canvas):
1659
1679
  dct[iid] = False
1660
1680
  return True
1661
1681
 
1662
- def get_redraw_selections(self, startr, endr):
1663
- d = defaultdict(list)
1682
+ def get_redraw_selections(self, startr: int, endr: int) -> dict[str, set[int]]:
1683
+ d = defaultdict(set)
1664
1684
  for item, box in self.MT.get_selection_items(columns=False):
1665
- d[box.type_].append(box.coords)
1666
- d2 = {}
1667
- if "cells" in d:
1668
- d2["cells"] = {r for r in range(startr, endr) for r1, c1, r2, c2 in d["cells"] if r1 <= r and r2 > r}
1669
- if "rows" in d:
1670
- d2["rows"] = {r for r in range(startr, endr) for r1, c1, r2, c2 in d["rows"] if r1 <= r and r2 > r}
1671
- return d2
1685
+ r1, c1, r2, c2 = box.coords
1686
+ for r in range(startr, endr):
1687
+ if r1 <= r and r2 > r:
1688
+ d[box.type_].add(r)
1689
+ return d
1672
1690
 
1673
1691
  def open_cell(self, event: object = None, ignore_existing_editor=False):
1674
1692
  if not self.MT.anything_selected() or (not ignore_existing_editor and self.text_editor.open):
@@ -1738,6 +1756,7 @@ class RowIndex(tk.Canvas):
1738
1756
  key=extra_func_key,
1739
1757
  value=text,
1740
1758
  loc=r,
1759
+ row=r,
1741
1760
  boxes=self.MT.get_boxes(),
1742
1761
  selected=self.MT.selected,
1743
1762
  )
@@ -1799,12 +1818,14 @@ class RowIndex(tk.Canvas):
1799
1818
  self.text_editor.tktext.focus_set()
1800
1819
  self.text_editor.window.scroll_to_bottom()
1801
1820
  self.text_editor.tktext.bind("<Alt-Return>", lambda _x: self.text_editor_newline_binding(r=r))
1821
+ self.text_editor.tktext.bind("<Alt-KP_Enter>", lambda _x: self.text_editor_newline_binding(r=r))
1802
1822
  if USER_OS == "darwin":
1803
1823
  self.text_editor.tktext.bind("<Option-Return>", lambda _x: self.text_editor_newline_binding(r=r))
1804
1824
  for key, func in self.MT.text_editor_user_bound_keys.items():
1805
1825
  self.text_editor.tktext.bind(key, func)
1806
1826
  self.text_editor.tktext.bind("<Tab>", lambda _x: self.close_text_editor((r, "Tab")))
1807
1827
  self.text_editor.tktext.bind("<Return>", lambda _x: self.close_text_editor((r, "Return")))
1828
+ self.text_editor.tktext.bind("<KP_Enter>", lambda _x: self.close_text_editor((r, "Return")))
1808
1829
  if not dropdown:
1809
1830
  self.text_editor.tktext.bind("<FocusOut>", lambda _x: self.close_text_editor((r, "FocusOut")))
1810
1831
  self.text_editor.tktext.bind("<Escape>", lambda _x: self.close_text_editor((r, "Escape")))
@@ -1892,6 +1913,8 @@ class RowIndex(tk.Canvas):
1892
1913
 
1893
1914
  def hide_text_editor(self, reason: None | str = None) -> None:
1894
1915
  if self.text_editor.open:
1916
+ for binding in text_editor_to_unbind:
1917
+ self.text_editor.tktext.unbind(binding)
1895
1918
  self.itemconfig(self.text_editor.canvas_id, state="hidden")
1896
1919
  self.text_editor.open = False
1897
1920
  if reason == "Escape":
@@ -1913,7 +1936,7 @@ class RowIndex(tk.Canvas):
1913
1936
  if editor_info is not None and len(editor_info) >= 2 and editor_info[1] == "Escape":
1914
1937
  self.hide_text_editor_and_dropdown()
1915
1938
  return
1916
- self.text_editor_value = self.text_editor.get()
1939
+ text_editor_value = self.text_editor.get()
1917
1940
  r = editor_info[0]
1918
1941
  datarn = r if self.MT.all_rows_displayed else self.MT.displayed_rows[r]
1919
1942
  event_data = event_dict(
@@ -1921,8 +1944,9 @@ class RowIndex(tk.Canvas):
1921
1944
  sheet=self.PAR.name,
1922
1945
  cells_index={datarn: self.get_cell_data(datarn)},
1923
1946
  key=editor_info[1] if len(editor_info) >= 2 else "FocusOut",
1924
- value=self.text_editor_value,
1947
+ value=text_editor_value,
1925
1948
  loc=r,
1949
+ row=r,
1926
1950
  boxes=self.MT.get_boxes(),
1927
1951
  selected=self.MT.selected,
1928
1952
  )
@@ -1934,11 +1958,11 @@ class RowIndex(tk.Canvas):
1934
1958
  check_input_valid=False,
1935
1959
  )
1936
1960
  if self.MT.edit_validation_func:
1937
- self.text_editor_value = self.MT.edit_validation_func(event_data)
1938
- if self.text_editor_value is not None and self.input_valid_for_cell(datarn, self.text_editor_value):
1939
- edited = set_data(value=self.text_editor_value)
1940
- elif self.input_valid_for_cell(datarn, self.text_editor_value):
1941
- edited = set_data(value=self.text_editor_value)
1961
+ text_editor_value = self.MT.edit_validation_func(event_data)
1962
+ if text_editor_value is not None and self.input_valid_for_cell(datarn, text_editor_value):
1963
+ edited = set_data(value=text_editor_value)
1964
+ elif self.input_valid_for_cell(datarn, text_editor_value):
1965
+ edited = set_data(value=text_editor_value)
1942
1966
  if edited:
1943
1967
  try_binding(self.extra_end_edit_cell_func, event_data)
1944
1968
  self.MT.recreate_all_selection_boxes()
@@ -2045,6 +2069,7 @@ class RowIndex(tk.Canvas):
2045
2069
  sheet=self.PAR.name,
2046
2070
  value=self.text_editor.get(),
2047
2071
  loc=r,
2072
+ row=r,
2048
2073
  boxes=self.MT.get_boxes(),
2049
2074
  selected=self.MT.selected,
2050
2075
  ),
@@ -2081,6 +2106,7 @@ class RowIndex(tk.Canvas):
2081
2106
  key="??",
2082
2107
  value=selection,
2083
2108
  loc=r,
2109
+ row=r,
2084
2110
  boxes=self.MT.get_boxes(),
2085
2111
  selected=self.MT.selected,
2086
2112
  )
@@ -2125,6 +2151,7 @@ class RowIndex(tk.Canvas):
2125
2151
 
2126
2152
  def hide_dropdown_window(self) -> None:
2127
2153
  if self.dropdown.open:
2154
+ self.dropdown.window.unbind("<FocusOut>")
2128
2155
  self.itemconfig(self.dropdown.canvas_id, state="hidden")
2129
2156
  self.dropdown.open = False
2130
2157
 
@@ -2302,6 +2329,7 @@ class RowIndex(tk.Canvas):
2302
2329
  key="??",
2303
2330
  value=value,
2304
2331
  loc=r,
2332
+ row=r,
2305
2333
  boxes=self.MT.get_boxes(),
2306
2334
  selected=self.MT.selected,
2307
2335
  )