]> git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/pydocview/PyDocViewDemo.py
change doc tweaks
[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: wxWindows License
11 #----------------------------------------------------------------------------
12
13
14 import sys
15 import os.path
16 import wx
17 import wx.lib.docview as docview
18 import wx.lib.pydocview as pydocview
19 import TextEditor
20 import FindService
21 _ = wx.GetTranslation
22
23
24 #----------------------------------------------------------------------------
25 # Classes
26 #----------------------------------------------------------------------------
27
28 class TextEditorApplication(pydocview.DocApp):
29
30 SPLASH = "splash.png"
31
32 def OnInit(self):
33 # Call the super - this is important!!!
34 pydocview.DocApp.OnInit(self)
35
36 # Show the splash dialog while everything is loading up
37 if os.path.exists(TextEditorApplication.SPLASH):
38 self.ShowSplash(TextEditorApplication.SPLASH)
39
40 # Set the name and the icon
41 self.SetAppName(_("wxPython PyDocView Demo"))
42 self.SetDefaultIcon(pydocview.getBlankIcon())
43
44 # Initialize the document manager
45 docManager = docview.DocManager(flags = self.GetDefaultDocManagerFlags())
46 self.SetDocumentManager(docManager)
47
48 # Create a template for text documents and associate it with the docmanager
49 textTemplate = docview.DocTemplate(docManager,
50 _("Text"),
51 "*.text;*.txt",
52 _("Text"),
53 _(".txt"),
54 _("Text Document"),
55 _("Text View"),
56 TextEditor.TextDocument,
57 TextEditor.TextView,
58 icon=pydocview.getBlankIcon())
59 docManager.AssociateTemplate(textTemplate)
60
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)))
69 else:
70 aboutService = self.InstallService(pydocview.AboutService())
71
72 # Install the TextEditor's option panel into the OptionsService
73 optionsService.AddOptionsPanel(TextEditor.TextOptionsPanel)
74
75 # If it is an MDI app open the main frame
76 self.OpenMainFrame()
77
78 # Open any files that were passed via the command line
79 self.OpenCommandLineArgs()
80
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()
84
85 # Close the splash dialog
86 if os.path.exists(TextEditorApplication.SPLASH):
87 self.CloseSplash()
88
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))
92
93 wx.UpdateUIEvent.SetUpdateInterval(1000) # Overhead of updating menus was too much. Change to update every N milliseconds.
94
95 # Tell the framework that everything is great
96 return True
97
98
99 #----------------------------------------------------------------------------
100 # Main
101 #----------------------------------------------------------------------------
102
103 # Run the TextEditorApplication and do not redirect output to the wxPython error dialog
104 app = TextEditorApplication(redirect=False)
105 app.MainLoop()