]>
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
):
32 # Call the super - this is important!!!
33 pydocview
.DocApp
.OnInit(self
)
35 # Show the splash dialog while everything is loading up
36 if os
.path
.exists("splash.jpg"):
37 self
.ShowSplash("splash.jpg")
39 # Set the name and the icon
40 self
.SetAppName(_("wxPython PyDocView Demo"))
41 self
.SetDefaultIcon(pydocview
.getBlankIcon())
43 # Initialize the document manager
44 docManager
= docview
.DocManager(flags
= self
.GetDefaultDocManagerFlags())
45 self
.SetDocumentManager(docManager
)
47 # Create a template for text documents and associate it with the docmanager
48 textTemplate
= docview
.DocTemplate(docManager
,
55 TextEditor
.TextDocument
,
57 icon
=pydocview
.getBlankIcon())
58 docManager
.AssociateTemplate(textTemplate
)
60 # Install services - these can install menu and toolbar items
61 textService
= self
.InstallService(TextEditor
.TextService())
62 findService
= self
.InstallService(FindService
.FindService())
63 optionsService
= self
.InstallService(pydocview
.DocOptionsService())
64 windowMenuService
= self
.InstallService(pydocview
.WindowMenuService())
65 filePropertiesService
= self
.InstallService(pydocview
.FilePropertiesService())
66 if os
.path
.exists("splash.jpg"):
67 aboutService
= self
.InstallService(pydocview
.AboutService(image
=wx
.Image("splash.jpg")))
69 aboutService
= self
.InstallService(pydocview
.AboutService())
71 # Install the TextEditor's option panel into the OptionsService
72 optionsService
.AddOptionsPanel(TextEditor
.TextOptionsPanel
)
74 # If it is an MDI app open the main frame
77 # Open any files that were passed via the command line
78 self
.OpenCommandLineArgs()
80 # If nothing was opened and it is an SDI app, open up an empty text document
81 if not docManager
.GetDocuments() and docManager
.GetFlags() & wx
.lib
.docview
.DOC_SDI
:
82 textTemplate
.CreateDocument('', docview
.DOC_NEW
).OnNewDocument()
84 # Close the splash dialog
85 if os
.path
.exists("splash.jpg"):
88 # Show the tips dialog
89 if os
.path
.exists("tips.txt"):
90 wx
.CallAfter(self
.ShowTip
, wx
.GetApp().GetTopWindow(), wx
.CreateFileTipProvider("tips.txt", 0))
92 # Tell the framework that everything is great
96 #----------------------------------------------------------------------------
98 #----------------------------------------------------------------------------
100 # Run the TextEditorApplication and do not redirect output to the wxPython error dialog
101 app
= TextEditorApplication(redirect
=False)