2005-04-08 15:04:58 -04:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Name: PyDocViewDemo.py
|
|
|
|
# Purpose: Demo of Python extensions to the wxWindows docview framework
|
|
|
|
#
|
|
|
|
# Author: Peter Yared, Morgan Hua
|
|
|
|
#
|
|
|
|
# Created: 5/15/03
|
|
|
|
# CVS-ID: $Id$
|
|
|
|
# Copyright: (c) 2003-2005 ActiveGrid, Inc.
|
2005-04-27 20:00:50 -04:00
|
|
|
# License: wxWindows License
|
2005-04-08 15:04:58 -04:00
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import wx
|
|
|
|
import wx.lib.docview as docview
|
|
|
|
import wx.lib.pydocview as pydocview
|
|
|
|
import TextEditor
|
|
|
|
import FindService
|
2005-04-27 20:00:50 -04:00
|
|
|
import os.path
|
2005-04-08 15:04:58 -04:00
|
|
|
_ = wx.GetTranslation
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Classes
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TextEditorApplication(pydocview.DocApp):
|
|
|
|
|
2005-05-31 20:18:42 -04:00
|
|
|
SPLASH = "splash.png"
|
|
|
|
|
2005-04-08 15:04:58 -04:00
|
|
|
def OnInit(self):
|
|
|
|
# Call the super - this is important!!!
|
|
|
|
pydocview.DocApp.OnInit(self)
|
|
|
|
|
|
|
|
# Show the splash dialog while everything is loading up
|
2005-05-31 20:18:42 -04:00
|
|
|
if os.path.exists(TextEditorApplication.SPLASH):
|
|
|
|
self.ShowSplash(TextEditorApplication.SPLASH)
|
2005-04-08 15:04:58 -04:00
|
|
|
|
|
|
|
# Set the name and the icon
|
|
|
|
self.SetAppName(_("wxPython PyDocView Demo"))
|
|
|
|
self.SetDefaultIcon(pydocview.getBlankIcon())
|
|
|
|
|
|
|
|
# Initialize the document manager
|
|
|
|
docManager = docview.DocManager(flags = self.GetDefaultDocManagerFlags())
|
|
|
|
self.SetDocumentManager(docManager)
|
|
|
|
|
|
|
|
# Create a template for text documents and associate it with the docmanager
|
|
|
|
textTemplate = docview.DocTemplate(docManager,
|
|
|
|
_("Text"),
|
|
|
|
"*.text;*.txt",
|
|
|
|
_("Text"),
|
|
|
|
_(".txt"),
|
|
|
|
_("Text Document"),
|
|
|
|
_("Text View"),
|
|
|
|
TextEditor.TextDocument,
|
|
|
|
TextEditor.TextView,
|
|
|
|
icon=pydocview.getBlankIcon())
|
|
|
|
docManager.AssociateTemplate(textTemplate)
|
|
|
|
|
|
|
|
# Install services - these can install menu and toolbar items
|
|
|
|
textService = self.InstallService(TextEditor.TextService())
|
|
|
|
findService = self.InstallService(FindService.FindService())
|
2005-05-18 20:21:49 -04:00
|
|
|
optionsService = self.InstallService(pydocview.DocOptionsService(supportedModes=wx.lib.docview.DOC_MDI))
|
2005-04-08 15:04:58 -04:00
|
|
|
windowMenuService = self.InstallService(pydocview.WindowMenuService())
|
|
|
|
filePropertiesService = self.InstallService(pydocview.FilePropertiesService())
|
2005-05-31 20:18:42 -04:00
|
|
|
if os.path.exists(TextEditorApplication.SPLASH):
|
|
|
|
aboutService = self.InstallService(pydocview.AboutService(image=wx.Image(TextEditorApplication.SPLASH)))
|
2005-04-27 20:00:50 -04:00
|
|
|
else:
|
|
|
|
aboutService = self.InstallService(pydocview.AboutService())
|
|
|
|
|
2005-04-08 15:04:58 -04:00
|
|
|
# Install the TextEditor's option panel into the OptionsService
|
|
|
|
optionsService.AddOptionsPanel(TextEditor.TextOptionsPanel)
|
|
|
|
|
|
|
|
# If it is an MDI app open the main frame
|
|
|
|
self.OpenMainFrame()
|
|
|
|
|
|
|
|
# Open any files that were passed via the command line
|
|
|
|
self.OpenCommandLineArgs()
|
|
|
|
|
|
|
|
# If nothing was opened and it is an SDI app, open up an empty text document
|
|
|
|
if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
|
|
|
|
textTemplate.CreateDocument('', docview.DOC_NEW).OnNewDocument()
|
|
|
|
|
|
|
|
# Close the splash dialog
|
2005-05-31 20:18:42 -04:00
|
|
|
if os.path.exists(TextEditorApplication.SPLASH):
|
2005-04-27 20:00:50 -04:00
|
|
|
self.CloseSplash()
|
2005-04-08 15:04:58 -04:00
|
|
|
|
|
|
|
# Show the tips dialog
|
2005-04-27 20:00:50 -04:00
|
|
|
if os.path.exists("tips.txt"):
|
|
|
|
wx.CallAfter(self.ShowTip, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("tips.txt", 0))
|
2005-04-08 15:04:58 -04:00
|
|
|
|
2005-06-11 19:18:57 -04:00
|
|
|
wx.UpdateUIEvent.SetUpdateInterval(400) # Overhead of updating menus was too much. Change to update every 400 milliseconds.
|
|
|
|
|
2005-04-08 15:04:58 -04:00
|
|
|
# Tell the framework that everything is great
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
# Main
|
|
|
|
#----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
# Run the TextEditorApplication and do not redirect output to the wxPython error dialog
|
|
|
|
app = TextEditorApplication(redirect=False)
|
|
|
|
app.MainLoop()
|