wxWidgets/wxPython/samples/docview/PyDocViewDemo.py

169 lines
8.1 KiB
Python
Raw Normal View History

#----------------------------------------------------------------------------
# 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 ActiveGrid, Inc.
# License: wxWindows license
#----------------------------------------------------------------------------
import sys
import wx
import wx.lib.docview
import wx.lib.pydocview
import activegrid.tool.TextEditor as TextEditor
import activegrid.tool.FindService as FindService
import wx.lib.pydocview as WindowMenuService
#----------------------------------------------------------------------------
# Classes
#----------------------------------------------------------------------------
class TextEditorApplication(wx.lib.pydocview.DocApp):
def OnInit(self):
wx.lib.pydocview.DocApp.OnInit(self)
wx.lib.pydocview.DocApp.ShowSplash(self, "activegrid/tool/images/splash.jpg")
self.SetAppName(wx.GetTranslation("wxPython DocView Demo"))
config = wx.Config(self.GetAppName(), style = wx.CONFIG_USE_LOCAL_FILE)
docManager = wx.lib.docview.DocManager(flags = self.GetDefaultDocManagerFlags())
self.SetDocumentManager(docManager)
textTemplate = wx.lib.docview.DocTemplate(docManager,
wx.GetTranslation("Text"),
"*.text;*.txt",
wx.GetTranslation("Text"),
wx.GetTranslation(".txt"),
wx.GetTranslation("Text Document"),
wx.GetTranslation("Text View"),
TextEditor.TextDocument,
TextEditor.TextView)
docManager.AssociateTemplate(textTemplate)
textService = self.InstallService(TextEditor.TextService())
findService = self.InstallService(FindService.FindService())
optionsService = self.InstallService(wx.lib.pydocview.DocOptionsService())
windowMenuService = self.InstallService(WindowMenuService.WindowMenuService())
optionsService.AddOptionsPanel(TextEditor.TextOptionsPanel)
filePropertiesService = self.InstallService(wx.lib.pydocview.FilePropertiesService())
self.SetDefaultIcon(getDocIcon())
if docManager.GetFlags() & wx.lib.docview.DOC_MDI:
frame = wx.lib.pydocview.DocMDIParentFrame(docManager, None, -1, wx.GetApp().GetAppName())
frame.Show(True)
wx.lib.pydocview.DocApp.CloseSplash(self)
self.OpenCommandLineArgs()
if not docManager.GetDocuments() and docManager.GetFlags() & wx.lib.docview.DOC_SDI:
textTemplate.CreateDocument('', wx.lib.docview.DOC_NEW).OnNewDocument()
wx.CallAfter(self.ShowTip, docManager.FindSuitableParent(), wx.CreateFileTipProvider("activegrid/tool/data/tips.txt", 0))
return True
#----------------------------------------------------------------------------
# Menu Bitmaps - generated by encode_bitmaps.py
#----------------------------------------------------------------------------
from wx import ImageFromStream, BitmapFromImage
from wx import EmptyIcon
import cStringIO
def getDocData():
return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00 \x00\x00\x00 \x08\x06\x00\
\x00\x00szz\xf4\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\x00\x05cID\
ATX\x85\xed\x97\xcbo\x1b\xd7\x15\xc6\x7fw^\x1c\x92C\x8a\xa4DQ\xa2)\xd9\xb2%?\
\xe0\xa7\x82\xc0\x85\x83"\xa8\x1b\x17AwYtQtU\xb4\x8b\xa2\x7fH\xfe\x8c\xee\
\x8b\xac\x124\xab\x02E\n\x17h\x01\x17\x86Q7\xaac7~I\xb2hZ\xe2sH\xce\x83s\xef\
\xedB\xa6dI~))\x90E\xf2\x01\x17\x98\xb9s\xe7\x9c\xef\x9c\xf9\xce\xb9w\x840L\
\xbeK\x18\xdf\xa9\xf7\x1f\x08\x00\xa2\xd5ji!\x04\xe3\xf1ma\x9a\x02!\x0c\xe0\
\xa0-\xa55O\xb6\x06t\xfb\x11\xa0\x98\xca\x99\x880\x0c5\xf0R\xe7B\x08\xb4\xde\
\xbd6\xc4\xd8\xee\x0bk\xb5\xde3\'\x84f\x10J\x06aB4R\xd8\x96\xc1\x97\x8f{\xfc\
\xfbq\x97-?\xa2\xe49\x9c\x9d\xf38u\xc4\xa3\x945\xb0\xc6\x8e\r!`\x1f\t!\xd8C\
\x004\x89\xd4\x04\xb1$\x88%#\xa9(f,\xd6\xdb!\xab\x9b\x01\x9b\xbd\x98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\xbb\x02\xfa\x06\x10\x80m\x1b\x18\xa6\xc9\xda3\x1f\xd71\xc9\xb9\
\xf6k\xdf\x91R\x12E\x11\xe2\x87\x7f\xc3\xef=\x81\xff\x01\x1d\xae\x83\xc3q\
\xb9\xc6\x9f\x00\x00\x00\x00IEND\xaeB`\x82'
def getDocBitmap():
return BitmapFromImage(getDocImage())
def getDocImage():
stream = cStringIO.StringIO(getDocData())
return ImageFromStream(stream)
def getDocIcon():
icon = EmptyIcon()
icon.CopyFromBitmap(getDocBitmap())
return icon
#----------------------------------------------------------------------------
# Main
#----------------------------------------------------------------------------
sys.stdout = sys.stderr
app = TextEditorApplication(redirect = False)
app.MainLoop()