dataframe-textual 3.0.0__tar.gz → 3.1.0__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 (24) hide show
  1. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/PKG-INFO +1 -1
  2. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/pyproject.toml +1 -1
  3. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/data_frame_table.py +84 -7
  4. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/loading_screen.py +5 -1
  5. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/uv.lock +1 -1
  6. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/.gitignore +0 -0
  7. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/LICENSE +0 -0
  8. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/README.md +0 -0
  9. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/main.py +0 -0
  10. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/__init__.py +0 -0
  11. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/__main__.py +0 -0
  12. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/commands.py +0 -0
  13. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/common.py +0 -0
  14. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/console_panel.py +0 -0
  15. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/data_frame_viewer.py +0 -0
  16. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/file_picker_screen.py +0 -0
  17. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/help_panel.py +0 -0
  18. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/keybindings.py +0 -0
  19. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/run_command_screen.py +0 -0
  20. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/status_bar.py +0 -0
  21. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/table_screen.py +0 -0
  22. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/text_screen.py +0 -0
  23. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/theme_screen.py +0 -0
  24. {dataframe_textual-3.0.0 → dataframe_textual-3.1.0}/src/dataframe_textual/yes_no_screen.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataframe-textual
3
- Version: 3.0.0
3
+ Version: 3.1.0
4
4
  Summary: Interactive terminal viewer/editor (TUI) for CSV/TSV, Excel, Parquet, JSONL, etc.
5
5
  Project-URL: Homepage, https://github.com/need47/dataframe-textual
6
6
  Project-URL: Repository, https://github.com/need47/dataframe-textual.git
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dataframe-textual"
7
- version = "3.0.0"
7
+ version = "3.1.0"
8
8
  description = "Interactive terminal viewer/editor (TUI) for CSV/TSV, Excel, Parquet, JSONL, etc."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -3,11 +3,12 @@
3
3
  import io
4
4
  import sys
5
5
  from collections import defaultdict, deque
6
- from dataclasses import dataclass
6
+ from dataclasses import dataclass, field
7
7
  from functools import partial
8
8
  from itertools import zip_longest
9
9
  from pathlib import Path
10
10
  from threading import Event
11
+ from types import MethodType
11
12
  from typing import TYPE_CHECKING, Any, Callable
12
13
 
13
14
  if TYPE_CHECKING:
@@ -393,25 +394,101 @@ class DataFrameTable(DataTable):
393
394
  return wrapper
394
395
 
395
396
  def with_busy_screen(func: Callable) -> Callable:
396
- """Decorator that shows a BusyScreen and runs the function in a background thread.
397
+ """Decorator that runs expensive work in a thread while showing BusyScreen.
397
398
 
398
- Handles the full lifecycle: sets ``task_done=False``, pushes
399
- :class:`BusyScreen`, runs the function via ``@work(thread=True)``,
400
- and guarantees ``task_done=True`` on completion.
399
+ The wrapped function executes on a worker thread. UI-affecting calls that
400
+ commonly follow data mutations (``setup_table``, ``move_cursor``, and
401
+ ``notify``) are deferred and replayed on the main thread after the busy
402
+ modal closes.
401
403
  """
402
404
 
405
+ @dataclass
406
+ class _BusyState:
407
+ """Deferred UI actions collected during worker execution."""
408
+
409
+ needs_setup_table: bool = False
410
+ pending_move_cursor: tuple[tuple, dict] | None = None
411
+ pending_notifies: list[tuple[tuple, dict]] = field(default_factory=list)
412
+
413
+ def _patch_ui_methods(self, state: _BusyState) -> tuple[Callable, Callable, Callable]:
414
+ """Patch UI-affecting methods to defer execution while worker thread is running."""
415
+ original_setup_table = self.setup_table
416
+ original_move_cursor = self.move_cursor
417
+ original_notify = self.notify
418
+
419
+ def defer_setup_table(_self, *setup_args, **setup_kwargs) -> None:
420
+ """Record table rebuild request for replay on the main thread."""
421
+ state.needs_setup_table = True
422
+
423
+ def defer_move_cursor(_self, *move_args, **move_kwargs) -> None:
424
+ """Keep only the latest cursor move request for replay."""
425
+ state.pending_move_cursor = (move_args, move_kwargs)
426
+
427
+ def defer_notify(_self, *notify_args, **notify_kwargs) -> None:
428
+ """Queue notifications to preserve order when replayed."""
429
+ state.pending_notifies.append((notify_args, notify_kwargs))
430
+
431
+ self.setup_table = MethodType(defer_setup_table, self)
432
+ self.move_cursor = MethodType(defer_move_cursor, self)
433
+ self.notify = MethodType(defer_notify, self)
434
+
435
+ return (original_setup_table, original_move_cursor, original_notify)
436
+
437
+ def _apply_deferred_ui(
438
+ self,
439
+ state: _BusyState,
440
+ original_setup_table: Callable,
441
+ original_move_cursor: Callable,
442
+ original_notify: Callable,
443
+ ) -> None:
444
+ """Apply deferred UI actions on the main thread after the worker completes."""
445
+ if state.needs_setup_table:
446
+ original_setup_table()
447
+
448
+ if state.pending_move_cursor is not None:
449
+ move_args, move_kwargs = state.pending_move_cursor
450
+ original_move_cursor(*move_args, **move_kwargs)
451
+
452
+ for notify_args, notify_kwargs in state.pending_notifies:
453
+ original_notify(*notify_args, **notify_kwargs)
454
+
403
455
  @work(thread=True)
404
- def _worker(self, *args, **kwargs):
456
+ def _worker(self, state: _BusyState, *args, **kwargs):
405
457
  """Execute the wrapped function in a background thread."""
458
+ original_setup_table, original_move_cursor, original_notify = _patch_ui_methods(self, state)
459
+
406
460
  try:
407
461
  func(self, *args, **kwargs)
408
462
  finally:
409
463
  self.task_done = True
464
+ # Restore original methods after the worker completes
465
+ self.setup_table = original_setup_table
466
+ self.move_cursor = original_move_cursor
467
+ self.notify = original_notify
410
468
 
411
469
  def wrapper(self, *args, **kwargs):
412
470
  """Set up BusyScreen and dispatch work to a background thread."""
471
+ state = _BusyState()
472
+ original_setup_table = self.setup_table
473
+ original_move_cursor = self.move_cursor
474
+ original_notify = self.notify
475
+ on_done = partial(
476
+ _apply_deferred_ui,
477
+ self,
478
+ state,
479
+ original_setup_table,
480
+ original_move_cursor,
481
+ original_notify,
482
+ )
483
+
413
484
  self.task_done = False
414
- self.app.push_screen(BusyScreen(self, task=partial(_worker, self, *args, **kwargs)))
485
+ self.app.push_screen(
486
+ BusyScreen(
487
+ self,
488
+ task=partial(_worker, self, state, *args, **kwargs),
489
+ on_done=on_done,
490
+ )
491
+ )
415
492
 
416
493
  return wrapper
417
494
 
@@ -81,16 +81,18 @@ class BusyScreen(ModalScreen):
81
81
  }
82
82
  """
83
83
 
84
- def __init__(self, dftable: "DataFrameTable", task: Callable) -> None:
84
+ def __init__(self, dftable: "DataFrameTable", task: Callable, on_done: Callable | None = None) -> None:
85
85
  """Initialize the busy screen.
86
86
 
87
87
  Args:
88
88
  dftable: The DataFrameTable associated with the running task.
89
89
  task: Callable to invoke on mount that starts the background work.
90
+ on_done: Optional callback invoked on the main thread after the modal is dismissed.
90
91
  """
91
92
  super().__init__()
92
93
  self.dftable = dftable
93
94
  self.run_task = task
95
+ self.on_done = on_done
94
96
 
95
97
  def compose(self) -> ComposeResult:
96
98
  """Compose the loading indicator widget."""
@@ -105,6 +107,8 @@ class BusyScreen(ModalScreen):
105
107
  """Check the loading progress of the dataframe."""
106
108
  if self.dftable.task_done:
107
109
  self.dismiss()
110
+ if self.on_done:
111
+ self.call_later(self.on_done)
108
112
 
109
113
  def action_cancel(self) -> None:
110
114
  self.dismiss()
@@ -187,7 +187,7 @@ wheels = [
187
187
 
188
188
  [[package]]
189
189
  name = "dataframe-textual"
190
- version = "3.0.0"
190
+ version = "3.1.0"
191
191
  source = { editable = "." }
192
192
  dependencies = [
193
193
  { name = "fastexcel" },