Updated docview library modules and sample apps from the ActiveGrid

folks.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33434 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn 2005-04-08 19:04:58 +00:00
parent 29ea653e5c
commit 3fa8f7227b
13 changed files with 1449 additions and 875 deletions

View File

@ -82,6 +82,9 @@ events in a wx.TreeCtrl.
Added wx.GetTopLevelWindows() function which returns a copy of the
list of top-level windows that currently exist in the application.
Updated docview library modules and sample apps from the ActiveGrid
folks.

View File

@ -6,7 +6,7 @@
#
# Created: 8/1/03
# CVS-ID: $Id$
# Copyright: (c) 2003, 2004 ActiveGrid, Inc. (Port of wxWindows classes by Julian Smart et al)
# Copyright: (c) 2003-2005 ActiveGrid, Inc. (Port of wxWindows classes by Julian Smart et al)
# License: wxWindows license
#----------------------------------------------------------------------------

View File

@ -1,85 +0,0 @@
#----------------------------------------------------------------------------
# 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
_ = wx.GetTranslation
#----------------------------------------------------------------------------
# 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(_("wxPython PyDocView 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,
_("Text"),
"*.text;*.txt",
_("Text"),
_(".txt"),
_("Text Document"),
_("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(wx.lib.pydocview.WindowMenuService())
optionsService.AddOptionsPanel(TextEditor.TextOptionsPanel)
filePropertiesService = self.InstallService(wx.lib.pydocview.FilePropertiesService())
aboutService = self.InstallService(wx.lib.pydocview.AboutService())
## self.SetDefaultIcon(getAppIcon()) # set this for your custom icon
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, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("activegrid/tool/data/tips.txt", 0))
return True
#----------------------------------------------------------------------------
# Main
#----------------------------------------------------------------------------
sys.stdout = sys.stderr
app = TextEditorApplication(redirect = False)
app.MainLoop()

View File

@ -1,3 +0,0 @@
Tips for PyDocViewDemo App
wxWindows rules!
Use the source, Luke!

View File

@ -6,8 +6,8 @@
#
# Created: 8/15/03
# CVS-ID: $Id$
# Copyright: (c) 2003-2004 ActiveGrid, Inc.
# License: wxWindows license
# Copyright: (c) 2003-2005 ActiveGrid, Inc.
# License: ASL 2.0 http://apache.org/licenses/LICENSE-2.0
#----------------------------------------------------------------------------
import wx

View File

@ -0,0 +1,95 @@
#----------------------------------------------------------------------------
# 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.
# License: ASL 2.0 http://apache.org/licenses/LICENSE-2.0
#----------------------------------------------------------------------------
import sys
import wx
import wx.lib.docview as docview
import wx.lib.pydocview as pydocview
import TextEditor
import FindService
_ = wx.GetTranslation
#----------------------------------------------------------------------------
# Classes
#----------------------------------------------------------------------------
class TextEditorApplication(pydocview.DocApp):
def OnInit(self):
# Call the super - this is important!!!
pydocview.DocApp.OnInit(self)
# Show the splash dialog while everything is loading up
self.ShowSplash("splash.jpg")
# 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())
optionsService = self.InstallService(pydocview.DocOptionsService())
windowMenuService = self.InstallService(pydocview.WindowMenuService())
filePropertiesService = self.InstallService(pydocview.FilePropertiesService())
aboutService = self.InstallService(pydocview.AboutService(image=wx.Image("splash.jpg")))
# 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
self.CloseSplash()
# Show the tips dialog
wx.CallAfter(self.ShowTip, wx.GetApp().GetTopWindow(), wx.CreateFileTipProvider("tips.txt", 0))
# 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()

View File

@ -6,8 +6,8 @@
#
# Created: 8/15/03
# CVS-ID: $Id$
# Copyright: (c) 2003-2004 ActiveGrid, Inc.
# License: wxWindows license
# Copyright: (c) 2003-2005 ActiveGrid, Inc.
# License: ASL 2.0 http://apache.org/licenses/LICENSE-2.0
#----------------------------------------------------------------------------
import wx
import wx.lib.docview
@ -142,7 +142,7 @@ class TextView(wx.lib.docview.View):
if not wx.lib.docview.View.OnClose(self, deleteWindow):
return False
self.Activate(False)
if deleteWindow:
if deleteWindow and self.GetFrame():
self.GetFrame().Destroy()
return True
@ -246,7 +246,7 @@ class TextView(wx.lib.docview.View):
event.Enable(self._textCtrl.CanPaste())
return True
elif id == wx.ID_CLEAR:
event.Enable(True) # wxBug: No matter what we do, the wxTextCtrl disables the Clear menu item and the menu item traps the Del key and the wxTextCtrl doesn't get it and can't delete the next character
event.Enable(self._textCtrl.CanCopy())
return True
elif id == wx.ID_SELECTALL:
event.Enable(hasText)

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

@ -0,0 +1 @@
wxPython is cool.

View File

@ -6,7 +6,7 @@
#
# Created: 5/15/03
# CVS-ID: $Id$
# Copyright: (c) 2003-2004 ActiveGrid, Inc. (Port of wxWindows classes by Julian Smart et al)
# Copyright: (c) 2003-2005 ActiveGrid, Inc. (Port of wxWindows classes by Julian Smart et al)
# License: wxWindows license
#----------------------------------------------------------------------------
@ -91,6 +91,7 @@ class Document(wx.EvtHandler):
self._documentTemplate = None
self._commandProcessor = None
self._savedYet = False
self._writeable = True
self._documentTitle = None
self._documentFile = None
@ -334,7 +335,7 @@ class Document(wx.EvtHandler):
Saves the document by calling OnSaveDocument if there is an associated
filename, or SaveAs if there is no filename.
"""
if not self.IsModified() and self._savedYet:
if not self.IsModified(): # and self._savedYet: This was here, but if it is not modified who cares if it hasn't been saved yet?
return True
if not self._documentFile or not self._savedYet:
@ -646,6 +647,29 @@ class Document(wx.EvtHandler):
view.OnChangeFilename()
def GetWriteable(self):
"""
Returns true if the document can be written to its accociated file path.
This method has been added to wxPython and is not in wxWindows.
"""
if not self._writeable:
return False
if not self._documentFile: # Doesn't exist, do a save as
return True
else:
return os.access(self._documentFile, os.W_OK)
def SetWriteable(self, writeable):
"""
Set to False if the document can not be saved. This will disable the ID_SAVE_AS
event and is useful for custom documents that should not be saveable. The ID_SAVE
event can be disabled by never Modifying the document. This method has been added
to wxPython and is not in wxWindows.
"""
self._writeable = writeable
class View(wx.EvtHandler):
"""
The view class can be used to model the viewing and editing component of
@ -753,7 +777,7 @@ class View(wx.EvtHandler):
else:
return
else:
if appName and not isinstance(self.GetFrame(), DocMDIChildFrame): # Don't need appname in title for MDI
if appName and isinstance(self.GetFrame(), DocChildFrame): # Only need app name in title for SDI
title = appName + _(" - ")
else:
title = ''
@ -1478,7 +1502,7 @@ class DocManager(wx.EvtHandler):
"""
Updates the user interface for the File Save As command.
"""
event.Enable(self.GetCurrentDocument() != None)
event.Enable(self.GetCurrentDocument() != None and self.GetCurrentDocument().GetWriteable())
def OnUpdateUndo(self, event):

File diff suppressed because it is too large Load Diff