Phoenix Logo

phoenix_title wx.lib.docview.Document

The document class can be used to model an application’s file-based data. It is part of the document/view framework supported by wxWindows, and cooperates with the View, DocTemplate and DocManager classes.

Note this wxPython version also keeps track of the modification date of the document and if it changes on disk outside of the application, we will warn the user before saving to avoid clobbering the file.


class_hierarchy Class Hierarchy

Inheritance diagram for class Document:

super_classes Known Superclasses

wx.EvtHandler


method_summary Methods Summary

__init__ Constructor. Define your own default constructor to initialize
AddView If the view is not already in the list of views, adds the view and
Close Closes the document, by calling OnSaveModified and then (if this true)
DeleteAllViews Calls View.Close and deletes each view. Deleting the final view will
DeleteContents Deletes the contents of the document. Override this method as
Destroy Destructor. Removes itself from the document manager.
Draw Called by printing framework to draw the view.
GetCommandProcessor Returns the command processor associated with this document.
GetDocumentManager Returns the associated document manager.
GetDocumentModificationDate Returns the file’s modification date when it was loaded from disk.
GetDocumentName The document type name given to the wxDocTemplate constructor,
GetDocumentSaved Returns True if the document has been saved.
GetDocumentTemplate Returns the template that created the document.
GetDocumentWindow Intended to return a suitable window for using as a parent for
GetFilename Gets the filename associated with this document, or “” if none is
GetFirstView A convenience function to get the first view for a document, because
GetPrintableName Copies a suitable document name into the supplied name buffer.
GetTitle Gets the title for this document. The document title is used for an
GetViews Returns the list whose elements are the views on the document.
GetWriteable Returns true if the document can be written to its accociated file path.
IsDocumentModificationDateCorrect Returns False if the file has been modified outside of the application.
IsModified Returns true if the document has been modified since the last save,
LoadObject Override this function and call it from your own LoadObject before
Modify Call with true to mark the document as modified since the last save,
NotifyClosing Notifies the views that the document is going to close.
OnChangedViewList Called when a view is added to or deleted from this document. The
OnCloseDocument The default implementation calls DeleteContents (an empty
OnCreate The default implementation calls DeleteContents (an empty
OnCreateCommandProcessor Override this function if you want a different (or no) command
OnNewDocument The default implementation calls OnSaveModified and DeleteContents,
OnOpenDocument Constructs an input file for the given filename (which must not
OnSaveDocument Constructs an output file for the given filename (which must
OnSaveModified If the document has been modified, prompts the user to ask if the
ProcessEvent Processes an event, searching event tables and calling zero or more
RemoveView Removes the view from the document’s list of views, and calls
Revert Override this function to revert the document to its last saved state.
Save Saves the document by calling OnSaveDocument if there is an
SaveAs Prompts the user for a file to save to, and then calls OnSaveDocument.
SaveObject Override this function and call it from your own SaveObject before
SetCommandProcessor Sets the command processor to be used for this document. The document
SetDocumentModificationDate Saves the file’s last modification date.
SetDocumentName Sets the document type name given to the DocTemplate constructor,
SetDocumentSaved Sets whether the document has been saved.
SetDocumentTemplate Sets the template that created the document. Should only be called by
SetFilename Sets the filename for this document. Usually called by the framework.
SetTitle Sets the title for this document. The document title is used for an
SetWriteable Set to False if the document can not be saved. This will disable the
UpdateAllViews Updates all views. If sender is not None, does not update this view.

api Class API



class Document(wx.EvtHandler)

The document class can be used to model an application’s file-based data. It is part of the document/view framework supported by wxWindows, and cooperates with the View, DocTemplate and DocManager classes.

Note this wxPython version also keeps track of the modification date of the document and if it changes on disk outside of the application, we will warn the user before saving to avoid clobbering the file.


Methods



__init__(self, parent=None)

Constructor. Define your own default constructor to initialize application-specific data.



AddView(self, view)

If the view is not already in the list of views, adds the view and calls OnChangedViewList.



Close(self)

Closes the document, by calling OnSaveModified and then (if this true) OnCloseDocument. This does not normally delete the document object: use DeleteAllViews to do this implicitly.



DeleteAllViews(self)

Calls View.Close and deletes each view. Deleting the final view will implicitly delete the document itself, because the wxView destructor calls RemoveView. This in turn calls Document.OnChangedViewList, whose default implemention is to save and delete the document if no views exist.



DeleteContents(self)

Deletes the contents of the document. Override this method as necessary.



Destroy(self)

Destructor. Removes itself from the document manager.



Draw(context)

Called by printing framework to draw the view.



GetCommandProcessor(self)

Returns the command processor associated with this document.



GetDocumentManager(self)

Returns the associated document manager.



GetDocumentModificationDate(self)

Returns the file’s modification date when it was loaded from disk. This is used to check if the file has been modified outside of the application.



GetDocumentName(self)

The document type name given to the wxDocTemplate constructor, copied to this document when the document is created. If several document templates are created that use the same document type, this variable is used in DocManager.CreateView to collate a list of alternative view types that can be used on this kind of document.



GetDocumentSaved(self)

Returns True if the document has been saved.



GetDocumentTemplate(self)

Returns the template that created the document.



GetDocumentWindow(self)

Intended to return a suitable window for using as a parent for document-related dialog boxes. By default, uses the frame associated with the first view.



GetFilename(self)

Gets the filename associated with this document, or “” if none is associated.



GetFirstView(self)

A convenience function to get the first view for a document, because in many cases a document will only have a single view.



GetPrintableName(self)

Copies a suitable document name into the supplied name buffer. The default function uses the title, or if there is no title, uses the filename; or if no filename, the string ‘Untitled’.



GetTitle(self)

Gets the title for this document. The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.



GetViews(self)

Returns the list whose elements are the views on the document.



GetWriteable(self)

Returns true if the document can be written to its accociated file path.



IsDocumentModificationDateCorrect(self)

Returns False if the file has been modified outside of the application.



IsModified(self)

Returns true if the document has been modified since the last save, false otherwise. You may need to override this if your document view maintains its own record of being modified (for example if using wxTextWindow to view and edit the document).



LoadObject(self, file)

Override this function and call it from your own LoadObject before loading your own data. LoadObject is called by the framework automatically when the document contents need to be loaded.

Note that the wxPython version simply sends you a Python file object, so you can use pickle.



Modify(self, modify)

Call with true to mark the document as modified since the last save, false otherwise. You may need to override this if your document view maintains its own record of being modified (for example if using wx.TextWindow to view and edit the document). This method has been extended to notify its views that the dirty flag has changed.



NotifyClosing(self)

Notifies the views that the document is going to close.



OnChangedViewList(self)

Called when a view is added to or deleted from this document. The default implementation saves and deletes the document if no views exist (the last one has just been removed).



OnCloseDocument(self)

The default implementation calls DeleteContents (an empty implementation) sets the modified flag to false. Override this to supply additional behaviour when the document is closed with Close.



OnCreate(self, path, flags)

The default implementation calls DeleteContents (an empty implementation) sets the modified flag to false. Override this to supply additional behaviour when the document is opened with Open.



OnCreateCommandProcessor(self)

Override this function if you want a different (or no) command processor to be created when the document is created. By default, it returns an instance of CommandProcessor.



OnNewDocument(self)

The default implementation calls OnSaveModified and DeleteContents, makes a default title for the document, and notifies the views that the filename (in fact, the title) has changed.



OnOpenDocument(self, filename)

Constructs an input file for the given filename (which must not be empty), and calls LoadObject. If LoadObject returns true, the document is set to unmodified; otherwise, an error message box is displayed. The document’s views are notified that the filename has changed, to give windows an opportunity to update their titles. All of the document’s views are then updated.



OnSaveDocument(self, filename)

Constructs an output file for the given filename (which must not be empty), and calls SaveObject. If SaveObject returns true, the document is set to unmodified; otherwise, an error message box is displayed.



OnSaveModified(self)

If the document has been modified, prompts the user to ask if the changes should be changed. If the user replies Yes, the Save function is called. If No, the document is marked as unmodified and the function succeeds. If Cancel, the function fails.



ProcessEvent(self, event)

Processes an event, searching event tables and calling zero or more suitable event handler function(s). Note that the ProcessEvent method is called from the wxPython docview framework directly since wxPython does not have a virtual ProcessEvent function.



RemoveView(self, view)

Removes the view from the document’s list of views, and calls OnChangedViewList.



Revert(self)

Override this function to revert the document to its last saved state.



Save(self)

Saves the document by calling OnSaveDocument if there is an associated filename, or SaveAs if there is no filename.



SaveAs(self)

Prompts the user for a file to save to, and then calls OnSaveDocument.



SaveObject(self, file)

Override this function and call it from your own SaveObject before saving your own data. SaveObject is called by the framework automatically when the document contents need to be saved.

Note that the wxPython version simply sends you a Python file object, so you can use pickle.



SetCommandProcessor(self, processor)

Sets the command processor to be used for this document. The document will then be responsible for its deletion. Normally you should not call this; override OnCreateCommandProcessor instead.



SetDocumentModificationDate(self)

Saves the file’s last modification date. This is used to check if the file has been modified outside of the application.



SetDocumentName(self, name)

Sets the document type name given to the DocTemplate constructor, copied to this document when the document is created. If several document templates are created that use the same document type, this variable is used in DocManager.CreateView to collate a list of alternative view types that can be used on this kind of document. Do not change the value of this variable.



SetDocumentSaved(self, saved=True)

Sets whether the document has been saved.



SetDocumentTemplate(self, template)

Sets the template that created the document. Should only be called by the framework.



SetFilename(self, filename, notifyViews = False)

Sets the filename for this document. Usually called by the framework. If notifyViews is true, View.OnChangeFilename is called for all views.



SetTitle(self, title)

Sets the title for this document. The document title is used for an associated frame (if any), and is usually constructed by the framework from the filename.



SetWriteable(self, writeable)

Set to False if the document can not be saved. This will disable the ID_SAVE_AS event and is useful for custom documents that should not be saveable. The ID_SAVE event can be disabled by never modifying the document.



UpdateAllViews(self, sender = None, hint = None)

Updates all views. If sender is not None, does not update this view. hint represents optional information to allow a view to optimize its update.