DocumentWindow

A window that can be used as the main interface to a document-based app.

Usage

A DocumentWindow is the same as a toga.MainWindow, except that it is bound to a toga.Document instance, exposed as the toga.DocumentWindow.doc attribute.

Instances of toga.DocumentWindow should be created as part of the create() method of an implementation of toga.Document.

Reference

class toga.DocumentWindow(doc, *args, **kwargs)

Bases: MainWindow

Create a new document Window.

A document window is a MainWindow (so it will have a menu bar, and can have a toolbar), bound to a document instance.

In addition to the required doc argument, accepts the same arguments as Window.

The default on_close handler will use the document’s modification status to determine if the document has been modified. It will allow the window to close if the document is fully saved, or the user explicitly declines the opportunity to save.

Parameters:

doc (Document) – The document being managed by this window

property doc: Document

The document displayed by this window.

async save()

Save the document associated with this window.

If the document associated with a window hasn’t been saved before, the user will be prompted to provide a filename.

Returns:

True if the save was successful; False if the save was aborted, or the document type doesn’t define a write() method.

async save_as()

Save the document associated with this window under a new filename.

The default implementation will prompt the user for a new filename, then save the document with that new filename.

Returns:

True if the save was successful; False if the save was aborted, or the document type doesn’t define a write() method.