.. 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.Trackable.html" title="wx.Trackable" alt="" coords="5,5,107,35"/> <area shape="rect" id="node2" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="57,83,168,112"/> <area shape="rect" id="node4" href="wx.lib.docview.Document.html" title="wx.lib.docview.Document" alt="" coords="23,160,203,189"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="131,5,212,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.


