]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/pydocview/PyDocViewDemo.py
typo
[wxWidgets.git] / wxPython / samples / pydocview / PyDocViewDemo.py
1 #----------------------------------------------------------------------------
2 # Name: PyDocViewDemo.py
3 # Purpose: Demo of Python extensions to the wxWindows docview framework
4 #
5 # Author: Peter Yared, Morgan Hua
6 #
7 # Created: 5/15/03
8 # CVS-ID: $Id$
9 # Copyright: (c) 2003-2005 ActiveGrid, Inc.
10 # License: ASL 2.0 http://apache.org/licenses/LICENSE-2.0
11 #----------------------------------------------------------------------------
12
13
14 import sys
15 import wx
16 import wx.lib.docview as docview
17 import wx.lib.pydocview as pydocview
18 import TextEditor
19 import FindService
20 _ = wx.GetTranslation
21
22
23 #----------------------------------------------------------------------------
24 # Classes
25 #----------------------------------------------------------------------------
26
27 class TextEditorApplication(pydocview.DocApp):
28
29
30 def OnInit(self):
31 # Call the super - this is important!!!
32 pydocview.DocApp.OnInit(self)
33
34 # Show the splash dialog while everything is loading up
35 self.ShowSplash("splash.jpg")
36
37 # Set the name and the icon
38 self.SetAppName(_("wxPython PyDocView Demo"))
39 self.SetDefaultIcon(pydocview.getBlankIcon())
40
41 # Initialize the document manager
42 docManager = docview.DocManager(flags = self.GetDefaultDocManagerFlags())
43 self.SetDocumentManager(docManager)
44
45 # Create a template for text documents and associate it with the docmanager
46 textTemplate = docview.DocTemplate(docManager,
47 _("Text"),
48 "*.text;*.txt",
49 _("Text"),
50 _(".txt"),
51 _("Text Document"),
52 _("Text View"),
53 TextEditor.TextDocument,
54 TextEditor.TextView,
55 icon=pydocview.getBlankIcon())
56 docManager.AssociateTemplate(textTemplate)
57
58 # Install services - these can install menu and toolbar items
59 textService = self.InstallService(TextEditor.TextService())
60 findService = self.InstallService(FindService.FindService())
61 optionsService = self.InstallService(pydocview.DocOptionsService())
62 windowMenuService = self.InstallService(pydocview.WindowMenuService())
63 filePropertiesService = self.InstallService(pydocview.FilePropertiesService())
64 aboutService = self.InstallService(pydocview.AboutService(image=wx.Image("splash.jpg")))
65
66 # Install the TextEditor's option panel into the OptionsService
67 optionsService.AddOptionsPanel(TextEditor.TextOptionsPanel)
68
69 # If it is an MDI app open the main frame
70 self.OpenMainFrame()
71
72 # Open any files that were passed via the command line
73 self.OpenCommandLineArgs()
74
75 # If nothing was opened and it is an SDI app, open up an empty text document
76 if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
77 textTemplate.CreateDocument('', docview.DOC_NEW).OnNewDocument()
78
79 # Close the splash dialog
80 self.CloseSplash()
81
82 # Show the tips dialog
83 wx.CallAfter(self.ShowTip, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("tips.txt", 0))
84
85 # Tell the framework that everything is great
86 return True
87
88
89 #----------------------------------------------------------------------------
90 # Main
91 #----------------------------------------------------------------------------
92
93 # Run the TextEditorApplication and do not redirect output to the wxPython error dialog
94 app = TextEditorApplication(redirect=False)
95 app.MainLoop()