]> git.saurik.com Git - wxWidgets.git/blame - wxPython/samples/pydocview/PyDocViewDemo.py
HandlePrintClient shouldn't go above a top-level window
[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
30
31 def OnInit(self):
32 # Call the super - this is important!!!
33 pydocview.DocApp.OnInit(self)
34
35 # Show the splash dialog while everything is loading up
bbf7159c
RD
36 if os.path.exists("splash.jpg"):
37 self.ShowSplash("splash.jpg")
3fa8f722
RD
38
39 # Set the name and the icon
40 self.SetAppName(_("wxPython PyDocView Demo"))
41 self.SetDefaultIcon(pydocview.getBlankIcon())
42
43 # Initialize the document manager
44 docManager = docview.DocManager(flags = self.GetDefaultDocManagerFlags())
45 self.SetDocumentManager(docManager)
46
47 # Create a template for text documents and associate it with the docmanager
48 textTemplate = docview.DocTemplate(docManager,
49 _("Text"),
50 "*.text;*.txt",
51 _("Text"),
52 _(".txt"),
53 _("Text Document"),
54 _("Text View"),
55 TextEditor.TextDocument,
56 TextEditor.TextView,
57 icon=pydocview.getBlankIcon())
58 docManager.AssociateTemplate(textTemplate)
59
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())
bbf7159c
RD
66 if os.path.exists("splash.jpg"):
67 aboutService = self.InstallService(pydocview.AboutService(image=wx.Image("splash.jpg")))
68 else:
69 aboutService = self.InstallService(pydocview.AboutService())
70
3fa8f722
RD
71 # Install the TextEditor's option panel into the OptionsService
72 optionsService.AddOptionsPanel(TextEditor.TextOptionsPanel)
73
74 # If it is an MDI app open the main frame
75 self.OpenMainFrame()
76
77 # Open any files that were passed via the command line
78 self.OpenCommandLineArgs()
79
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()
83
84 # Close the splash dialog
bbf7159c
RD
85 if os.path.exists("splash.jpg"):
86 self.CloseSplash()
3fa8f722
RD
87
88 # Show the tips dialog
bbf7159c
RD
89 if os.path.exists("tips.txt"):
90 wx.CallAfter(self.ShowTip, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("tips.txt", 0))
3fa8f722
RD
91
92 # Tell the framework that everything is great
93 return True
94
95
96#----------------------------------------------------------------------------
97# Main
98#----------------------------------------------------------------------------
99
100# Run the TextEditorApplication and do not redirect output to the wxPython error dialog
101app = TextEditorApplication(redirect=False)
102app.MainLoop()