dataframe-textual 2.27.0__tar.gz → 2.29.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dataframe-textual
3
- Version: 2.27.0
3
+ Version: 2.29.0
4
4
  Summary: Interactive terminal viewer/editor for tabular data
5
5
  Project-URL: Homepage, https://github.com/need47/dataframe-textual
6
6
  Project-URL: Repository, https://github.com/need47/dataframe-textual.git
@@ -154,7 +154,7 @@ dv data1.tsv < data2.tsv
154
154
 
155
155
  When multiple files are opened:
156
156
  - Each file appears as a separate tab. An Excel file may contain multiple tabs.
157
- - Switch between tabs using `>` (next) or `<` (previous), or use `b` for cycling through tabs
157
+ - Move the current tab with `>` (right, wrap to first) or `<` (left, wrap to last); use `b` to cycle tabs
158
158
  - Save current tab to file with `Ctrl+T`
159
159
  - Save all tabs to file with `Ctrl+A`
160
160
  - Duplicate the current tab with `Ctrl+D`
@@ -259,8 +259,8 @@ dv data-1.csv data-2.csv --all-in-one
259
259
 
260
260
  | Key | Action |
261
261
  | -------------- | ------------------------------------------------------------- |
262
- | `>` | Move to next tab |
263
- | `<` | Move to previous tab |
262
+ | `>` | Move current tab right (wrap to first) |
263
+ | `<` | Move current tab left (wrap to last) |
264
264
  | `b` | Cycle through tabs |
265
265
  | `B` | Toggle tab bar visibility |
266
266
  | `q` | Close current tab (prompts to save unsaved changes) |
@@ -115,7 +115,7 @@ dv data1.tsv < data2.tsv
115
115
 
116
116
  When multiple files are opened:
117
117
  - Each file appears as a separate tab. An Excel file may contain multiple tabs.
118
- - Switch between tabs using `>` (next) or `<` (previous), or use `b` for cycling through tabs
118
+ - Move the current tab with `>` (right, wrap to first) or `<` (left, wrap to last); use `b` to cycle tabs
119
119
  - Save current tab to file with `Ctrl+T`
120
120
  - Save all tabs to file with `Ctrl+A`
121
121
  - Duplicate the current tab with `Ctrl+D`
@@ -220,8 +220,8 @@ dv data-1.csv data-2.csv --all-in-one
220
220
 
221
221
  | Key | Action |
222
222
  | -------------- | ------------------------------------------------------------- |
223
- | `>` | Move to next tab |
224
- | `<` | Move to previous tab |
223
+ | `>` | Move current tab right (wrap to first) |
224
+ | `<` | Move current tab left (wrap to last) |
225
225
  | `b` | Cycle through tabs |
226
226
  | `B` | Toggle tab bar visibility |
227
227
  | `q` | Close current tab (prompts to save unsaved changes) |
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dataframe-textual"
7
- version = "2.27.0"
7
+ version = "2.29.0"
8
8
  description = "Interactive terminal viewer/editor for tabular data"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -27,8 +27,8 @@ class DataFrameViewer(App):
27
27
  # 📊 DataFrame Viewer - App Controls
28
28
 
29
29
  ## ⚙️ File & Tab Management
30
- - **>** - ▶️ Next tab
31
- - **<** - ◀️ Previous tab
30
+ - **>** - ▶️ Move current tab right (wrap to first)
31
+ - **<** - ◀️ Move current tab left (wrap to last)
32
32
  - **b** - 🔄 Cycle through tabs
33
33
  - **B** - 👁️ Toggle tab bar visibility
34
34
  - **q** - ❌ Close current tab (prompts to save unsaved changes)
@@ -73,8 +73,9 @@ class DataFrameViewer(App):
73
73
  ("W", "save_all_tabs_overwrite", "Save All Tabs (overwrite)"),
74
74
  ("ctrl+d", "duplicate_tab", "Duplicate Tab"),
75
75
  ("k", "select_theme", "Select Theme"),
76
- ("greater_than_sign,b", "next_tab(1)", "Next Tab"), # '>' and 'b'
77
- ("less_than_sign", "next_tab(-1)", "Prev Tab"), # '<'
76
+ ("greater_than_sign", "move_tab(1)", "Move tab right"), # '>'
77
+ ("less_than_sign", "move_tab(-1)", "Move tab left"), # '<'
78
+ ("b", "next_tab(1)", "Next Tab"),
78
79
  ]
79
80
 
80
81
  CSS = """
@@ -357,6 +358,15 @@ class DataFrameViewer(App):
357
358
  """
358
359
  self.do_next_tab(offset)
359
360
 
361
+ def action_move_tab(self, offset: int = 1) -> None:
362
+ """Move the current tab left or right with wrap.
363
+
364
+ Args:
365
+ offset: Direction to move (+1 right, -1 left). Defaults to 1.
366
+ """
367
+
368
+ self.do_move_tab(offset)
369
+
360
370
  def do_next_tab(self, offset: int = 1) -> None:
361
371
  """Switch to the next tab or previous tab.
362
372
 
@@ -375,6 +385,49 @@ class DataFrameViewer(App):
375
385
  except (NoMatches, ValueError):
376
386
  pass
377
387
 
388
+ def do_move_tab(self, offset: int = 1) -> None:
389
+ """Move the active tab left or right with wrap.
390
+
391
+ Args:
392
+ offset: Direction to move (+1 right, -1 left). Defaults to 1.
393
+ """
394
+
395
+ if len(self.tabs) <= 1:
396
+ return
397
+
398
+ try:
399
+ tabs = list(self.tabs.keys())
400
+ active_pane = self.tabbed.active_pane
401
+ current_index = tabs.index(active_pane)
402
+
403
+ tabs.pop(current_index)
404
+ # len(tabs) is now len(self.tabs) - 1, but we want modulo len(self.tabs)
405
+ new_index = (current_index + offset) % (len(tabs) + 1)
406
+ tabs.insert(new_index, active_pane)
407
+
408
+ # Rebuild self.tabs to preserve new order
409
+ self.tabs = {pane: self.tabs[pane] for pane in tabs}
410
+
411
+ active_tab = self.tabbed.get_tab(active_pane.id)
412
+
413
+ if new_index == 0:
414
+ reference_pane = tabs[1]
415
+ reference_tab = self.tabbed.get_tab(reference_pane.id)
416
+ active_tab.parent.move_child(active_tab, before=reference_tab)
417
+ active_pane.parent.move_child(active_pane, before=reference_pane)
418
+ else:
419
+ reference_pane = tabs[new_index - 1]
420
+ reference_tab = self.tabbed.get_tab(reference_pane.id)
421
+ active_tab.parent.move_child(active_tab, after=reference_tab)
422
+ active_pane.parent.move_child(active_pane, after=reference_pane)
423
+
424
+ # Reset the active pane highlight visually
425
+ tabs_widget = self.query_one(ContentTabs)
426
+ self.call_after_refresh(lambda: tabs_widget._highlight_active())
427
+
428
+ except Exception as e:
429
+ self.log(f"Error moving tab: {e}")
430
+
378
431
  def action_toggle_tab_bar(self) -> None:
379
432
  """Toggle the tab bar visibility.
380
433
 
@@ -9,6 +9,7 @@ from functools import partial
9
9
 
10
10
  import polars as pl
11
11
  from rich.text import Text
12
+ from textual import work
12
13
  from textual.app import ComposeResult
13
14
  from textual.coordinate import Coordinate
14
15
  from textual.renderables.bar import Bar
@@ -33,9 +34,11 @@ class TableScreen(ModalScreen):
33
34
 
34
35
  TableScreen > DataTable {
35
36
  width: auto;
37
+ max-width: 100%;
36
38
  height: auto;
39
+ min-width: 20; /* for LoadIndicator */
40
+ min-height: 3; /* for LoadIndicator */
37
41
  border: solid $primary;
38
- max-width: 100%;
39
42
  overflow: auto;
40
43
  }
41
44
  """
@@ -288,11 +291,23 @@ class StatisticsScreen(TableScreen):
288
291
  def __init__(self, dftable: "DataFrameTable", cidx: int | None = None):
289
292
  super().__init__(dftable)
290
293
  self.cidx = cidx # None for dataframe statistics, otherwise column index
291
- self.df = self.build_df()
294
+ self.df: pl.DataFrame = None
292
295
 
293
296
  def on_mount(self) -> None:
294
297
  """Create the statistics table."""
298
+ self.table.loading = True
299
+ self.calculate_statistics()
300
+
301
+ @work(thread=True)
302
+ def calculate_statistics(self) -> None:
303
+ """Calculate statistics in a background thread."""
304
+ self.df = self.build_df()
305
+ self.app.call_from_thread(self._on_calculation_ready)
306
+
307
+ def _on_calculation_ready(self) -> None:
295
308
  self.build_table()
309
+ self.table.loading = False
310
+ self.table.focus()
296
311
 
297
312
  def build_table(self) -> None:
298
313
  """Build the statistics table."""
@@ -417,13 +432,23 @@ class FrequencyScreen(TableScreen):
417
432
  self.cidx = cidx
418
433
  self.sorted_columns = {1: True} # Count sort by default
419
434
  self.total_count = len(dftable.df)
420
-
421
- col = dftable.df.columns[self.cidx]
422
- self.df: pl.DataFrame = dftable.df.lazy().select(pl.col(col).value_counts(sort=True)).unnest(col).collect()
435
+ self.df: pl.DataFrame = None
423
436
 
424
437
  def on_mount(self) -> None:
425
- """Create the frequency table."""
438
+ """Start frequency calculation."""
439
+ self.table.loading = True
440
+ self.calculate_frequency()
441
+
442
+ @work(thread=True)
443
+ def calculate_frequency(self) -> None:
444
+ col = self.dftable.df.columns[self.cidx]
445
+ self.df = self.dftable.df.lazy().select(pl.col(col).value_counts(sort=True)).unnest(col).collect()
446
+ self.app.call_from_thread(self._on_calculation_ready)
447
+
448
+ def _on_calculation_ready(self) -> None:
426
449
  self.build_table()
450
+ self.table.loading = False
451
+ self.table.focus()
427
452
 
428
453
  def on_key(self, event):
429
454
  if event.key == "left_square_bracket": # '['
@@ -493,7 +518,7 @@ class FrequencyScreen(TableScreen):
493
518
  highlight_range=(0.0, percentage / 100 * 10),
494
519
  width=10,
495
520
  ),
496
- key=str(row_idx + 1),
521
+ label=str(row_idx + 1),
497
522
  )
498
523
 
499
524
  # Add a total row
@@ -513,7 +538,6 @@ class FrequencyScreen(TableScreen):
513
538
  highlight_range=(0.0, 10),
514
539
  width=10,
515
540
  ),
516
- key="total",
517
541
  )
518
542
 
519
543
  def sort_by_column(self, descending: bool) -> None:
@@ -9,8 +9,7 @@ from textual.widgets import OptionList
9
9
 
10
10
  class ThemeScreen(ModalScreen):
11
11
  BINDINGS = [
12
- ("q", "cancel", "Cancel"),
13
- ("escape", "cancel", "Cancel"),
12
+ ("q,escape", "cancel", "Cancel"),
14
13
  ]
15
14
 
16
15
  DEFAULT_CSS = """
@@ -21,9 +20,8 @@ class ThemeScreen(ModalScreen):
21
20
  #theme-container {
22
21
  width: 40;
23
22
  height: auto;
24
- padding: 0 1;
25
- border: solid $accent;
26
- border-title-color: $accent;
23
+ border: solid $primary;
24
+ border-title-color: $primary;
27
25
  }
28
26
 
29
27
  #theme-list {
@@ -34,9 +32,8 @@ class ThemeScreen(ModalScreen):
34
32
 
35
33
  def __init__(self) -> None:
36
34
  super().__init__()
37
- self.themes = list(BUILTIN_THEMES.keys())
38
- self.original_theme = ""
39
- self._confirmed = False
35
+ self.themes = sorted(list(BUILTIN_THEMES.keys()))
36
+ self.original_theme = self.app.theme
40
37
 
41
38
  def compose(self) -> ComposeResult:
42
39
  with Container(id="theme-container") as container:
@@ -44,28 +41,22 @@ class ThemeScreen(ModalScreen):
44
41
  yield OptionList(*self.themes, id="theme-list")
45
42
 
46
43
  def on_mount(self) -> None:
47
- self.original_theme = self.app.theme
48
44
  options = self.query_one(OptionList)
49
45
  if self.original_theme in self.themes:
50
46
  options.highlighted = self.themes.index(self.original_theme)
51
47
  options.focus()
52
48
 
53
49
  def _set_theme(self, theme: str) -> None:
54
- if theme in BUILTIN_THEMES:
50
+ if theme in self.themes:
55
51
  self.app.theme = theme
56
52
 
57
53
  def on_option_list_option_highlighted(self, event: OptionList.OptionHighlighted) -> None:
58
54
  self._set_theme(str(event.option.prompt))
59
55
 
60
56
  def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
61
- self._confirmed = True
62
57
  self._set_theme(str(event.option.prompt))
63
58
  self.app.pop_screen()
64
59
 
65
60
  def action_cancel(self) -> None:
66
61
  self.app.theme = self.original_theme
67
62
  self.app.pop_screen()
68
-
69
- def on_unmount(self) -> None:
70
- if not self._confirmed:
71
- self.app.theme = self.original_theme
@@ -36,8 +36,8 @@ class YMNScreen(ModalScreen):
36
36
  YMNScreen > Container {
37
37
  width: auto;
38
38
  height: auto;
39
- border: solid $accent;
40
- border-title-color: $accent;
39
+ border: solid $primary;
40
+ border-title-color: $primary;
41
41
  padding: 1 2;
42
42
  overflow: auto;
43
43
  }