tksheet 7.0.6__py3-none-any.whl → 7.1.1__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/functions.py CHANGED
@@ -4,6 +4,7 @@ import bisect
4
4
  import pickle
5
5
  import re
6
6
  import zlib
7
+ from collections import deque
7
8
  from collections.abc import (
8
9
  Callable,
9
10
  Generator,
@@ -244,6 +245,14 @@ def is_iterable(o: object) -> bool:
244
245
  return False
245
246
 
246
247
 
248
+ def unpack(t: tuple[object] | tuple[Iterator[object]]) -> tuple[object]:
249
+ if not len(t):
250
+ return t
251
+ if is_iterable(t[0]) and len(t) == 1:
252
+ return t[0]
253
+ return t
254
+
255
+
247
256
  def is_type_int(o: object) -> bool:
248
257
  return isinstance(o, int) and not isinstance(o, bool)
249
258
 
@@ -336,7 +345,7 @@ def get_seq_without_gaps_at_index(
336
345
  return seq
337
346
 
338
347
 
339
- def consecutive_chunks(seq: list[object]) -> list[object]:
348
+ def consecutive_chunks(seq: list[object]) -> Generator[object]:
340
349
  if not seq:
341
350
  yield seq
342
351
  start = 0
@@ -357,6 +366,21 @@ def is_contiguous(seq: list[int]) -> bool:
357
366
  return all(i == (prev := prev + 1) for i in itr)
358
367
 
359
368
 
369
+ def get_last(
370
+ it: Iterator,
371
+ ) -> object:
372
+ if hasattr(it, "__reversed__"):
373
+ try:
374
+ return next(reversed(it))
375
+ except Exception:
376
+ return None
377
+ else:
378
+ try:
379
+ return deque(it, maxlen=1)[0]
380
+ except Exception:
381
+ return None
382
+
383
+
360
384
  def index_exists(seq: Sequence[object], index: int) -> bool:
361
385
  try:
362
386
  seq[index]
@@ -1080,14 +1104,6 @@ def del_named_span_options_nested(options: dict, itr1: Iterator, itr2: Iterator,
1080
1104
  del options[k][type_]
1081
1105
 
1082
1106
 
1083
- def coords_tag_to_int_tuple(s: str) -> tuple[int, int, int, int] | tuple[int, int]:
1084
- return tuple(map(int, filter(None, s.split("_"))))
1085
-
1086
-
1087
- def coords_tag_to_box_nt(s: str) -> Box_nt[int, int, int, int]:
1088
- return Box_nt(*(map(int, filter(None, s.split("_")))))
1089
-
1090
-
1091
1107
  def add_highlight(
1092
1108
  options: dict,
1093
1109
  key: int | tuple[int, int],
@@ -1238,6 +1254,11 @@ def mod_span(
1238
1254
  return to_set_to
1239
1255
 
1240
1256
 
1257
+ def mod_span_widget(span: Span, widget: object) -> Span:
1258
+ span.widget = widget
1259
+ return span
1260
+
1261
+
1241
1262
  def mod_event_val(
1242
1263
  event_data: EventDataDict,
1243
1264
  val: object,
@@ -1246,3 +1267,15 @@ def mod_event_val(
1246
1267
  event_data.value = val
1247
1268
  event_data.loc = loc
1248
1269
  return event_data
1270
+
1271
+
1272
+ def pop_positions(
1273
+ itr: Iterator[int],
1274
+ to_pop: dict[int, int], # displayed index: data index
1275
+ save_to: dict[int, int],
1276
+ ) -> Iterator[int]:
1277
+ for i, pos in enumerate(itr()):
1278
+ if i in to_pop:
1279
+ save_to[to_pop[i]] = pos
1280
+ else:
1281
+ yield pos