1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
class CDocument
Class CDocument represents a document, one of the most basic objects. A
document is a unit of data which the user opens with the File Open
command and saves with the File Save command.
In an SDI application, the same document is reused each time the user
selects File New or File Open. In an MDI app, a new document is created
each time. So you must put initialization code into OnNewDocument or
OnOpenDocument and you must put de-initialization code into
OnCloseDocument.
Instance Variables
wpyParent
For a document, the parent is the template which created
the document.
wpyChildList
For a document, the child list is a list of frames which
belong to the document.
wpyViewList
A list of all the views which show this document.
Methods you will probably override:
__init__(self, templ)
templ: The template being used to create the document.
DeleteContents(self)
Called to delete the contents of a document. It is called just
before the document is destroyed. In a SDI app, it is called to
insure the document is empty so it can be reused.
The default implementation does nothing and you should provide
your own method.
SerializeIn(self, file_object)
Sent when the user requests the document to be read from disk.
The "file_object" is a file object open for reading.
The default implementation does nothing and you should provide
your own method.
SerializeOut(self, file_object)
Sent when the user requests the document to be written to disk.
The "file_object" is a file object open for writing.
The default implementation does nothing and you should provide
your own method.
Methods you will probably use as is:
SetModifiedFlag(self, value = 1)
Call this method after you have modified the document. This
ensures that the user is prompted to save a modified document.
To mark a document as clean, call with a value of zero.
SetTitle(self, title)
Set the title of the document. This determines the titles on all
frames which show the document. The default title is wpyText of
the document template. For SDI frames, the frame title is
CWinApp::wpyMainTitle plus the document title.
UpdateAllViews(self, sender, update)
sender, the view which is notifying the other views of a change, or None.
update, an arbitrary Python object passed to OnUpdate.
Call this after you call SetModifiedFlag. It informs all views
other than the view specified by "sender" that the document has
been modified and should be re-displayed. It calls the view's
OnUpdate method passing it "update". Use "update" to pass
information on how much of the document was changed.
Virtual methods you could override and/or call the base class:
int OnNewDocument(self)
Called as part of the File New command. The default implementation
calls DeleteContents and marks the new document as clean. You should
call the base class method in your override. A return of zero
indicates failure, otherwise success.
This method is not usually replaced.
int OnOpenDocument(self, filename)
Called as part of the File Open command. The default implementation
calls DeleteContents, calls SerializeIn to read in the document,
and marks the new document as clean. You could override this
method to provide a different file interface. Return zero to
indicate failure, otherwise success.
void OnCloseDocument(self)
Called when the document is closed. The default implementation
calls DeleteContents, and then closes the frame windows for all
the views attached to the document. You can call the base class
method in your override.
int OnSaveDocument(self, filename)
Called as part of the File Save and File Save As command. The
default implementation opens the specified file, calls SerializeOut
to write it, and marks the document as clean. A return of zero
indicates failure, otherwise success.
|