tksheet 7.4.21__tar.gz → 7.4.22__tar.gz

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.
Files changed (26) hide show
  1. {tksheet-7.4.21/tksheet.egg-info → tksheet-7.4.22}/PKG-INFO +1 -1
  2. {tksheet-7.4.21 → tksheet-7.4.22}/pyproject.toml +1 -1
  3. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/__init__.py +1 -1
  4. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/main_table.py +27 -12
  5. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/other_classes.py +2 -2
  6. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/sheet.py +35 -38
  7. {tksheet-7.4.21 → tksheet-7.4.22/tksheet.egg-info}/PKG-INFO +1 -1
  8. {tksheet-7.4.21 → tksheet-7.4.22}/LICENSE.txt +0 -0
  9. {tksheet-7.4.21 → tksheet-7.4.22}/README.md +0 -0
  10. {tksheet-7.4.21 → tksheet-7.4.22}/setup.cfg +0 -0
  11. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/colors.py +0 -0
  12. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/column_headers.py +0 -0
  13. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/constants.py +0 -0
  14. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/find_window.py +0 -0
  15. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/formatters.py +0 -0
  16. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/functions.py +0 -0
  17. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/row_index.py +0 -0
  18. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/sheet_options.py +0 -0
  19. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/sorting.py +0 -0
  20. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/text_editor.py +0 -0
  21. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/themes.py +0 -0
  22. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/tksheet_types.py +0 -0
  23. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet/top_left_rectangle.py +0 -0
  24. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet.egg-info/SOURCES.txt +0 -0
  25. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet.egg-info/dependency_links.txt +0 -0
  26. {tksheet-7.4.21 → tksheet-7.4.22}/tksheet.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tksheet
3
- Version: 7.4.21
3
+ Version: 7.4.22
4
4
  Summary: Tkinter table / sheet and treeview widget
5
5
  Author-email: ragardner <github@ragardner.simplelogin.com>
6
6
  License: Copyright (c) 2019 ragardner and open source contributors
@@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
6
6
  name = "tksheet"
7
7
  description = "Tkinter table / sheet and treeview widget"
8
8
  readme = "README.md"
9
- version = "7.4.21"
9
+ version = "7.4.22"
10
10
  authors = [{ name = "ragardner", email = "github@ragardner.simplelogin.com" }]
11
11
  requires-python = ">=3.8"
12
12
  license = {file = "LICENSE.txt"}
@@ -4,7 +4,7 @@
4
4
  tksheet - A Python tkinter table widget
5
5
  """
6
6
 
7
- __version__ = "7.4.21"
7
+ __version__ = "7.4.22"
8
8
 
9
9
  from .colors import (
10
10
  color_map,
@@ -1324,7 +1324,7 @@ class MainTable(tk.Canvas):
1324
1324
  and self.input_valid_for_cell(r, datacn, val, ignore_empty=True)
1325
1325
  )
1326
1326
  ):
1327
- rows[r][datacn] = val
1327
+ rows[r][datacn] = self.format_value(datarn, datacn, val)
1328
1328
  ctr += 1
1329
1329
  if ctr:
1330
1330
  event_data = self.add_rows(
@@ -1374,7 +1374,7 @@ class MainTable(tk.Canvas):
1374
1374
  and self.input_valid_for_cell(datarn, c, val, ignore_empty=True)
1375
1375
  )
1376
1376
  ):
1377
- columns[c][datarn] = val
1377
+ columns[c][datarn] = self.format_value(datarn, datacn, val)
1378
1378
  ctr += 1
1379
1379
  if ctr:
1380
1380
  event_data = self.add_columns(
@@ -4788,7 +4788,7 @@ class MainTable(tk.Canvas):
4788
4788
  # if there are named spans where columns were added
4789
4789
  # add options to gap which was created by adding columns
4790
4790
  totalrows = None
4791
- new_ops = self.PAR.create_options_from_span
4791
+ new_ops = partial(self.PAR.create_options_from_span, set_data=False)
4792
4792
  qkspan = self.span()
4793
4793
  for span in self.named_spans.values():
4794
4794
  if isinstance(span["from_c"], int):
@@ -4851,7 +4851,7 @@ class MainTable(tk.Canvas):
4851
4851
  # if there are named spans where rows were added
4852
4852
  # add options to gap which was created by adding rows
4853
4853
  totalcols = None
4854
- new_ops = self.PAR.create_options_from_span
4854
+ new_ops = partial(self.PAR.create_options_from_span, set_data=False)
4855
4855
  qkspan = self.span()
4856
4856
  for span in self.named_spans.values():
4857
4857
  if isinstance(span["from_r"], int):
@@ -5119,7 +5119,7 @@ class MainTable(tk.Canvas):
5119
5119
  )
5120
5120
  if isinstance(self._headers, list) and header:
5121
5121
  self._headers = insert_items(self._headers, header, self.CH.fix_header)
5122
- if push_ops:
5122
+ if push_ops and columns:
5123
5123
  self.adjust_options_post_add_columns(
5124
5124
  cols=tuple(columns),
5125
5125
  create_ops=create_ops,
@@ -5241,7 +5241,7 @@ class MainTable(tk.Canvas):
5241
5241
  repeat(default_width, maxcn + 1 - (len(self.col_positions) - 1)),
5242
5242
  )
5243
5243
  )
5244
- if push_ops:
5244
+ if push_ops and rows:
5245
5245
  self.adjust_options_post_add_rows(
5246
5246
  rows=tuple(rows),
5247
5247
  create_ops=create_ops,
@@ -5370,11 +5370,16 @@ class MainTable(tk.Canvas):
5370
5370
  for datacn, column in enumerate(columns, data_ins_col):
5371
5371
  if column:
5372
5372
  header_dict[datacn] = column[0]
5373
- columns_dict[datacn] = dict(enumerate(islice(column, 1, None)))
5373
+ columns_dict[datacn] = {
5374
+ datarn: self.format_value(datarn, datacn, v)
5375
+ for datarn, v in enumerate(islice(column, 1, None))
5376
+ }
5374
5377
  else:
5375
5378
  for datacn, column in enumerate(columns, data_ins_col):
5376
5379
  if column:
5377
- columns_dict[datacn] = dict(enumerate(column))
5380
+ columns_dict[datacn] = {
5381
+ datarn: self.format_value(datarn, datacn, v) for datarn, v in enumerate(column)
5382
+ }
5378
5383
 
5379
5384
  rng = range(displayed_ins_col, displayed_ins_col + len(columns_dict))
5380
5385
  if widths is None:
@@ -5414,12 +5419,12 @@ class MainTable(tk.Canvas):
5414
5419
  if row:
5415
5420
  index_dict[datarn] = row[0]
5416
5421
  if len(row) > 1:
5417
- rows_dict[datarn] = row[1:]
5422
+ rows_dict[datarn] = [self.format_value(datarn, datacn, v) for datacn, v in enumerate(row[1:])]
5418
5423
  else:
5419
5424
  rows_dict[datarn] = []
5420
5425
  else:
5421
5426
  for datarn, row in enumerate(rows, data_ins_row):
5422
- rows_dict[datarn] = row
5427
+ rows_dict[datarn] = [self.format_value(datarn, datacn, v) for datacn, v in enumerate(row)]
5423
5428
 
5424
5429
  rng = range(displayed_ins_row, displayed_ins_row + len(rows_dict))
5425
5430
  if heights is None:
@@ -5561,7 +5566,6 @@ class MainTable(tk.Canvas):
5561
5566
  if self.PAR.ops.treeview:
5562
5567
  event_data["deleted"]["index"] = {datarn: self._row_index[datarn] for datarn in rows}
5563
5568
  event_data = self.RI.tree_del_rows(event_data=event_data)
5564
-
5565
5569
  elif isinstance(self._row_index, list):
5566
5570
  for i, datarn in enumerate(rows):
5567
5571
  r = datarn - i
@@ -7996,6 +8000,17 @@ class MainTable(tk.Canvas):
7996
8000
  else:
7997
8001
  self.data[datarn][datacn] = value
7998
8002
 
8003
+ def format_value(self, datarn: int, datacn: int, value: Any) -> Any:
8004
+ if (datarn, datacn) in self.cell_options and "checkbox" in self.cell_options[(datarn, datacn)]:
8005
+ return try_to_bool(value)
8006
+ elif kwargs := self.get_cell_kwargs(datarn, datacn, key="format"):
8007
+ if kwargs["formatter"] is None:
8008
+ return format_data(value=value, **kwargs)
8009
+ else:
8010
+ return kwargs["formatter"](value, **kwargs)
8011
+ else:
8012
+ return value
8013
+
7999
8014
  def get_value_for_empty_cell(self, datarn: int, datacn: int, r_ops: bool = True, c_ops: bool = True) -> Any:
8000
8015
  kwargs = self.get_cell_kwargs(
8001
8016
  datarn,
@@ -8010,7 +8025,7 @@ class MainTable(tk.Canvas):
8010
8025
  elif "dropdown" in kwargs and kwargs["dropdown"]["validate_input"] and kwargs["dropdown"]["values"]:
8011
8026
  return kwargs["dropdown"]["values"][0]
8012
8027
  else:
8013
- return ""
8028
+ return self.format_value(datarn, datacn, "")
8014
8029
 
8015
8030
  def get_empty_row_seq(
8016
8031
  self, datarn: int, end: int, start: int = 0, r_ops: bool = True, c_ops: bool = True
@@ -440,7 +440,7 @@ class Span(dict):
440
440
  try:
441
441
  # Deep copy non-callable items in kwargs
442
442
  span[key][k] = copy.deepcopy(v)
443
- except (TypeError, AttributeError):
443
+ except Exception:
444
444
  # Handle non-copyable objects (e.g., complex closures or objects)
445
445
  span[key][k] = v # Fallback to shallow copy
446
446
  elif key == "convert" and callable(value):
@@ -450,7 +450,7 @@ class Span(dict):
450
450
  # Deep copy other values to handle nested objects like DotDict
451
451
  try:
452
452
  span[key] = copy.deepcopy(value)
453
- except (TypeError, AttributeError):
453
+ except Exception:
454
454
  # Fallback for non-copyable objects
455
455
  span[key] = value # Shallow copy as fallback
456
456
 
@@ -954,8 +954,11 @@ class Sheet(tk.Frame):
954
954
  self.create_options_from_span(span)
955
955
  return span
956
956
 
957
- def create_options_from_span(self, span: Span) -> Sheet:
958
- getattr(self, span.type_)(span, **span.kwargs)
957
+ def create_options_from_span(self, span: Span, set_data: bool = True) -> Sheet:
958
+ if span.type_ == "format":
959
+ self.format(span, set_data=set_data, **span.kwargs)
960
+ else:
961
+ getattr(self, span.type_)(span, **span.kwargs)
959
962
  return self
960
963
 
961
964
  def del_named_span(self, name: str) -> Sheet:
@@ -1534,32 +1537,22 @@ class Sheet(tk.Frame):
1534
1537
  event_data = set_h(startc, data, event_data)
1535
1538
  # add row/column lines (positions) if required
1536
1539
  if self.MT.all_columns_displayed and maxc >= (ncols := len(self.MT.col_positions) - 1):
1537
- _, _, widths = self.MT.get_args_for_add_columns(
1538
- data_ins_col=len(self.MT.col_positions) - 1,
1539
- displayed_ins_col=len(self.MT.col_positions) - 1,
1540
- columns=maxc + 1 - ncols,
1541
- widths=None,
1542
- headers=False,
1543
- )
1540
+ disp_ins_col, widths_n_cols = len(self.MT.col_positions) - 1, maxc + 1 - ncols
1541
+ w = self.ops.default_column_width
1544
1542
  event_data = self.MT.add_columns(
1545
1543
  columns={},
1546
1544
  header={},
1547
- column_widths=widths,
1545
+ column_widths=dict(zip(range(disp_ins_col, disp_ins_col + widths_n_cols), repeat(w))),
1548
1546
  event_data=event_data,
1549
1547
  create_selections=False,
1550
1548
  )
1551
1549
  if self.MT.all_rows_displayed and maxr >= (nrows := len(self.MT.row_positions) - 1):
1552
- _, _, heights = self.MT.get_args_for_add_rows(
1553
- data_ins_row=len(self.MT.row_positions) - 1,
1554
- displayed_ins_row=len(self.MT.row_positions) - 1,
1555
- rows=maxr + 1 - nrows,
1556
- heights=None,
1557
- row_index=False,
1558
- )
1550
+ disp_ins_row, heights_n_rows = len(self.MT.row_positions) - 1, maxr + 1 - nrows
1551
+ h = self.MT.get_default_row_height()
1559
1552
  event_data = self.MT.add_rows(
1560
1553
  rows={},
1561
1554
  index={},
1562
- row_heights=heights,
1555
+ row_heights=dict(zip(range(disp_ins_row, disp_ins_row + heights_n_rows), repeat(h))),
1563
1556
  event_data=event_data,
1564
1557
  create_selections=False,
1565
1558
  )
@@ -2580,6 +2573,7 @@ class Sheet(tk.Frame):
2580
2573
  formatter_options: dict | None = None,
2581
2574
  formatter_class: Any = None,
2582
2575
  redraw: bool = True,
2576
+ set_data: bool = True,
2583
2577
  **kwargs,
2584
2578
  ) -> Span:
2585
2579
  if formatter_options is None:
@@ -2592,36 +2586,39 @@ class Sheet(tk.Frame):
2592
2586
  for c in cols:
2593
2587
  self.del_cell_options_checkbox(r, c)
2594
2588
  add_to_options(self.MT.cell_options, (r, c), "format", kwargs)
2595
- self.MT.set_cell_data(
2596
- r,
2597
- c,
2598
- value=kwargs["value"] if "value" in kwargs else self.MT.get_cell_data(r, c),
2599
- kwargs=kwargs,
2600
- )
2589
+ if set_data:
2590
+ self.MT.set_cell_data(
2591
+ r,
2592
+ c,
2593
+ value=kwargs["value"] if "value" in kwargs else self.MT.get_cell_data(r, c),
2594
+ kwargs=kwargs,
2595
+ )
2601
2596
  elif span.kind == "row":
2602
2597
  for r in rows:
2603
2598
  self.del_row_options_checkbox(r)
2604
2599
  kwargs = fix_format_kwargs(kwargs)
2605
2600
  add_to_options(self.MT.row_options, r, "format", kwargs)
2606
- for c in cols:
2607
- self.MT.set_cell_data(
2608
- r,
2609
- c,
2610
- value=kwargs["value"] if "value" in kwargs else self.MT.get_cell_data(r, c),
2611
- kwargs=kwargs,
2612
- )
2601
+ if set_data:
2602
+ for c in cols:
2603
+ self.MT.set_cell_data(
2604
+ r,
2605
+ c,
2606
+ value=kwargs["value"] if "value" in kwargs else self.MT.get_cell_data(r, c),
2607
+ kwargs=kwargs,
2608
+ )
2613
2609
  elif span.kind == "column":
2614
2610
  for c in cols:
2615
2611
  self.del_column_options_checkbox(c)
2616
2612
  kwargs = fix_format_kwargs(kwargs)
2617
2613
  add_to_options(self.MT.col_options, c, "format", kwargs)
2618
- for r in rows:
2619
- self.MT.set_cell_data(
2620
- r,
2621
- c,
2622
- value=kwargs["value"] if "value" in kwargs else self.MT.get_cell_data(r, c),
2623
- kwargs=kwargs,
2624
- )
2614
+ if set_data:
2615
+ for r in rows:
2616
+ self.MT.set_cell_data(
2617
+ r,
2618
+ c,
2619
+ value=kwargs["value"] if "value" in kwargs else self.MT.get_cell_data(r, c),
2620
+ kwargs=kwargs,
2621
+ )
2625
2622
  self.set_refresh_timer(redraw)
2626
2623
  return span
2627
2624
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: tksheet
3
- Version: 7.4.21
3
+ Version: 7.4.22
4
4
  Summary: Tkinter table / sheet and treeview widget
5
5
  Author-email: ragardner <github@ragardner.simplelogin.com>
6
6
  License: Copyright (c) 2019 ragardner and open source contributors
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes