phoenix_title wx.lib.docview.DocManager

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


class_hierarchy Class Hierarchy

Inheritance diagram for class DocManager:

super_classes Known Superclasses

wx.EvtHandler


method_summary Methods Summary

__init__

Constructor. Create a document manager instance dynamically near the

ActivateView

Sets the current view.

AddDocument

Adds the document to the list of documents.

AddFileToHistory

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

AssociateTemplate

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

Clear

Closes all currently opened document by callling CloseDocuments

CloseDocument

Closes the specified document.

CloseDocuments

Closes all currently opened documents.

CreateDocument

Creates a new document in a manner determined by the flags parameter,

CreateView

Creates a new view for the given document. If more than one view is

DeleteTemplate

Placeholder, not yet implemented in wxWindows.

Destroy

Destructor.

DisassociateTemplate

Removes the template from the list of templates.

FileHistoryAddFilesToMenu

Appends the files in the history list, to all menus managed by the

FileHistoryLoad

Loads the file history from a config object.

FileHistoryRemoveMenu

Removes the given menu from the list of menus managed by the file

FileHistorySave

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

FileHistoryUseMenu

Use this menu for appending recently-visited document filenames, for

FindSuitableParent

Returns a parent frame or dialog, either the frame with the current

FindTemplateForPath

Given a path, try to find template that matches the extension. This is

FlushDoc

Placeholder, not yet implemented in wxWindows.

GetCurrentDocument

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

GetCurrentView

Returns the currently active view.

GetDocuments

Returns the list of documents.

GetFileHistory

Returns the file history.

GetFlags

Returns the document manager’s flags.

GetHistoryFile

Returns the file at index i from the file history.

GetHistoryFilesCount

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

GetLastActiveView

Returns the last active view. This is used in the SDI framework where dialogs can be mistaken for a view

GetMaxDocsOpen

Returns the number of documents that can be open simultaneously.

GetTemplates

Returns the document manager’s template list.

Initialize

Initializes data; currently just calls OnCreateFileHistory. Some data

MakeDefaultName

Returns a suitable default name. This is implemented by appending an

MakeFrameTitle

Returns a suitable title for a document frame. This is implemented by

MatchTemplate

Placeholder, not yet implemented in wxWindows.

OnCreateFileHistory

A hook to allow a derived class to create a different type of file

OnFileClose

Closes and deletes the currently active document.

OnFileCloseAll

Closes and deletes all the currently opened documents.

OnFileNew

Creates a new document and reads in the selected file.

OnFileOpen

Creates a new document and reads in the selected file.

OnFileRevert

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

OnFileSave

Saves the current document by calling Document.Save for

OnFileSaveAs

Calls Document.SaveAs for the current document.

OnOpenFileFailure

Called when there is an error opening a file.

OnPreview

Previews the current document by calling its View’s

OnPrint

Prints the current document by calling its View’s

OnPrintSetup

Presents the print setup dialog.

OnRedo

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

OnUndo

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

OnUpdateFileClose

Updates the user interface for the File Close command.

OnUpdateFileCloseAll

Updates the user interface for the File Close All command.

OnUpdateFileNew

Updates the user interface for the File New command.

OnUpdateFileOpen

Updates the user interface for the File Open command.

OnUpdateFileRevert

Updates the user interface for the File Revert command.

OnUpdateFileSave

Updates the user interface for the File Save command.

OnUpdateFileSaveAs

Updates the user interface for the File Save As command.

OnUpdatePreview

Updates the user interface for the Print Preview command.

OnUpdatePrint

Updates the user interface for the Print command.

OnUpdatePrintSetup

Updates the user interface for the Print Setup command.

OnUpdateRedo

Updates the user interface for the Redo command.

OnUpdateUndo

Updates the user interface for the Undo command.

ProcessEvent

Processes an event, searching event tables and calling zero or more

ProcessUpdateUIEvent

Processes a UI event, searching event tables and calling zero or more

RemoveDocument

Removes the document from the list of documents.

RemoveFileFromHistory

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

SelectDocumentPath

Under Windows, pops up a file selector with a list of filters

SelectDocumentType

Returns a document template by asking the user (if there is more than

SelectViewType

Returns a document template by asking the user (if there is

SetMaxDocsOpen

Sets the maximum number of documents that can be open at a time. By


api Class API

class DocManager(wx.EvtHandler)

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


Methods

__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.



ActivateView(self, view, activate=True, deleting=False)

Sets the current view.



AddDocument(self, document)

Adds the document to the list of documents.



AddFileToHistory(self, fileName)

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



AssociateTemplate(self, docTemplate)

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



Clear(self, force=True)

Closes all currently opened document by callling CloseDocuments and clears the document manager’s templates.



CloseDocument(self, doc, force=True)

Closes the specified document.



CloseDocuments(self, force=True)

Closes all currently opened documents.



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.



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.



DeleteTemplate(self, template, flags)

Placeholder, not yet implemented in wxWindows.



Destroy(self)

Destructor.



DisassociateTemplate(self, docTemplate)

Removes the template from the list of templates.



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.



FileHistoryLoad(self, config)

Loads the file history from a config object.



FileHistoryRemoveMenu(self, menu)

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



FileHistorySave(self, config)

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



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.



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.



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 version looks for and returns a default template if no specific template is found.



FlushDoc(self, doc)

Placeholder, not yet implemented in wxWindows.



GetCurrentDocument(self)

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



GetCurrentView(self)

Returns the currently active view.



GetDocuments(self)

Returns the list of documents.



GetFileHistory(self)

Returns the file history.



GetFlags(self)

Returns the document manager’s flags.



GetHistoryFile(self, i)

Returns the file at index i from the file history.



GetHistoryFilesCount(self)

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



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.



GetMaxDocsOpen(self)

Returns the number of documents that can be open simultaneously.



GetTemplates(self)

Returns the document manager’s template list.



Initialize(self)

Initializes data; currently just calls 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 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 OnCreateFileHistory from the default.

The bottom line: if you’re not deriving from Initialize, forget it and construct DocManager with no arguments.



MakeDefaultName(self)

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



MakeFrameTitle(self)

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



MatchTemplate(self, path)

Placeholder, not yet implemented in wxWindows.



OnCreateFileHistory(self)

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



OnFileClose(self, event)

Closes and deletes the currently active document.



OnFileCloseAll(self, event)

Closes and deletes all the currently opened documents.



OnFileNew(self, event)

Creates a new document and reads in the selected file.



OnFileOpen(self, event)

Creates a new document and reads in the selected file.



OnFileRevert(self, event)

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



OnFileSave(self, event)

Saves the current document by calling Document.Save for the current document.



OnFileSaveAs(self, event)

Calls Document.SaveAs for the current document.



OnOpenFileFailure(self)

Called when there is an error opening a file.



OnPreview(self, event)

Previews the current document by calling its View’s OnCreatePrintout method.



OnPrint(self, event)

Prints the current document by calling its View’s OnCreatePrintout method.



OnPrintSetup(self, event)

Presents the print setup dialog.



OnRedo(self, event)

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



OnUndo(self, event)

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



OnUpdateFileClose(self, event)

Updates the user interface for the File Close command.



OnUpdateFileCloseAll(self, event)

Updates the user interface for the File Close All command.



OnUpdateFileNew(self, event)

Updates the user interface for the File New command.



OnUpdateFileOpen(self, event)

Updates the user interface for the File Open command.



OnUpdateFileRevert(self, event)

Updates the user interface for the File Revert command.



OnUpdateFileSave(self, event)

Updates the user interface for the File Save command.



OnUpdateFileSaveAs(self, event)

Updates the user interface for the File Save As command.



OnUpdatePreview(self, event)

Updates the user interface for the Print Preview command.



OnUpdatePrint(self, event)

Updates the user interface for the Print command.



OnUpdatePrintSetup(self, event)

Updates the user interface for the Print Setup command.



OnUpdateRedo(self, event)

Updates the user interface for the Redo command.



OnUpdateUndo(self, event)

Updates the user interface for the Undo command.



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.



ProcessUpdateUIEvent(self, event)

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



RemoveDocument(self, doc)

Removes the document from the list of documents.



RemoveFileFromHistory(self, i)

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



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 DocManager.CreateDocument.



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.



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.



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.