]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/pydocview/PyDocViewDemo.py
'[1219035] cleanup: miscellaneous' and minor source cleaning.
[wxWidgets.git] / wxPython / samples / pydocview / PyDocViewDemo.py
CommitLineData
3fa8f722
RD
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.
bbf7159c 10# License: wxWindows License
3fa8f722
RD
11#----------------------------------------------------------------------------
12
13
14import sys
15import wx
16import wx.lib.docview as docview
17import wx.lib.pydocview as pydocview
18import TextEditor
19import FindService
bbf7159c 20import os.path
3fa8f722
RD
21_ = wx.GetTranslation
22
23
24#----------------------------------------------------------------------------
25# Classes
26#----------------------------------------------------------------------------
27
28class TextEditorApplication(pydocview.DocApp):
29
e4f504f0
RD
30 SPLASH = "splash.png"
31
3fa8f722
RD
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
e4f504f0
RD
37 if os.path.exists(TextEditorApplication.SPLASH):
38 self.ShowSplash(TextEditorApplication.SPLASH)
3fa8f722
RD
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())
6f1a3f9c 64 optionsService = self.InstallService(pydocview.DocOptionsService(supportedModes=wx.lib.docview.DOC_MDI))
3fa8f722
RD
65 windowMenuService = self.InstallService(pydocview.WindowMenuService())
66 filePropertiesService = self.InstallService(pydocview.FilePropertiesService())
e4f504f0
RD
67 if os.path.exists(TextEditorApplication.SPLASH):
68 aboutService = self.InstallService(pydocview.AboutService(image=wx.Image(TextEditorApplication.SPLASH)))
bbf7159c
RD
69 else:
70 aboutService = self.InstallService(pydocview.AboutService())
71
3fa8f722
RD
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
e4f504f0 86 if os.path.exists(TextEditorApplication.SPLASH):
bbf7159c 87 self.CloseSplash()
3fa8f722
RD
88
89 # Show the tips dialog
bbf7159c
RD
90 if os.path.exists("tips.txt"):
91 wx.CallAfter(self.ShowTip, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("tips.txt", 0))
3fa8f722 92
2eeaec19
RD
93 wx.UpdateUIEvent.SetUpdateInterval(400) # Overhead of updating menus was too much. Change to update every 400 milliseconds.
94
3fa8f722
RD
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
104app = TextEditorApplication(redirect=False)
105app.MainLoop()