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

Explore the nursery.start() style API for exposing window objects #194

Open
altendky opened this issue Dec 25, 2020 · 1 comment
Open

Explore the nursery.start() style API for exposing window objects #194

altendky opened this issue Dec 25, 2020 · 1 comment

Comments

@altendky
Copy link
Owner

await get_input() doesn't enable testing since the caller has no access to the window or other resources. Presently the focus has been on doing window = create_window(); await window.wait(). Consider offering window = await nursery.start(create_window).

@altendky
Copy link
Owner Author

A common need is to create a window and then wait for it to be shown. With the existing approach here in QTrio we create the window, connect to it's shown signal (which has to be added), start the window, then wait for the shown signal. With the proposed nursery.start() usage this all collapses down to window = await nursery.start(create_window). create_window() in this case will create the window, show it, then return that object through the task_status that nursery.start() provides and we assign it to window. It is good to still be able to access all the separate pieces but helpful to not _have_ to deal with them every time. This retains testability since you do launch the window in a separate task and also get the window object so you can poke at it programmatically. This was approach suggested by one of the Trio dev's when I described the window as being like a server that we need to start and then let the user interact with, just as they would with a webserver you might run except the server input is clicks
and keypresses and resize events etc instead of http.

Here's some very verbose 'create the window and launch a fake-user to wait for the window to be shown and then run the window':
https://github.com/altendky/qtrio/blob/master/qtrio/_tests/examples/test_crossingpaths.py#L24-L40

    async def user():
        async for emission in emissions.channel:
            [text] = emission.args
            results.append(text)

    async with trio.open_nursery() as nursery:
        async with qtrio.enter_emissions_channel(
            signals=[label.text_changed],
        ) as emissions:
            nursery.start_soon(user)

            await qtrio.examples.crossingpaths.main(
                label=label,
                message="test world",
                change_delay=0.01,
                close_delay=0.01,
            )

And the new-style using nursery.start() over in ssst where the user action just goes below nursery.start():
https://github.com/altendky/ssst/blob/46232ec16627e309d1f48dd3ff6e7c6145a9132b/src/ssst/_tests/gui/test_main.py#L39-L41

    main_window: ssst.gui.main.Window = await nursery.start(
        functools.partial(ssst.gui.main.Window.start, title="title")
    )

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

1 participant