Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataTable Actions and Events prioritization #1669

Closed
alexveden opened this issue Jan 26, 2023 · 3 comments
Closed

DataTable Actions and Events prioritization #1669

alexveden opened this issue Jan 26, 2023 · 3 comments

Comments

@alexveden
Copy link

This issue is more like feature request.

Let's assume in this app I'd like to trigger 'Run' command on selection, and 'Show' log when the link action is triggered.

Action comes first, but the event is triggered sequentially. So it would be great to have something like prevent_default available for actions.
But currently clicking on ShowLog triggers both action_show_log and on_data_table_row_selected.

textual_action

from textual.app import App
from textual.widgets import Header, Footer
from textual.containers import Container
from textual.widgets import DataTable, ListView, ListItem, Label, Button
from textual.widget import Widget
from datetime import datetime


class TableTestApp(App):
    BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]

    def compose(self):
        """Create child widgets for the app."""
        yield Header()
        yield Label('Select row', id='label')
        yield DataTable(id='data_table')
        yield Footer()

    def on_mount(self):
        table: DataTable = self.query_one('#data_table', DataTable)
        table.cursor_type = 'row'
        table.add_columns('Status', 'File', 'Log', 'Run')

        table.add_row('OK', 'my1.py', '--', 'Run')
        table.add_row('WARN', 'my2.py', '--', 'Run')
        table.add_row('ERR', 'my3.py', f"[@click=show_log('abs')]ShowLog[/]", 'Run')

    
    def on_data_table_row_selected(self, event):
         label = self.query_one('#label', Label)
         label.update(f'Row selected: {event.cursor_row}')

    def action_show_log(self, fn):
        label = self.query_one('#label', Label)
        label.update(f'Show log: {fn}')
        self.log('action_show_log')

    def action_toggle_dark(self) -> None:
        """An action to toggle dark mode."""
        self.dark = not self.dark

if __name__ == "__main__":
    #print("Hello world")
    app = TableTestApp()
    app.run()
@github-actions
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

@willmcgugan
Copy link
Collaborator

I suspect the interaction of the @click with cursor events will always be a bit awkward. It may be better to handle the cell clicking within the message handler.

Closing for now. But willing to reconsider if there is still a need.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants