Textualize/textual

KeyError on DataTable border title link click

max-arnold opened this issue · 2 comments

  1. Run the attached MRE
  2. Click on the right bottom table subtitle link
╭────────────────────────────────────── Traceback (most recent call last) ───────────────────────────────────────╮
│ /Users/user/.virtualenvs/textual-db/lib/python3.12/site-packages/textual/widgets/_data_table.py:2447          │
│ in _on_click                                                                                                   │
│                                                                                                                │
│   2444 │   │   if not meta:                                                                                    │
│   2445 │   │   │   return                                                                                      │
│   2446 │   │                                                                                                   │
│ ❱ 2447 │   │   row_index = meta["row"]                                                                         │
│   2448 │   │   column_index = meta["column"]                                                                   │
│   2449 │   │   is_header_click = self.show_header and row_index == -1                                          │
│   2450 │   │   is_row_label_click = self.show_row_labels and column_index == -1                                │
│                                                                                                                │
│ ╭───────────────────── locals ─────────────────────╮                                                           │
│ │ event = Click(x=108, y=4, button=1)              │                                                           │
│ │  meta = {'@click': ('toggle_status', ())} │                                                           │
│ │  self = DataTable()                              │                                                           │
│ ╰──────────────────────────────────────────────────╯                                                           │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
KeyError: 'row'
from textual.app import App, ComposeResult
from textual.widgets import DataTable, Footer

ROWS = [
    ("Job", "Status"),
    ("Job 1", "Running"),
    ("Job 2", "Finished"),
]


class TableApp(App):
    BINDINGS = [
        ("t", "toggle_status", "Toggle"),
    ]
    running = False

    def compose(self) -> ComposeResult:
        yield DataTable(cursor_type="row")
        yield Footer()

    def on_mount(self) -> None:
        table = self.query_one(DataTable)
        table.add_columns(*ROWS[0])
        table.styles.border = ('solid', 'red')
        self.update_jobs()

    def update_jobs(self):
        table = self.query_one(DataTable)
        table.clear()
        table.add_rows([r for r in ROWS[1:] if not self.running or r[1] == "Running"])
        table.border_subtitle = "[b][@click=toggle_status()]{}[/][/]".format("▶️  running" if self.running else "*️⃣  all")
        table.refresh(layout=True)

    def action_toggle_status(self):
        self.running = not self.running
        self.update_jobs()

app = TableApp()
if __name__ == "__main__":
    app.run()
textual diagnose
# Textual Diagnostics

## Versions

| Name    | Value  |
|---------|--------|
| Textual | 0.56.0 |
| Rich    | 13.7.1 |

## Python

| Name           | Value                                                   |
|----------------|---------------------------------------------------------|
| Version        | 3.12.0                                                  |
| Implementation | CPython                                                 |
| Compiler       | Clang 14.0.3 (clang-1403.0.22.14.1)                     |
| Executable     | /Users/user/.virtualenvs/textual-db/bin/python |

## Operating System

| Name    | Value                                                                                                  |
|---------|--------------------------------------------------------------------------------------------------------|
| System  | Darwin                                                                                                 |
| Release | 22.6.0                                                                                                 |
| Version | Darwin Kernel Version 22.6.0: Mon Feb 19 19:48:53 PST 2024; root:xnu-8796.141.3.704.6~1/RELEASE_X86_64 |

## Terminal

| Name                 | Value              |
|----------------------|--------------------|
| Terminal Application | iTerm.app (3.4.23) |
| TERM                 | xterm-256color     |
| COLORTERM            | truecolor          |
| FORCE_COLOR          | *Not set*          |
| NO_COLOR             | *Not set*          |

## Rich Console options

| Name           | Value                |
|----------------|----------------------|
| size           | width=114, height=55 |
| legacy_windows | False                |
| min_width      | 1                    |
| max_width      | 114                  |
| is_terminal    | False                |
| encoding       | utf-8                |
| max_height     | 55                   |
| justify        | None                 |
| overflow       | None                 |
| no_wrap        | False                |
| highlight      | None                 |
| markup         | None                 |
| height         | None                 |

We found the following entry in the FAQ which you may find helpful:

Feel free to close this issue if you found an answer in the FAQ. Otherwise, please give us a little time to review.

This is an automated reply, generated by FAQtory

Don't forget to star the repository!

Follow @textualizeio for Textual updates.