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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
|
.. wxPython Phoenix documentation
This file was generated by Phoenix's sphinx generator and associated
tools, do not edit by hand.
Copyright: (c) 2011-2018 by Total Control Software
License: wxWindows License
.. include:: headings.inc
.. currentmodule:: wx.lib.docview
.. highlight:: python
.. _wx.lib.docview.Document:
==========================================================================================================================================
|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 :class:`View`, :class:`DocTemplate` and :class:`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
=================================
.. raw:: html
<div id="toggleBlock" onclick="return toggleVisibility(this)" class="closed" style="cursor:pointer;">
<img id="toggleBlock-trigger" src="_static/images/closed.png"/>
Inheritance diagram for class <strong>Document</strong>:
</div>
<div id="toggleBlock-summary" style="display:block;"></div>
<div id="toggleBlock-content" style="display:none;">
<p class="graphviz">
<center><img src="_static/images/inheritance/wx.lib.docview.Document_inheritance.png" alt="Inheritance diagram of Document" usemap="#dummy" class="inheritance"/></center>
</div>
<script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
<map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.lib.docview.Document.html" title="wx.lib.docview.Document" alt="" coords="14,160,193,189"/> <area shape="rect" id="node2" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="48,83,159,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="5,5,87,35"/> <area shape="rect" id="node4" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="112,5,213,35"/> </map>
</p>
|
|super_classes| Known Superclasses
==================================
:class:`wx.EvtHandler`
|
|method_summary| Methods Summary
================================
================================================================================ ================================================================================
:meth:`~wx.lib.docview.Document.__init__` Constructor. Define your own default constructor to initialize
:meth:`~wx.lib.docview.Document.AddView` If the view is not already in the list of views, adds the view and
:meth:`~wx.lib.docview.Document.Close` Closes the document, by calling :meth:`~wx.lib.docview.Document.OnSaveModified` and then (if this true)
:meth:`~wx.lib.docview.Document.DeleteAllViews` Calls :meth:`View.Close` and deletes each view. Deleting the final view will
:meth:`~wx.lib.docview.Document.DeleteContents` Deletes the contents of the document. Override this method as
:meth:`~wx.lib.docview.Document.Destroy` Destructor. Removes itself from the document manager.
:meth:`~wx.lib.docview.Document.Draw` Called by printing framework to draw the view.
:meth:`~wx.lib.docview.Document.GetCommandProcessor` Returns the command processor associated with this document.
:meth:`~wx.lib.docview.Document.GetDocumentManager` Returns the associated document manager.
:meth:`~wx.lib.docview.Document.GetDocumentModificationDate` Returns the file's modification date when it was loaded from disk.
:meth:`~wx.lib.docview.Document.GetDocumentName` The document type name given to the wxDocTemplate constructor,
:meth:`~wx.lib.docview.Document.GetDocumentSaved` Returns ``True`` if the document has been saved.
:meth:`~wx.lib.docview.Document.GetDocumentTemplate` Returns the template that created the document.
:meth:`~wx.lib.docview.Document.GetDocumentWindow` Intended to return a suitable window for using as a parent for
:meth:`~wx.lib.docview.Document.GetFilename` Gets the filename associated with this document, or "" if none is
:meth:`~wx.lib.docview.Document.GetFirstView` A convenience function to get the first view for a document, because
:meth:`~wx.lib.docview.Document.GetPrintableName` Copies a suitable document name into the supplied name buffer.
:meth:`~wx.lib.docview.Document.GetTitle` Gets the title for this document. The document title is used for an
:meth:`~wx.lib.docview.Document.GetViews` Returns the list whose elements are the views on the document.
:meth:`~wx.lib.docview.Document.GetWriteable` Returns true if the document can be written to its accociated file path.
:meth:`~wx.lib.docview.Document.IsDocumentModificationDateCorrect` Returns ``False`` if the file has been modified outside of the application.
:meth:`~wx.lib.docview.Document.IsModified` Returns true if the document has been modified since the last save,
:meth:`~wx.lib.docview.Document.LoadObject` Override this function and call it from your own ``LoadObject`` before
:meth:`~wx.lib.docview.Document.Modify` Call with true to mark the document as modified since the last save,
:meth:`~wx.lib.docview.Document.NotifyClosing` Notifies the views that the document is going to close.
:meth:`~wx.lib.docview.Document.OnChangedViewList` Called when a view is added to or deleted from this document. The
:meth:`~wx.lib.docview.Document.OnCloseDocument` The default implementation calls :meth:`~wx.lib.docview.Document.DeleteContents` (an empty
:meth:`~wx.lib.docview.Document.OnCreate` The default implementation calls :meth:`~wx.lib.docview.Document.DeleteContents` (an empty
:meth:`~wx.lib.docview.Document.OnCreateCommandProcessor` Override this function if you want a different (or no) command
:meth:`~wx.lib.docview.Document.OnNewDocument` The default implementation calls OnSaveModified and DeleteContents,
:meth:`~wx.lib.docview.Document.OnOpenDocument` Constructs an input file for the given filename (which must not
:meth:`~wx.lib.docview.Document.OnSaveDocument` Constructs an output file for the given filename (which must
:meth:`~wx.lib.docview.Document.OnSaveModified` If the document has been modified, prompts the user to ask if the
:meth:`~wx.lib.docview.Document.ProcessEvent` Processes an event, searching event tables and calling zero or more
:meth:`~wx.lib.docview.Document.RemoveView` Removes the view from the document's list of views, and calls
:meth:`~wx.lib.docview.Document.Revert` Override this function to revert the document to its last saved state.
:meth:`~wx.lib.docview.Document.Save` Saves the document by calling :meth:`~wx.lib.docview.Document.OnSaveDocument` if there is an
:meth:`~wx.lib.docview.Document.SaveAs` Prompts the user for a file to save to, and then calls :meth:`OnSaveDocument`.
:meth:`~wx.lib.docview.Document.SaveObject` Override this function and call it from your own ``SaveObject`` before
:meth:`~wx.lib.docview.Document.SetCommandProcessor` Sets the command processor to be used for this document. The document
:meth:`~wx.lib.docview.Document.SetDocumentModificationDate` Saves the file's last modification date.
:meth:`~wx.lib.docview.Document.SetDocumentName` Sets the document type name given to the :class:`DocTemplate` constructor,
:meth:`~wx.lib.docview.Document.SetDocumentSaved` Sets whether the document has been saved.
:meth:`~wx.lib.docview.Document.SetDocumentTemplate` Sets the template that created the document. Should only be called by
:meth:`~wx.lib.docview.Document.SetFilename` Sets the filename for this document. Usually called by the framework.
:meth:`~wx.lib.docview.Document.SetTitle` Sets the title for this document. The document title is used for an
:meth:`~wx.lib.docview.Document.SetWriteable` Set to ``False`` if the document can not be saved. This will disable the
:meth:`~wx.lib.docview.Document.UpdateAllViews` Updates all views. If sender is non-NULL, 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 :class:`View`, :class:`DocTemplate` and :class:`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.
.. method:: __init__(self, parent=None)
Constructor. Define your own default constructor to initialize
application-specific data.
.. method:: AddView(self, view)
If the view is not already in the list of views, adds the view and
calls :meth:`OnChangedViewList`.
.. method:: Close(self)
Closes the document, by calling :meth:`OnSaveModified` and then (if this true)
:meth:`OnCloseDocument`. This does not normally delete the document object:
use :meth:`DeleteAllViews` to do this implicitly.
.. method:: DeleteAllViews(self)
Calls :meth:`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 :meth:`Document.OnChangedViewList`,
whose default implemention is to save and delete the document if no
views exist.
.. method:: DeleteContents(self)
Deletes the contents of the document. Override this method as
necessary.
.. method:: Destroy(self)
Destructor. Removes itself from the document manager.
.. method:: Draw(context)
Called by printing framework to draw the view.
.. method:: GetCommandProcessor(self)
Returns the command processor associated with this document.
.. method:: GetDocumentManager(self)
Returns the associated document manager.
.. method:: 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.
.. method:: 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 :meth:`DocManager.CreateView` to collate a list of
alternative view types that can be used on this kind of document.
.. method:: GetDocumentSaved(self)
Returns ``True`` if the document has been saved.
.. method:: GetDocumentTemplate(self)
Returns the template that created the document.
.. method:: 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.
.. method:: GetFilename(self)
Gets the filename associated with this document, or "" if none is
associated.
.. method:: 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.
.. method:: 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'.
.. method:: 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.
.. method:: GetViews(self)
Returns the list whose elements are the views on the document.
.. method:: GetWriteable(self)
Returns true if the document can be written to its accociated file path.
.. method:: IsDocumentModificationDateCorrect(self)
Returns ``False`` if the file has been modified outside of the application.
.. method:: 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).
.. method:: 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.
.. method:: 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
:class:`wx.TextWindow` to view and edit the document).
This method has been extended to notify its views that the dirty
flag has changed.
.. method:: NotifyClosing(self)
Notifies the views that the document is going to close.
.. method:: 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).
.. method:: OnCloseDocument(self)
The default implementation calls :meth:`DeleteContents` (an empty
implementation) sets the modified flag to false. Override this to
supply additional behaviour when the document is closed with Close.
.. method:: OnCreate(self, path, flags)
The default implementation calls :meth:`DeleteContents` (an empty
implementation) sets the modified flag to false. Override this to
supply additional behaviour when the document is opened with Open.
.. method:: 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 :class:`CommandProcessor`.
.. method:: 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.
.. method:: OnOpenDocument(self, filename)
Constructs an input file for the given filename (which must not
be empty), and calls :meth:`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.
.. method:: OnSaveDocument(self, filename)
Constructs an output file for the given filename (which must
not be empty), and calls :meth:`SaveObject`. If :meth:`SaveObject`
returns true, the document is set to unmodified; otherwise, an
error message box is displayed.
.. method:: 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.
.. method:: 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.
.. method:: RemoveView(self, view)
Removes the view from the document's list of views, and calls
:meth:`OnChangedViewList`.
.. method:: Revert(self)
Override this function to revert the document to its last saved state.
.. method:: Save(self)
Saves the document by calling :meth:`OnSaveDocument` if there is an
associated filename, or :meth:`SaveAs` if there is no filename.
.. method:: SaveAs(self)
Prompts the user for a file to save to, and then calls :meth:`OnSaveDocument`.
.. method:: 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.
.. method:: 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 :meth:`OnCreateCommandProcessor` instead.
.. method:: SetDocumentModificationDate(self)
Saves the file's last modification date.
This is used to check if the file has been modified outside of
the application.
.. method:: SetDocumentName(self, name)
Sets the document type name given to the :class:`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 :meth:`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.
.. method:: SetDocumentSaved(self, saved=True)
Sets whether the document has been saved.
.. method:: SetDocumentTemplate(self, template)
Sets the template that created the document. Should only be called by
the framework.
.. method:: SetFilename(self, filename, notifyViews = False)
Sets the filename for this document. Usually called by the framework.
If notifyViews is true, :meth:`View.OnChangeFilename` is called for all
views.
.. method:: 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.
.. method:: 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.
.. method:: UpdateAllViews(self, sender = None, hint = None)
Updates all views. If sender is non-NULL, does not update this view.
hint represents optional information to allow a view to optimize its
update.
|