-
-
Notifications
You must be signed in to change notification settings - Fork 672
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
Add support for background and session-based apps #2651
Conversation
709370e
to
b50b2c3
Compare
3f3c0c5
to
88d331b
Compare
3cbb993
to
3830177
Compare
This isn't required for the event loop to run, and assinging a main form in Winforms forces the form to be displayed.
This is only useful on X11, and even there is only used to preserve window position when a session is restored, when the app window doesn't have a unique name.
3830177
to
89c1ec0
Compare
As we discussed starting at #2099 (comment), this can now be written as |
docs/reference/api/app.rst
Outdated
:class:`toga.Window` | ||
~~~~~~~~~~~~~~~~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hiding the module name would make the page more readable. In fact, I think we should be doing this more generally in the docs.
:class:`toga.Window` | |
~~~~~~~~~~~~~~~~~~~~ | |
:class:`Window` | |
~~~~~~~~~~~~~~~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed; however, AIUI, the ~
is the preferred way to do this; that keeps the Sphinx reference explicit, while hiding the context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes a difference when there are more than two components. For example, :any:~toga.App.exit
will display as exit
, while :any:App.exit
will display as App.exit
.
If you use the :any:
syntax, Sphinx doesn't require names to be absolute, it just searches for a match among all the targets in the docs, and gives an error if it doesn't find exactly one. This usually allows you to write the names in the RST exactly as you want them to appear in the HTML.
I'm not suggesting any more changes to this PR, just that in future it's probably better to avoid littering the docs with toga
everywhere. Note that toga
is already hidden in the right sidebar, and in argument and return types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another advantage of using :any:
is that it gives an error if it doesn't find a valid target, while :class:
, :meth:
, etc. all fail silently and output the text with no hyperlink.
Co-authored-by: Malcolm Smith <smith@chaquo.com>
I agree that it can be spelled like this; but "logic I want to run as soon as the event loop is running" is a very common pattern; and that logic won't always be async. To my mind, providing explicit support for this use case is worth it, even if it can be replicated with other primitives - if only for the beginner use case, because it means we can expose the capability without needing to give a full primer on what a "task" is in the context of asyncio. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After discussion, we agreed to do the following in a separate PR:
- Change
running
into an event handler calledon_running
. Like other event handlers, this will support being assigned as a property or a constructor argument. - Since the App class is designed to be subclassed, we'll also support overriding the event property with a synchronous or asynchronous method.
- Do the same with
on_exit
.
See #2678 for the discussed changes around |
Builds on #2649; that PR should be reviewed and merged before reviewing this one.
Derived from #2244.
Adds support for 2 new application types:
Includes a new
statusiconapp
example to demonstrate background apps. This is a bit of a stub until full status icon support is added in a subsequent PR. The key detail is that a background app is configured by settingmain_window = toga.App.BACKGROUND
.The
documentapp
example is used as an example of session-based apps; the addition from this PR is that configuring the app requires settingmain_window = None
.This PR also adds a
runnning()
method on apps that can be overridden by subclasses; this is guaranteed to be executed as soon as the main event loop starts. This simplifies a common use case of using startup() to add a background task. Thestatusiconapp
contains a simple example of usage.This PR uses the document-based app as a testing exemplar of session-based apps. Testing the session-based API requires loosening some of the test coverage related to document handling; these tests will be made more robust in a subsequent PR that finalises the Document API.
Two notable minor changes:
MainWindow
renders it in the display without callingshow()
#2653.Refs #2209.
Refs #97.
PR Checklist: