-
-
Notifications
You must be signed in to change notification settings - Fork 674
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
KeyError when re-creating a sub-window which contains widgets with ids #2190
Comments
Thanks for the report. I can confirm I can reproduce this problem; it appears that when the window is being closed, the content of that window isn't being deregistered from the app registry. That shouldn't require an additional step - the app registry uses weakrefs, so as soon as there's no object referencing it, the widget should be cleaned up. This appears to be a garbage collection issue. If you put a call to The naive solution would be to invoke the garbage collector on a window close... but I'm not sure if that's the right permanent solution. |
A suggestion from @mhsmith about a possible fix - instead of treating the app registry as an index of every widget in existence (which becomes subject to garbage collection), it should only store widgets that are "in the DOM" - that is - widgets that are in a layout. That way, we can reliably say a widget is removed from the app registry when the window is closed (because it has been removed from the app's "DOM"), even though there may still be a reference to the widget somewhere in code. When it is re-added to a layout, it gets re-added to the app registry. This would theoretically allow for 2 widgets with the same ID to exist, but you wouldn't be able to look up a widget by instance unless it was in a layout, and only one of them would be able to be in a layout at any given time. One possible way to implement this would be to replace the app widget registry with an implementation that is a proxy around the window registries .That is,
That is - you look up a widget on the app by looking up the widget on each window in the app. This would also require that the |
Same issue here. This part works great (pseudo code):
Error happens on the last line below:
|
I found a workaround: Solved all my issues related to this. Let me know if it's a bad idea, or if it might cause a crash. |
@hyuri I'd consider it at least a little risky. Calling It's also not a public API, so I wouldn't consider it a long term solution. |
Describe the bug
On desktops, when you close and then re-create a sub-window which contains widgets that have an id, you get following error:
Steps to reproduce
non_resize_window.content = toga.Box(children=[toga.Label("This window is not resizable", id="label1")])
KeyError: "There is already a widget with the id 'label1'"
Expected behavior
It should be possible to re-create the sub-window without getting this KeyError.
Screenshots
No response
Environment
Logs
Additional context
No response
The text was updated successfully, but these errors were encountered: