Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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 dynamic update (several times in one function) #3775

Closed
nickkitovsky opened this issue Nov 29, 2023 · 0 comments
Closed

DataTable dynamic update (several times in one function) #3775

nickkitovsky opened this issue Nov 29, 2023 · 0 comments

Comments

@nickkitovsky
Copy link

nickkitovsky commented Nov 29, 2023

Tell me a way to update fields in the DataTable within one function (this works great if you hang it, for example, on a Button.Pressed handler), but in one function sequentially.

from time import sleep

from textual import on
from textual.app import App, ComposeResult
from textual.coordinate import Coordinate
from textual.widgets import Button, DataTable


class TableApp(App):
    cnt = 0

    def compose(self) -> ComposeResult:
        yield Button()
        yield DataTable(cursor_type='row')

    def on_mount(self) -> None:
        self.table = self.query_one(DataTable)
        self.table.add_column('A')
        self.table.add_row('0')

    def change_value(self):
        self.table.update_cell_at(
            coordinate=Coordinate(row=0, column=0),
            value=self.cnt,
            update_width=True,
        )
        self.cnt += 1

    @on(message_type=Button.Pressed)
    def input_typing_handler(self, event: Button.Pressed) -> None:
        self.change_value()
        sleep(3)  # some hard work
        self.change_value()
app = TableApp()
if __name__ == '__main__':
    app.run()

I don't see two consecutive changes using the change_value function with a break for some external function, I immediately get the last result after the work is done (speed(3) in the example.
I tried to create custom message class and run

self.post_message(MyCustomMessage()) 
sleep(3)  # some hard work
self.post_message(MyCustomMessage())

But the result was the same.
The same applies to different cells; changes are not applied one by one, but only after the function is completely completed

@Textualize Textualize deleted a comment from github-actions bot Nov 29, 2023
@Textualize Textualize locked and limited conversation to collaborators Nov 29, 2023
@davep davep converted this issue into discussion #3776 Nov 29, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant