dataframe-textual 2.26.1__tar.gz → 2.28.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.26.1
3
+ Version: 2.28.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
@@ -280,7 +280,7 @@ dv data-1.csv data-2.csv --all-in-one
280
280
  | Key | Action |
281
281
  | ------------------------ | ------------------------------------------ |
282
282
  | `F1` | Toggle help panel |
283
- | `k` | Cycle through dark, light and other themes |
283
+ | `k` | Select theme |
284
284
  | `Ctrl+P` -> `Screenshot` | Capture terminal view as a SVG image |
285
285
 
286
286
  ---
@@ -241,7 +241,7 @@ dv data-1.csv data-2.csv --all-in-one
241
241
  | Key | Action |
242
242
  | ------------------------ | ------------------------------------------ |
243
243
  | `F1` | Toggle help panel |
244
- | `k` | Cycle through dark, light and other themes |
244
+ | `k` | Select theme |
245
245
  | `Ctrl+P` -> `Screenshot` | Capture terminal view as a SVG image |
246
246
 
247
247
  ---
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "dataframe-textual"
7
- version = "2.26.1"
7
+ version = "2.28.0"
8
8
  description = "Interactive terminal viewer/editor for tabular data"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -9,10 +9,11 @@ import polars as pl
9
9
  from textual.app import App, ComposeResult
10
10
  from textual.css.query import NoMatches
11
11
  from textual.events import Click
12
- from textual.theme import BUILTIN_THEMES
13
12
  from textual.widgets import TabbedContent, TabPane
14
13
  from textual.widgets.tabbed_content import ContentTab, ContentTabs
15
14
 
15
+ from dataframe_textual.theme_screen import ThemeScreen
16
+
16
17
  from .common import RID, SUPPORTED_FORMATS, Source, get_next_item, load_file
17
18
  from .data_frame_help_panel import DataFrameHelpPanel
18
19
  from .data_frame_table import DataFrameTable
@@ -44,7 +45,7 @@ class DataFrameViewer(App):
44
45
 
45
46
  ## 🎨 View & Settings
46
47
  - **F1** - ❓ Toggle this help panel
47
- - **k** - 🌙 Cycle through themes
48
+ - **k** - 🌙 Select theme
48
49
  - **Ctrl+P -> Screenshot** - 📸 Capture terminal view as a SVG image
49
50
 
50
51
  ## ⭐ Features
@@ -71,6 +72,7 @@ class DataFrameViewer(App):
71
72
  ("w", "save_current_tab_overwrite", "Save Current Tab (overwrite)"),
72
73
  ("W", "save_all_tabs_overwrite", "Save All Tabs (overwrite)"),
73
74
  ("ctrl+d", "duplicate_tab", "Duplicate Tab"),
75
+ ("k", "select_theme", "Select Theme"),
74
76
  ("greater_than_sign,b", "next_tab(1)", "Next Tab"), # '>' and 'b'
75
77
  ("less_than_sign", "next_tab(-1)", "Prev Tab"), # '<'
76
78
  ]
@@ -179,18 +181,6 @@ class DataFrameViewer(App):
179
181
  # self.log(self.tree)
180
182
  pass
181
183
 
182
- def on_key(self, event) -> None:
183
- """Handle key press events at the application level.
184
-
185
- Currently handles theme cycling with the 'k' key.
186
-
187
- Args:
188
- event: The key event object containing key information.
189
- """
190
- if event.key == "k":
191
- self.theme = get_next_item(list(BUILTIN_THEMES.keys()), self.theme)
192
- self.notify(f"Switched to theme: [$success]{self.theme}[/]", title="SwitchTheme")
193
-
194
184
  def on_click(self, event: Click) -> None:
195
185
  """Handle mouse click events on tabs.
196
186
 
@@ -314,6 +304,10 @@ class DataFrameViewer(App):
314
304
  """
315
305
  self.do_duplicate_tab()
316
306
 
307
+ def action_select_theme(self) -> None:
308
+ """Open the theme selection screen."""
309
+ self.push_screen(ThemeScreen())
310
+
317
311
  def do_duplicate_tab(self) -> None:
318
312
  """Duplicate the currently active tab.
319
313
 
@@ -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
  """
@@ -210,7 +213,9 @@ class RowDetailScreen(TableScreen):
210
213
  self.table.add_column("Value")
211
214
 
212
215
  # Get all columns and values from the dataframe row
213
- for col, val, dtype in zip(self.dftable.df.columns, self.dftable.df.row(self.ridx), self.dftable.df.dtypes):
216
+ for idx, (col, val, dtype) in enumerate(
217
+ zip(self.dftable.df.columns, self.dftable.df.row(self.ridx), self.dftable.df.dtypes)
218
+ ):
214
219
  if col in self.dftable.hidden_columns or col == RID:
215
220
  continue # Skip RID column
216
221
  formatted_row = []
@@ -218,7 +223,7 @@ class RowDetailScreen(TableScreen):
218
223
 
219
224
  dc = DtypeConfig(dtype)
220
225
  formatted_row.append(dc.format(val, justify="", thousand_separator=self.thousand_separator))
221
- self.table.add_row(*formatted_row)
226
+ self.table.add_row(*formatted_row, label=str(idx + 1))
222
227
 
223
228
  self.table.cursor_type = "row"
224
229
 
@@ -286,11 +291,23 @@ class StatisticsScreen(TableScreen):
286
291
  def __init__(self, dftable: "DataFrameTable", cidx: int | None = None):
287
292
  super().__init__(dftable)
288
293
  self.cidx = cidx # None for dataframe statistics, otherwise column index
289
- self.df = self.build_df()
294
+ self.df: pl.DataFrame = None
290
295
 
291
296
  def on_mount(self) -> None:
292
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:
293
308
  self.build_table()
309
+ self.table.loading = False
310
+ self.table.focus()
294
311
 
295
312
  def build_table(self) -> None:
296
313
  """Build the statistics table."""
@@ -415,13 +432,23 @@ class FrequencyScreen(TableScreen):
415
432
  self.cidx = cidx
416
433
  self.sorted_columns = {1: True} # Count sort by default
417
434
  self.total_count = len(dftable.df)
418
-
419
- col = dftable.df.columns[self.cidx]
420
- self.df: pl.DataFrame = dftable.df.lazy().select(pl.col(col).value_counts(sort=True)).unnest(col).collect()
435
+ self.df: pl.DataFrame = None
421
436
 
422
437
  def on_mount(self) -> None:
423
- """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:
424
449
  self.build_table()
450
+ self.table.loading = False
451
+ self.table.focus()
425
452
 
426
453
  def on_key(self, event):
427
454
  if event.key == "left_square_bracket": # '['
@@ -626,24 +653,22 @@ class MetaColumnScreen(TableScreen):
626
653
  """Build the column metadata table."""
627
654
  self.table.clear(columns=True)
628
655
  self.table.add_column("Column")
629
- self.table.add_column("Name")
630
656
  self.table.add_column("Type")
631
657
 
632
658
  # Get schema information
633
659
  schema = self.dftable.df.schema
634
- dc_int = DtypeConfig(pl.Int64)
635
660
  dc_str = DtypeConfig(pl.String)
636
661
 
637
662
  # Add a row for each column
638
- for idx, (col_name, col_type) in enumerate(schema.items(), 1):
663
+ for idx, (col_name, col_type) in enumerate(schema.items()):
639
664
  if col_name == RID:
640
665
  continue # Skip RID column
641
666
 
642
667
  dc = DtypeConfig(col_type)
643
668
  self.table.add_row(
644
- dc_int.format(idx, thousand_separator=self.thousand_separator),
645
669
  col_name,
646
670
  dc_str.format("Datetime" if str(col_type).startswith("Datetime") else col_type, style=dc.style),
671
+ label=str(idx + 1),
647
672
  )
648
673
 
649
674
  self.table.cursor_type = "row"
@@ -0,0 +1,64 @@
1
+ """A theme screen to select theme from a list of available themes."""
2
+
3
+ from textual.app import ComposeResult
4
+ from textual.containers import Container
5
+ from textual.screen import ModalScreen
6
+ from textual.theme import BUILTIN_THEMES
7
+ from textual.widgets import OptionList
8
+
9
+
10
+ class ThemeScreen(ModalScreen):
11
+ BINDINGS = [
12
+ ("q", "cancel", "Cancel"),
13
+ ("escape", "cancel", "Cancel"),
14
+ ]
15
+
16
+ DEFAULT_CSS = """
17
+ ThemeScreen {
18
+ align: center middle;
19
+ }
20
+
21
+ #theme-container {
22
+ width: 40;
23
+ height: auto;
24
+ padding: 0 1;
25
+ border: solid $accent;
26
+ border-title-color: $accent;
27
+ }
28
+
29
+ #theme-list {
30
+ height: 20;
31
+ border: none;
32
+ }
33
+ """
34
+
35
+ def __init__(self) -> None:
36
+ super().__init__()
37
+ self.themes = list(BUILTIN_THEMES.keys())
38
+ self.original_theme = self.app.theme
39
+
40
+ def compose(self) -> ComposeResult:
41
+ with Container(id="theme-container") as container:
42
+ container.border_title = "Select Theme"
43
+ yield OptionList(*self.themes, id="theme-list")
44
+
45
+ def on_mount(self) -> None:
46
+ options = self.query_one(OptionList)
47
+ if self.original_theme in self.themes:
48
+ options.highlighted = self.themes.index(self.original_theme)
49
+ options.focus()
50
+
51
+ def _set_theme(self, theme: str) -> None:
52
+ if theme in self.themes:
53
+ self.app.theme = theme
54
+
55
+ def on_option_list_option_highlighted(self, event: OptionList.OptionHighlighted) -> None:
56
+ self._set_theme(str(event.option.prompt))
57
+
58
+ def on_option_list_option_selected(self, event: OptionList.OptionSelected) -> None:
59
+ self._set_theme(str(event.option.prompt))
60
+ self.app.pop_screen()
61
+
62
+ def action_cancel(self) -> None:
63
+ self.app.theme = self.original_theme
64
+ self.app.pop_screen()
@@ -175,7 +175,7 @@ class YesNoScreen(YMNScreen):
175
175
  DEFAULT_CSS = YMNScreen.DEFAULT_CSS.replace("YMNScreen", "YesNoScreen") + """
176
176
  YesNoScreen > Container {
177
177
  min-width: 48;
178
- max-width: 64;
178
+ max-width: 72;
179
179
  }
180
180
 
181
181
  YesNoScreen Label {
@@ -373,7 +373,6 @@ class SaveFileScreen(YesNoScreen):
373
373
  self.all_tabs = all_tabs
374
374
  super().__init__(
375
375
  title="Save to File",
376
- label="Filename",
377
376
  input=filename,
378
377
  yes=f"Save {tab_count} Tabs" if self.all_tabs else "Save Current Tab" if tab_count > 1 else "Save",
379
378
  no="Cancel",
@@ -171,7 +171,7 @@ wheels = [
171
171
 
172
172
  [[package]]
173
173
  name = "dataframe-textual"
174
- version = "2.26.1"
174
+ version = "2.28.0"
175
175
  source = { editable = "." }
176
176
  dependencies = [
177
177
  { name = "fastexcel" },