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

Finalize API for Document-based apps #2666

Merged
merged 61 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from 52 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
53d1a5b
Update documentation and examples for document API.
freakboy3742 Jun 25, 2024
d793d60
Update core and core tests to match documentation.
freakboy3742 Jun 27, 2024
f543a52
Add document type registration to example document app.
freakboy3742 Jun 28, 2024
2d377f9
Add document API tests for macOS.
freakboy3742 Jun 29, 2024
8e46ad4
Update document tests for iOS and Android.
freakboy3742 Jun 29, 2024
5d57a38
Initial attempt at GTK and Winforms document API tests.
freakboy3742 Jun 29, 2024
eb65ee9
Use an automated approach to window cleanup.
freakboy3742 Jun 29, 2024
e1dcd2c
Minor cleanups and test fixes.
freakboy3742 Jun 29, 2024
8dc24e3
Mark GTK and Winforms as using default command line handling.
freakboy3742 Jun 29, 2024
0e85f43
Add error handling to GTK/Winforms document handling.
freakboy3742 Jun 29, 2024
34129cb
Add Open menu item for GTK and Winforms.
freakboy3742 Jun 29, 2024
ea2e6e5
Create an empty document on GTK and Winforms startup.
freakboy3742 Jun 29, 2024
0e3d025
Remove need for Document to have an implementation.
freakboy3742 Jul 1, 2024
118b93e
Merge branch 'main' into document-api
freakboy3742 Jul 15, 2024
808b1f7
Merge branch 'main' into document-api
freakboy3742 Jul 18, 2024
699f506
Add factory method for standard commands, and backend implementation …
freakboy3742 Jul 19, 2024
9816d28
Add backend implementations of commands.
freakboy3742 Jul 19, 2024
780e7f3
Remove backend representations for DocumentMainWindow.
freakboy3742 Jul 19, 2024
f8ca850
Fixes for test coverage and platform menus.
freakboy3742 Jul 19, 2024
44dbb54
Add handling for non-defined document commands.
freakboy3742 Jul 19, 2024
f60d39c
Add documentation and core implemenation for new/save/save as/save all.
freakboy3742 Jul 2, 2024
91df79a
Add cocoa implementation of new/save/save as/save all and testbed tests.
freakboy3742 Jul 2, 2024
8c9b7c3
Add GTK and Winforms implementation and tests.
freakboy3742 Jul 2, 2024
e7e0cc5
Add second doctype registration for coverage.
freakboy3742 Jul 2, 2024
48a773d
Additional test fixes and coverage.
freakboy3742 Jul 19, 2024
35df5b5
Add resilience to adding missing commands.
freakboy3742 Jul 19, 2024
84cddeb
Make the file management programmatic API public.
freakboy3742 Jul 19, 2024
5a991ac
Speculative fix for macOS app shutdown issues.
freakboy3742 Jul 19, 2024
6d7a0fa
Add document modification and focus API.
freakboy3742 Jul 23, 2024
098480c
Open the existing representation of a document.
freakboy3742 Jul 23, 2024
b40f013
Minor behavior corrections for Linux paths and focus.
freakboy3742 Jul 23, 2024
833c923
Corrections for Python3.8 path handling on Windows.
freakboy3742 Jul 23, 2024
ea4065a
Open documents into 'existing' windows on GTK and Linux.
freakboy3742 Jul 23, 2024
31c68d1
Merge branch 'main' into document-api
mhsmith Jul 25, 2024
46535b7
Apply suggestions from code review
freakboy3742 Jul 27, 2024
d85f346
Rename is_modified -> modified.
freakboy3742 Jul 27, 2024
7dd5b54
Simplify handling of replacement filenames.
freakboy3742 Jul 27, 2024
9ecc086
Update docstrings to consistently refer to standard commands.
freakboy3742 Jul 27, 2024
eca1987
Rename DocumentMainWindow to DocumentWindow.
freakboy3742 Jul 27, 2024
7ef9991
Make modified a writable document property.
freakboy3742 Jul 27, 2024
013b123
Correct the save_as testbed test.
freakboy3742 Jul 27, 2024
df258ce
Correct widget support data.
freakboy3742 Jul 29, 2024
dc150da
Apply suggestions from code review
freakboy3742 Aug 17, 2024
7f9d456
Merge branch 'main' into document-api
freakboy3742 Aug 17, 2024
facd630
Removed some duplicated details in the command docs.
freakboy3742 Aug 17, 2024
dbf55e5
Corrected some pre-commit issues.
freakboy3742 Aug 17, 2024
8d5945b
Reorganization of document-based classes.
freakboy3742 Aug 17, 2024
2a21108
Correct the expected error type.
freakboy3742 Aug 17, 2024
c3116eb
Correct some documentation markup.
freakboy3742 Aug 17, 2024
e67601c
Refactor the document control commands into DocumentSet.
freakboy3742 Aug 18, 2024
3862233
Correct wording to avoid spelling issue.
freakboy3742 Aug 18, 2024
43236b5
Simplify the API for creating standard commands.
freakboy3742 Aug 18, 2024
84b2860
Add links to default Command actions.
freakboy3742 Aug 19, 2024
46e7ab0
Rename Document.document_type; corrected and simplified open/save logic.
freakboy3742 Aug 20, 2024
8443dd2
Move document types to DocumentSet, and move extension handling to Do…
freakboy3742 Aug 20, 2024
10c8621
Remove document.close
freakboy3742 Aug 20, 2024
ccea366
Simpified cleanup of replacement marker.
freakboy3742 Aug 20, 2024
351028f
Update documentation for new types/extensions format.
freakboy3742 Aug 20, 2024
58089aa
Apply suggestions from code review
freakboy3742 Aug 22, 2024
c181f61
Move deprecated property back to the deprecated class.
freakboy3742 Aug 22, 2024
2589966
Add a hide method to Document for parity.
freakboy3742 Aug 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions android/src/toga_android/app.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import asyncio
import sys
import warnings

from android.content import Context
Expand All @@ -11,9 +10,8 @@
from org.beeware.android import IPythonApp, MainActivity

import toga
from toga.command import Command, Group, Separator
from toga.command import Group, Separator
from toga.dialogs import InfoDialog
from toga.handlers import simple_handler

from .libs import events
from .screens import Screen as ScreenImpl
Expand Down Expand Up @@ -186,6 +184,9 @@ def onPrepareOptionsMenu(self, menu):
class App:
# Android apps exit when the last window is closed
CLOSE_ON_LAST_WINDOW = True
# Android doesn't have command line handling;
# but saying it does shortcuts the default handling
HANDLES_COMMAND_LINE = True

def __init__(self, interface):
self.interface = interface
Expand All @@ -210,16 +211,8 @@ def create(self):
# Commands and menus
######################################################################

def create_app_commands(self):
self.interface.commands.add(
# About should be the last item in the menu, in a section on its own.
Command(
simple_handler(self.interface.about),
f"About {self.interface.formal_name}",
section=sys.maxsize,
id=Command.ABOUT,
),
)
def create_standard_commands(self):
pass

def create_menus(self):
# Menu items are configured as part of onPrepareOptionsMenu; trigger that
Expand Down
28 changes: 28 additions & 0 deletions android/src/toga_android/command.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,38 @@
import sys

from org.beeware.android import MainActivity

from toga import Command as StandardCommand


class Command:
def __init__(self, interface):
self.interface = interface
self.native = []

@classmethod
def standard(cls, app, id):
# ---- Help menu ----------------------------------
if id == StandardCommand.ABOUT:
return {
"text": f"About {app.formal_name}",
"section": sys.maxsize,
}
# ---- Undefined commands--------------------------
elif id in {
StandardCommand.EXIT,
StandardCommand.NEW,
StandardCommand.OPEN,
StandardCommand.PREFERENCES,
StandardCommand.SAVE,
StandardCommand.SAVE_AS,
StandardCommand.SAVE_ALL,
StandardCommand.VISIT_HOMEPAGE,
}:
# These are valid commands, but they're not defined on Android.
return None

raise ValueError(f"Unknown standard command {id!r}")

def set_enabled(self, value):
MainActivity.singletonThis.invalidateOptionsMenu()
File renamed without changes.
1 change: 1 addition & 0 deletions changes/2209.feature.2.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The API for Documents and document types has been finalized. Document handling behavior is now controlled by declaring document types as part of your ``toga.App`` definition.
11 changes: 11 additions & 0 deletions changes/2209.removal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
The API for Documents and Document-based apps has been significantly modified. Unfortunately, these changes are not backwards compatible; any existing Document-based app will require modification.

The ``DocumentApp`` base class is no longer required. Apps can subclass ``App``, providing the same arguments as before.

The API for ``Document`` subclasses has also changed:

* A path is no longer provided as an argument to the Document constructor;

* The ``document_type`` is now specified as a class property; and
freakboy3742 marked this conversation as resolved.
Show resolved Hide resolved

* The ``can_close()`` handler is no longer honored. Documents now track if they are modified, and have a default ``on_close`` handler that uses the modification status of a document to control whether a document can close. Invoking ``touch()`` on document will mark a document as modified. This modification flag is cleared by saving the document.
Loading