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

Proper way to remove widgets #160

Closed
artur-shaik opened this issue Nov 12, 2021 · 9 comments
Closed

Proper way to remove widgets #160

artur-shaik opened this issue Nov 12, 2021 · 9 comments

Comments

@artur-shaik
Copy link

How I can properly reload my view with new widgets, by removing old ones?

@bot-boi
Copy link

bot-boi commented Nov 12, 2021

I've been poking around the source the past couple days and I haven't seen anything like def remove_widget. I think this might be intentional but I'm not sure. You could delete the Widget object from the View.widgets property but I haven't tried that yet. You could also try setting the visible property of your widget to False.

@bot-boi
Copy link

bot-boi commented Nov 13, 2021

You could also overwrite an area with a widget with None in a GridView for example, by using add_widget or place. There isn't really a proper way to do it

@artur-shaik
Copy link
Author

I've tried to do self.view.widgets.clear(). Set becomes empty, but widgets still in view.

@artur-shaik
Copy link
Author

artur-shaik commented Nov 13, 2021

Ok, looks like find some hacky solution that works:

        if isinstance(self.view.layout, DockLayout):
            self.view.layout.docks.clear()
        self.view.widgets.clear()

@stephenlutes
Copy link

@artur-shaik I was unable to get this to work outside of on_mount at the very start. How did you implement it?

@artur-shaik
Copy link
Author

@stephenlutes I've implemented in inside textual event loop, not sure why you need it outside?

@stephenlutes
Copy link

stephenlutes commented Jan 6, 2022

I may be going about this the wrong way. I am trying to clear everything within an action when a certain key is pressed.

Update
I was able to get it to work by moving it into on_key instead of binding to an action.

@willmcgugan
Copy link
Collaborator

@github-actions
Copy link

Did we solve your problem?

Consider buying the Textualize developers a coffee to say thanks.

Textualize

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

4 participants