]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/pydocview/PyDocViewDemo.py
1 #----------------------------------------------------------------------------
2 # Name: PyDocViewDemo.py
3 # Purpose: Demo of Python extensions to the wxWindows docview framework
5 # Author: Peter Yared, Morgan Hua
9 # Copyright: (c) 2003-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
16 import wx
.lib
.docview
as docview
17 import wx
.lib
.pydocview
as pydocview
24 #----------------------------------------------------------------------------
26 #----------------------------------------------------------------------------
28 class TextEditorApplication(pydocview
.DocApp
):
33 # Call the super - this is important!!!
34 pydocview
.DocApp
.OnInit(self
)
36 # Show the splash dialog while everything is loading up
37 if os
.path
.exists(TextEditorApplication
.SPLASH
):
38 self
.ShowSplash(TextEditorApplication
.SPLASH
)
40 # Set the name and the icon
41 self
.SetAppName(_("wxPython PyDocView Demo"))
42 self
.SetDefaultIcon(pydocview
.getBlankIcon())
44 # Initialize the document manager
45 docManager
= docview
.DocManager(flags
= self
.GetDefaultDocManagerFlags())
46 self
.SetDocumentManager(docManager
)
48 # Create a template for text documents and associate it with the docmanager
49 textTemplate
= docview
.DocTemplate(docManager
,
56 TextEditor
.TextDocument
,
58 icon
=pydocview
.getBlankIcon())
59 docManager
.AssociateTemplate(textTemplate
)
61 # Install services - these can install menu and toolbar items
62 textService
= self
.InstallService(TextEditor
.TextService())
63 findService
= self
.InstallService(FindService
.FindService())
64 optionsService
= self
.InstallService(pydocview
.DocOptionsService(supportedModes
=wx
.lib
.docview
.DOC_MDI
))
65 windowMenuService
= self
.InstallService(pydocview
.WindowMenuService())
66 filePropertiesService
= self
.InstallService(pydocview
.FilePropertiesService())
67 if os
.path
.exists(TextEditorApplication
.SPLASH
):
68 aboutService
= self
.InstallService(pydocview
.AboutService(image
=wx
.Image(TextEditorApplication
.SPLASH
)))
70 aboutService
= self
.InstallService(pydocview
.AboutService())
72 # Install the TextEditor's option panel into the OptionsService
73 optionsService
.AddOptionsPanel(TextEditor
.TextOptionsPanel
)
75 # If it is an MDI app open the main frame
78 # Open any files that were passed via the command line
79 self
.OpenCommandLineArgs()
81 # If nothing was opened and it is an SDI app, open up an empty text document
82 if not docManager
.GetDocuments() and docManager
.GetFlags() & wx
.lib
.docview
.DOC_SDI
:
83 textTemplate
.CreateDocument('', docview
.DOC_NEW
).OnNewDocument()
85 # Close the splash dialog
86 if os
.path
.exists(TextEditorApplication
.SPLASH
):
89 # Show the tips dialog
90 if os
.path
.exists("tips.txt"):
91 wx
.CallAfter(self
.ShowTip
, wx
.GetApp().GetTopWindow(), wx
.CreateFileTipProvider("tips.txt", 0))
93 wx
.UpdateUIEvent
.SetUpdateInterval(400) # Overhead of updating menus was too much. Change to update every 400 milliseconds.
95 # Tell the framework that everything is great
99 #----------------------------------------------------------------------------
101 #----------------------------------------------------------------------------
103 # Run the TextEditorApplication and do not redirect output to the wxPython error dialog
104 app
= TextEditorApplication(redirect
=False)