Giter Site home page Giter Site logo

Comments (7)

willmcgugan avatar willmcgugan commented on July 16, 2024 2

That should work. Try with the next release, which should be out this weekend.

from textual.

willmcgugan avatar willmcgugan commented on July 16, 2024 1

The API has change a bit since this example, but it shouldn't require an explicit refresh now.

from textual.

davidbrochart avatar davidbrochart commented on July 16, 2024

Just tried with v0.1.8:

from textual.widgets import Placeholder
from textual.layouts.grid import GridLayout

    
class Notebook(App):
    async def on_load(self, event: events.Load) -> None:
        await self.bind("q,ctrl+c", "quit", "Quit")
        await self.bind("a", "a")

    async def on_startup(self, event: events.Startup) -> None:

        self.layout = GridLayout()
        await self.push_view(View(layout=self.layout))

        self.layout.add_column(size=50, name="info")
        self.layout.add_column(fraction=1, name="cell")

        self.layout.add_row(fraction=1, name="1")

        self.layout.add_areas(
            info1="info,1",
            cell1="cell,1",
        )

        self.layout.place(
            info1=Placeholder(name="info1"),
            cell1=Placeholder(name="cell1"),
        )

    async def action_a(self):
        self.layout.add_row(fraction=1, name="2")
        self.layout.add_areas(
            info2="info,2",
            cell2="cell,2",
        )
        self.layout.place(
            info2=Placeholder(name="info2"),
            cell2=Placeholder(name="cell2"),
        )


Notebook.run(title="Notebook")

Nothing happens when I press a.
If I move the code of action_a at the end of on_startup, it works fine.

from textual.

willmcgugan avatar willmcgugan commented on July 16, 2024

Not sure why that is not working, I'll look in to it. In the meantime you can add the following to force a refresh of the layout:

await self.view.refresh_layout()

from textual.

davidbrochart avatar davidbrochart commented on July 16, 2024

Thanks, that works!

from textual.

davidbrochart avatar davidbrochart commented on July 16, 2024

It looks like the issue is still there:

from textual.app import App
from textual.widgets import Placeholder


class Notebook(App):
    async def on_load(self) -> None:
        await self.bind("q,ctrl+c", "quit", "Quit")
        await self.bind("a", "add_cell", "Add cell")

    async def on_mount(self) -> None:

        self.grid = await self.view.dock_grid(edge="left",  name="left")

        self.grid.add_column(size=50, name="info")
        self.grid.add_column(fraction=1, name="cell")

        self.grid.add_row(fraction=1, name="1")

        self.grid.add_areas(
            info1="info,1",
            cell1="cell,1",
        )

        self.grid.place(
            info1=Placeholder(name="info1"),
            cell1=Placeholder(name="cell1"),
        )

    async def action_add_cell(self):
        self.grid.add_row(fraction=1, name="2")
        self.grid.add_areas(
            info2="info,2",
            cell2="cell,2",
        )
        self.grid.place(
            info2=Placeholder(name="info2"),
            cell2=Placeholder(name="cell2"),
        )

Notebook.run(title="Notebook", log="textual.log")

from textual.

albertored avatar albertored commented on July 16, 2024

Hi @willmcgugan, thanks for the amazig work!
I have almost the same use case of @davidbrochart but as he said this is not working, I tried also adding await self.view.refresh_layout() but with no luck. I spent a couple of hours digging in the code but I'm afraid I have no clue on what is the problem

from textual.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.