tksheet 7.1.8__py3-none-any.whl → 7.1.9__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.1.8"
7
+ __version__ = "7.1.9"
8
8
 
9
9
  from .colors import (
10
10
  color_map,
tksheet/functions.py CHANGED
@@ -614,7 +614,7 @@ def try_binding(
614
614
  event: dict,
615
615
  new_name: None | str = None,
616
616
  ) -> bool:
617
- if binding is not None:
617
+ if binding:
618
618
  try:
619
619
  if new_name is None:
620
620
  binding(event)
tksheet/main_table.py CHANGED
@@ -1130,7 +1130,11 @@ class MainTable(tk.Canvas):
1130
1130
  )
1131
1131
  else:
1132
1132
  disp_new_idxs = {}
1133
- totalrows = self.fix_data_len(move_to)
1133
+ self.fix_data_len(move_to)
1134
+ totalrows = max(
1135
+ self.total_data_rows(),
1136
+ len(self.row_positions) - 1,
1137
+ )
1134
1138
  if self.all_rows_displayed or data_indexes:
1135
1139
  data_new_idxs = get_new_indexes(seqlen=totalrows, move_to=move_to, to_move=to_move)
1136
1140
  elif not self.all_rows_displayed and not data_indexes:
@@ -1157,7 +1161,12 @@ class MainTable(tk.Canvas):
1157
1161
  ) -> tuple[dict[int, int], dict[int, int], EventDataDict]:
1158
1162
  self.saved_row_heights = {}
1159
1163
  if not isinstance(totalrows, int):
1160
- totalrows = self.fix_data_len(max(data_new_idxs.values(), default=0))
1164
+ totalrows = max(
1165
+ self.total_data_rows(),
1166
+ len(self.row_positions) - 1,
1167
+ max(data_new_idxs.values(), default=0),
1168
+ )
1169
+ totalrows = self.fix_data_len(totalrows)
1161
1170
  if event_data is None:
1162
1171
  event_data = event_dict(
1163
1172
  name="move_rows",
@@ -1444,9 +1453,7 @@ class MainTable(tk.Canvas):
1444
1453
  saved_cells = True
1445
1454
 
1446
1455
  if modification["moved"]["columns"]:
1447
- totalcols = self.equalize_data_row_lengths()
1448
- if totalcols < (mx_k := max(modification["moved"]["columns"]["data"].values())):
1449
- totalcols = mx_k
1456
+ totalcols = max(self.equalize_data_row_lengths(), max(modification["moved"]["columns"]["data"].values()))
1450
1457
  data_new_idxs, disp_new_idxs, event_data = self.move_columns_adjust_options_dict(
1451
1458
  data_new_idxs=dict(
1452
1459
  zip(
@@ -1471,9 +1478,7 @@ class MainTable(tk.Canvas):
1471
1478
  self.restore_options_named_spans(modification)
1472
1479
 
1473
1480
  if modification["moved"]["rows"]:
1474
- totalrows = self.total_data_rows()
1475
- if totalrows < (mx_k := max(modification["moved"]["rows"]["data"].values())):
1476
- totalrows = mx_k
1481
+ totalrows = max(self.total_data_rows(), max(modification["moved"]["rows"]["data"].values()))
1477
1482
  data_new_idxs, disp_new_idxs, event_data = self.move_rows_adjust_options_dict(
1478
1483
  data_new_idxs=dict(
1479
1484
  zip(
@@ -2745,8 +2750,7 @@ class MainTable(tk.Canvas):
2745
2750
 
2746
2751
  def mouse_motion(self, event: object):
2747
2752
  self.reset_mouse_motion_creations()
2748
- if self.extra_motion_func:
2749
- self.extra_motion_func(event)
2753
+ try_binding(self.extra_motion_func, event)
2750
2754
 
2751
2755
  def not_currently_resizing(self) -> bool:
2752
2756
  return all(v is None for v in (self.RI.rsz_h, self.RI.rsz_w, self.CH.rsz_h, self.CH.rsz_w))
@@ -2759,12 +2763,15 @@ class MainTable(tk.Canvas):
2759
2763
  r = self.identify_row(y=event.y)
2760
2764
  c = self.identify_col(x=event.x)
2761
2765
  if r < len(self.row_positions) - 1 and c < len(self.col_positions) - 1:
2762
- if self.col_selected(c) and self.rc_popup_menus_enabled:
2763
- popup_menu = self.CH.ch_rc_popup_menu
2764
- elif self.row_selected(r) and self.rc_popup_menus_enabled:
2765
- popup_menu = self.RI.ri_rc_popup_menu
2766
- elif self.cell_selected(r, c) and self.rc_popup_menus_enabled:
2767
- popup_menu = self.rc_popup_menu
2766
+ if self.col_selected(c):
2767
+ if self.rc_popup_menus_enabled:
2768
+ popup_menu = self.CH.ch_rc_popup_menu
2769
+ elif self.row_selected(r):
2770
+ if self.rc_popup_menus_enabled:
2771
+ popup_menu = self.RI.ri_rc_popup_menu
2772
+ elif self.cell_selected(r, c):
2773
+ if self.rc_popup_menus_enabled:
2774
+ popup_menu = self.rc_popup_menu
2768
2775
  else:
2769
2776
  if self.rc_select_enabled:
2770
2777
  if self.single_selection_enabled:
@@ -2774,9 +2781,9 @@ class MainTable(tk.Canvas):
2774
2781
  if self.rc_popup_menus_enabled:
2775
2782
  popup_menu = self.rc_popup_menu
2776
2783
  else:
2784
+ self.deselect("all")
2777
2785
  popup_menu = self.empty_rc_popup_menu
2778
- if self.extra_rc_func:
2779
- self.extra_rc_func(event)
2786
+ try_binding(self.extra_rc_func, event)
2780
2787
  if popup_menu is not None:
2781
2788
  popup_menu.tk_popup(event.x_root, event.y_root)
2782
2789
 
@@ -2800,8 +2807,7 @@ class MainTable(tk.Canvas):
2800
2807
  if r < len(self.row_positions) - 1 and c < len(self.col_positions) - 1:
2801
2808
  self.toggle_select_cell(r, c, redraw=True)
2802
2809
  self.b1_pressed_loc = (r, c)
2803
- if self.extra_b1_press_func:
2804
- self.extra_b1_press_func(event)
2810
+ try_binding(self.extra_b1_press_func, event)
2805
2811
 
2806
2812
  def create_resize_line(self, x1, y1, x2, y2, width, fill, tag):
2807
2813
  if self.hidd_resize_lines:
@@ -2969,8 +2975,7 @@ class MainTable(tk.Canvas):
2969
2975
  need_redraw = True
2970
2976
  if need_redraw:
2971
2977
  self.main_table_redraw_grid_and_text(redraw_header=True, redraw_row_index=True, redraw_table=True)
2972
- if self.extra_b1_motion_func:
2973
- self.extra_b1_motion_func(event)
2978
+ try_binding(self.extra_b1_motion_func, event)
2974
2979
 
2975
2980
  def ctrl_b1_motion(self, event: object):
2976
2981
  if self.ctrl_select_enabled and self.drag_selection_enabled and self.not_currently_resizing():
@@ -3082,8 +3087,7 @@ class MainTable(tk.Canvas):
3082
3087
  self.mouseclick_outside_editor_or_dropdown_all_canvases()
3083
3088
  self.b1_pressed_loc = None
3084
3089
  self.closed_dropdown = None
3085
- if self.extra_b1_release_func:
3086
- self.extra_b1_release_func(event)
3090
+ try_binding(self.extra_b1_release_func, event)
3087
3091
 
3088
3092
  def double_b1(self, event=None):
3089
3093
  self.mouseclick_outside_editor_or_dropdown_all_canvases()
@@ -3107,8 +3111,7 @@ class MainTable(tk.Canvas):
3107
3111
  self.toggle_select_cell(r, c, redraw=True)
3108
3112
  if self.edit_cell_enabled:
3109
3113
  self.open_cell(event)
3110
- if self.extra_double_b1_func:
3111
- self.extra_double_b1_func(event)
3114
+ try_binding(self.extra_double_b1_func, event)
3112
3115
 
3113
3116
  def identify_row(self, event=None, y=None, allow_end=True):
3114
3117
  if event is None:
@@ -3329,7 +3332,9 @@ class MainTable(tk.Canvas):
3329
3332
  else (
3330
3333
  default_row_height
3331
3334
  if h == old_default_row_height
3332
- else self.min_row_height if h < self.min_row_height else h
3335
+ else self.min_row_height
3336
+ if h < self.min_row_height
3337
+ else h
3333
3338
  )
3334
3339
  )
3335
3340
  for h in self.gen_row_heights()
@@ -4274,7 +4279,7 @@ class MainTable(tk.Canvas):
4274
4279
  return event_data
4275
4280
 
4276
4281
  def rc_add_columns(self, event: object = None):
4277
- rowlen = self.equalize_data_row_lengths(include_header=False)
4282
+ rowlen = self.equalize_data_row_lengths()
4278
4283
  selcols = sorted(self.get_selected_cols())
4279
4284
  if (
4280
4285
  selcols
@@ -4860,24 +4865,15 @@ class MainTable(tk.Canvas):
4860
4865
  return self._row_index
4861
4866
 
4862
4867
  def total_data_cols(self, include_header: bool = True) -> int:
4863
- h_total = 0
4864
- d_total = 0
4865
- if include_header:
4866
- if isinstance(self._headers, (list, tuple)):
4867
- h_total = len(self._headers)
4868
- # map() for some reason is 15% faster than max(key=len)
4869
- # using python 3.11 windows 11
4868
+ h_total = len(self._headers) if include_header and isinstance(self._headers, (list, tuple)) else 0
4869
+ # map() for some reason is 15% faster than max(key=len) using python 3.11 windows 11
4870
4870
  d_total = max(map(len, self.data), default=0)
4871
- return h_total if h_total > d_total else d_total
4871
+ return max(h_total, d_total)
4872
4872
 
4873
4873
  def total_data_rows(self, include_index: bool = True) -> int:
4874
- i_total = 0
4875
- d_total = 0
4876
- if include_index:
4877
- if isinstance(self._row_index, (list, tuple)):
4878
- i_total = len(self._row_index)
4874
+ i_total = len(self._row_index) if include_index and isinstance(self._row_index, (list, tuple)) else 0
4879
4875
  d_total = len(self.data)
4880
- return i_total if i_total > d_total else d_total
4876
+ return max(i_total, d_total)
4881
4877
 
4882
4878
  def data_dimensions(self, total_rows: int | None = None, total_columns: int | None = None):
4883
4879
  if total_rows is None and total_columns is None:
@@ -4897,7 +4893,7 @@ class MainTable(tk.Canvas):
4897
4893
 
4898
4894
  def equalize_data_row_lengths(
4899
4895
  self,
4900
- include_header: bool = False,
4896
+ include_header: bool = True,
4901
4897
  total_data_cols: int | None = None,
4902
4898
  at_least_cols: int | None = None,
4903
4899
  ) -> int:
@@ -4905,6 +4901,7 @@ class MainTable(tk.Canvas):
4905
4901
  total_data_cols = self.total_data_cols(include_header=include_header)
4906
4902
  if isinstance(at_least_cols, int) and at_least_cols > total_data_cols:
4907
4903
  total_data_cols = at_least_cols
4904
+ total_data_cols = max(total_data_cols, len(self.col_positions) - 1)
4908
4905
  if include_header and total_data_cols > len(self._headers):
4909
4906
  self.CH.fix_header(total_data_cols)
4910
4907
  for rn, r in enumerate(self.data):
tksheet/sheet.py CHANGED
@@ -46,6 +46,7 @@ from .other_classes import (
46
46
  GeneratedMouseEvent,
47
47
  Node,
48
48
  Selected,
49
+ SelectionBox,
49
50
  Span,
50
51
  )
51
52
  from .row_index import RowIndex
@@ -1070,6 +1071,17 @@ class Sheet(tk.Frame):
1070
1071
  self.MT.redo(event)
1071
1072
  return self
1072
1073
 
1074
+ def has_focus(
1075
+ self,
1076
+ ) -> bool:
1077
+ """
1078
+ Check if any Sheet widgets have focus
1079
+ Includes child widgets such as scroll bars
1080
+ Returns bool
1081
+ """
1082
+ widget = self.focus_get()
1083
+ return widget == self or any(widget == c for c in self.children.values())
1084
+
1073
1085
  def focus_set(
1074
1086
  self,
1075
1087
  canvas: Literal[
@@ -1391,11 +1403,7 @@ class Sheet(tk.Frame):
1391
1403
  # retrieving a list of index cells or
1392
1404
  elif (index and not span.transposed and not table and not header) or (
1393
1405
  # it's a column that's spread across sublists
1394
- table
1395
- and res
1396
- and not span.transposed
1397
- and len(res[0]) == 1
1398
- and len(res[-1]) == 1
1406
+ table and res and not span.transposed and len(res[0]) == 1 and len(res[-1]) == 1
1399
1407
  ):
1400
1408
  res = list(chain.from_iterable(res))
1401
1409
  elif span.ndim == 1:
@@ -2389,8 +2397,31 @@ class Sheet(tk.Frame):
2389
2397
  self.set_refresh_timer(redraw)
2390
2398
  return data_idxs, disp_idxs, event_data
2391
2399
 
2392
- def equalize_data_row_lengths(self, include_header: bool = False) -> int:
2393
- return self.MT.equalize_data_row_lengths(include_header=include_header)
2400
+ def equalize_data_row_lengths(
2401
+ self,
2402
+ include_header: bool = True,
2403
+ ) -> int:
2404
+ return self.MT.equalize_data_row_lengths(
2405
+ include_header=include_header,
2406
+ )
2407
+
2408
+ def full_move_rows_idxs(self, data_idxs: dict[int, int]) -> dict[int, int]:
2409
+ """
2410
+ Converts the dict provided by moving rows event data
2411
+ Under the keys ['moved']['rows']['data']
2412
+ Into a dict of {old index: new index} for every row
2413
+ Includes row numbers in cell options, spans, etc.
2414
+ """
2415
+ return self.MT.get_full_new_idxs(self.MT.get_max_row_idx(), data_idxs)
2416
+
2417
+ def full_move_columns_idxs(self, data_idxs: dict[int, int]) -> dict[int, int]:
2418
+ """
2419
+ Converts the dict provided by moving columns event data
2420
+ Under the keys ['moved']['columns']['data']
2421
+ Into a dict of {old index: new index} for every column
2422
+ Includes column numbers in cell options, spans, etc.
2423
+ """
2424
+ return self.MT.get_full_new_idxs(self.MT.get_max_column_idx(), data_idxs)
2394
2425
 
2395
2426
  # Highlighting Cells
2396
2427
 
@@ -2976,6 +3007,10 @@ class Sheet(tk.Frame):
2976
3007
  )
2977
3008
  return self
2978
3009
 
3010
+ @property
3011
+ def canvas_boxes(self) -> dict[int, SelectionBox]:
3012
+ return self.MT.selection_boxes
3013
+
2979
3014
  def cell_selected(
2980
3015
  self,
2981
3016
  r: int,
@@ -3008,8 +3043,17 @@ class Sheet(tk.Frame):
3008
3043
  def all_selected(self) -> bool:
3009
3044
  return self.MT.all_selected()
3010
3045
 
3011
- def get_ctrl_x_c_boxes(self) -> tuple[dict[tuple[int, int, int, int], str], int]:
3012
- return self.MT.get_ctrl_x_c_boxes()
3046
+ def get_ctrl_x_c_boxes(
3047
+ self,
3048
+ nrows: bool = True,
3049
+ ) -> tuple[dict[tuple[int, int, int, int], str], int] | dict[tuple[int, int, int, int], str]:
3050
+ if nrows:
3051
+ return self.MT.get_ctrl_x_c_boxes()
3052
+ return self.MT.get_ctrl_x_c_boxes()[0]
3053
+
3054
+ @property
3055
+ def ctrl_boxes(self) -> dict[tuple[int, int, int, int], str]:
3056
+ return self.MT.get_ctrl_x_c_boxes()[0]
3013
3057
 
3014
3058
  def get_selected_min_max(
3015
3059
  self,
@@ -4466,7 +4510,7 @@ class Sheet(tk.Frame):
4466
4510
  self.RI.tree_rns = {n.iid: i for i, n in enumerate(self.MT._row_index)}
4467
4511
  self.hide_rows(
4468
4512
  set(self.RI.tree_rns[iid] for iid in self.get_children() if self.RI.tree[iid].parent),
4469
- deselect_all=True,
4513
+ deselect_all=False,
4470
4514
  data_indexes=True,
4471
4515
  )
4472
4516
  return self
@@ -4793,7 +4837,7 @@ class Sheet(tk.Frame):
4793
4837
  reattach = move
4794
4838
 
4795
4839
  def exists(self, item: str) -> bool:
4796
- return item in self.RI.tree
4840
+ return item.lower() in self.RI.tree
4797
4841
 
4798
4842
  def parent(self, item: str) -> str:
4799
4843
  if (item := item.lower()) not in self.RI.tree:
@@ -5419,7 +5463,7 @@ class Sheet(tk.Frame):
5419
5463
  row: int = 0,
5420
5464
  column: int = 0,
5421
5465
  cells: list = [],
5422
- canvas: str = "table",
5466
+ canvas: Literal["table", "index", "header"] = "table",
5423
5467
  bg: bool | None | str = False,
5424
5468
  fg: bool | None | str = False,
5425
5469
  redraw: bool = True,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: tksheet
3
- Version: 7.1.8
3
+ Version: 7.1.9
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
@@ -1,20 +1,20 @@
1
- tksheet/__init__.py,sha256=QkLl7gG86v_1GMYTSGmOr137dpoTBZE2IpCEgCB40d8,1994
1
+ tksheet/__init__.py,sha256=9Wvm_zS75-z0FFGXl9Vz1cGsXbUBi983lVC3VmLnmhM,1994
2
2
  tksheet/colors.py,sha256=1k06VorynLmnC4FdJg8H4reIA6rXaeXBpdMwXLhN8oc,51594
3
3
  tksheet/column_headers.py,sha256=u5SRsI3VAoqxpUpPQZfu2Zimmf2OmZUBD_hMJKso-pw,100204
4
4
  tksheet/formatters.py,sha256=DXif00aq9DgFpXwkbiqD86KxtDg0Meop51hLY-KcGNQ,10037
5
- tksheet/functions.py,sha256=__21LS0cft9quuzFXcJ0BMbB0DEntvS4NQvreGk2U8Y,39709
6
- tksheet/main_table.py,sha256=zY5RNV2AyJ3jM8JPMmYrwCXGsnefnVVlXcjaqYxdxvg,318290
5
+ tksheet/functions.py,sha256=ytmHQtSa8cN6dKYLFra5G0393-4sU7bivvT_U4wxksI,39697
6
+ tksheet/main_table.py,sha256=YKlcqiSj089i0-HXGtPBTLGW28Y7d_lv6hFFF6S_pQM,318310
7
7
  tksheet/other_classes.py,sha256=P3FYUYreLhstATvHCNow8sDQoCsD_02KB6oXcca3ahE,13628
8
8
  tksheet/row_index.py,sha256=wfOPHitGfipTysCMfQA-Nl4mJawmkv9gm5CAtIlKgxo,105673
9
- tksheet/sheet.py,sha256=WvCuIszL31oJLhf0XJpvc0kHxa1yMAwEjiPrjeLkAQ8,257298
9
+ tksheet/sheet.py,sha256=n_LrHnd4Xim2TzgJ1DY8Z1n2aaUdtwWiRukvxFMTOws,258919
10
10
  tksheet/sheet_options.py,sha256=mh0rTvWrFvIKaiv88jtMZy0TSA8zTS1GXSe88u8_rzk,11978
11
11
  tksheet/text_editor.py,sha256=81_IZKrTVa2KIx2cJ4n3cFvFMAwvbHIQYgqtyat-97I,6681
12
12
  tksheet/themes.py,sha256=OwUe31NRbosjw3ZoZsMyB8lNVyYin9YcKLhCturi5q8,13398
13
13
  tksheet/top_left_rectangle.py,sha256=-2u9GfOvcqhkKwHEtbqdFvXCY3RbvL5k2Sh9l3r_k04,8275
14
14
  tksheet/types.py,sha256=IgoEHMbceKpakcZtanxKaKJ4RdCq7UW6EoEIIz5O59k,340
15
15
  tksheet/vars.py,sha256=8Qxas-m5nU-yMaeAweO4Z30FM9cOQoRTiOsH4kgZp5s,2288
16
- tksheet-7.1.8.dist-info/LICENSE.txt,sha256=ndbcCPe9SlHfweE_W2RAueWUe2k7yudyxYLq6WjFdn4,1101
17
- tksheet-7.1.8.dist-info/METADATA,sha256=eyi1aRtOSI35o-qYZpAJSZMyYjisRqRyZk_qg1JWx74,6013
18
- tksheet-7.1.8.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
19
- tksheet-7.1.8.dist-info/top_level.txt,sha256=my61PXCcck_HHAc9cq3NAlyAr3A3FXxCy9gptEOaCN8,8
20
- tksheet-7.1.8.dist-info/RECORD,,
16
+ tksheet-7.1.9.dist-info/LICENSE.txt,sha256=ndbcCPe9SlHfweE_W2RAueWUe2k7yudyxYLq6WjFdn4,1101
17
+ tksheet-7.1.9.dist-info/METADATA,sha256=Nyratgt4E9d83xYtfOpdQh4nd8o4HzTiV7-Mz61RPZw,6013
18
+ tksheet-7.1.9.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
19
+ tksheet-7.1.9.dist-info/top_level.txt,sha256=my61PXCcck_HHAc9cq3NAlyAr3A3FXxCy9gptEOaCN8,8
20
+ tksheet-7.1.9.dist-info/RECORD,,