.. wxPython Phoenix documentation

   This file was generated by Phoenix's sphinx generator and associated
   tools, do not edit by hand.

   Copyright: (c) 2011-2020 by Total Control Software
   License:   wxWindows License

.. include:: headings.inc

.. currentmodule:: wx.lib.docview

.. highlight:: python



.. _wx.lib.docview.DocManager:

==========================================================================================================================================
|phoenix_title|  **wx.lib.docview.DocManager**
==========================================================================================================================================

The :class:`DocManager` class is part of the document/view framework,
and cooperates with the :class:`View`, :class:`Document` and
:class:`DocTemplate` classes.



|

|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>DocManager</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.DocManager_inheritance.png" alt="Inheritance diagram of DocManager" usemap="#dummy" class="inheritance"/></center>
   <script type="text/javascript">toggleVisibilityOnLoad(document.getElementById('toggleBlock'))</script>
   <map id="dummy" name="dummy"> <area shape="rect" id="node1" href="wx.lib.docview.DocManager.html" title="wx.lib.docview.DocManager" alt="" coords="7,160,210,189"/> <area shape="rect" id="node2" href="wx.EvtHandler.html" title="wx.EvtHandler" alt="" coords="50,83,167,112"/> <area shape="rect" id="node3" href="wx.Object.html" title="wx.Object" alt="" coords="5,5,92,35"/> <area shape="rect" id="node4" href="wx.Trackable.html" title="wx.Trackable" alt="" coords="117,5,223,35"/> </map> 
   </p>
   </div>

|


|super_classes| Known Superclasses
==================================

:class:`wx.EvtHandler`

|


|method_summary| Methods Summary
================================

================================================================================ ================================================================================
:meth:`~wx.lib.docview.DocManager.__init__`                                      Constructor. Create a document manager instance dynamically near the
:meth:`~wx.lib.docview.DocManager.ActivateView`                                  Sets the current view.
:meth:`~wx.lib.docview.DocManager.AddDocument`                                   Adds the document to the list of documents.
:meth:`~wx.lib.docview.DocManager.AddFileToHistory`                              Adds a file to the file history list, if we have a pointer to an
:meth:`~wx.lib.docview.DocManager.AssociateTemplate`                             Adds the template to the document manager's template list.
:meth:`~wx.lib.docview.DocManager.Clear`                                         Closes all currently opened document by callling :meth:`~wx.lib.docview.DocManager.CloseDocuments`
:meth:`~wx.lib.docview.DocManager.CloseDocument`                                 Closes the specified document.
:meth:`~wx.lib.docview.DocManager.CloseDocuments`                                Closes all currently opened documents.
:meth:`~wx.lib.docview.DocManager.CreateDocument`                                Creates a new document in a manner determined by the flags parameter,
:meth:`~wx.lib.docview.DocManager.CreateView`                                    Creates a new view for the given document. If more than one view is
:meth:`~wx.lib.docview.DocManager.DeleteTemplate`                                Placeholder, not yet implemented in wxWindows.
:meth:`~wx.lib.docview.DocManager.Destroy`                                       Destructor.
:meth:`~wx.lib.docview.DocManager.DisassociateTemplate`                          Removes the template from the list of templates.
:meth:`~wx.lib.docview.DocManager.FileHistoryAddFilesToMenu`                     Appends the files in the history list, to all menus managed by the
:meth:`~wx.lib.docview.DocManager.FileHistoryLoad`                               Loads the file history from a config object.
:meth:`~wx.lib.docview.DocManager.FileHistoryRemoveMenu`                         Removes the given menu from the list of menus managed by the file
:meth:`~wx.lib.docview.DocManager.FileHistorySave`                               Saves the file history into a config object. This must be called
:meth:`~wx.lib.docview.DocManager.FileHistoryUseMenu`                            Use this menu for appending recently-visited document filenames, for
:meth:`~wx.lib.docview.DocManager.FindSuitableParent`                            Returns a parent frame or dialog, either the frame with the current
:meth:`~wx.lib.docview.DocManager.FindTemplateForPath`                           Given a path, try to find template that matches the extension. This is
:meth:`~wx.lib.docview.DocManager.FlushDoc`                                      Placeholder, not yet implemented in wxWindows.
:meth:`~wx.lib.docview.DocManager.GetCurrentDocument`                            Returns the document associated with the currently active view (if any).
:meth:`~wx.lib.docview.DocManager.GetCurrentView`                                Returns the currently active view.
:meth:`~wx.lib.docview.DocManager.GetDocuments`                                  Returns the list of documents.
:meth:`~wx.lib.docview.DocManager.GetFileHistory`                                Returns the file history.
:meth:`~wx.lib.docview.DocManager.GetFlags`                                      Returns the document manager's flags.
:meth:`~wx.lib.docview.DocManager.GetHistoryFile`                                Returns the file at index i from the file history.
:meth:`~wx.lib.docview.DocManager.GetHistoryFilesCount`                          Returns the number of files currently stored in the file history.
:meth:`~wx.lib.docview.DocManager.GetLastActiveView`                             Returns the last active view.  This is used in the SDI framework where dialogs can be mistaken for a view
:meth:`~wx.lib.docview.DocManager.GetMaxDocsOpen`                                Returns the number of documents that can be open simultaneously.
:meth:`~wx.lib.docview.DocManager.GetTemplates`                                  Returns the document manager's template list.
:meth:`~wx.lib.docview.DocManager.Initialize`                                    Initializes data; currently just calls :meth:`OnCreateFileHistory`. Some data
:meth:`~wx.lib.docview.DocManager.MakeDefaultName`                               Returns a suitable default name. This is implemented by appending an
:meth:`~wx.lib.docview.DocManager.MakeFrameTitle`                                Returns a suitable title for a document frame. This is implemented by
:meth:`~wx.lib.docview.DocManager.MatchTemplate`                                 Placeholder, not yet implemented in wxWindows.
:meth:`~wx.lib.docview.DocManager.OnCreateFileHistory`                           A hook to allow a derived class to create a different type of file
:meth:`~wx.lib.docview.DocManager.OnFileClose`                                   Closes and deletes the currently active document.
:meth:`~wx.lib.docview.DocManager.OnFileCloseAll`                                Closes and deletes all the currently opened documents.
:meth:`~wx.lib.docview.DocManager.OnFileNew`                                     Creates a new document and reads in the selected file.
:meth:`~wx.lib.docview.DocManager.OnFileOpen`                                    Creates a new document and reads in the selected file.
:meth:`~wx.lib.docview.DocManager.OnFileRevert`                                  Reverts the current document by calling wxDocument.Save for the current
:meth:`~wx.lib.docview.DocManager.OnFileSave`                                    Saves the current document by calling :meth:`Document.Save` for
:meth:`~wx.lib.docview.DocManager.OnFileSaveAs`                                  Calls :meth:`Document.SaveAs` for the current document.
:meth:`~wx.lib.docview.DocManager.OnOpenFileFailure`                             Called when there is an error opening a file.
:meth:`~wx.lib.docview.DocManager.OnPreview`                                     Previews the current document by calling its View's
:meth:`~wx.lib.docview.DocManager.OnPrint`                                       Prints the current document by calling its View's
:meth:`~wx.lib.docview.DocManager.OnPrintSetup`                                  Presents the print setup dialog.
:meth:`~wx.lib.docview.DocManager.OnRedo`                                        Issues a Redo command to the current document's command processor.
:meth:`~wx.lib.docview.DocManager.OnUndo`                                        Issues an Undo command to the current document's command processor.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileClose`                             Updates the user interface for the File Close command.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileCloseAll`                          Updates the user interface for the File Close All command.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileNew`                               Updates the user interface for the File New command.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileOpen`                              Updates the user interface for the File Open command.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileRevert`                            Updates the user interface for the File Revert command.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileSave`                              Updates the user interface for the File Save command.
:meth:`~wx.lib.docview.DocManager.OnUpdateFileSaveAs`                            Updates the user interface for the File Save As command.
:meth:`~wx.lib.docview.DocManager.OnUpdatePreview`                               Updates the user interface for the Print Preview command.
:meth:`~wx.lib.docview.DocManager.OnUpdatePrint`                                 Updates the user interface for the Print command.
:meth:`~wx.lib.docview.DocManager.OnUpdatePrintSetup`                            Updates the user interface for the Print Setup command.
:meth:`~wx.lib.docview.DocManager.OnUpdateRedo`                                  Updates the user interface for the Redo command.
:meth:`~wx.lib.docview.DocManager.OnUpdateUndo`                                  Updates the user interface for the Undo command.
:meth:`~wx.lib.docview.DocManager.ProcessEvent`                                  Processes an event, searching event tables and calling zero or more
:meth:`~wx.lib.docview.DocManager.ProcessUpdateUIEvent`                          Processes a UI event, searching event tables and calling zero or more
:meth:`~wx.lib.docview.DocManager.RemoveDocument`                                Removes the document from the list of documents.
:meth:`~wx.lib.docview.DocManager.RemoveFileFromHistory`                         Removes a file from the file history list, if we have a pointer to an
:meth:`~wx.lib.docview.DocManager.SelectDocumentPath`                            Under Windows, pops up a file selector with a list of filters
:meth:`~wx.lib.docview.DocManager.SelectDocumentType`                            Returns a document template by asking the user (if there is more than
:meth:`~wx.lib.docview.DocManager.SelectViewType`                                Returns a document template by asking the user (if there is
:meth:`~wx.lib.docview.DocManager.SetMaxDocsOpen`                                Sets the maximum number of documents that can be open at a time. By
================================================================================ ================================================================================


|


|api| Class API
===============


.. class:: DocManager(wx.EvtHandler)

   The :class:`DocManager` class is part of the document/view framework,
   and cooperates with the :class:`View`, :class:`Document` and
   :class:`DocTemplate` classes.

   .. method:: __init__(self, flags=DEFAULT_DOCMAN_FLAGS, initialize=True)

      Constructor. Create a document manager instance dynamically near the
      start of your application before doing any document or view operations.
      
      flags is used in the Python version to indicate whether the document
      manager is in DOC_SDI or DOC_MDI mode.
      
      If initialize is true, the Initialize function will be called to
      create a default history list object. If you derive from wxDocManager,
      you may wish to call the base constructor with false, and then call
      Initialize in your own constructor, to allow your own Initialize or
      OnCreateFileHistory functions to be called.


   .. method:: ActivateView(self, view, activate=True, deleting=False)

      Sets the current view.


   .. method:: AddDocument(self, document)

      Adds the document to the list of documents.


   .. method:: AddFileToHistory(self, fileName)

      Adds a file to the file history list, if we have a pointer to an
      appropriate file menu.


   .. method:: AssociateTemplate(self, docTemplate)

      Adds the template to the document manager's template list.


   .. method:: Clear(self, force=True)

      Closes all currently opened document by callling :meth:`CloseDocuments`
      and clears the document manager's templates.


   .. method:: CloseDocument(self, doc, force=True)

      Closes the specified document.


   .. method:: CloseDocuments(self, force=True)

      Closes all currently opened documents.


   .. method:: CreateDocument(self, path, flags=0)

      Creates a new document in a manner determined by the flags parameter,
      which can be:
      
      ``wx.lib.docview.DOC_NEW`` Creates a fresh document.
      ``wx.lib.docview.DOC_SILENT`` Silently loads the given document file.
      
      If ``wx.lib.docview.DOC_NEW`` is present, a new document will be
      created and returned, possibly after asking the user for a template to
      use if there is more than one document template. ``If
      wx.lib.docview.DOC_SILENT`` is present, a new document will be created
      and the given file loaded into it. If neither of these flags is
      present, the user will be presented with a file selector for the file
      to load, and the template to use will be determined by the extension
      (Windows) or by popping up a template choice list (other platforms).
      
      If the maximum number of documents has been reached, this function
      will delete the oldest currently loaded document before creating a new
      one.
      
      wxPython version supports the document manager's
      ``wx.lib.docview.DOC_OPEN_ONCE`` and ``wx.lib.docview.DOC_NO_VIEW``
      flag.
      
      if ``wx.lib.docview.DOC_OPEN_ONCE`` is present, trying to open the
      same file multiple times will just return the same document. if
      ``wx.lib.docview.DOC_NO_VIEW`` is present, opening a file will
      generate the document, but not generate a corresponding view.


   .. method:: CreateView(self, doc, flags=0)

      Creates a new view for the given document. If more than one view is
      allowed for the document (by virtue of multiple templates mentioning
      the same document type), a choice of view is presented to the user.


   .. method:: DeleteTemplate(self, template, flags)

      Placeholder, not yet implemented in wxWindows.


   .. method:: Destroy(self)

      Destructor.


   .. method:: DisassociateTemplate(self, docTemplate)

      Removes the template from the list of templates.


   .. method:: FileHistoryAddFilesToMenu(self, menu=None)

      Appends the files in the history list, to all menus managed by the
      file history object.
      
      If menu is specified, appends the files in the history list to the
      given menu only.


   .. method:: FileHistoryLoad(self, config)

      Loads the file history from a config object.


   .. method:: FileHistoryRemoveMenu(self, menu)

      Removes the given menu from the list of menus managed by the file
      history object.


   .. method:: FileHistorySave(self, config)

      Saves the file history into a config object. This must be called
      explicitly by the application.


   .. method:: FileHistoryUseMenu(self, menu)

      Use this menu for appending recently-visited document filenames, for
      convenient access. Calling this function with a valid menu enables the
      history list functionality.
      
      Note that you can add multiple menus using this function, to be
      managed by the file history object.


   .. method:: FindSuitableParent(self)

      Returns a parent frame or dialog, either the frame with the current
      focus or if there is no current focus the application's top frame.


   .. method:: FindTemplateForPath(self, path)

      Given a path, try to find template that matches the extension. This is
      only an approximate method of finding a template for creating a
      document.
      
      Note this wxPython verson looks for and returns a default template
      if no specific template is found.


   .. method:: FlushDoc(self, doc)

      Placeholder, not yet implemented in wxWindows.


   .. method:: GetCurrentDocument(self)

      Returns the document associated with the currently active view (if any).


   .. method:: GetCurrentView(self)

      Returns the currently active view.


   .. method:: GetDocuments(self)

      Returns the list of documents.


   .. method:: GetFileHistory(self)

      Returns the file history.


   .. method:: GetFlags(self)

      Returns the document manager's flags.


   .. method:: GetHistoryFile(self, i)

      Returns the file at index i from the file history.


   .. method:: GetHistoryFilesCount(self)

      Returns the number of files currently stored in the file history.


   .. method:: GetLastActiveView(self)

      Returns the last active view.  This is used in the SDI framework where dialogs can be mistaken for a view
      and causes the framework to deactivete the current view.  This happens when something like a custom dialog box used
      to operate on the current view is shown.


   .. method:: GetMaxDocsOpen(self)

      Returns the number of documents that can be open simultaneously.


   .. method:: GetTemplates(self)

      Returns the document manager's template list.


   .. method:: Initialize(self)

      Initializes data; currently just calls :meth:`OnCreateFileHistory`. Some data
      cannot always be initialized in the constructor because the programmer
      must be given the opportunity to override functionality. In fact
      ``Initialize`` is called from the :class:`DocManager` constructor, but this can
      be vetoed by passing false to the second argument, allowing the
      derived class's constructor to call ``Initialize``, possibly calling a
      different :meth:`OnCreateFileHistory` from the default.
      
      The bottom line: if you're not deriving from ``Initialize``, forget it and
      construct :class:`DocManager` with no arguments.


   .. method:: MakeDefaultName(self)

      Returns a suitable default name. This is implemented by appending an
      integer counter to the string "Untitled" and incrementing the counter.


   .. method:: MakeFrameTitle(self)

      Returns a suitable title for a document frame. This is implemented by
      appending the document name to the application name.


   .. method:: MatchTemplate(self, path)

      Placeholder, not yet implemented in wxWindows.


   .. method:: OnCreateFileHistory(self)

      A hook to allow a derived class to create a different type of file
      history. Called from :meth:`Initialize`.


   .. method:: OnFileClose(self, event)

      Closes and deletes the currently active document.


   .. method:: OnFileCloseAll(self, event)

      Closes and deletes all the currently opened documents.


   .. method:: OnFileNew(self, event)

      Creates a new document and reads in the selected file.


   .. method:: OnFileOpen(self, event)

      Creates a new document and reads in the selected file.


   .. method:: OnFileRevert(self, event)

      Reverts the current document by calling wxDocument.Save for the current
      document.


   .. method:: OnFileSave(self, event)

      Saves the current document by calling :meth:`Document.Save` for
      the current document.


   .. method:: OnFileSaveAs(self, event)

      Calls :meth:`Document.SaveAs` for the current document.


   .. method:: OnOpenFileFailure(self)

      Called when there is an error opening a file.


   .. method:: OnPreview(self, event)

      Previews the current document by calling its View's
      :meth:`~View.OnCreatePrintout` method.


   .. method:: OnPrint(self, event)

      Prints the current document by calling its View's
      :meth:`~View.OnCreatePrintout` method.


   .. method:: OnPrintSetup(self, event)

      Presents the print setup dialog.


   .. method:: OnRedo(self, event)

      Issues a Redo command to the current document's command processor.


   .. method:: OnUndo(self, event)

      Issues an Undo command to the current document's command processor.


   .. method:: OnUpdateFileClose(self, event)

      Updates the user interface for the File Close command.


   .. method:: OnUpdateFileCloseAll(self, event)

      Updates the user interface for the File Close All command.


   .. method:: OnUpdateFileNew(self, event)

      Updates the user interface for the File New command.


   .. method:: OnUpdateFileOpen(self, event)

      Updates the user interface for the File Open command.


   .. method:: OnUpdateFileRevert(self, event)

      Updates the user interface for the File Revert command.


   .. method:: OnUpdateFileSave(self, event)

      Updates the user interface for the File Save command.


   .. method:: OnUpdateFileSaveAs(self, event)

      Updates the user interface for the File Save As command.


   .. method:: OnUpdatePreview(self, event)

      Updates the user interface for the Print Preview command.


   .. method:: OnUpdatePrint(self, event)

      Updates the user interface for the Print command.


   .. method:: OnUpdatePrintSetup(self, event)

      Updates the user interface for the Print Setup command.


   .. method:: OnUpdateRedo(self, event)

      Updates the user interface for the Redo command.


   .. method:: OnUpdateUndo(self, event)

      Updates the user interface for the Undo command.


   .. 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:: ProcessUpdateUIEvent(self, event)

      Processes a UI event, searching event tables and calling zero or more
      suitable event handler function(s).


   .. method:: RemoveDocument(self, doc)

      Removes the document from the list of documents.


   .. method:: RemoveFileFromHistory(self, i)

      Removes a file from the file history list, if we have a pointer to an
      appropriate file menu.


   .. method:: SelectDocumentPath(self, templates, flags, save)

      Under Windows, pops up a file selector with a list of filters
      corresponding to document templates. The wxDocTemplate corresponding
      to the selected file's extension is returned.
      
      On other platforms, if there is more than one document template a
      choice list is popped up, followed by a file selector.
      
      This function is used in :meth:`DocManager.CreateDocument`.


   .. method:: SelectDocumentType(self, temps, sort=False)

      Returns a document template by asking the user (if there is more than
      one template). This function is used in :methW`DocManager.CreateDocument`.
      
      Parameters
      
      templates - list of templates from which to choose a desired template.
      
      sort - If more than one template is passed in in templates, then this
      parameter indicates whether the list of templates that the user will
      have to choose from is sorted or not when shown the choice box dialog.
      Default is false.


   .. method:: SelectViewType(self, temps, sort=False)

      Returns a document template by asking the user (if there is
      more than one template), displaying a list of valid views.
      This function is used in wxDocManager::CreateView. The dialog
      normally will not appear because the array of templates only
      contains those relevant to the document in question, and
      often there will only be one such.


   .. method:: SetMaxDocsOpen(self, maxDocsOpen)

      Sets the maximum number of documents that can be open at a time. By
      default, this is 10,000. If you set it to 1, existing documents will
      be saved and deleted when the user tries to open or create a new one
      (similar to the behaviour of Windows Write, for example). Allowing
      multiple documents gives behaviour more akin to MS Word and other
      Multiple Document Interface applications.


