Dynamic View and multiple Windows per App
See original GitHub issueRelated to #10 but hopefully this issue can serve as a more general discussion about handling Apps with multiple Windows.
The first issue I have encountered is that a View cannot contain exclusively Window components. See the snippet in #10 for which the App is not terminated. I think it’s because the App is creating a window for its children, however when these are Windows themselves then the root window is “invisible” and can’t be closed. Adding any other component to the View resolves this:
import edifice as ed
class MyApp(ed.Component):
def render(self):
return ed.View()(
ed.Label("Hello"),
ed.Window()(ed.Label("Hello")),
)
if __name__ == "__main__":
ed.App(MyApp()).start()
The second thing is that I am not quite sure how to go about dynamically managing windows. An example of spawning a window from a button click would be interesting (if it is possible). Then there is also the possibility of dynamic Views where some components could be invisible depending on a conditional…
Lastly, the snippet above creates two windows (one for MyApp, implicitly, and one for the second Label). They can be closed independently. In many cases, it would be desirable to assign one window as the root or parent window. When closed, it should close all of it’s children and terminate the App.
As time permits, I’ll dig into thee implementations some more and hopefully I can help in some way (even if it’s just testing or documentation).
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Here’s an example of how to create new windows on the click of a button, and how to close all windows once the main window is closed:
It uses the
List
component as you noted, which holds a list of subcomponents without mounting them into any UI element. Closing a window is done the same way you would hide an UI element, i.e. by not returning that window in the render function.I think this solution fits well with the design of the rest of the library. However, the way the library handles windows isn’t perfect: when the user closes a window that does not have an on_close event defined, the window will disappear, but the internal state will not register that the window is gone. This means that next time render is called, the window will be resurrected. I’m not sure about the best way of handling this inconsistency. The simplest way is to block the usual window closing mechanism, and only close a window when it’s not rendered by anything. But I think this is bad default behavior and would result in overhead for almost all situations. The current version will get all the simple cases right, but could result in inconsistencies with multiple windows if the user isn’t careful. Do you have any thoughts on how this might be better designed?
Just a heads up that I’m too busy to really look at this, and my original use-case isn’t going to happen in the form that I planned. Feel free to close this, or you can leave it open in case there are any takers. I’ll definitely recommend that people check out this package if I find anyone looking for simple/reactive UI in python 😃