]> git.saurik.com Git - wxWidgets.git/commitdiff
Updated docview library modules and sample apps from the ActiveGrid
authorRobin Dunn <robin@alldunn.com>
Fri, 8 Apr 2005 19:04:58 +0000 (19:04 +0000)
committerRobin Dunn <robin@alldunn.com>
Fri, 8 Apr 2005 19:04:58 +0000 (19:04 +0000)
folks.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33434 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

16 files changed:
wxPython/docs/CHANGES.txt
wxPython/samples/docview/DocViewDemo.py
wxPython/samples/docview/PyDocViewDemo.py [deleted file]
wxPython/samples/docview/activegrid/__init__.py [deleted file]
wxPython/samples/docview/activegrid/tool/FindService.py [deleted file]
wxPython/samples/docview/activegrid/tool/TextEditor.py [deleted file]
wxPython/samples/docview/activegrid/tool/__init__.py [deleted file]
wxPython/samples/docview/activegrid/tool/data/tips.txt [deleted file]
wxPython/samples/docview/activegrid/tool/images/splash.jpg [deleted file]
wxPython/samples/pydocview/FindService.py [new file with mode: 0644]
wxPython/samples/pydocview/PyDocViewDemo.py [new file with mode: 0644]
wxPython/samples/pydocview/TextEditor.py [new file with mode: 0644]
wxPython/samples/pydocview/splash.jpg [new file with mode: 0644]
wxPython/samples/pydocview/tips.txt [new file with mode: 0644]
wxPython/wx/lib/docview.py
wxPython/wx/lib/pydocview.py

index 8ead239ebb801fdea153e50e426ebdaae7e01ba6..454eb6dbd2e89810f7fe5f60a107a3cfd88a80cd 100644 (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. 
+
 
 
 
index c22b3539ccb93135da91574b56f075c60b559c5a..62aeefbe6fe524d259455f2ca1f026c317a85bd0 100644 (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
 #----------------------------------------------------------------------------
 
diff --git a/wxPython/samples/docview/PyDocViewDemo.py b/wxPython/samples/docview/PyDocViewDemo.py
deleted file mode 100644 (file)
index 9243aea..0000000
+++ /dev/null
@@ -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()
diff --git a/wxPython/samples/docview/activegrid/__init__.py b/wxPython/samples/docview/activegrid/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/wxPython/samples/docview/activegrid/tool/FindService.py b/wxPython/samples/docview/activegrid/tool/FindService.py
deleted file mode 100644 (file)
index 4606a67..0000000
+++ /dev/null
@@ -1,521 +0,0 @@
-#----------------------------------------------------------------------------
-# Name:         FindService.py
-# Purpose:      Find Service for pydocview
-#
-# Author:       Peter Yared, Morgan Hua
-#
-# Created:      8/15/03
-# CVS-ID:       $Id$
-# Copyright:    (c) 2003-2004 ActiveGrid, Inc.
-# License:      wxWindows license
-#----------------------------------------------------------------------------
-
-import wx
-import wx.lib.docview
-import wx.lib.pydocview
-import re
-_ = wx.GetTranslation
-
-
-#----------------------------------------------------------------------------
-# Constants
-#----------------------------------------------------------------------------
-FIND_MATCHPATTERN = "FindMatchPattern"
-FIND_MATCHREPLACE = "FindMatchReplace"
-FIND_MATCHCASE = "FindMatchCase"
-FIND_MATCHWHOLEWORD = "FindMatchWholeWordOnly"
-FIND_MATCHREGEXPR = "FindMatchRegularExpr"
-FIND_MATCHWRAP = "FindMatchWrap"
-FIND_MATCHUPDOWN = "FindMatchUpDown"
-
-FIND_SYNTAXERROR = -2
-
-SPACE = 10
-HALF_SPACE = 5
-
-
-#----------------------------------------------------------------------------
-# Classes
-#----------------------------------------------------------------------------
-
-class FindService(wx.lib.pydocview.DocService):
-
-    #----------------------------------------------------------------------------
-    # Constants
-    #----------------------------------------------------------------------------
-    FIND_ID = wx.NewId()            # for bringing up Find dialog box
-    FINDONE_ID = wx.NewId()         # for doing Find
-    FIND_PREVIOUS_ID = wx.NewId()   # for doing Find Next
-    FIND_NEXT_ID = wx.NewId()       # for doing Find Prev
-    REPLACE_ID = wx.NewId()         # for bringing up Replace dialog box
-    REPLACEONE_ID = wx.NewId()      # for doing a Replace
-    REPLACEALL_ID = wx.NewId()      # for doing Replace All
-    GOTO_LINE_ID = wx.NewId()       # for bringing up Goto dialog box
-
-    # Extending bitmasks: wx.FR_WHOLEWORD, wx.FR_MATCHCASE, and wx.FR_DOWN
-    FR_REGEXP = max([wx.FR_WHOLEWORD, wx.FR_MATCHCASE, wx.FR_DOWN]) << 1
-    FR_WRAP = FR_REGEXP << 1
-
-
-    def __init__(self):
-        self._replaceDialog = None
-        self._findDialog = None
-        self._findReplaceData = wx.FindReplaceData()
-        self._findReplaceData.SetFlags(wx.FR_DOWN)
-
-
-    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
-        """ Install Find Service Menu Items """
-        editMenu = menuBar.GetMenu(menuBar.FindMenu(_("&Edit")))
-        editMenu.AppendSeparator()
-        editMenu.Append(FindService.FIND_ID, _("&Find...\tCtrl+F"), _("Finds the specified text"))
-        wx.EVT_MENU(frame, FindService.FIND_ID, frame.ProcessEvent)
-        wx.EVT_UPDATE_UI(frame, FindService.FIND_ID, frame.ProcessUpdateUIEvent)
-        editMenu.Append(FindService.FIND_PREVIOUS_ID, _("Find &Previous\tShift+F3"), _("Finds the specified text"))
-        wx.EVT_MENU(frame, FindService.FIND_PREVIOUS_ID, frame.ProcessEvent)
-        wx.EVT_UPDATE_UI(frame, FindService.FIND_PREVIOUS_ID, frame.ProcessUpdateUIEvent)
-        editMenu.Append(FindService.FIND_NEXT_ID, _("Find &Next\tF3"), _("Finds the specified text"))
-        wx.EVT_MENU(frame, FindService.FIND_NEXT_ID, frame.ProcessEvent)
-        wx.EVT_UPDATE_UI(frame, FindService.FIND_NEXT_ID, frame.ProcessUpdateUIEvent)
-        editMenu.Append(FindService.REPLACE_ID, _("R&eplace...\tCtrl+H"), _("Replaces specific text with different text"))
-        wx.EVT_MENU(frame, FindService.REPLACE_ID, frame.ProcessEvent)
-        wx.EVT_UPDATE_UI(frame, FindService.REPLACE_ID, frame.ProcessUpdateUIEvent)
-        editMenu.Append(FindService.GOTO_LINE_ID, _("&Go to Line...\tCtrl+G"), _("Goes to a certain line in the file"))
-        wx.EVT_MENU(frame, FindService.GOTO_LINE_ID, frame.ProcessEvent)
-        wx.EVT_UPDATE_UI(frame, FindService.GOTO_LINE_ID, frame.ProcessUpdateUIEvent)
-
-        # wxBug: wxToolBar::GetToolPos doesn't exist, need it to find cut tool and then insert find in front of it.
-        toolBar.InsertTool(6, FindService.FIND_ID, getFindBitmap(), shortHelpString = _("Find"), longHelpString = _("Finds the specified text"))
-        toolBar.InsertSeparator(6)
-        toolBar.Realize()
-
-        frame.Bind(wx.EVT_FIND, frame.ProcessEvent)
-        frame.Bind(wx.EVT_FIND_NEXT, frame.ProcessEvent)
-        frame.Bind(wx.EVT_FIND_REPLACE, frame.ProcessEvent)
-        frame.Bind(wx.EVT_FIND_REPLACE_ALL, frame.ProcessEvent)
-
-
-    def ProcessUpdateUIEvent(self, event):
-        id = event.GetId()
-        if id == FindService.FIND_ID:
-            event.Enable(False)
-            return True
-        elif id == FindService.FIND_PREVIOUS_ID:
-            event.Enable(False)
-            return True
-        elif id == FindService.FIND_NEXT_ID:
-            event.Enable(False)
-            return True
-        elif id == FindService.REPLACE_ID:
-            event.Enable(False)
-            return True
-        elif id == FindService.GOTO_LINE_ID:
-            event.Enable(False)
-            return True
-        else:
-            return False
-
-
-    def ShowFindReplaceDialog(self, findString="", replace = False):
-        """ Display find/replace dialog box.
-        
-            Parameters: findString is the default value shown in the find/replace dialog input field.
-            If replace is True, the replace dialog box is shown, otherwise only the find dialog box is shown. 
-        """
-        if replace:
-            if self._findDialog != None:
-                # No reason to have both find and replace dialogs up at the same time
-                self._findDialog.DoClose()
-                self._findDialog = None
-
-            self._replaceDialog = FindReplaceDialog(self.GetDocumentManager().FindSuitableParent(), -1, _("Replace"), size=(320,200), findString=findString)
-            self._replaceDialog.Show(True)
-        else:
-            if self._replaceDialog != None:
-                # No reason to have both find and replace dialogs up at the same time
-                self._replaceDialog.DoClose()
-                self._replaceDialog = None
-
-            self._findDialog = FindDialog(self.GetDocumentManager().FindSuitableParent(), -1, _("Find"), size=(320,200), findString=findString)
-            self._findDialog.Show(True)
-
-
-
-    def OnFindClose(self, event):
-        """ Cleanup handles when find/replace dialog is closed """
-        if self._findDialog != None:
-            self._findDialog = None
-        elif self._replaceDialog != None:
-            self._replaceDialog = None
-
-
-    def GetCurrentDialog(self):
-        """ return handle to either the find or replace dialog """
-        if self._findDialog != None:
-            return self._findDialog
-        return self._replaceDialog
-
-
-    def GetLineNumber(self, parent):
-        """ Display Goto Line Number dialog box """
-        line = -1
-        dialog = wx.TextEntryDialog(parent, _("Enter line number to go to:"), _("Go to Line"))
-        if dialog.ShowModal() == wx.ID_OK:
-            try:
-                line = int(dialog.GetValue())
-                if line > 65535:
-                    line = 65535
-            except:
-                pass
-        dialog.Destroy()
-        # This one is ugly:  wx.GetNumberFromUser("", _("Enter line number to go to:"), _("Go to Line"), 1, min = 1, max = 65535, parent = parent)
-        return line
-
-
-    def DoFind(self, findString, replaceString, text, startLoc, endLoc, down, matchCase, wholeWord, regExpr = False, replace = False, replaceAll = False, wrap = False):
-        """ Do the actual work of the find/replace.
-        
-            Returns the tuple (count, start, end, newText).
-            count = number of string replacements
-            start = start position of found string
-            end = end position of found string
-            newText = new replaced text 
-        """
-        flags = 0
-        if regExpr:
-            pattern = findString
-        else:
-            pattern = re.escape(findString)  # Treat the strings as a literal string
-        if not matchCase:
-            flags = re.IGNORECASE
-        if wholeWord:
-            pattern = r"\b%s\b" % pattern
-            
-        try:
-            reg = re.compile(pattern, flags)
-        except:
-            # syntax error of some sort
-            import sys
-            msgTitle = wx.GetApp().GetAppName()
-            if not msgTitle:
-                msgTitle = _("Regular Expression Search")
-            wx.MessageBox(_("Invalid regular expression \"%s\". %s") % (pattern, sys.exc_value),
-                          msgTitle,
-                          wx.OK | wx.ICON_EXCLAMATION,
-                          self.GetView())
-            return FIND_SYNTAXERROR, None, None, None
-
-        if replaceAll:
-            newText, count = reg.subn(replaceString, text)
-            if count == 0:
-                return -1, None, None, None
-            else:
-                return count, None, None, newText
-
-        start = -1
-        if down:
-            match = reg.search(text, endLoc)
-            if match == None:
-                if wrap:  # try again, but this time from top of file
-                    match = reg.search(text, 0)
-                    if match == None:
-                        return -1, None, None, None
-                else:
-                    return -1, None, None, None
-            start = match.start()
-            end = match.end()
-        else:
-            match = reg.search(text)
-            if match == None:
-                return -1, None, None, None
-            found = None
-            i, j = match.span()
-            while i < startLoc and j <= startLoc:
-                found = match
-                if i == j:
-                    j = j + 1
-                match = reg.search(text, j)
-                if match == None:
-                    break
-                i, j = match.span()
-            if found == None:
-                if wrap:  # try again, but this time from bottom of file
-                    match = reg.search(text, startLoc)
-                    if match == None:
-                        return -1, None, None, None
-                    found = None
-                    i, j = match.span()
-                    end = len(text)
-                    while i < end and j <= end:
-                        found = match
-                        if i == j:
-                            j = j + 1
-                        match = reg.search(text, j)
-                        if match == None:
-                            break
-                        i, j = match.span()
-                    if found == None:
-                        return -1, None, None, None
-                else:
-                    return -1, None, None, None
-            start = found.start()
-            end = found.end()
-
-        if replace and start != -1:
-            newText, count = reg.subn(replaceString, text, 1)
-            return count, start, end, newText
-
-        return 0, start, end, None
-
-
-    def SaveFindConfig(self, findString, wholeWord, matchCase, regExpr = None, wrap = None, upDown = None, replaceString = None):
-        """ Save find/replace patterns and search flags to registry.
-        
-            findString = search pattern
-            wholeWord = match whole word only
-            matchCase = match case
-            regExpr = use regular expressions in search pattern
-            wrap = return to top/bottom of file on search
-            upDown = search up or down from current cursor position
-            replaceString = replace string
-        """
-        config = wx.ConfigBase_Get()
-
-        config.Write(FIND_MATCHPATTERN, findString)
-        config.WriteInt(FIND_MATCHCASE, matchCase)
-        config.WriteInt(FIND_MATCHWHOLEWORD, wholeWord)
-        if replaceString != None:
-            config.Write(FIND_MATCHREPLACE, replaceString)
-        if regExpr != None:
-            config.WriteInt(FIND_MATCHREGEXPR, regExpr)
-        if wrap != None:
-            config.WriteInt(FIND_MATCHWRAP, wrap)
-        if upDown != None:
-            config.WriteInt(FIND_MATCHUPDOWN, upDown)
-
-
-    def GetFindString(self):
-        """ Load the search pattern from registry """
-        return wx.ConfigBase_Get().Read(FIND_MATCHPATTERN, "")
-
-
-    def GetReplaceString(self):
-        """ Load the replace pattern from registry """
-        return wx.ConfigBase_Get().Read(FIND_MATCHREPLACE, "")
-
-
-    def GetFlags(self):
-        """ Load search parameters from registry """
-        config = wx.ConfigBase_Get()
-
-        flags = 0
-        if config.ReadInt(FIND_MATCHWHOLEWORD, False):
-            flags = flags | wx.FR_WHOLEWORD
-        if config.ReadInt(FIND_MATCHCASE, False):
-            flags = flags | wx.FR_MATCHCASE
-        if config.ReadInt(FIND_MATCHUPDOWN, False):
-            flags = flags | wx.FR_DOWN
-        if config.ReadInt(FIND_MATCHREGEXPR, False):
-            flags = flags | FindService.FR_REGEXP
-        if config.ReadInt(FIND_MATCHWRAP, False):
-            flags = flags | FindService.FR_WRAP
-        return flags
-
-
-class FindDialog(wx.Dialog):
-    """ Find Dialog with regular expression matching and wrap to top/bottom of file. """
-
-    def __init__(self, parent, id, title, size, findString=None):
-        wx.Dialog.__init__(self, parent, id, title, size=size)
-
-        config = wx.ConfigBase_Get()
-        borderSizer = wx.BoxSizer(wx.VERTICAL)
-        gridSizer = wx.GridBagSizer(SPACE, SPACE)
-
-        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
-        lineSizer.Add(wx.StaticText(self, -1, _("Find what:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, SPACE)
-        if not findString:
-            findString = config.Read(FIND_MATCHPATTERN, "")
-        self._findCtrl = wx.TextCtrl(self, -1, findString, size=(200,-1))
-        lineSizer.Add(self._findCtrl, 0)
-        gridSizer.Add(lineSizer, pos=(0,0), span=(1,2))
-        choiceSizer = wx.BoxSizer(wx.VERTICAL)
-        self._wholeWordCtrl = wx.CheckBox(self, -1, _("Match whole word only"))
-        self._wholeWordCtrl.SetValue(config.ReadInt(FIND_MATCHWHOLEWORD, False))
-        self._matchCaseCtrl = wx.CheckBox(self, -1, _("Match case"))
-        self._matchCaseCtrl.SetValue(config.ReadInt(FIND_MATCHCASE, False))
-        self._regExprCtrl = wx.CheckBox(self, -1, _("Regular expression"))
-        self._regExprCtrl.SetValue(config.ReadInt(FIND_MATCHREGEXPR, False))
-        self._wrapCtrl = wx.CheckBox(self, -1, _("Wrap"))
-        self._wrapCtrl.SetValue(config.ReadInt(FIND_MATCHWRAP, False))
-        choiceSizer.Add(self._wholeWordCtrl, 0, wx.BOTTOM, SPACE)
-        choiceSizer.Add(self._matchCaseCtrl, 0, wx.BOTTOM, SPACE)
-        choiceSizer.Add(self._regExprCtrl, 0, wx.BOTTOM, SPACE)
-        choiceSizer.Add(self._wrapCtrl, 0)
-        gridSizer.Add(choiceSizer, pos=(1,0), span=(2,1))
-
-        self._radioBox = wx.RadioBox(self, -1, _("Direction"), choices = ["Up", "Down"])
-        self._radioBox.SetSelection(config.ReadInt(FIND_MATCHUPDOWN, 1))
-        gridSizer.Add(self._radioBox, pos=(1,1), span=(2,1))
-
-        buttonSizer = wx.BoxSizer(wx.VERTICAL)
-        findBtn = wx.Button(self, FindService.FINDONE_ID, _("Find Next"))
-        findBtn.SetDefault()
-        wx.EVT_BUTTON(self, FindService.FINDONE_ID, self.OnActionEvent)
-        cancelBtn = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
-        wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnClose)
-        buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
-        buttonSizer.Add(cancelBtn, 0)
-        gridSizer.Add(buttonSizer, pos=(0,2), span=(3,1))
-
-        borderSizer.Add(gridSizer, 0, wx.ALL, SPACE)
-
-        self.Bind(wx.EVT_CLOSE, self.OnClose)
-
-        self.SetSizer(borderSizer)
-        self.Fit()
-        self._findCtrl.SetFocus()
-
-    def SaveConfig(self):
-        """ Save find patterns and search flags to registry. """
-        findService = wx.GetApp().GetService(FindService)
-        if findService:
-            findService.SaveFindConfig(self._findCtrl.GetValue(),
-                                       self._wholeWordCtrl.IsChecked(),
-                                       self._matchCaseCtrl.IsChecked(),
-                                       self._regExprCtrl.IsChecked(),
-                                       self._wrapCtrl.IsChecked(),
-                                       self._radioBox.GetSelection(),
-                                       )
-
-
-    def DoClose(self):
-        self.SaveConfig()
-        self.Destroy()
-
-
-    def OnClose(self, event):
-        findService = wx.GetApp().GetService(FindService)
-        if findService:
-            findService.OnFindClose(event)
-        self.DoClose()
-
-
-    def OnActionEvent(self, event):
-        self.SaveConfig()
-
-        if wx.GetApp().GetDocumentManager().GetFlags() & wx.lib.docview.DOC_MDI:
-            if wx.GetApp().GetTopWindow().ProcessEvent(event):
-                return True
-        else:
-            view = wx.GetApp().GetDocumentManager().GetLastActiveView()
-            if view and view.ProcessEvent(event):
-                return True
-        return False
-
-
-class FindReplaceDialog(FindDialog):
-    """ Find/Replace Dialog with regular expression matching and wrap to top/bottom of file. """
-
-    def __init__(self, parent, id, title, size, findString=None):
-        wx.Dialog.__init__(self, parent, id, title, size=size)
-
-        config = wx.ConfigBase_Get()
-        borderSizer = wx.BoxSizer(wx.VERTICAL)
-        gridSizer = wx.GridBagSizer(SPACE, SPACE)
-
-        gridSizer2 = wx.GridBagSizer(SPACE, SPACE)
-        gridSizer2.Add(wx.StaticText(self, -1, _("Find what:")), flag=wx.ALIGN_CENTER_VERTICAL, pos=(0,0))
-        if not findString:
-            findString = config.Read(FIND_MATCHPATTERN, "")
-        self._findCtrl = wx.TextCtrl(self, -1, findString, size=(200,-1))
-        gridSizer2.Add(self._findCtrl, pos=(0,1))
-        gridSizer2.Add(wx.StaticText(self, -1, _("Replace with:")), flag=wx.ALIGN_CENTER_VERTICAL, pos=(1,0))
-        self._replaceCtrl = wx.TextCtrl(self, -1, config.Read(FIND_MATCHREPLACE, ""), size=(200,-1))
-        gridSizer2.Add(self._replaceCtrl, pos=(1,1))
-        gridSizer.Add(gridSizer2, pos=(0,0), span=(1,2))
-        choiceSizer = wx.BoxSizer(wx.VERTICAL)
-        self._wholeWordCtrl = wx.CheckBox(self, -1, _("Match whole word only"))
-        self._wholeWordCtrl.SetValue(config.ReadInt(FIND_MATCHWHOLEWORD, False))
-        self._matchCaseCtrl = wx.CheckBox(self, -1, _("Match case"))
-        self._matchCaseCtrl.SetValue(config.ReadInt(FIND_MATCHCASE, False))
-        self._regExprCtrl = wx.CheckBox(self, -1, _("Regular expression"))
-        self._regExprCtrl.SetValue(config.ReadInt(FIND_MATCHREGEXPR, False))
-        self._wrapCtrl = wx.CheckBox(self, -1, _("Wrap"))
-        self._wrapCtrl.SetValue(config.ReadInt(FIND_MATCHWRAP, False))
-        choiceSizer.Add(self._wholeWordCtrl, 0, wx.BOTTOM, SPACE)
-        choiceSizer.Add(self._matchCaseCtrl, 0, wx.BOTTOM, SPACE)
-        choiceSizer.Add(self._regExprCtrl, 0, wx.BOTTOM, SPACE)
-        choiceSizer.Add(self._wrapCtrl, 0)
-        gridSizer.Add(choiceSizer, pos=(1,0), span=(2,1))
-
-        self._radioBox = wx.RadioBox(self, -1, _("Direction"), choices = ["Up", "Down"])
-        self._radioBox.SetSelection(config.ReadInt(FIND_MATCHUPDOWN, 1))
-        gridSizer.Add(self._radioBox, pos=(1,1), span=(2,1))
-
-        buttonSizer = wx.BoxSizer(wx.VERTICAL)
-        findBtn = wx.Button(self, FindService.FINDONE_ID, _("Find Next"))
-        findBtn.SetDefault()
-        wx.EVT_BUTTON(self, FindService.FINDONE_ID, self.OnActionEvent)
-        cancelBtn = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
-        wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnClose)
-        replaceBtn = wx.Button(self, FindService.REPLACEONE_ID, _("Replace"))
-        wx.EVT_BUTTON(self, FindService.REPLACEONE_ID, self.OnActionEvent)
-        replaceAllBtn = wx.Button(self, FindService.REPLACEALL_ID, _("Replace All"))
-        wx.EVT_BUTTON(self, FindService.REPLACEALL_ID, self.OnActionEvent)
-        buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
-        buttonSizer.Add(replaceBtn, 0, wx.BOTTOM, HALF_SPACE)
-        buttonSizer.Add(replaceAllBtn, 0, wx.BOTTOM, HALF_SPACE)
-        buttonSizer.Add(cancelBtn, 0)
-        gridSizer.Add(buttonSizer, pos=(0,2), span=(3,1))
-
-        borderSizer.Add(gridSizer, 0, wx.ALL, SPACE)
-
-        self.Bind(wx.EVT_CLOSE, self.OnClose)
-
-        self.SetSizer(borderSizer)
-        self.Fit()
-        self._findCtrl.SetFocus()
-        
-
-    def SaveConfig(self):
-        """ Save find/replace patterns and search flags to registry. """
-        findService = wx.GetApp().GetService(FindService)
-        if findService:
-            findService.SaveFindConfig(self._findCtrl.GetValue(),
-                                       self._wholeWordCtrl.IsChecked(),
-                                       self._matchCaseCtrl.IsChecked(),
-                                       self._regExprCtrl.IsChecked(),
-                                       self._wrapCtrl.IsChecked(),
-                                       self._radioBox.GetSelection(),
-                                       self._replaceCtrl.GetValue()
-                                       )
-
-
-#----------------------------------------------------------------------------
-# Menu Bitmaps - generated by encode_bitmaps.py
-#----------------------------------------------------------------------------
-from wx import ImageFromStream, BitmapFromImage
-import cStringIO
-
-
-def getFindData():
-    return \
-'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
-\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
-\x00\x00\x81IDAT8\x8d\xa5S\xc1\x16\xc0\x10\x0ckk\xff\xff\xc7d\x87\xad^U\r\
-\x93S\xe5U$\n\xb3$:\xc1e\x17(\x19Z\xb3$\x9e\xf1DD\xe2\x15\x01x\xea\x93\xef\
-\x04\x989\xea\x1b\xf2U\xc0\xda\xb4\xeb\x11\x1f:\xd8\xb5\xff8\x93\xd4\xa9\xae\
-@/S\xaaUwJ3\x85\xc0\x81\xee\xeb.q\x17C\x81\xd5XU \x1a\x93\xc6\x18\x8d\x90\
-\xe8}\x89\x00\x9a&\x9b_k\x94\x0c\xdf\xd78\xf8\x0b\x99Y\xb4\x08c\x9e\xfe\xc6\
-\xe3\x087\xf9\xd0D\x180\xf1#\x8e\x00\x00\x00\x00IEND\xaeB`\x82' 
-
-
-def getFindBitmap():
-    return BitmapFromImage(getFindImage())
-
-
-def getFindImage():
-    stream = cStringIO.StringIO(getFindData())
-    return ImageFromStream(stream)
-
diff --git a/wxPython/samples/docview/activegrid/tool/TextEditor.py b/wxPython/samples/docview/activegrid/tool/TextEditor.py
deleted file mode 100644 (file)
index 9f0517e..0000000
+++ /dev/null
@@ -1,551 +0,0 @@
-#----------------------------------------------------------------------------
-# Name:         TextEditor.py
-# Purpose:      Text Editor for pydocview
-#
-# Author:       Peter Yared
-#
-# Created:      8/15/03
-# CVS-ID:       $Id$
-# Copyright:    (c) 2003-2004 ActiveGrid, Inc.
-# License:      wxWindows license
-#----------------------------------------------------------------------------
-import wx
-import wx.lib.docview
-import wx.lib.pydocview
-import string
-import FindService
-_ = wx.GetTranslation
-
-class TextDocument(wx.lib.docview.Document):
-
-
-    def OnSaveDocument(self, filename):
-        view = self.GetFirstView()
-        if not view.GetTextCtrl().SaveFile(filename):
-            return False
-        self.Modify(False)
-        self.SetDocumentSaved(True)
-        #if wx.Platform == "__WXMAC__":
-        #    fn = wx.Filename(filename)
-        #    fn.MacSetDefaultTypeAndCreator()
-        return True
-
-
-    def OnOpenDocument(self, filename):
-        view = self.GetFirstView()
-        if not view.GetTextCtrl().LoadFile(filename):
-            return False
-        self.SetFilename(filename, True)
-        self.Modify(False)
-        self.UpdateAllViews()
-        self._savedYet = True
-        return True
-
-
-    def IsModified(self):
-        view = self.GetFirstView()
-        if view and view.GetTextCtrl():
-            return wx.lib.docview.Document.IsModified(self) or view.GetTextCtrl().IsModified()
-        else:
-            return wx.lib.docview.Document.IsModified(self)
-
-
-    def Modify(self, mod):
-        view = self.GetFirstView()
-        wx.lib.docview.Document.Modify(self, mod)
-        if not mod and view and view.GetTextCtrl():
-            view.GetTextCtrl().DiscardEdits()
-
-
-class TextView(wx.lib.docview.View):
-
-
-    #----------------------------------------------------------------------------
-    # Overridden methods
-    #----------------------------------------------------------------------------
-
-    def __init__(self):
-        wx.lib.docview.View.__init__(self)
-        self._textCtrl = None
-        self._wordWrap = wx.ConfigBase_Get().ReadInt("TextEditorWordWrap", True)
-
-
-    def OnCreate(self, doc, flags):
-        frame = wx.GetApp().CreateDocumentFrame(self, doc, flags)
-        sizer = wx.BoxSizer()
-        font, color = self._GetFontAndColorFromConfig()
-        self._textCtrl = self._BuildTextCtrl(frame, font, color = color)
-        sizer.Add(self._textCtrl, 1, wx.EXPAND, 0)
-        frame.SetSizer(sizer)
-        frame.Layout()
-        frame.Show(True)
-        self.Activate()
-        return True
-
-
-    def _BuildTextCtrl(self, parent, font, color = wx.BLACK, value = "", selection = [0, 0]):
-        if self._wordWrap:
-            wordWrapStyle = wx.TE_WORDWRAP
-        else:
-            wordWrapStyle = wx.TE_DONTWRAP
-        textCtrl = wx.TextCtrl(parent, -1, pos = wx.DefaultPosition, size = parent.GetClientSize(), style = wx.TE_MULTILINE | wordWrapStyle)
-        textCtrl.SetFont(font)
-        textCtrl.SetForegroundColour(color)
-        textCtrl.SetValue(value)
-        return textCtrl
-
-
-    def _GetFontAndColorFromConfig(self):
-        font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
-        config = wx.ConfigBase_Get()
-        fontData = config.Read("TextEditorFont", "")
-        if fontData:
-            nativeFont = wx.NativeFontInfo()
-            nativeFont.FromString(fontData)
-            font.SetNativeFontInfo(nativeFont)
-        color = wx.BLACK
-        colorData = config.Read("TextEditorColor", "")
-        if colorData:
-            red = int("0x" + colorData[0:2], 16)
-            green = int("0x" + colorData[2:4], 16)
-            blue = int("0x" + colorData[4:6], 16)
-            color = wx.Color(red, green, blue)
-        return font, color
-
-
-    def OnCreateCommandProcessor(self):
-        # Don't create a command processor, it has its own
-        pass
-
-
-    def OnActivateView(self, activate, activeView, deactiveView):
-        if activate and self._textCtrl:
-            # In MDI mode just calling set focus doesn't work and in SDI mode using CallAfter causes an endless loop
-            if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI:
-                self._textCtrl.SetFocus()
-            else:
-                def SetFocusToTextCtrl():
-                    if self._textCtrl:  # Need to make sure it is there in case we are in the closeall mode of the MDI window
-                        self._textCtrl.SetFocus()
-                wx.CallAfter(SetFocusToTextCtrl)
-
-
-    def OnUpdate(self, sender = None, hint = None):
-        if hint == "Word Wrap":
-            self.SetWordWrap(wx.ConfigBase_Get().ReadInt("TextEditorWordWrap", True))
-        elif hint == "Font":
-            font, color = self._GetFontAndColorFromConfig()
-            self.SetFont(font, color)
-
-
-    def OnClose(self, deleteWindow = True):
-        if not wx.lib.docview.View.OnClose(self, deleteWindow):
-            return False
-        self.Activate(False)
-        if deleteWindow:
-            self.GetFrame().Destroy()
-        return True
-
-
-    # Since ProcessEvent is not virtual, we have to trap the relevant events using this pseudo-ProcessEvent instead of EVT_MENU
-    def ProcessEvent(self, event):
-        id = event.GetId()
-        if id == wx.ID_UNDO:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.Undo()
-            return True
-        elif id == wx.ID_REDO:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.Redo()
-            return True
-        elif id == wx.ID_CUT:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.Cut()
-            return True
-        elif id == wx.ID_COPY:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.Copy()
-            return True
-        elif id == wx.ID_PASTE:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.Paste()
-            return True
-        elif id == wx.ID_CLEAR:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.Replace(self._textCtrl.GetSelection()[0], self._textCtrl.GetSelection()[1], '')
-            return True
-        elif id == wx.ID_SELECTALL:
-            if not self._textCtrl:
-                return False
-            self._textCtrl.SetSelection(-1, -1)
-            return True
-        elif id == TextService.CHOOSE_FONT_ID:
-            if not self._textCtrl:
-                return False
-            self.OnChooseFont(event)
-            return True
-        elif id == TextService.WORD_WRAP_ID:
-            if not self._textCtrl:
-                return False
-            self.OnWordWrap(event)
-            return True
-        elif id == FindService.FindService.FIND_ID:
-            self.OnFind()
-            return True
-        elif id == FindService.FindService.FIND_PREVIOUS_ID:
-            self.DoFind(forceFindPrevious = True)
-            return True
-        elif id == FindService.FindService.FIND_NEXT_ID:
-            self.DoFind(forceFindNext = True)
-            return True
-        elif id == FindService.FindService.REPLACE_ID:
-            self.OnFind(replace = True)
-            return True
-        elif id == FindService.FindService.FINDONE_ID:
-            self.DoFind()
-            return True
-        elif id == FindService.FindService.REPLACEONE_ID:
-            self.DoFind(replace = True)
-            return True
-        elif id == FindService.FindService.REPLACEALL_ID:
-            self.DoFind(replaceAll = True)
-            return True
-        elif id == FindService.FindService.GOTO_LINE_ID:
-            self.OnGotoLine(event)
-            return True
-        else:
-            return wx.lib.docview.View.ProcessEvent(self, event)
-
-
-    def ProcessUpdateUIEvent(self, event):
-        if not self._textCtrl:
-            return False
-
-        hasText = len(self._textCtrl.GetValue()) > 0
-
-        id = event.GetId()
-        if id == wx.ID_UNDO:
-            event.Enable(self._textCtrl.CanUndo())
-            return True
-        elif id == wx.ID_REDO:
-            event.Enable(self._textCtrl.CanRedo())
-            return True
-        if id == wx.ID_CUT:
-            event.Enable(self._textCtrl.CanCut())
-            return True
-        elif id == wx.ID_COPY:
-            event.Enable(self._textCtrl.CanCopy())
-            return True
-        elif id == wx.ID_PASTE:
-            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
-            return True
-        elif id == wx.ID_SELECTALL:
-            event.Enable(hasText)
-            return True
-        elif id == TextService.CHOOSE_FONT_ID:
-            event.Enable(True)
-            return True
-        elif id == TextService.WORD_WRAP_ID:
-            event.Enable(True)
-            return True
-        elif id == FindService.FindService.FIND_ID:
-            event.Enable(hasText)
-            return True
-        elif id == FindService.FindService.FIND_PREVIOUS_ID:
-            event.Enable(hasText and
-                         self._FindServiceHasString() and
-                         self._textCtrl.GetSelection()[0] > 0)
-            return True
-        elif id == FindService.FindService.FIND_NEXT_ID:
-            event.Enable(hasText and
-                         self._FindServiceHasString() and
-                         self._textCtrl.GetSelection()[0] < len(self._textCtrl.GetValue()))
-            return True
-        elif id == FindService.FindService.REPLACE_ID:
-            event.Enable(hasText)
-            return True
-        elif id == FindService.FindService.GOTO_LINE_ID:
-            event.Enable(True)
-            return True
-        else:
-            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)
-
-
-    #----------------------------------------------------------------------------
-    # Methods for TextDocument to call
-    #----------------------------------------------------------------------------
-
-    def GetTextCtrl(self):
-        return self._textCtrl
-
-
-    #----------------------------------------------------------------------------
-    # Format methods
-    #----------------------------------------------------------------------------
-
-    def OnChooseFont(self, event):
-        data = wx.FontData()
-        data.EnableEffects(True)
-        data.SetInitialFont(self._textCtrl.GetFont())
-        data.SetColour(self._textCtrl.GetForegroundColour())
-        fontDialog = wx.FontDialog(self.GetFrame(), data)
-        if fontDialog.ShowModal() == wx.ID_OK:
-            data = fontDialog.GetFontData()
-            self.SetFont(data.GetChosenFont(), data.GetColour())
-        fontDialog.Destroy()
-
-
-    def SetFont(self, font, color):
-        self._textCtrl.SetFont(font)
-        self._textCtrl.SetForegroundColour(color)
-        self._textCtrl.Refresh()
-        self._textCtrl.Layout()
-
-
-    def OnWordWrap(self, event):
-        self.SetWordWrap(not self.GetWordWrap())
-
-
-    def GetWordWrap(self):
-        return self._wordWrap
-
-
-    def SetWordWrap(self, wordWrap = True):
-        self._wordWrap = wordWrap
-        temp = self._textCtrl
-        self._textCtrl = self._BuildTextCtrl(temp.GetParent(),
-                                             font = temp.GetFont(),
-                                             color = temp.GetForegroundColour(),
-                                             value = temp.GetValue(),
-                                             selection = temp.GetSelection())
-        self.GetDocument().Modify(temp.IsModified())
-        temp.Destroy()
-
-
-    #----------------------------------------------------------------------------
-    # Find methods
-    #----------------------------------------------------------------------------
-
-    def OnFind(self, replace = False):
-        findService = wx.GetApp().GetService(FindService.FindService)
-        if findService:
-            findService.ShowFindReplaceDialog(findString = self._textCtrl.GetStringSelection(), replace = replace)
-
-
-    def DoFind(self, forceFindNext = False, forceFindPrevious = False, replace = False, replaceAll = False):
-        findService = wx.GetApp().GetService(FindService.FindService)
-        if not findService:
-            return
-        findString = findService.GetFindString()
-        if len(findString) == 0:
-            return -1
-        replaceString = findService.GetReplaceString()
-        flags = findService.GetFlags()
-        startLoc, endLoc = self._textCtrl.GetSelection()
-
-        wholeWord = flags & wx.FR_WHOLEWORD > 0
-        matchCase = flags & wx.FR_MATCHCASE > 0
-        regExp = flags & FindService.FindService.FR_REGEXP > 0
-        down = flags & wx.FR_DOWN > 0
-        wrap = flags & FindService.FindService.FR_WRAP > 0
-
-        if forceFindPrevious:   # this is from function keys, not dialog box
-            down = False
-            wrap = False        # user would want to know they're at the end of file
-        elif forceFindNext:
-            down = True
-            wrap = False        # user would want to know they're at the end of file
-
-        # On replace dialog operations, user is allowed to replace the currently highlighted text to determine if it should be replaced or not.
-        # Typically, it is the text from a previous find operation, but we must check to see if it isn't, user may have moved the cursor or selected some other text accidentally.
-        # If the text is a match, then replace it.
-        if replace:
-            result, start, end, replText = findService.DoFind(findString, replaceString, self._textCtrl.GetStringSelection(), 0, 0, True, matchCase, wholeWord, regExp, replace)
-            if result > 0:
-                self._textCtrl.Replace(startLoc, endLoc, replaceString)
-                self.GetDocument().Modify(True)
-                wx.GetApp().GetTopWindow().PushStatusText(_("1 occurrence of \"%s\" replaced") % findString)
-                if down:
-                    startLoc += len(replText)  # advance start location past replacement string to new text
-                endLoc = startLoc
-
-        text = self._textCtrl.GetValue()
-        if wx.Platform == "__WXMSW__":
-            text = string.replace(text, '\n', '\r\n')
-
-        # Find the next matching text occurance or if it is a ReplaceAll, replace all occurances
-        # Even if the user is Replacing, we should replace here, but only select the text and let the user replace it with the next Replace operation
-        result, start, end, text = findService.DoFind(findString, replaceString, text, startLoc, endLoc, down, matchCase, wholeWord, regExp, False, replaceAll, wrap)
-        if result > 0:
-            self._textCtrl.SetValue(text)
-            self.GetDocument().Modify(True)
-            if result == 1:
-                wx.GetApp().GetTopWindow().PushStatusText(_("1 occurrence of \"%s\" replaced") % findString)
-            else:
-                wx.GetApp().GetTopWindow().PushStatusText(_("%i occurrences of \"%s\" replaced") % (result, findString))
-        elif result == 0:
-            self._textCtrl.SetSelection(start, end)
-            self._textCtrl.SetFocus()
-            wx.GetApp().GetTopWindow().PushStatusText(_("Found \"%s\"") % findString)
-        else:
-            wx.GetApp().GetTopWindow().PushStatusText(_("Can't find \"%s\"") % findString)
-
-
-    def _FindServiceHasString(self):
-        findService = wx.GetApp().GetService(FindService.FindService)
-        if not findService or not findService.GetFindString():
-            return False
-        return True
-
-
-    def OnGotoLine(self, event):
-        findService = wx.GetApp().GetService(FindService.FindService)
-        if findService:
-            line = findService.GetLineNumber(self.GetDocumentManager().FindSuitableParent())
-            if line > -1:
-                pos = self._textCtrl.XYToPosition(0, line - 1)
-                self._textCtrl.SetSelection(pos, pos)
-
-
-class TextService(wx.lib.pydocview.DocService):
-
-
-    WORD_WRAP_ID = wx.NewId()
-    CHOOSE_FONT_ID = wx.NewId()
-
-
-    def __init__(self):
-        wx.lib.pydocview.DocService.__init__(self)
-
-
-    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
-        if document and document.GetDocumentTemplate().GetDocumentType() != TextDocument:
-            return
-        config = wx.ConfigBase_Get()
-
-        formatMenuIndex = menuBar.FindMenu(_("&Format"))
-        if formatMenuIndex > -1:
-            formatMenu = menuBar.GetMenu(formatMenuIndex)
-        else:
-            formatMenu = wx.Menu()
-        formatMenu = wx.Menu()
-        if not menuBar.FindItemById(TextService.WORD_WRAP_ID):
-            formatMenu.AppendCheckItem(TextService.WORD_WRAP_ID, _("Word Wrap"), _("Wraps text horizontally when checked"))
-            formatMenu.Check(TextService.WORD_WRAP_ID, config.ReadInt("TextEditorWordWrap", True))
-            wx.EVT_MENU(frame, TextService.WORD_WRAP_ID, frame.ProcessEvent)
-            wx.EVT_UPDATE_UI(frame, TextService.WORD_WRAP_ID, frame.ProcessUpdateUIEvent)
-        if not menuBar.FindItemById(TextService.CHOOSE_FONT_ID):
-            formatMenu.Append(TextService.CHOOSE_FONT_ID, _("Font..."), _("Sets the font to use"))
-            wx.EVT_MENU(frame, TextService.CHOOSE_FONT_ID, frame.ProcessEvent)
-            wx.EVT_UPDATE_UI(frame, TextService.CHOOSE_FONT_ID, frame.ProcessUpdateUIEvent)
-        if formatMenuIndex == -1:
-            viewMenuIndex = menuBar.FindMenu(_("&View"))
-            menuBar.Insert(viewMenuIndex + 1, formatMenu, _("&Format"))
-
-
-    def ProcessUpdateUIEvent(self, event):
-        id = event.GetId()
-        if id == TextService.CHOOSE_FONT_ID:
-            event.Enable(False)
-            return True
-        elif id == TextService.WORD_WRAP_ID:
-            event.Enable(False)
-            return True
-        else:
-            return False
-
-
-class TextOptionsPanel(wx.Panel):
-
-
-    def __init__(self, parent, id):
-        wx.Panel.__init__(self, parent, id)
-        SPACE = 10
-        HALF_SPACE   = 5
-        config = wx.ConfigBase_Get()
-        self._textFont = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
-        fontData = config.Read("TextEditorFont", "")
-        if fontData:
-            nativeFont = wx.NativeFontInfo()
-            nativeFont.FromString(fontData)
-            self._textFont.SetNativeFontInfo(nativeFont)
-        self._originalTextFont = self._textFont
-        self._textColor = wx.BLACK
-        colorData = config.Read("TextEditorColor", "")
-        if colorData:
-            red = int("0x" + colorData[0:2], 16)
-            green = int("0x" + colorData[2:4], 16)
-            blue = int("0x" + colorData[4:6], 16)
-            self._textColor = wx.Color(red, green, blue)
-        self._originalTextColor = self._textColor
-        parent.AddPage(self, _("Text"))
-        fontLabel = wx.StaticText(self, -1, _("Font:"))
-        self._sampleTextCtrl = wx.TextCtrl(self, -1, "", size = (125, -1))
-        self._sampleTextCtrl.SetEditable(False)
-        chooseFontButton = wx.Button(self, -1, _("Choose Font..."))
-        wx.EVT_BUTTON(self, chooseFontButton.GetId(), self.OnChooseFont)
-        self._wordWrapCheckBox = wx.CheckBox(self, -1, _("Wrap words inside text area"))
-        self._wordWrapCheckBox.SetValue(wx.ConfigBase_Get().ReadInt("TextEditorWordWrap", True))
-        textPanelBorderSizer = wx.BoxSizer(wx.VERTICAL)
-        textPanelSizer = wx.BoxSizer(wx.VERTICAL)
-        textFontSizer = wx.BoxSizer(wx.HORIZONTAL)
-        textFontSizer.Add(fontLabel, 0, wx.ALIGN_LEFT | wx.RIGHT | wx.TOP, HALF_SPACE)
-        textFontSizer.Add(self._sampleTextCtrl, 0, wx.ALIGN_LEFT | wx.EXPAND | wx.RIGHT, HALF_SPACE)
-        textFontSizer.Add(chooseFontButton, 0, wx.ALIGN_RIGHT | wx.LEFT, HALF_SPACE)
-        textPanelSizer.Add(textFontSizer, 0, wx.ALL, HALF_SPACE)
-        textPanelSizer.Add(self._wordWrapCheckBox, 0, wx.ALL, HALF_SPACE)
-        textPanelBorderSizer.Add(textPanelSizer, 0, wx.ALL, SPACE)
-        self.SetSizer(textPanelBorderSizer)
-        self.UpdateSampleFont()
-
-
-    def UpdateSampleFont(self):
-        nativeFont = wx.NativeFontInfo()
-        nativeFont.FromString(self._textFont.GetNativeFontInfoDesc())
-        font = wx.NullFont
-        font.SetNativeFontInfo(nativeFont)
-        font.SetPointSize(self._sampleTextCtrl.GetFont().GetPointSize())  # Use the standard point size
-        self._sampleTextCtrl.SetFont(font)
-        self._sampleTextCtrl.SetForegroundColour(self._textColor)
-        self._sampleTextCtrl.SetValue(_("%d pt. %s") % (self._textFont.GetPointSize(), self._textFont.GetFaceName()))
-        self._sampleTextCtrl.Refresh()
-        self.Layout()
-
-
-    def OnChooseFont(self, event):
-        data = wx.FontData()
-        data.EnableEffects(True)
-        data.SetInitialFont(self._textFont)
-        data.SetColour(self._textColor)
-        fontDialog = wx.FontDialog(self, data)
-        if fontDialog.ShowModal() == wx.ID_OK:
-            data = fontDialog.GetFontData()
-            self._textFont = data.GetChosenFont()
-            self._textColor = data.GetColour()
-            self.UpdateSampleFont()
-        fontDialog.Destroy()
-
-
-    def OnOK(self, optionsDialog):
-        config = wx.ConfigBase_Get()
-        doWordWrapUpdate = config.ReadInt("TextEditorWordWrap", True) != self._wordWrapCheckBox.GetValue()
-        config.WriteInt("TextEditorWordWrap", self._wordWrapCheckBox.GetValue())
-        doFontUpdate = self._originalTextFont != self._textFont or self._originalTextColor != self._textColor
-        config.Write("TextEditorFont", self._textFont.GetNativeFontInfoDesc())
-        config.Write("TextEditorColor", "%02x%02x%02x" % (self._textColor.Red(), self._textColor.Green(), self._textColor.Blue()))
-        if doWordWrapUpdate or doFontUpdate:
-            for document in optionsDialog.GetDocManager().GetDocuments():
-                if document.GetDocumentTemplate().GetDocumentType() == TextDocument:
-                    if doWordWrapUpdate:
-                        document.UpdateAllViews(hint = "Word Wrap")
-                    if doFontUpdate:
-                        document.UpdateAllViews(hint = "Font")
diff --git a/wxPython/samples/docview/activegrid/tool/__init__.py b/wxPython/samples/docview/activegrid/tool/__init__.py
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/wxPython/samples/docview/activegrid/tool/data/tips.txt b/wxPython/samples/docview/activegrid/tool/data/tips.txt
deleted file mode 100644 (file)
index f102916..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-Tips for PyDocViewDemo App
-wxWindows rules!
-Use the source, Luke!
\ No newline at end of file
diff --git a/wxPython/samples/docview/activegrid/tool/images/splash.jpg b/wxPython/samples/docview/activegrid/tool/images/splash.jpg
deleted file mode 100644 (file)
index 2416247..0000000
Binary files a/wxPython/samples/docview/activegrid/tool/images/splash.jpg and /dev/null differ
diff --git a/wxPython/samples/pydocview/FindService.py b/wxPython/samples/pydocview/FindService.py
new file mode 100644 (file)
index 0000000..6a7e8c5
--- /dev/null
@@ -0,0 +1,521 @@
+#----------------------------------------------------------------------------
+# Name:         FindService.py
+# Purpose:      Find Service for pydocview
+#
+# Author:       Peter Yared, Morgan Hua
+#
+# Created:      8/15/03
+# CVS-ID:       $Id$
+# Copyright:    (c) 2003-2005 ActiveGrid, Inc.
+# License:      ASL 2.0  http://apache.org/licenses/LICENSE-2.0
+#----------------------------------------------------------------------------
+
+import wx
+import wx.lib.docview
+import wx.lib.pydocview
+import re
+_ = wx.GetTranslation
+
+
+#----------------------------------------------------------------------------
+# Constants
+#----------------------------------------------------------------------------
+FIND_MATCHPATTERN = "FindMatchPattern"
+FIND_MATCHREPLACE = "FindMatchReplace"
+FIND_MATCHCASE = "FindMatchCase"
+FIND_MATCHWHOLEWORD = "FindMatchWholeWordOnly"
+FIND_MATCHREGEXPR = "FindMatchRegularExpr"
+FIND_MATCHWRAP = "FindMatchWrap"
+FIND_MATCHUPDOWN = "FindMatchUpDown"
+
+FIND_SYNTAXERROR = -2
+
+SPACE = 10
+HALF_SPACE = 5
+
+
+#----------------------------------------------------------------------------
+# Classes
+#----------------------------------------------------------------------------
+
+class FindService(wx.lib.pydocview.DocService):
+
+    #----------------------------------------------------------------------------
+    # Constants
+    #----------------------------------------------------------------------------
+    FIND_ID = wx.NewId()            # for bringing up Find dialog box
+    FINDONE_ID = wx.NewId()         # for doing Find
+    FIND_PREVIOUS_ID = wx.NewId()   # for doing Find Next
+    FIND_NEXT_ID = wx.NewId()       # for doing Find Prev
+    REPLACE_ID = wx.NewId()         # for bringing up Replace dialog box
+    REPLACEONE_ID = wx.NewId()      # for doing a Replace
+    REPLACEALL_ID = wx.NewId()      # for doing Replace All
+    GOTO_LINE_ID = wx.NewId()       # for bringing up Goto dialog box
+
+    # Extending bitmasks: wx.FR_WHOLEWORD, wx.FR_MATCHCASE, and wx.FR_DOWN
+    FR_REGEXP = max([wx.FR_WHOLEWORD, wx.FR_MATCHCASE, wx.FR_DOWN]) << 1
+    FR_WRAP = FR_REGEXP << 1
+
+
+    def __init__(self):
+        self._replaceDialog = None
+        self._findDialog = None
+        self._findReplaceData = wx.FindReplaceData()
+        self._findReplaceData.SetFlags(wx.FR_DOWN)
+
+
+    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
+        """ Install Find Service Menu Items """
+        editMenu = menuBar.GetMenu(menuBar.FindMenu(_("&Edit")))
+        editMenu.AppendSeparator()
+        editMenu.Append(FindService.FIND_ID, _("&Find...\tCtrl+F"), _("Finds the specified text"))
+        wx.EVT_MENU(frame, FindService.FIND_ID, frame.ProcessEvent)
+        wx.EVT_UPDATE_UI(frame, FindService.FIND_ID, frame.ProcessUpdateUIEvent)
+        editMenu.Append(FindService.FIND_PREVIOUS_ID, _("Find &Previous\tShift+F3"), _("Finds the specified text"))
+        wx.EVT_MENU(frame, FindService.FIND_PREVIOUS_ID, frame.ProcessEvent)
+        wx.EVT_UPDATE_UI(frame, FindService.FIND_PREVIOUS_ID, frame.ProcessUpdateUIEvent)
+        editMenu.Append(FindService.FIND_NEXT_ID, _("Find &Next\tF3"), _("Finds the specified text"))
+        wx.EVT_MENU(frame, FindService.FIND_NEXT_ID, frame.ProcessEvent)
+        wx.EVT_UPDATE_UI(frame, FindService.FIND_NEXT_ID, frame.ProcessUpdateUIEvent)
+        editMenu.Append(FindService.REPLACE_ID, _("R&eplace...\tCtrl+H"), _("Replaces specific text with different text"))
+        wx.EVT_MENU(frame, FindService.REPLACE_ID, frame.ProcessEvent)
+        wx.EVT_UPDATE_UI(frame, FindService.REPLACE_ID, frame.ProcessUpdateUIEvent)
+        editMenu.Append(FindService.GOTO_LINE_ID, _("&Go to Line...\tCtrl+G"), _("Goes to a certain line in the file"))
+        wx.EVT_MENU(frame, FindService.GOTO_LINE_ID, frame.ProcessEvent)
+        wx.EVT_UPDATE_UI(frame, FindService.GOTO_LINE_ID, frame.ProcessUpdateUIEvent)
+
+        # wxBug: wxToolBar::GetToolPos doesn't exist, need it to find cut tool and then insert find in front of it.
+        toolBar.InsertTool(6, FindService.FIND_ID, getFindBitmap(), shortHelpString = _("Find"), longHelpString = _("Finds the specified text"))
+        toolBar.InsertSeparator(6)
+        toolBar.Realize()
+
+        frame.Bind(wx.EVT_FIND, frame.ProcessEvent)
+        frame.Bind(wx.EVT_FIND_NEXT, frame.ProcessEvent)
+        frame.Bind(wx.EVT_FIND_REPLACE, frame.ProcessEvent)
+        frame.Bind(wx.EVT_FIND_REPLACE_ALL, frame.ProcessEvent)
+
+
+    def ProcessUpdateUIEvent(self, event):
+        id = event.GetId()
+        if id == FindService.FIND_ID:
+            event.Enable(False)
+            return True
+        elif id == FindService.FIND_PREVIOUS_ID:
+            event.Enable(False)
+            return True
+        elif id == FindService.FIND_NEXT_ID:
+            event.Enable(False)
+            return True
+        elif id == FindService.REPLACE_ID:
+            event.Enable(False)
+            return True
+        elif id == FindService.GOTO_LINE_ID:
+            event.Enable(False)
+            return True
+        else:
+            return False
+
+
+    def ShowFindReplaceDialog(self, findString="", replace = False):
+        """ Display find/replace dialog box.
+        
+            Parameters: findString is the default value shown in the find/replace dialog input field.
+            If replace is True, the replace dialog box is shown, otherwise only the find dialog box is shown. 
+        """
+        if replace:
+            if self._findDialog != None:
+                # No reason to have both find and replace dialogs up at the same time
+                self._findDialog.DoClose()
+                self._findDialog = None
+
+            self._replaceDialog = FindReplaceDialog(self.GetDocumentManager().FindSuitableParent(), -1, _("Replace"), size=(320,200), findString=findString)
+            self._replaceDialog.Show(True)
+        else:
+            if self._replaceDialog != None:
+                # No reason to have both find and replace dialogs up at the same time
+                self._replaceDialog.DoClose()
+                self._replaceDialog = None
+
+            self._findDialog = FindDialog(self.GetDocumentManager().FindSuitableParent(), -1, _("Find"), size=(320,200), findString=findString)
+            self._findDialog.Show(True)
+
+
+
+    def OnFindClose(self, event):
+        """ Cleanup handles when find/replace dialog is closed """
+        if self._findDialog != None:
+            self._findDialog = None
+        elif self._replaceDialog != None:
+            self._replaceDialog = None
+
+
+    def GetCurrentDialog(self):
+        """ return handle to either the find or replace dialog """
+        if self._findDialog != None:
+            return self._findDialog
+        return self._replaceDialog
+
+
+    def GetLineNumber(self, parent):
+        """ Display Goto Line Number dialog box """
+        line = -1
+        dialog = wx.TextEntryDialog(parent, _("Enter line number to go to:"), _("Go to Line"))
+        if dialog.ShowModal() == wx.ID_OK:
+            try:
+                line = int(dialog.GetValue())
+                if line > 65535:
+                    line = 65535
+            except:
+                pass
+        dialog.Destroy()
+        # This one is ugly:  wx.GetNumberFromUser("", _("Enter line number to go to:"), _("Go to Line"), 1, min = 1, max = 65535, parent = parent)
+        return line
+
+
+    def DoFind(self, findString, replaceString, text, startLoc, endLoc, down, matchCase, wholeWord, regExpr = False, replace = False, replaceAll = False, wrap = False):
+        """ Do the actual work of the find/replace.
+        
+            Returns the tuple (count, start, end, newText).
+            count = number of string replacements
+            start = start position of found string
+            end = end position of found string
+            newText = new replaced text 
+        """
+        flags = 0
+        if regExpr:
+            pattern = findString
+        else:
+            pattern = re.escape(findString)  # Treat the strings as a literal string
+        if not matchCase:
+            flags = re.IGNORECASE
+        if wholeWord:
+            pattern = r"\b%s\b" % pattern
+            
+        try:
+            reg = re.compile(pattern, flags)
+        except:
+            # syntax error of some sort
+            import sys
+            msgTitle = wx.GetApp().GetAppName()
+            if not msgTitle:
+                msgTitle = _("Regular Expression Search")
+            wx.MessageBox(_("Invalid regular expression \"%s\". %s") % (pattern, sys.exc_value),
+                          msgTitle,
+                          wx.OK | wx.ICON_EXCLAMATION,
+                          self.GetView())
+            return FIND_SYNTAXERROR, None, None, None
+
+        if replaceAll:
+            newText, count = reg.subn(replaceString, text)
+            if count == 0:
+                return -1, None, None, None
+            else:
+                return count, None, None, newText
+
+        start = -1
+        if down:
+            match = reg.search(text, endLoc)
+            if match == None:
+                if wrap:  # try again, but this time from top of file
+                    match = reg.search(text, 0)
+                    if match == None:
+                        return -1, None, None, None
+                else:
+                    return -1, None, None, None
+            start = match.start()
+            end = match.end()
+        else:
+            match = reg.search(text)
+            if match == None:
+                return -1, None, None, None
+            found = None
+            i, j = match.span()
+            while i < startLoc and j <= startLoc:
+                found = match
+                if i == j:
+                    j = j + 1
+                match = reg.search(text, j)
+                if match == None:
+                    break
+                i, j = match.span()
+            if found == None:
+                if wrap:  # try again, but this time from bottom of file
+                    match = reg.search(text, startLoc)
+                    if match == None:
+                        return -1, None, None, None
+                    found = None
+                    i, j = match.span()
+                    end = len(text)
+                    while i < end and j <= end:
+                        found = match
+                        if i == j:
+                            j = j + 1
+                        match = reg.search(text, j)
+                        if match == None:
+                            break
+                        i, j = match.span()
+                    if found == None:
+                        return -1, None, None, None
+                else:
+                    return -1, None, None, None
+            start = found.start()
+            end = found.end()
+
+        if replace and start != -1:
+            newText, count = reg.subn(replaceString, text, 1)
+            return count, start, end, newText
+
+        return 0, start, end, None
+
+
+    def SaveFindConfig(self, findString, wholeWord, matchCase, regExpr = None, wrap = None, upDown = None, replaceString = None):
+        """ Save find/replace patterns and search flags to registry.
+        
+            findString = search pattern
+            wholeWord = match whole word only
+            matchCase = match case
+            regExpr = use regular expressions in search pattern
+            wrap = return to top/bottom of file on search
+            upDown = search up or down from current cursor position
+            replaceString = replace string
+        """
+        config = wx.ConfigBase_Get()
+
+        config.Write(FIND_MATCHPATTERN, findString)
+        config.WriteInt(FIND_MATCHCASE, matchCase)
+        config.WriteInt(FIND_MATCHWHOLEWORD, wholeWord)
+        if replaceString != None:
+            config.Write(FIND_MATCHREPLACE, replaceString)
+        if regExpr != None:
+            config.WriteInt(FIND_MATCHREGEXPR, regExpr)
+        if wrap != None:
+            config.WriteInt(FIND_MATCHWRAP, wrap)
+        if upDown != None:
+            config.WriteInt(FIND_MATCHUPDOWN, upDown)
+
+
+    def GetFindString(self):
+        """ Load the search pattern from registry """
+        return wx.ConfigBase_Get().Read(FIND_MATCHPATTERN, "")
+
+
+    def GetReplaceString(self):
+        """ Load the replace pattern from registry """
+        return wx.ConfigBase_Get().Read(FIND_MATCHREPLACE, "")
+
+
+    def GetFlags(self):
+        """ Load search parameters from registry """
+        config = wx.ConfigBase_Get()
+
+        flags = 0
+        if config.ReadInt(FIND_MATCHWHOLEWORD, False):
+            flags = flags | wx.FR_WHOLEWORD
+        if config.ReadInt(FIND_MATCHCASE, False):
+            flags = flags | wx.FR_MATCHCASE
+        if config.ReadInt(FIND_MATCHUPDOWN, False):
+            flags = flags | wx.FR_DOWN
+        if config.ReadInt(FIND_MATCHREGEXPR, False):
+            flags = flags | FindService.FR_REGEXP
+        if config.ReadInt(FIND_MATCHWRAP, False):
+            flags = flags | FindService.FR_WRAP
+        return flags
+
+
+class FindDialog(wx.Dialog):
+    """ Find Dialog with regular expression matching and wrap to top/bottom of file. """
+
+    def __init__(self, parent, id, title, size, findString=None):
+        wx.Dialog.__init__(self, parent, id, title, size=size)
+
+        config = wx.ConfigBase_Get()
+        borderSizer = wx.BoxSizer(wx.VERTICAL)
+        gridSizer = wx.GridBagSizer(SPACE, SPACE)
+
+        lineSizer = wx.BoxSizer(wx.HORIZONTAL)
+        lineSizer.Add(wx.StaticText(self, -1, _("Find what:")), 0, wx.ALIGN_CENTER_VERTICAL|wx.RIGHT, SPACE)
+        if not findString:
+            findString = config.Read(FIND_MATCHPATTERN, "")
+        self._findCtrl = wx.TextCtrl(self, -1, findString, size=(200,-1))
+        lineSizer.Add(self._findCtrl, 0)
+        gridSizer.Add(lineSizer, pos=(0,0), span=(1,2))
+        choiceSizer = wx.BoxSizer(wx.VERTICAL)
+        self._wholeWordCtrl = wx.CheckBox(self, -1, _("Match whole word only"))
+        self._wholeWordCtrl.SetValue(config.ReadInt(FIND_MATCHWHOLEWORD, False))
+        self._matchCaseCtrl = wx.CheckBox(self, -1, _("Match case"))
+        self._matchCaseCtrl.SetValue(config.ReadInt(FIND_MATCHCASE, False))
+        self._regExprCtrl = wx.CheckBox(self, -1, _("Regular expression"))
+        self._regExprCtrl.SetValue(config.ReadInt(FIND_MATCHREGEXPR, False))
+        self._wrapCtrl = wx.CheckBox(self, -1, _("Wrap"))
+        self._wrapCtrl.SetValue(config.ReadInt(FIND_MATCHWRAP, False))
+        choiceSizer.Add(self._wholeWordCtrl, 0, wx.BOTTOM, SPACE)
+        choiceSizer.Add(self._matchCaseCtrl, 0, wx.BOTTOM, SPACE)
+        choiceSizer.Add(self._regExprCtrl, 0, wx.BOTTOM, SPACE)
+        choiceSizer.Add(self._wrapCtrl, 0)
+        gridSizer.Add(choiceSizer, pos=(1,0), span=(2,1))
+
+        self._radioBox = wx.RadioBox(self, -1, _("Direction"), choices = ["Up", "Down"])
+        self._radioBox.SetSelection(config.ReadInt(FIND_MATCHUPDOWN, 1))
+        gridSizer.Add(self._radioBox, pos=(1,1), span=(2,1))
+
+        buttonSizer = wx.BoxSizer(wx.VERTICAL)
+        findBtn = wx.Button(self, FindService.FINDONE_ID, _("Find Next"))
+        findBtn.SetDefault()
+        wx.EVT_BUTTON(self, FindService.FINDONE_ID, self.OnActionEvent)
+        cancelBtn = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
+        wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnClose)
+        buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
+        buttonSizer.Add(cancelBtn, 0)
+        gridSizer.Add(buttonSizer, pos=(0,2), span=(3,1))
+
+        borderSizer.Add(gridSizer, 0, wx.ALL, SPACE)
+
+        self.Bind(wx.EVT_CLOSE, self.OnClose)
+
+        self.SetSizer(borderSizer)
+        self.Fit()
+        self._findCtrl.SetFocus()
+
+    def SaveConfig(self):
+        """ Save find patterns and search flags to registry. """
+        findService = wx.GetApp().GetService(FindService)
+        if findService:
+            findService.SaveFindConfig(self._findCtrl.GetValue(),
+                                       self._wholeWordCtrl.IsChecked(),
+                                       self._matchCaseCtrl.IsChecked(),
+                                       self._regExprCtrl.IsChecked(),
+                                       self._wrapCtrl.IsChecked(),
+                                       self._radioBox.GetSelection(),
+                                       )
+
+
+    def DoClose(self):
+        self.SaveConfig()
+        self.Destroy()
+
+
+    def OnClose(self, event):
+        findService = wx.GetApp().GetService(FindService)
+        if findService:
+            findService.OnFindClose(event)
+        self.DoClose()
+
+
+    def OnActionEvent(self, event):
+        self.SaveConfig()
+
+        if wx.GetApp().GetDocumentManager().GetFlags() & wx.lib.docview.DOC_MDI:
+            if wx.GetApp().GetTopWindow().ProcessEvent(event):
+                return True
+        else:
+            view = wx.GetApp().GetDocumentManager().GetLastActiveView()
+            if view and view.ProcessEvent(event):
+                return True
+        return False
+
+
+class FindReplaceDialog(FindDialog):
+    """ Find/Replace Dialog with regular expression matching and wrap to top/bottom of file. """
+
+    def __init__(self, parent, id, title, size, findString=None):
+        wx.Dialog.__init__(self, parent, id, title, size=size)
+
+        config = wx.ConfigBase_Get()
+        borderSizer = wx.BoxSizer(wx.VERTICAL)
+        gridSizer = wx.GridBagSizer(SPACE, SPACE)
+
+        gridSizer2 = wx.GridBagSizer(SPACE, SPACE)
+        gridSizer2.Add(wx.StaticText(self, -1, _("Find what:")), flag=wx.ALIGN_CENTER_VERTICAL, pos=(0,0))
+        if not findString:
+            findString = config.Read(FIND_MATCHPATTERN, "")
+        self._findCtrl = wx.TextCtrl(self, -1, findString, size=(200,-1))
+        gridSizer2.Add(self._findCtrl, pos=(0,1))
+        gridSizer2.Add(wx.StaticText(self, -1, _("Replace with:")), flag=wx.ALIGN_CENTER_VERTICAL, pos=(1,0))
+        self._replaceCtrl = wx.TextCtrl(self, -1, config.Read(FIND_MATCHREPLACE, ""), size=(200,-1))
+        gridSizer2.Add(self._replaceCtrl, pos=(1,1))
+        gridSizer.Add(gridSizer2, pos=(0,0), span=(1,2))
+        choiceSizer = wx.BoxSizer(wx.VERTICAL)
+        self._wholeWordCtrl = wx.CheckBox(self, -1, _("Match whole word only"))
+        self._wholeWordCtrl.SetValue(config.ReadInt(FIND_MATCHWHOLEWORD, False))
+        self._matchCaseCtrl = wx.CheckBox(self, -1, _("Match case"))
+        self._matchCaseCtrl.SetValue(config.ReadInt(FIND_MATCHCASE, False))
+        self._regExprCtrl = wx.CheckBox(self, -1, _("Regular expression"))
+        self._regExprCtrl.SetValue(config.ReadInt(FIND_MATCHREGEXPR, False))
+        self._wrapCtrl = wx.CheckBox(self, -1, _("Wrap"))
+        self._wrapCtrl.SetValue(config.ReadInt(FIND_MATCHWRAP, False))
+        choiceSizer.Add(self._wholeWordCtrl, 0, wx.BOTTOM, SPACE)
+        choiceSizer.Add(self._matchCaseCtrl, 0, wx.BOTTOM, SPACE)
+        choiceSizer.Add(self._regExprCtrl, 0, wx.BOTTOM, SPACE)
+        choiceSizer.Add(self._wrapCtrl, 0)
+        gridSizer.Add(choiceSizer, pos=(1,0), span=(2,1))
+
+        self._radioBox = wx.RadioBox(self, -1, _("Direction"), choices = ["Up", "Down"])
+        self._radioBox.SetSelection(config.ReadInt(FIND_MATCHUPDOWN, 1))
+        gridSizer.Add(self._radioBox, pos=(1,1), span=(2,1))
+
+        buttonSizer = wx.BoxSizer(wx.VERTICAL)
+        findBtn = wx.Button(self, FindService.FINDONE_ID, _("Find Next"))
+        findBtn.SetDefault()
+        wx.EVT_BUTTON(self, FindService.FINDONE_ID, self.OnActionEvent)
+        cancelBtn = wx.Button(self, wx.ID_CANCEL, _("Cancel"))
+        wx.EVT_BUTTON(self, wx.ID_CANCEL, self.OnClose)
+        replaceBtn = wx.Button(self, FindService.REPLACEONE_ID, _("Replace"))
+        wx.EVT_BUTTON(self, FindService.REPLACEONE_ID, self.OnActionEvent)
+        replaceAllBtn = wx.Button(self, FindService.REPLACEALL_ID, _("Replace All"))
+        wx.EVT_BUTTON(self, FindService.REPLACEALL_ID, self.OnActionEvent)
+        buttonSizer.Add(findBtn, 0, wx.BOTTOM, HALF_SPACE)
+        buttonSizer.Add(replaceBtn, 0, wx.BOTTOM, HALF_SPACE)
+        buttonSizer.Add(replaceAllBtn, 0, wx.BOTTOM, HALF_SPACE)
+        buttonSizer.Add(cancelBtn, 0)
+        gridSizer.Add(buttonSizer, pos=(0,2), span=(3,1))
+
+        borderSizer.Add(gridSizer, 0, wx.ALL, SPACE)
+
+        self.Bind(wx.EVT_CLOSE, self.OnClose)
+
+        self.SetSizer(borderSizer)
+        self.Fit()
+        self._findCtrl.SetFocus()
+        
+
+    def SaveConfig(self):
+        """ Save find/replace patterns and search flags to registry. """
+        findService = wx.GetApp().GetService(FindService)
+        if findService:
+            findService.SaveFindConfig(self._findCtrl.GetValue(),
+                                       self._wholeWordCtrl.IsChecked(),
+                                       self._matchCaseCtrl.IsChecked(),
+                                       self._regExprCtrl.IsChecked(),
+                                       self._wrapCtrl.IsChecked(),
+                                       self._radioBox.GetSelection(),
+                                       self._replaceCtrl.GetValue()
+                                       )
+
+
+#----------------------------------------------------------------------------
+# Menu Bitmaps - generated by encode_bitmaps.py
+#----------------------------------------------------------------------------
+from wx import ImageFromStream, BitmapFromImage
+import cStringIO
+
+
+def getFindData():
+    return \
+'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
+\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
+\x00\x00\x81IDAT8\x8d\xa5S\xc1\x16\xc0\x10\x0ckk\xff\xff\xc7d\x87\xad^U\r\
+\x93S\xe5U$\n\xb3$:\xc1e\x17(\x19Z\xb3$\x9e\xf1DD\xe2\x15\x01x\xea\x93\xef\
+\x04\x989\xea\x1b\xf2U\xc0\xda\xb4\xeb\x11\x1f:\xd8\xb5\xff8\x93\xd4\xa9\xae\
+@/S\xaaUwJ3\x85\xc0\x81\xee\xeb.q\x17C\x81\xd5XU \x1a\x93\xc6\x18\x8d\x90\
+\xe8}\x89\x00\x9a&\x9b_k\x94\x0c\xdf\xd78\xf8\x0b\x99Y\xb4\x08c\x9e\xfe\xc6\
+\xe3\x087\xf9\xd0D\x180\xf1#\x8e\x00\x00\x00\x00IEND\xaeB`\x82' 
+
+
+def getFindBitmap():
+    return BitmapFromImage(getFindImage())
+
+
+def getFindImage():
+    stream = cStringIO.StringIO(getFindData())
+    return ImageFromStream(stream)
+
diff --git a/wxPython/samples/pydocview/PyDocViewDemo.py b/wxPython/samples/pydocview/PyDocViewDemo.py
new file mode 100644 (file)
index 0000000..c898393
--- /dev/null
@@ -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()
diff --git a/wxPython/samples/pydocview/TextEditor.py b/wxPython/samples/pydocview/TextEditor.py
new file mode 100644 (file)
index 0000000..2e432cf
--- /dev/null
@@ -0,0 +1,551 @@
+#----------------------------------------------------------------------------
+# Name:         TextEditor.py
+# Purpose:      Text Editor for pydocview
+#
+# Author:       Peter Yared
+#
+# Created:      8/15/03
+# CVS-ID:       $Id$
+# Copyright:    (c) 2003-2005 ActiveGrid, Inc.
+# License:      ASL 2.0  http://apache.org/licenses/LICENSE-2.0
+#----------------------------------------------------------------------------
+import wx
+import wx.lib.docview
+import wx.lib.pydocview
+import string
+import FindService
+_ = wx.GetTranslation
+
+class TextDocument(wx.lib.docview.Document):
+
+
+    def OnSaveDocument(self, filename):
+        view = self.GetFirstView()
+        if not view.GetTextCtrl().SaveFile(filename):
+            return False
+        self.Modify(False)
+        self.SetDocumentSaved(True)
+        #if wx.Platform == "__WXMAC__":
+        #    fn = wx.Filename(filename)
+        #    fn.MacSetDefaultTypeAndCreator()
+        return True
+
+
+    def OnOpenDocument(self, filename):
+        view = self.GetFirstView()
+        if not view.GetTextCtrl().LoadFile(filename):
+            return False
+        self.SetFilename(filename, True)
+        self.Modify(False)
+        self.UpdateAllViews()
+        self._savedYet = True
+        return True
+
+
+    def IsModified(self):
+        view = self.GetFirstView()
+        if view and view.GetTextCtrl():
+            return wx.lib.docview.Document.IsModified(self) or view.GetTextCtrl().IsModified()
+        else:
+            return wx.lib.docview.Document.IsModified(self)
+
+
+    def Modify(self, mod):
+        view = self.GetFirstView()
+        wx.lib.docview.Document.Modify(self, mod)
+        if not mod and view and view.GetTextCtrl():
+            view.GetTextCtrl().DiscardEdits()
+
+
+class TextView(wx.lib.docview.View):
+
+
+    #----------------------------------------------------------------------------
+    # Overridden methods
+    #----------------------------------------------------------------------------
+
+    def __init__(self):
+        wx.lib.docview.View.__init__(self)
+        self._textCtrl = None
+        self._wordWrap = wx.ConfigBase_Get().ReadInt("TextEditorWordWrap", True)
+
+
+    def OnCreate(self, doc, flags):
+        frame = wx.GetApp().CreateDocumentFrame(self, doc, flags)
+        sizer = wx.BoxSizer()
+        font, color = self._GetFontAndColorFromConfig()
+        self._textCtrl = self._BuildTextCtrl(frame, font, color = color)
+        sizer.Add(self._textCtrl, 1, wx.EXPAND, 0)
+        frame.SetSizer(sizer)
+        frame.Layout()
+        frame.Show(True)
+        self.Activate()
+        return True
+
+
+    def _BuildTextCtrl(self, parent, font, color = wx.BLACK, value = "", selection = [0, 0]):
+        if self._wordWrap:
+            wordWrapStyle = wx.TE_WORDWRAP
+        else:
+            wordWrapStyle = wx.TE_DONTWRAP
+        textCtrl = wx.TextCtrl(parent, -1, pos = wx.DefaultPosition, size = parent.GetClientSize(), style = wx.TE_MULTILINE | wordWrapStyle)
+        textCtrl.SetFont(font)
+        textCtrl.SetForegroundColour(color)
+        textCtrl.SetValue(value)
+        return textCtrl
+
+
+    def _GetFontAndColorFromConfig(self):
+        font = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
+        config = wx.ConfigBase_Get()
+        fontData = config.Read("TextEditorFont", "")
+        if fontData:
+            nativeFont = wx.NativeFontInfo()
+            nativeFont.FromString(fontData)
+            font.SetNativeFontInfo(nativeFont)
+        color = wx.BLACK
+        colorData = config.Read("TextEditorColor", "")
+        if colorData:
+            red = int("0x" + colorData[0:2], 16)
+            green = int("0x" + colorData[2:4], 16)
+            blue = int("0x" + colorData[4:6], 16)
+            color = wx.Color(red, green, blue)
+        return font, color
+
+
+    def OnCreateCommandProcessor(self):
+        # Don't create a command processor, it has its own
+        pass
+
+
+    def OnActivateView(self, activate, activeView, deactiveView):
+        if activate and self._textCtrl:
+            # In MDI mode just calling set focus doesn't work and in SDI mode using CallAfter causes an endless loop
+            if self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI:
+                self._textCtrl.SetFocus()
+            else:
+                def SetFocusToTextCtrl():
+                    if self._textCtrl:  # Need to make sure it is there in case we are in the closeall mode of the MDI window
+                        self._textCtrl.SetFocus()
+                wx.CallAfter(SetFocusToTextCtrl)
+
+
+    def OnUpdate(self, sender = None, hint = None):
+        if hint == "Word Wrap":
+            self.SetWordWrap(wx.ConfigBase_Get().ReadInt("TextEditorWordWrap", True))
+        elif hint == "Font":
+            font, color = self._GetFontAndColorFromConfig()
+            self.SetFont(font, color)
+
+
+    def OnClose(self, deleteWindow = True):
+        if not wx.lib.docview.View.OnClose(self, deleteWindow):
+            return False
+        self.Activate(False)
+        if deleteWindow and self.GetFrame():
+            self.GetFrame().Destroy()
+        return True
+
+
+    # Since ProcessEvent is not virtual, we have to trap the relevant events using this pseudo-ProcessEvent instead of EVT_MENU
+    def ProcessEvent(self, event):
+        id = event.GetId()
+        if id == wx.ID_UNDO:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.Undo()
+            return True
+        elif id == wx.ID_REDO:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.Redo()
+            return True
+        elif id == wx.ID_CUT:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.Cut()
+            return True
+        elif id == wx.ID_COPY:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.Copy()
+            return True
+        elif id == wx.ID_PASTE:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.Paste()
+            return True
+        elif id == wx.ID_CLEAR:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.Replace(self._textCtrl.GetSelection()[0], self._textCtrl.GetSelection()[1], '')
+            return True
+        elif id == wx.ID_SELECTALL:
+            if not self._textCtrl:
+                return False
+            self._textCtrl.SetSelection(-1, -1)
+            return True
+        elif id == TextService.CHOOSE_FONT_ID:
+            if not self._textCtrl:
+                return False
+            self.OnChooseFont(event)
+            return True
+        elif id == TextService.WORD_WRAP_ID:
+            if not self._textCtrl:
+                return False
+            self.OnWordWrap(event)
+            return True
+        elif id == FindService.FindService.FIND_ID:
+            self.OnFind()
+            return True
+        elif id == FindService.FindService.FIND_PREVIOUS_ID:
+            self.DoFind(forceFindPrevious = True)
+            return True
+        elif id == FindService.FindService.FIND_NEXT_ID:
+            self.DoFind(forceFindNext = True)
+            return True
+        elif id == FindService.FindService.REPLACE_ID:
+            self.OnFind(replace = True)
+            return True
+        elif id == FindService.FindService.FINDONE_ID:
+            self.DoFind()
+            return True
+        elif id == FindService.FindService.REPLACEONE_ID:
+            self.DoFind(replace = True)
+            return True
+        elif id == FindService.FindService.REPLACEALL_ID:
+            self.DoFind(replaceAll = True)
+            return True
+        elif id == FindService.FindService.GOTO_LINE_ID:
+            self.OnGotoLine(event)
+            return True
+        else:
+            return wx.lib.docview.View.ProcessEvent(self, event)
+
+
+    def ProcessUpdateUIEvent(self, event):
+        if not self._textCtrl:
+            return False
+
+        hasText = len(self._textCtrl.GetValue()) > 0
+
+        id = event.GetId()
+        if id == wx.ID_UNDO:
+            event.Enable(self._textCtrl.CanUndo())
+            return True
+        elif id == wx.ID_REDO:
+            event.Enable(self._textCtrl.CanRedo())
+            return True
+        if id == wx.ID_CUT:
+            event.Enable(self._textCtrl.CanCut())
+            return True
+        elif id == wx.ID_COPY:
+            event.Enable(self._textCtrl.CanCopy())
+            return True
+        elif id == wx.ID_PASTE:
+            event.Enable(self._textCtrl.CanPaste())
+            return True
+        elif id == wx.ID_CLEAR:
+            event.Enable(self._textCtrl.CanCopy())
+            return True
+        elif id == wx.ID_SELECTALL:
+            event.Enable(hasText)
+            return True
+        elif id == TextService.CHOOSE_FONT_ID:
+            event.Enable(True)
+            return True
+        elif id == TextService.WORD_WRAP_ID:
+            event.Enable(True)
+            return True
+        elif id == FindService.FindService.FIND_ID:
+            event.Enable(hasText)
+            return True
+        elif id == FindService.FindService.FIND_PREVIOUS_ID:
+            event.Enable(hasText and
+                         self._FindServiceHasString() and
+                         self._textCtrl.GetSelection()[0] > 0)
+            return True
+        elif id == FindService.FindService.FIND_NEXT_ID:
+            event.Enable(hasText and
+                         self._FindServiceHasString() and
+                         self._textCtrl.GetSelection()[0] < len(self._textCtrl.GetValue()))
+            return True
+        elif id == FindService.FindService.REPLACE_ID:
+            event.Enable(hasText)
+            return True
+        elif id == FindService.FindService.GOTO_LINE_ID:
+            event.Enable(True)
+            return True
+        else:
+            return wx.lib.docview.View.ProcessUpdateUIEvent(self, event)
+
+
+    #----------------------------------------------------------------------------
+    # Methods for TextDocument to call
+    #----------------------------------------------------------------------------
+
+    def GetTextCtrl(self):
+        return self._textCtrl
+
+
+    #----------------------------------------------------------------------------
+    # Format methods
+    #----------------------------------------------------------------------------
+
+    def OnChooseFont(self, event):
+        data = wx.FontData()
+        data.EnableEffects(True)
+        data.SetInitialFont(self._textCtrl.GetFont())
+        data.SetColour(self._textCtrl.GetForegroundColour())
+        fontDialog = wx.FontDialog(self.GetFrame(), data)
+        if fontDialog.ShowModal() == wx.ID_OK:
+            data = fontDialog.GetFontData()
+            self.SetFont(data.GetChosenFont(), data.GetColour())
+        fontDialog.Destroy()
+
+
+    def SetFont(self, font, color):
+        self._textCtrl.SetFont(font)
+        self._textCtrl.SetForegroundColour(color)
+        self._textCtrl.Refresh()
+        self._textCtrl.Layout()
+
+
+    def OnWordWrap(self, event):
+        self.SetWordWrap(not self.GetWordWrap())
+
+
+    def GetWordWrap(self):
+        return self._wordWrap
+
+
+    def SetWordWrap(self, wordWrap = True):
+        self._wordWrap = wordWrap
+        temp = self._textCtrl
+        self._textCtrl = self._BuildTextCtrl(temp.GetParent(),
+                                             font = temp.GetFont(),
+                                             color = temp.GetForegroundColour(),
+                                             value = temp.GetValue(),
+                                             selection = temp.GetSelection())
+        self.GetDocument().Modify(temp.IsModified())
+        temp.Destroy()
+
+
+    #----------------------------------------------------------------------------
+    # Find methods
+    #----------------------------------------------------------------------------
+
+    def OnFind(self, replace = False):
+        findService = wx.GetApp().GetService(FindService.FindService)
+        if findService:
+            findService.ShowFindReplaceDialog(findString = self._textCtrl.GetStringSelection(), replace = replace)
+
+
+    def DoFind(self, forceFindNext = False, forceFindPrevious = False, replace = False, replaceAll = False):
+        findService = wx.GetApp().GetService(FindService.FindService)
+        if not findService:
+            return
+        findString = findService.GetFindString()
+        if len(findString) == 0:
+            return -1
+        replaceString = findService.GetReplaceString()
+        flags = findService.GetFlags()
+        startLoc, endLoc = self._textCtrl.GetSelection()
+
+        wholeWord = flags & wx.FR_WHOLEWORD > 0
+        matchCase = flags & wx.FR_MATCHCASE > 0
+        regExp = flags & FindService.FindService.FR_REGEXP > 0
+        down = flags & wx.FR_DOWN > 0
+        wrap = flags & FindService.FindService.FR_WRAP > 0
+
+        if forceFindPrevious:   # this is from function keys, not dialog box
+            down = False
+            wrap = False        # user would want to know they're at the end of file
+        elif forceFindNext:
+            down = True
+            wrap = False        # user would want to know they're at the end of file
+
+        # On replace dialog operations, user is allowed to replace the currently highlighted text to determine if it should be replaced or not.
+        # Typically, it is the text from a previous find operation, but we must check to see if it isn't, user may have moved the cursor or selected some other text accidentally.
+        # If the text is a match, then replace it.
+        if replace:
+            result, start, end, replText = findService.DoFind(findString, replaceString, self._textCtrl.GetStringSelection(), 0, 0, True, matchCase, wholeWord, regExp, replace)
+            if result > 0:
+                self._textCtrl.Replace(startLoc, endLoc, replaceString)
+                self.GetDocument().Modify(True)
+                wx.GetApp().GetTopWindow().PushStatusText(_("1 occurrence of \"%s\" replaced") % findString)
+                if down:
+                    startLoc += len(replText)  # advance start location past replacement string to new text
+                endLoc = startLoc
+
+        text = self._textCtrl.GetValue()
+        if wx.Platform == "__WXMSW__":
+            text = string.replace(text, '\n', '\r\n')
+
+        # Find the next matching text occurance or if it is a ReplaceAll, replace all occurances
+        # Even if the user is Replacing, we should replace here, but only select the text and let the user replace it with the next Replace operation
+        result, start, end, text = findService.DoFind(findString, replaceString, text, startLoc, endLoc, down, matchCase, wholeWord, regExp, False, replaceAll, wrap)
+        if result > 0:
+            self._textCtrl.SetValue(text)
+            self.GetDocument().Modify(True)
+            if result == 1:
+                wx.GetApp().GetTopWindow().PushStatusText(_("1 occurrence of \"%s\" replaced") % findString)
+            else:
+                wx.GetApp().GetTopWindow().PushStatusText(_("%i occurrences of \"%s\" replaced") % (result, findString))
+        elif result == 0:
+            self._textCtrl.SetSelection(start, end)
+            self._textCtrl.SetFocus()
+            wx.GetApp().GetTopWindow().PushStatusText(_("Found \"%s\"") % findString)
+        else:
+            wx.GetApp().GetTopWindow().PushStatusText(_("Can't find \"%s\"") % findString)
+
+
+    def _FindServiceHasString(self):
+        findService = wx.GetApp().GetService(FindService.FindService)
+        if not findService or not findService.GetFindString():
+            return False
+        return True
+
+
+    def OnGotoLine(self, event):
+        findService = wx.GetApp().GetService(FindService.FindService)
+        if findService:
+            line = findService.GetLineNumber(self.GetDocumentManager().FindSuitableParent())
+            if line > -1:
+                pos = self._textCtrl.XYToPosition(0, line - 1)
+                self._textCtrl.SetSelection(pos, pos)
+
+
+class TextService(wx.lib.pydocview.DocService):
+
+
+    WORD_WRAP_ID = wx.NewId()
+    CHOOSE_FONT_ID = wx.NewId()
+
+
+    def __init__(self):
+        wx.lib.pydocview.DocService.__init__(self)
+
+
+    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
+        if document and document.GetDocumentTemplate().GetDocumentType() != TextDocument:
+            return
+        config = wx.ConfigBase_Get()
+
+        formatMenuIndex = menuBar.FindMenu(_("&Format"))
+        if formatMenuIndex > -1:
+            formatMenu = menuBar.GetMenu(formatMenuIndex)
+        else:
+            formatMenu = wx.Menu()
+        formatMenu = wx.Menu()
+        if not menuBar.FindItemById(TextService.WORD_WRAP_ID):
+            formatMenu.AppendCheckItem(TextService.WORD_WRAP_ID, _("Word Wrap"), _("Wraps text horizontally when checked"))
+            formatMenu.Check(TextService.WORD_WRAP_ID, config.ReadInt("TextEditorWordWrap", True))
+            wx.EVT_MENU(frame, TextService.WORD_WRAP_ID, frame.ProcessEvent)
+            wx.EVT_UPDATE_UI(frame, TextService.WORD_WRAP_ID, frame.ProcessUpdateUIEvent)
+        if not menuBar.FindItemById(TextService.CHOOSE_FONT_ID):
+            formatMenu.Append(TextService.CHOOSE_FONT_ID, _("Font..."), _("Sets the font to use"))
+            wx.EVT_MENU(frame, TextService.CHOOSE_FONT_ID, frame.ProcessEvent)
+            wx.EVT_UPDATE_UI(frame, TextService.CHOOSE_FONT_ID, frame.ProcessUpdateUIEvent)
+        if formatMenuIndex == -1:
+            viewMenuIndex = menuBar.FindMenu(_("&View"))
+            menuBar.Insert(viewMenuIndex + 1, formatMenu, _("&Format"))
+
+
+    def ProcessUpdateUIEvent(self, event):
+        id = event.GetId()
+        if id == TextService.CHOOSE_FONT_ID:
+            event.Enable(False)
+            return True
+        elif id == TextService.WORD_WRAP_ID:
+            event.Enable(False)
+            return True
+        else:
+            return False
+
+
+class TextOptionsPanel(wx.Panel):
+
+
+    def __init__(self, parent, id):
+        wx.Panel.__init__(self, parent, id)
+        SPACE = 10
+        HALF_SPACE   = 5
+        config = wx.ConfigBase_Get()
+        self._textFont = wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL)
+        fontData = config.Read("TextEditorFont", "")
+        if fontData:
+            nativeFont = wx.NativeFontInfo()
+            nativeFont.FromString(fontData)
+            self._textFont.SetNativeFontInfo(nativeFont)
+        self._originalTextFont = self._textFont
+        self._textColor = wx.BLACK
+        colorData = config.Read("TextEditorColor", "")
+        if colorData:
+            red = int("0x" + colorData[0:2], 16)
+            green = int("0x" + colorData[2:4], 16)
+            blue = int("0x" + colorData[4:6], 16)
+            self._textColor = wx.Color(red, green, blue)
+        self._originalTextColor = self._textColor
+        parent.AddPage(self, _("Text"))
+        fontLabel = wx.StaticText(self, -1, _("Font:"))
+        self._sampleTextCtrl = wx.TextCtrl(self, -1, "", size = (125, -1))
+        self._sampleTextCtrl.SetEditable(False)
+        chooseFontButton = wx.Button(self, -1, _("Choose Font..."))
+        wx.EVT_BUTTON(self, chooseFontButton.GetId(), self.OnChooseFont)
+        self._wordWrapCheckBox = wx.CheckBox(self, -1, _("Wrap words inside text area"))
+        self._wordWrapCheckBox.SetValue(wx.ConfigBase_Get().ReadInt("TextEditorWordWrap", True))
+        textPanelBorderSizer = wx.BoxSizer(wx.VERTICAL)
+        textPanelSizer = wx.BoxSizer(wx.VERTICAL)
+        textFontSizer = wx.BoxSizer(wx.HORIZONTAL)
+        textFontSizer.Add(fontLabel, 0, wx.ALIGN_LEFT | wx.RIGHT | wx.TOP, HALF_SPACE)
+        textFontSizer.Add(self._sampleTextCtrl, 0, wx.ALIGN_LEFT | wx.EXPAND | wx.RIGHT, HALF_SPACE)
+        textFontSizer.Add(chooseFontButton, 0, wx.ALIGN_RIGHT | wx.LEFT, HALF_SPACE)
+        textPanelSizer.Add(textFontSizer, 0, wx.ALL, HALF_SPACE)
+        textPanelSizer.Add(self._wordWrapCheckBox, 0, wx.ALL, HALF_SPACE)
+        textPanelBorderSizer.Add(textPanelSizer, 0, wx.ALL, SPACE)
+        self.SetSizer(textPanelBorderSizer)
+        self.UpdateSampleFont()
+
+
+    def UpdateSampleFont(self):
+        nativeFont = wx.NativeFontInfo()
+        nativeFont.FromString(self._textFont.GetNativeFontInfoDesc())
+        font = wx.NullFont
+        font.SetNativeFontInfo(nativeFont)
+        font.SetPointSize(self._sampleTextCtrl.GetFont().GetPointSize())  # Use the standard point size
+        self._sampleTextCtrl.SetFont(font)
+        self._sampleTextCtrl.SetForegroundColour(self._textColor)
+        self._sampleTextCtrl.SetValue(_("%d pt. %s") % (self._textFont.GetPointSize(), self._textFont.GetFaceName()))
+        self._sampleTextCtrl.Refresh()
+        self.Layout()
+
+
+    def OnChooseFont(self, event):
+        data = wx.FontData()
+        data.EnableEffects(True)
+        data.SetInitialFont(self._textFont)
+        data.SetColour(self._textColor)
+        fontDialog = wx.FontDialog(self, data)
+        if fontDialog.ShowModal() == wx.ID_OK:
+            data = fontDialog.GetFontData()
+            self._textFont = data.GetChosenFont()
+            self._textColor = data.GetColour()
+            self.UpdateSampleFont()
+        fontDialog.Destroy()
+
+
+    def OnOK(self, optionsDialog):
+        config = wx.ConfigBase_Get()
+        doWordWrapUpdate = config.ReadInt("TextEditorWordWrap", True) != self._wordWrapCheckBox.GetValue()
+        config.WriteInt("TextEditorWordWrap", self._wordWrapCheckBox.GetValue())
+        doFontUpdate = self._originalTextFont != self._textFont or self._originalTextColor != self._textColor
+        config.Write("TextEditorFont", self._textFont.GetNativeFontInfoDesc())
+        config.Write("TextEditorColor", "%02x%02x%02x" % (self._textColor.Red(), self._textColor.Green(), self._textColor.Blue()))
+        if doWordWrapUpdate or doFontUpdate:
+            for document in optionsDialog.GetDocManager().GetDocuments():
+                if document.GetDocumentTemplate().GetDocumentType() == TextDocument:
+                    if doWordWrapUpdate:
+                        document.UpdateAllViews(hint = "Word Wrap")
+                    if doFontUpdate:
+                        document.UpdateAllViews(hint = "Font")
diff --git a/wxPython/samples/pydocview/splash.jpg b/wxPython/samples/pydocview/splash.jpg
new file mode 100644 (file)
index 0000000..2416247
Binary files /dev/null and b/wxPython/samples/pydocview/splash.jpg differ
diff --git a/wxPython/samples/pydocview/tips.txt b/wxPython/samples/pydocview/tips.txt
new file mode 100644 (file)
index 0000000..e820ecd
--- /dev/null
@@ -0,0 +1 @@
+wxPython is cool.
\ No newline at end of file
index aad8359e1478cc61b2c57e9cd017ef855919b0b5..01c490c2dcefc43b151b77ee89cf98eb06eedea9 100644 (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):
index 3e7b7b8fb8bdab47f575ccd6d98b1b446b44fa21..41ed58dee7d1268beb3139925d5746e61f56a486 100644 (file)
@@ -2,11 +2,11 @@
 # Name:         pydocview.py
 # Purpose:      Python extensions to the wxWindows docview framework
 #
-# Author:       Peter Yared
+# Author:       Peter Yared, Morgan Hua
 #
 # Created:      5/15/03
 # CVS-ID:       $Id$
-# Copyright:    (c) 2003-2004 ActiveGrid, Inc.
+# Copyright:    (c) 2003-2005 ActiveGrid, Inc.
 # License:      wxWindows license
 #----------------------------------------------------------------------------
 
@@ -21,11 +21,13 @@ import os.path
 import time
 import string
 import pickle
-import getpass
 import tempfile
 import mmap
 _ = wx.GetTranslation
-
+if wx.Platform == '__WXMSW__':
+    _WINDOWS = True
+else:
+    _WINDOWS = False
 
 #----------------------------------------------------------------------------
 # Constants
@@ -50,448 +52,1142 @@ SAVEALL_ID = wx.NewId()
 WINDOW_MENU_NUM_ITEMS = 9
 
 
-class DocService(wx.EvtHandler):
+class DocFrameMixIn:
     """
-    An abstract class used to add reusable services to a docview application.
+    Class with common code used by DocMDIParentFrame, DocTabbedParentFrame, and
+    DocSDIFrame.
     """
-
-
-    def __init__(self):
-        """Initializes the DocService."""
-        pass
-
+    
 
     def GetDocumentManager(self):
-        """Returns the DocManager for the docview application."""
-        return self._docManager
-
-
-    def SetDocumentManager(self, docManager):
-        """Sets the DocManager for the docview application."""
-        self._docManager = docManager
-
-
-    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
-        """Called to install controls into the menubar and toolbar of a SDI or MDI window.  Override this method for a particular service."""
-        pass
-
-
-    def ProcessEventBeforeWindows(self, event):
         """
-        Processes an event before the main window has a chance to process the window. 
-        Override this method for a particular service.
+        Returns the document manager associated with the DocMDIParentFrame.
         """
-        return False
+        return self._docManager
 
 
-    def ProcessUpdateUIEventBeforeWindows(self, event):
+    def InitializePrintData(self):
         """
-        Processes a UI event before the main window has a chance to process the window.
-        Override this method for a particular service.
+        Initializes the PrintData that is used when printing.
         """
-        return False
+        self._printData = wx.PrintData()
+        self._printData.SetPaperId(wx.PAPER_LETTER)
 
 
-    def ProcessEvent(self, event):
+    def CreateDefaultMenuBar(self, sdi=False):
         """
-        Processes an event, searching event tables and calling zero or more
-        suitable event handler function(s).  Note that the ProcessEvent
-        method is called from the wxPython docview framework directly since
-        wxPython does not have a virtual ProcessEvent function.
+        Creates the default MenuBar.  Contains File, Edit, View, Tools, and Help menus.
         """
-        return False
+        menuBar = wx.MenuBar()
+
+        fileMenu = wx.Menu()
+        fileMenu.Append(wx.ID_NEW, _("&New...\tCtrl+N"), _("Creates a new document"))
+        fileMenu.Append(wx.ID_OPEN, _("&Open...\tCtrl+O"), _("Opens an existing document"))
+        fileMenu.Append(wx.ID_CLOSE, _("&Close"), _("Closes the active document"))
+        if not sdi:
+            fileMenu.Append(wx.ID_CLOSE_ALL, _("Close A&ll"), _("Closes all open documents"))
+        fileMenu.AppendSeparator()
+        fileMenu.Append(wx.ID_SAVE, _("&Save\tCtrl+S"), _("Saves the active document"))
+        fileMenu.Append(wx.ID_SAVEAS, _("Save &As..."), _("Saves the active document with a new name"))
+        fileMenu.Append(SAVEALL_ID, _("Save All\tCtrl+Shift+A"), _("Saves the all active documents"))
+        wx.EVT_MENU(self, SAVEALL_ID, self.ProcessEvent)
+        wx.EVT_UPDATE_UI(self, SAVEALL_ID, self.ProcessUpdateUIEvent)
+        fileMenu.AppendSeparator()
+        fileMenu.Append(wx.ID_PRINT, _("&Print\tCtrl+P"), _("Prints the active document"))
+        fileMenu.Append(wx.ID_PREVIEW, _("Print Pre&view"), _("Displays full pages"))
+        fileMenu.Append(wx.ID_PRINT_SETUP, _("Page Set&up"), _("Changes page layout settings"))
+        fileMenu.AppendSeparator()
+        if wx.Platform == '__WXMAC__':
+            fileMenu.Append(wx.ID_EXIT, _("&Quit"), _("Closes this program"))
+        else:
+            fileMenu.Append(wx.ID_EXIT, _("E&xit"), _("Closes this program"))
+        self._docManager.FileHistoryUseMenu(fileMenu)
+        self._docManager.FileHistoryAddFilesToMenu()
+        menuBar.Append(fileMenu, _("&File"));
 
+        editMenu = wx.Menu()
+        editMenu.Append(wx.ID_UNDO, _("&Undo\tCtrl+Z"), _("Reverses the last action"))
+        editMenu.Append(wx.ID_REDO, _("&Redo\tCtrl+Y"), _("Reverses the last undo"))
+        editMenu.AppendSeparator()
+        #item = wxMenuItem(self.editMenu, wxID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard"))
+        #item.SetBitmap(getCutBitmap())
+        #editMenu.AppendItem(item)
+        editMenu.Append(wx.ID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard"))
+        wx.EVT_MENU(self, wx.ID_CUT, self.ProcessEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_CUT, self.ProcessUpdateUIEvent)
+        editMenu.Append(wx.ID_COPY, _("&Copy\tCtrl+C"), _("Copies the selection and puts it on the Clipboard"))
+        wx.EVT_MENU(self, wx.ID_COPY, self.ProcessEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_COPY, self.ProcessUpdateUIEvent)
+        editMenu.Append(wx.ID_PASTE, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents"))
+        wx.EVT_MENU(self, wx.ID_PASTE, self.ProcessEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_PASTE, self.ProcessUpdateUIEvent)
+        editMenu.Append(wx.ID_CLEAR, _("Cle&ar"), _("Erases the selection"))
+        wx.EVT_MENU(self, wx.ID_CLEAR, self.ProcessEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_CLEAR, self.ProcessUpdateUIEvent)
+        editMenu.AppendSeparator()
+        editMenu.Append(wx.ID_SELECTALL, _("Select A&ll\tCtrl+A"), _("Selects all available data"))
+        wx.EVT_MENU(self, wx.ID_SELECTALL, self.ProcessEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_SELECTALL, self.ProcessUpdateUIEvent)
+        menuBar.Append(editMenu, _("&Edit"))
+        if sdi:
+            if self.GetDocument() and self.GetDocument().GetCommandProcessor():
+                self.GetDocument().GetCommandProcessor().SetEditMenu(editMenu)
+            
+        viewMenu = wx.Menu()
+        viewMenu.AppendCheckItem(VIEW_TOOLBAR_ID, _("&Toolbar"), _("Shows or hides the toolbar"))
+        wx.EVT_MENU(self, VIEW_TOOLBAR_ID, self.OnViewToolBar)
+        wx.EVT_UPDATE_UI(self, VIEW_TOOLBAR_ID, self.OnUpdateViewToolBar)
+        viewMenu.AppendCheckItem(VIEW_STATUSBAR_ID, _("&Status Bar"), _("Shows or hides the status bar"))
+        wx.EVT_MENU(self, VIEW_STATUSBAR_ID, self.OnViewStatusBar)
+        wx.EVT_UPDATE_UI(self, VIEW_STATUSBAR_ID, self.OnUpdateViewStatusBar)
+        menuBar.Append(viewMenu, _("&View"))
 
-    def ProcessUpdateUIEvent(self, event):
-        """
-        Processes a UI event, searching event tables and calling zero or more
-        suitable event handler function(s).  Note that the ProcessEvent
-        method is called from the wxPython docview framework directly since
-        wxPython does not have a virtual ProcessEvent function.
-        """
-        return False
+        helpMenu = wx.Menu()
+        helpMenu.Append(wx.ID_ABOUT, _("&About" + " " + wx.GetApp().GetAppName()), _("Displays program information, version number, and copyright"))
+        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
+        menuBar.Append(helpMenu, _("&Help"))
 
+        wx.EVT_UPDATE_UI(self, wx.ID_ABOUT, self.ProcessUpdateUIEvent)  # Using ID_ABOUT to update the window menu, the window menu items are not triggering
 
-    def OnCloseFrame(self, event):
-        """
-        Called when the a docview frame is being closed.  Override this method
-        so a service can either do cleanup or veto the frame being closed by
-        returning false.
-        """
-        return True
+        if sdi:  # TODO: Is this really needed?
+            wx.EVT_COMMAND_FIND_CLOSE(self, -1, self.ProcessEvent)
+            
+        return menuBar
 
 
-    def OnExit(self):
+    def CreateDefaultStatusBar(self):
         """
-        Called when the the docview application is being closed.  Override this method
-        so a service can either do cleanup or veto the frame being closed by
-        returning false.
+        Creates the default StatusBar.
         """
-        pass
+        wx.Frame.CreateStatusBar(self)
+        self.GetStatusBar().Show(wx.ConfigBase_Get().ReadInt("ViewStatusBar", True))
+        self.UpdateStatus()
+        return self.GetStatusBar()
 
 
-    def GetMenuItemPos(self, menu, id):
+    def CreateDefaultToolBar(self):
         """
-        Utility method used to find the position of a menu item so that services can
-        easily find where to insert a menu item in InstallControls.
+        Creates the default ToolBar.
         """
-        menuItems = menu.GetMenuItems()
-        for i, menuItem in enumerate(menuItems):
-            if menuItem.GetId() == id:
-                return i
-        return i
+        self._toolBar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
+        self._toolBar.AddSimpleTool(wx.ID_NEW, getNewBitmap(), _("New"), _("Creates a new document"))
+        self._toolBar.AddSimpleTool(wx.ID_OPEN, getOpenBitmap(), _("Open"), _("Opens an existing document"))
+        self._toolBar.AddSimpleTool(wx.ID_SAVE, getSaveBitmap(), _("Save"), _("Saves the active document"))
+        self._toolBar.AddSimpleTool(SAVEALL_ID, getSaveAllBitmap(), _("Save All"), _("Saves all the active documents"))
+        self._toolBar.AddSeparator()
+        self._toolBar.AddSimpleTool(wx.ID_PRINT, getPrintBitmap(), _("Print"), _("Displays full pages"))
+        self._toolBar.AddSimpleTool(wx.ID_PREVIEW, getPrintPreviewBitmap(), _("Print Preview"), _("Prints the active document"))
+        self._toolBar.AddSeparator()
+        self._toolBar.AddSimpleTool(wx.ID_CUT, getCutBitmap(), _("Cut"), _("Cuts the selection and puts it on the Clipboard"))
+        self._toolBar.AddSimpleTool(wx.ID_COPY, getCopyBitmap(), _("Copy"), _("Copies the selection and puts it on the Clipboard"))
+        self._toolBar.AddSimpleTool(wx.ID_PASTE, getPasteBitmap(), _("Paste"), _("Inserts Clipboard contents"))
+        self._toolBar.AddSimpleTool(wx.ID_UNDO, getUndoBitmap(), _("Undo"), _("Reverses the last action"))
+        self._toolBar.AddSimpleTool(wx.ID_REDO, getRedoBitmap(), _("Redo"), _("Reverses the last undo"))
+        self._toolBar.Realize()
+        self._toolBar.Show(wx.ConfigBase_Get().ReadInt("ViewToolBar", True))
+
+        return self._toolBar
 
 
-    def GetView(self):
+    def OnFileSaveAll(self, event):
         """
-        Called by WindowMenuService to get views for services that don't
-        have dedicated documents such as the Outline Service.
+        Saves all of the currently open documents.
         """
-        return None
-
-
-class DocOptionsService(DocService):
-    """
-    A service that implements an options menu item and an options dialog with
-    notebook tabs.  New tabs can be added by other services by calling the
-    "AddOptionsPanel" method.
-    """
+        docs = wx.GetApp().GetDocumentManager().GetDocuments()
+        for doc in docs:
+            doc.Save()
 
 
-    def __init__(self, showGeneralOptions = True):
+    def OnAbout(self, event):
         """
-        Initializes the options service with the option of suppressing the default
-        general options pane that is included with the options service by setting
-        showGeneralOptions to False.
+        Invokes the about dialog.
         """
-        DocService.__init__(self)
-        self.ClearOptionsPanels()
-        self._toolOptionsID = wx.NewId()
-        if showGeneralOptions:
-            self.AddOptionsPanel(GeneralOptionsPanel)
+        aboutService = wx.GetApp().GetService(AboutService)
+        if aboutService:
+            aboutService.ShowAbout()
 
 
-    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
+    def OnViewToolBar(self, event):
         """
-        Installs a "Tools" menu with an "Options" menu item.
+        Toggles whether the ToolBar is visible.
         """
-        toolsMenuIndex = menuBar.FindMenu(_("&Tools"))
-        if toolsMenuIndex > -1:
-            toolsMenu = menuBar.GetMenu(toolsMenuIndex)
-        else:
-            toolsMenu = wx.Menu()
-        if toolsMenuIndex == -1:
-            formatMenuIndex = menuBar.FindMenu(_("&Format"))
-            menuBar.Insert(formatMenuIndex + 1, toolsMenu, _("&Tools"))
-        if toolsMenu:
-            if toolsMenu.GetMenuItemCount():
-                toolsMenu.AppendSeparator()
-            toolsMenu.Append(self._toolOptionsID, _("&Options..."), _("Sets options"))
-            wx.EVT_MENU(frame, self._toolOptionsID, frame.ProcessEvent)
-            
+        self._toolBar.Show(not self._toolBar.IsShown())
+        self._LayoutFrame()
 
-    def ProcessEvent(self, event):
+
+    def OnUpdateViewToolBar(self, event):
         """
-        Checks to see if the "Options" menu item has been selected.
+        Updates the View ToolBar menu item.
         """
-        id = event.GetId()
-        if id == self._toolOptionsID:
-            self.OnOptions(event)
-            return True
-        else:
-            return False
+        event.Check(self.GetToolBar().IsShown())
 
 
-    def ClearOptionsPanels(self):
+    def OnViewStatusBar(self, event):
         """
-        Clears all of the options panels that have been added into the
-        options dialog.
+        Toggles whether the StatusBar is visible.
         """
-        self._optionsPanels = []
+        self.GetStatusBar().Show(not self.GetStatusBar().IsShown())
+        self._LayoutFrame()
 
 
-    def AddOptionsPanel(self, optionsPanel):
+    def OnUpdateViewStatusBar(self, event):
         """
-        Adds an options panel to the options dialog. 
+        Updates the View StatusBar menu item.
         """
-        self._optionsPanels.append(optionsPanel)
+        event.Check(self.GetStatusBar().IsShown())
 
 
-    def OnOptions(self, event):
+    def UpdateStatus(self, message = _("Ready")):
         """
-        Shows the options dialog, called when the "Options" menu item is selected.
+        Updates the StatusBar.
         """
-        if len(self._optionsPanels) == 0:
-            return
-        optionsDialog = OptionsDialog(wx.GetApp().GetTopWindow(), self._optionsPanels, self._docManager)
-        if optionsDialog.ShowModal() == wx.ID_OK:
-            optionsDialog.OnOK(optionsDialog)  # wxBug: wxDialog should be calling this automatically but doesn't
-        optionsDialog.Destroy()
+        # wxBug: Menubar and toolbar help strings don't pop the status text back
+        if self.GetStatusBar().GetStatusText() != message:
+            self.GetStatusBar().PushStatusText(message)
 
 
-class OptionsDialog(wx.Dialog):
+class DocMDIParentFrameMixIn:
     """
-    A default options dialog used by the OptionsService that hosts a notebook
-    tab of options panels.
+    Class with common code used by DocMDIParentFrame and DocTabbedParentFrame.
     """
+    
 
-
-    def __init__(self, parent, optionsPanelClasses, docManager):
+    def _GetPosSizeFromConfig(self, pos, size):
         """
-        Initializes the options dialog with a notebook page that contains new
-        instances of the passed optionsPanelClasses.
+        Adjusts the position and size of the frame using the saved config position and size.
         """
-        wx.Dialog.__init__(self, parent, -1, _("Options"), size = (310, 400))
+        config = wx.ConfigBase_Get()
+        if pos == wx.DefaultPosition and size == wx.DefaultSize and config.ReadInt("MDIFrameMaximized", False):
+            pos = [0, 0]
+            size = wx.DisplaySize()
+            # wxBug: Need to set to fill screen to get around bug where maximize is leaving shadow of statusbar, check out maximize call at end of this function
+        else:
+            if pos == wx.DefaultPosition:
+                pos = config.ReadInt("MDIFrameXLoc", -1), config.ReadInt("MDIFrameYLoc", -1)
+
+            if wx.Display_GetFromPoint(pos) == -1:  # Check if the frame position is offscreen
+                pos = wx.DefaultPosition
+                
+            if size == wx.DefaultSize:
+                size = wx.Size(config.ReadInt("MDIFrameXSize", 450), config.ReadInt("MDIFrameYSize", 300))
+        return pos, size
+
+
+    def _InitFrame(self, embeddedWindows):
+        """
+        Initializes the frame and creates the default menubar, toolbar, and status bar.
+        """
+        self._embeddedWindows = []
+        self.SetDropTarget(_DocFrameFileDropTarget(self._docManager, self))
+
+        if wx.GetApp().GetDefaultIcon():
+            self.SetIcon(wx.GetApp().GetDefaultIcon())
+
+        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
+        wx.EVT_SIZE(self, self.OnSize)
+
+        self.InitializePrintData()
+
+        toolBar = self.CreateDefaultToolBar()
+        self.SetToolBar(toolBar)
+        menuBar = self.CreateDefaultMenuBar()
+        statusBar = self.CreateDefaultStatusBar()
+
+        config = wx.ConfigBase_Get()
+        if config.ReadInt("MDIFrameMaximized", False):
+            # wxBug: On maximize, statusbar leaves a residual that needs to be refereshed, happens even when user does it
+            self.Maximize()
+
+        self.CreateEmbeddedWindows(embeddedWindows)
+        self._LayoutFrame()
+
+        wx.GetApp().SetTopWindow(self)  # Need to do this here in case the services are looking for wx.GetApp().GetTopWindow()
+        for service in wx.GetApp().GetServices():
+            service.InstallControls(self, menuBar = menuBar, toolBar = toolBar, statusBar = statusBar)
+            if hasattr(service, "ShowWindow"):
+                service.ShowWindow()  # instantiate service windows for correct positioning, we'll hide/show them later based on user preference
+
+        self.SetMenuBar(menuBar)  # wxBug: Have to set the menubar at the very end or the automatic MDI "window" menu doesn't get put in the right place when the services add new menus to the menubar
+
+
+    def ProcessEvent(self, event):
+        """
+        Processes an event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        id = event.GetId()
+        if id == SAVEALL_ID:
+            self.OnFileSaveAll(event)
+            return True
+            
+        return wx.GetApp().ProcessEvent(event)
+
+
+    def ProcessUpdateUIEvent(self, event):
+        """
+        Processes a UI event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        id = event.GetId()
+        if id == wx.ID_CUT:
+            event.Enable(False)
+            return True
+        elif id == wx.ID_COPY:
+            event.Enable(False)
+            return True
+        elif id == wx.ID_PASTE:
+            event.Enable(False)
+            return True
+        elif id == wx.ID_CLEAR:
+            event.Enable(False)
+            return True
+        elif id == wx.ID_SELECTALL:
+            event.Enable(False)
+            return True
+        elif id == SAVEALL_ID:
+            filesModified = False
+            docs = wx.GetApp().GetDocumentManager().GetDocuments()
+            for doc in docs:
+                if doc.IsModified():
+                    filesModified = True
+                    break
+                
+            event.Enable(filesModified)
+            return True
+        else:
+            return wx.GetApp().ProcessUpdateUIEvent(event)
+
+
+    def CreateEmbeddedWindows(self, windows = 0):
+        """
+        Create the specified embedded windows around the edges of the frame.
+        """
+        frameSize = self.GetSize()   # TODO: GetClientWindow.GetSize is still returning 0,0 since the frame isn't fully constructed yet, so using full frame size
+        defaultHSize = int(frameSize[0] / 6)
+        defaultVSize = int(frameSize[1] / 7)
+        defaultSubVSize = int(frameSize[1] / 2)
+        config = wx.ConfigBase_Get()
+        if windows & (EMBEDDED_WINDOW_LEFT | EMBEDDED_WINDOW_TOPLEFT | EMBEDDED_WINDOW_BOTTOMLEFT):
+            self._leftEmbWindow = self._CreateEmbeddedWindow(self, (config.ReadInt("MDIEmbedLeftSize", defaultHSize), -1), wx.LAYOUT_VERTICAL, wx.LAYOUT_LEFT, visible = config.ReadInt("MDIEmbedLeftVisible", 1), sash = wx.SASH_RIGHT)
+        else:
+            self._leftEmbWindow = None
+        if windows & EMBEDDED_WINDOW_TOPLEFT:
+            self._topLeftEmbWindow = self._CreateEmbeddedWindow(self._leftEmbWindow, (-1, config.ReadInt("MDIEmbedTopLeftSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_TOP, visible = config.ReadInt("MDIEmbedTopLeftVisible", 1), sash = wx.SASH_BOTTOM)
+        else:
+            self._topLeftEmbWindow = None
+        if windows & EMBEDDED_WINDOW_BOTTOMLEFT:
+            self._bottomLeftEmbWindow = self._CreateEmbeddedWindow(self._leftEmbWindow, (-1, config.ReadInt("MDIEmbedBottomLeftSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_BOTTOM, visible = config.ReadInt("MDIEmbedBottomLeftVisible", 1))
+        else:
+            self._bottomLeftEmbWindow = None
+        if windows & (EMBEDDED_WINDOW_RIGHT | EMBEDDED_WINDOW_TOPRIGHT | EMBEDDED_WINDOW_BOTTOMRIGHT):
+            self._rightEmbWindow = self._CreateEmbeddedWindow(self, (config.ReadInt("MDIEmbedRightSize", defaultHSize), -1), wx.LAYOUT_VERTICAL, wx.LAYOUT_RIGHT, visible = config.ReadInt("MDIEmbedRightVisible", 1), sash = wx.SASH_LEFT)
+        else:
+            self._rightEmbWindow = None
+        if windows & EMBEDDED_WINDOW_TOPRIGHT:
+            self._topRightEmbWindow = self._CreateEmbeddedWindow(self._rightEmbWindow, (-1, config.ReadInt("MDIEmbedTopRightSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_TOP, visible = config.ReadInt("MDIEmbedTopRightVisible", 1), sash = wx.SASH_BOTTOM)
+        else:
+            self._topRightEmbWindow = None
+        if windows & EMBEDDED_WINDOW_BOTTOMRIGHT:
+            self._bottomRightEmbWindow = self._CreateEmbeddedWindow(self._rightEmbWindow, (-1, config.ReadInt("MDIEmbedBottomRightSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_BOTTOM, visible = config.ReadInt("MDIEmbedBottomRightVisible", 1))
+        else:
+            self._bottomRightEmbWindow = None
+        if windows & EMBEDDED_WINDOW_TOP:
+            self._topEmbWindow = self._CreateEmbeddedWindow(self, (-1, config.ReadInt("MDIEmbedTopSize", defaultVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_TOP, visible = config.ReadInt("MDIEmbedTopVisible", 1), sash = wx.SASH_BOTTOM)
+        else:
+            self._topEmbWindow = None
+        if windows & EMBEDDED_WINDOW_BOTTOM:
+            self._bottomEmbWindow = self._CreateEmbeddedWindow(self, (-1, config.ReadInt("MDIEmbedBottomSize", defaultVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_BOTTOM, visible = config.ReadInt("MDIEmbedBottomVisible", 1), sash = wx.SASH_TOP)
+        else:
+            self._bottomEmbWindow = None
+
+
+    def SaveEmbeddedWindowSizes(self):
+        """
+        Saves the sizes of the embedded windows.
+        """
+        config = wx.ConfigBase_Get()
+        if not self.IsMaximized():
+            config.WriteInt("MDIFrameXLoc", self.GetPositionTuple()[0])
+            config.WriteInt("MDIFrameYLoc", self.GetPositionTuple()[1])
+            config.WriteInt("MDIFrameXSize", self.GetSizeTuple()[0])
+            config.WriteInt("MDIFrameYSize", self.GetSizeTuple()[1])
+        config.WriteInt("MDIFrameMaximized", self.IsMaximized())
+        config.WriteInt("ViewToolBar", self._toolBar.IsShown())
+        config.WriteInt("ViewStatusBar", self.GetStatusBar().IsShown())
+
+        if self._leftEmbWindow:
+            config.WriteInt("MDIEmbedLeftSize", self._leftEmbWindow.GetSize()[0])
+            config.WriteInt("MDIEmbedLeftVisible", self._leftEmbWindow.IsShown())
+        if self._topLeftEmbWindow:
+            if self._topLeftEmbWindow._sizeBeforeHidden:
+                size = self._topLeftEmbWindow._sizeBeforeHidden[1]
+            else:
+                size = self._topLeftEmbWindow.GetSize()[1]
+            config.WriteInt("MDIEmbedTopLeftSize", size)
+            config.WriteInt("MDIEmbedTopLeftVisible", self._topLeftEmbWindow.IsShown())
+        if self._bottomLeftEmbWindow:
+            if self._bottomLeftEmbWindow._sizeBeforeHidden:
+                size = self._bottomLeftEmbWindow._sizeBeforeHidden[1]
+            else:
+                size = self._bottomLeftEmbWindow.GetSize()[1]
+            config.WriteInt("MDIEmbedBottomLeftSize", size)
+            config.WriteInt("MDIEmbedBottomLeftVisible", self._bottomLeftEmbWindow.IsShown())
+        if self._rightEmbWindow:
+            config.WriteInt("MDIEmbedRightSize", self._rightEmbWindow.GetSize()[0])
+            config.WriteInt("MDIEmbedRightVisible", self._rightEmbWindow.IsShown())
+        if self._topRightEmbWindow:
+            if self._topRightEmbWindow._sizeBeforeHidden:
+                size = self._topRightEmbWindow._sizeBeforeHidden[1]
+            else:
+                size = self._topRightEmbWindow.GetSize()[1]
+            config.WriteInt("MDIEmbedTopRightSize", size)
+            config.WriteInt("MDIEmbedTopRightVisible", self._topRightEmbWindow.IsShown())
+        if self._bottomRightEmbWindow:
+            if self._bottomRightEmbWindow._sizeBeforeHidden:
+                size = self._bottomRightEmbWindow._sizeBeforeHidden[1]
+            else:
+                size = self._bottomRightEmbWindow.GetSize()[1]
+            config.WriteInt("MDIEmbedBottomRightSize", size)
+            config.WriteInt("MDIEmbedBottomRightVisible", self._bottomRightEmbWindow.IsShown())
+        if self._topEmbWindow:
+            config.WriteInt("MDIEmbedTopSize", self._topEmbWindow.GetSize()[1])
+            config.WriteInt("MDIEmbedTopVisible", self._topEmbWindow.IsShown())
+        if self._bottomEmbWindow:
+            config.WriteInt("MDIEmbedBottomSize", self._bottomEmbWindow.GetSize()[1])
+            config.WriteInt("MDIEmbedBottomVisible", self._bottomEmbWindow.IsShown())
+
+
+    def GetEmbeddedWindow(self, loc):
+        """
+        Returns the instance of the embedded window specified by the embedded window location constant.
+        """
+        if loc == EMBEDDED_WINDOW_TOP:
+            return self._topEmbWindow
+        elif loc == EMBEDDED_WINDOW_BOTTOM:
+            return self._bottomEmbWindow
+        elif loc == EMBEDDED_WINDOW_LEFT:
+            return self._leftEmbWindow
+        elif loc == EMBEDDED_WINDOW_RIGHT:
+            return self._rightEmbWindow
+        elif loc == EMBEDDED_WINDOW_TOPLEFT:
+            return self._topLeftEmbWindow
+        elif loc == EMBEDDED_WINDOW_BOTTOMLEFT:
+            return self._bottomLeftEmbWindow
+        elif loc == EMBEDDED_WINDOW_TOPRIGHT:
+            return self._topRightEmbWindow
+        elif loc == EMBEDDED_WINDOW_BOTTOMRIGHT:
+            return self._bottomRightEmbWindow
+        return None
+
+
+    def _CreateEmbeddedWindow(self, parent, size, orientation, alignment, visible = True, sash = None):
+        """
+        Creates the embedded window with the specified size, orientation, and alignment.  If the 
+        window is not visible it will retain the size with which it was last viewed.
+        """
+        window = wx.SashLayoutWindow(parent, wx.NewId(), style = wx.NO_BORDER | wx.SW_3D)
+        window.SetDefaultSize(size)
+        window.SetOrientation(orientation)
+        window.SetAlignment(alignment)
+        if sash != None:  # wx.SASH_TOP is 0 so check for None instead of just doing "if sash:"
+            window.SetSashVisible(sash, True)
+        ####
+        def OnEmbeddedWindowSashDrag(event):
+            if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
+                return
+            sashWindow = event.GetEventObject()
+            if sashWindow.GetAlignment() == wx.LAYOUT_TOP or sashWindow.GetAlignment() == wx.LAYOUT_BOTTOM:
+                size = wx.Size(-1, event.GetDragRect().height)
+            else:
+                size = wx.Size(event.GetDragRect().width, -1)
+            event.GetEventObject().SetDefaultSize(size)
+            self._LayoutFrame()
+            sashWindow.Refresh()
+            if isinstance(sashWindow.GetParent(), wx.SashLayoutWindow):
+                sashWindow.Show()
+                parentSashWindow = sashWindow.GetParent()  # Force a refresh
+                parentSashWindow.Layout()
+                parentSashWindow.Refresh()
+                parentSashWindow.SetSize((parentSashWindow.GetSize().width + 1, parentSashWindow.GetSize().height + 1))
+        ####
+        wx.EVT_SASH_DRAGGED(window, window.GetId(), OnEmbeddedWindowSashDrag)
+        window._sizeBeforeHidden = None
+        if not visible:
+            window.Show(False)
+            if isinstance(parent, wx.SashLayoutWindow): # It's a window embedded in another sash window so remember its actual size to show it again
+                window._sizeBeforeHidden = size
+        return window
+
+
+    def ShowEmbeddedWindow(self, window, show = True):
+        """
+        Shows or hides the embedded window specified by the embedded window location constant.
+        """
+        window.Show(show)
+        if isinstance(window.GetParent(), wx.SashLayoutWindow):  # It is a parent sashwindow with multiple embedded sashwindows
+            parentSashWindow = window.GetParent()
+            if show:  # Make sure it is visible in case all of the subwindows were hidden
+                parentSashWindow.Show()                
+            if show and window._sizeBeforeHidden:
+                if window._sizeBeforeHidden[1] == parentSashWindow.GetClientSize()[1]:
+                    if window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).IsShown():
+                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).GetSize()[1]))
+                    elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).IsShown():
+                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).GetSize()[1]))
+                    elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).IsShown():
+                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).GetSize()[1]))
+                    elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).IsShown():
+                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).GetSize()[1]))
+                else:
+                    window.SetDefaultSize(window._sizeBeforeHidden)
+                    # If it is not the size of the full parent sashwindow set the other window's size so that if it gets shown it will have a cooresponding size
+                    if window._sizeBeforeHidden[1] < parentSashWindow.GetClientSize()[1]:
+                        otherWindowSize = (-1, parentSashWindow.GetClientSize()[1] - window._sizeBeforeHidden[1])
+                        if window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT):
+                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).SetDefaultSize(otherWindowSize)
+                        elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT):
+                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).SetDefaultSize(otherWindowSize)
+                        elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT):
+                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).SetDefaultSize(otherWindowSize)
+                        elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT):
+                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).SetDefaultSize(otherWindowSize)
+                    
+            if not show:
+                if window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).IsShown() \
+                    or window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).IsShown() \
+                    or window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).IsShown() \
+                    or window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).IsShown():
+                    parentSashWindow.Hide()  # Hide the parent sashwindow if all of the children are hidden
+            parentSashWindow.Layout()   # Force a refresh
+            parentSashWindow.Refresh()
+            parentSashWindow.SetSize((parentSashWindow.GetSize().width + 1, parentSashWindow.GetSize().height + 1))
+        self._LayoutFrame()
+
+
+    def HideEmbeddedWindow(self):
+        """
+        Hides the embedded window specified by the embedded window location constant.
+        """
+        self.ShowEmbeddedWindow(show = False)
+
+
+class DocTabbedChildFrame(wx.Panel):
+    """
+    The wxDocMDIChildFrame class provides a default frame for displaying
+    documents on separate windows. This class can only be used for MDI child
+    frames.
+
+    The class is part of the document/view framework supported by wxWindows,
+    and cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
+    classes.
+    """
+
+
+    def __init__(self, doc, view, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"):
+        """
+        Constructor.  Note that the event table must be rebuilt for the
+        frame since the EvtHandler is not virtual.
+        """
+        wx.Panel.__init__(self, frame.GetNotebook(), id)
+        self._childDocument = doc
+        self._childView = view
+        frame.AddNotebookPage(self, doc.GetPrintableName())
+        if view:
+            view.SetFrame(self)
+
+
+    def GetIcon(self):
+        """
+        Dummy method since the icon of tabbed frames are managed by the notebook.
+        """
+        return None
+        
+
+    def SetIcon(self, icon):
+        """
+        Dummy method since the icon of tabbed frames are managed by the notebook.
+        """
+        pass
+
+
+    def Destroy(self):
+        """
+        Removes the current notebook page.
+        """
+        wx.GetApp().GetTopWindow().RemoveNotebookPage(self)
+
+
+    def SetFocus(self):
+        """
+        Activates the current notebook page.
+        """
+        wx.GetApp().GetTopWindow().ActivateNotebookPage(self)
+
+
+    def Activate(self):  # Need this in case there are embedded sash windows and such, OnActivate is not getting called
+        """
+        Activates the current view.
+        """
+        # Called by Project Editor
+        if self._childView:
+            self._childView.Activate(True)
+
+
+    def GetTitle(self):
+        """
+        Returns the frame's title.
+        """
+        wx.GetApp().GetTopWindow().GetNotebookPageTitle(self)
+
+
+    def SetTitle(self, title):
+        """
+        Sets the frame's title.
+        """
+        wx.GetApp().GetTopWindow().SetNotebookPageTitle(self, title)
+
+
+    def ProcessEvent(event):
+        """
+        Processes an event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        if not self._childView or not self._childView.ProcessEvent(event):
+            if not isinstance(event, wx.CommandEvent) or not self.GetParent() or not self.GetParent().ProcessEvent(event):
+                return False
+            else:
+                return True
+        else:
+            return True
+
+
+    def GetDocument(self):
+        """
+        Returns the document associated with this frame.
+        """
+        return self._childDocument
+
+
+    def SetDocument(self, document):
+        """
+        Sets the document for this frame.
+        """
+        self._childDocument = document
+
+
+    def GetView(self):
+        """
+        Returns the view associated with this frame.
+        """
+        return self._childView
+
+
+    def SetView(self, view):
+        """
+        Sets the view for this frame.
+        """
+        self._childView = view
 
-        self._optionsPanels = []
+
+class DocTabbedParentFrame(wx.Frame, DocFrameMixIn, DocMDIParentFrameMixIn):
+    """
+    The DocTabbedParentFrame class provides a default top-level frame for
+    applications using the document/view framework. This class can only be
+    used for MDI parent frames that use a tabbed interface.
+
+    It cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
+    classes.
+    """
+
+
+    def __init__(self, docManager, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "DocTabbedParentFrame", embeddedWindows = 0):
+        """
+        Constructor.  Note that the event table must be rebuilt for the
+        frame since the EvtHandler is not virtual.
+        """
+        pos, size = self._GetPosSizeFromConfig(pos, size)
+        wx.Frame.__init__(self, frame, id, title, pos, size, style, name)
+
+        # From docview.MDIParentFrame
         self._docManager = docManager
 
-        HALF_SPACE = 5
-        SPACE = 10
+        wx.EVT_CLOSE(self, self.OnCloseWindow)
 
-        sizer = wx.BoxSizer(wx.VERTICAL)
+        wx.EVT_MENU(self, wx.ID_EXIT, self.OnExit)
+        wx.EVT_MENU_RANGE(self, wx.ID_FILE1, wx.ID_FILE9, self.OnMRUFile)
 
-        optionsNotebook = wx.Notebook(self, -1, size = (310, 375), style = wx.NB_MULTILINE)
-        sizer.Add(optionsNotebook, 0, wx.ALL | wx.EXPAND, SPACE)
-        for optionsPanelClass in optionsPanelClasses:
-            optionsPanel = optionsPanelClass(optionsNotebook, -1)
-            self._optionsPanels.append(optionsPanel)
-        sizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, HALF_SPACE)
-        self.SetSizer(sizer)
-        self.Layout()
-        self.Fit()
-        wx.CallAfter(self.DoRefresh)
+        wx.EVT_MENU(self, wx.ID_NEW, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_OPEN, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_CLOSE_ALL, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_CLOSE, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_REVERT, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_SAVE, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_SAVEAS, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_UNDO, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_REDO, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_PRINT, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_PRINT_SETUP, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_PREVIEW, self.ProcessEvent)
+        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
 
+        wx.EVT_UPDATE_UI(self, wx.ID_NEW, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_OPEN, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_CLOSE_ALL, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_CLOSE, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_REVERT, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_SAVE, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_SAVEAS, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_UNDO, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_REDO, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_PRINT, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_PRINT_SETUP, self.ProcessUpdateUIEvent)
+        wx.EVT_UPDATE_UI(self, wx.ID_PREVIEW, self.ProcessUpdateUIEvent)
+        # End From docview.MDIParentFrame
+
+        self.CreateNotebook()
+        self._InitFrame(embeddedWindows)
+        
 
-    def DoRefresh(self):
+    def _LayoutFrame(self):
         """
-        wxBug: On Windows XP when using a multiline notebook the default page doesn't get
-        drawn, but it works when using a single line notebook.
+        Lays out the frame.
         """
-        self.Refresh()
+        wx.LayoutAlgorithm().LayoutFrame(self, self._notebook)
+        
+
+    def CreateNotebook(self):
+        """
+        Creates the notebook to use for the tabbed document interface.
+        """     
+        self._notebook = wx.Notebook(self, wx.NewId())
+        # self._notebook.SetSizer(wx.NotebookSizer(self._notebook))
+        wx.EVT_NOTEBOOK_PAGE_CHANGED(self, self._notebook.GetId(), self.OnNotebookPageChanged)
+        wx.EVT_RIGHT_DOWN(self._notebook, self.OnNotebookRightClick)
+
+        templates = wx.GetApp().GetDocumentManager().GetTemplates()
+        iconList = wx.ImageList(16, 16, initialCount = len(templates))
+        self._iconIndexLookup = []
+        for template in templates:
+            icon = template.GetIcon()
+            if icon:
+                if icon.GetHeight() != 16:
+                    icon.SetHeight(16)  # wxBug: img2py.py uses EmptyIcon which is 32x32
+                if icon.GetWidth() != 16:
+                    icon.SetWidth(16)   # wxBug: img2py.py uses EmptyIcon which is 32x32
+                iconIndex = iconList.AddIcon(icon)
+                self._iconIndexLookup.append((template, iconIndex))
+                
+        icon = getBlankIcon()
+        if icon.GetHeight() != 16:
+            icon.SetHeight(16)  # wxBug: img2py.py uses EmptyIcon which is 32x32
+        if icon.GetWidth() != 16:
+            icon.SetWidth(16)   # wxBug: img2py.py uses EmptyIcon which is 32x32
+        self._blankIconIndex = iconList.AddIcon(icon)
+        self._notebook.AssignImageList(iconList)
 
 
-    def GetDocManager(self):
+    def GetNotebook(self):
         """
-        Returns the document manager passed to the OptionsDialog constructor.
+        Returns the notebook used by the tabbed document interface.
         """
-        return self._docManager
+        return self._notebook
+        
+
+    def GetActiveChild(self):
+        """
+        Returns the active notebook page, which to the framework is treated as
+        a document frame.
+        """
+        index = self._notebook.GetSelection()
+        if index == -1:
+            return None
+        return self._notebook.GetPage(index)
 
 
-    def OnOK(self, event):
+    def OnNotebookPageChanged(self, event):
         """
-        Calls the OnOK method of all of the OptionDialog's embedded panels
+        Activates a notebook page's view when it is selected.
         """
-        for optionsPanel in self._optionsPanels:
-            optionsPanel.OnOK(event)
+        index = self._notebook.GetSelection()
+        if index > -1:
+            self._notebook.GetPage(index).GetView().Activate()
 
 
-class GeneralOptionsPanel(wx.Panel):
-    """
-    A general options panel that is used in the OptionDialog to configure the
-    generic properties of a pydocview application, such as "show tips at startup"
-    and whether to use SDI or MDI for the application.
-    """
+    def OnNotebookRightClick(self, event):
+        """
+        Handles right clicks for the notebook, enabling users to either close
+        a tab or select from the available documents if the user clicks on the
+        notebook's white space.
+        """
+        index, type = self._notebook.HitTest(event.GetPosition())
+        menu = wx.Menu()
+        x, y = event.GetX(), event.GetY()
+        if index > -1:
+            doc = self._notebook.GetPage(index).GetView().GetDocument()
+            id = wx.NewId()
+            menu.Append(id, _("Close"))
+            def OnRightMenuSelect(event):
+                doc.DeleteAllViews()
+            wx.EVT_MENU(self, id, OnRightMenuSelect)
+            if self._notebook.GetPageCount() > 1:
+                menu.AppendSeparator()
+                tabsMenu = wx.Menu()
+                menu.AppendMenu(wx.NewId(), _("Select Tab"), tabsMenu)
+        else:
+            y = y - 25  # wxBug: It is offsetting click events in the blank notebook area
+            tabsMenu = menu
+
+        if self._notebook.GetPageCount() > 1:
+            selectIDs = {}
+            for i in range(0, self._notebook.GetPageCount()):
+                id = wx.NewId()
+                selectIDs[id] = i
+                tabsMenu.Append(id, self._notebook.GetPageText(i))
+                def OnRightMenuSelect(event):
+                    self._notebook.SetSelection(selectIDs[event.GetId()])
+                wx.EVT_MENU(self, id, OnRightMenuSelect)
+        
+        self._notebook.PopupMenu(menu, wx.Point(x, y))
+        menu.Destroy()
+            
+            
+    def AddNotebookPage(self, panel, title):
+        """
+        Adds a document page to the notebook.
+        """
+        self._notebook.AddPage(panel, title)
+        index = self._notebook.GetPageCount() - 1
+        self._notebook.SetSelection(index)
 
+        found = False  # Now set the icon
+        template = panel.GetDocument().GetDocumentTemplate()
+        if template:
+            for t, iconIndex in self._iconIndexLookup:
+                if t is template:
+                    self._notebook.SetPageImage(index, iconIndex)
+                    found = True
+                    break
+        if not found:
+            self._notebook.SetPageImage(index, self._blankIconIndex)
+        self._notebook.Layout()
 
-    def __init__(self, parent, id):
+
+    def RemoveNotebookPage(self, panel):
         """
-        Initializes the panel by adding an "Options" folder tab to the parent notebook and
-        populating the panel with the generic properties of a pydocview application. 
+        Removes a document page from the notebook.
         """
-        wx.Panel.__init__(self, parent, id)
-        SPACE = 10
-        HALF_SPACE = 5
-        backgroundColor = wx.WHITE
-        config = wx.ConfigBase_Get()
-        self._showTipsCheckBox = wx.CheckBox(self, -1, _("Show tips at start up"))
-        self._showTipsCheckBox.SetBackgroundColour(backgroundColor) # wxBUG: uses wrong background color
-        self._showTipsCheckBox.SetValue(config.ReadInt("ShowTipAtStartup", True))
-        self._documentRadioBox = wx.RadioBox(self, -1, _("Document interface"),
-                                      choices = [_("Show each document in its own window (SDI)"),
-                                                 _("Show All documents in a single window (MDI)")],
-                                      majorDimension=1,
-                                      )
-        if config.ReadInt("UseMDI", True):
-            self._documentRadioBox.SetSelection(1)
+        index = self.GetNotebookPageIndex(panel)
+        if index > -1:
+            self._notebook.DeletePage(index)
+
+
+    def ActivateNotebookPage(self, panel):
+        """
+        Sets the notebook to the specified panel.
+        """
+        index = self.GetNotebookPageIndex(panel)
+        if index > -1:
+            self._notebook.SetSelection(index)
+        
+
+    def GetNotebookPageTitle(self, panel):
+        self._notebook.GetPageText(self.GetNotebookPageIndex(panel))
+        
+
+    def SetNotebookPageTitle(self, panel, title):
+        self._notebook.SetPageText(self.GetNotebookPageIndex(panel), title)
+        
+
+    def GetNotebookPageIndex(self, panel):
+        """
+        Returns the index of particular notebook panel.
+        """
+        index = -1
+        for i in range(self._notebook.GetPageCount()):
+            if self._notebook.GetPage(i) == panel:
+                index = i
+                break
+        return index
+        
+
+    def ProcessEvent(self, event):
+        """
+        Processes an event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        if wx.GetApp().ProcessEventBeforeWindows(event):
+            return True
+        if self._docManager and self._docManager.ProcessEvent(event):
+            return True
+        return DocMDIParentFrameMixIn.ProcessEvent(self, event)
+
+
+    def ProcessUpdateUIEvent(self, event):
+        """
+        Processes a UI event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        if wx.GetApp().ProcessUpdateUIEventBeforeWindows(event):
+            return True
+        if self._docManager and self._docManager.ProcessUpdateUIEvent(event):
+            return True
+        return DocMDIParentFrameMixIn.ProcessUpdateUIEvent(self, event)
+
+
+    def OnExit(self, event):
+        """
+        Called when File/Exit is chosen and closes the window.
+        """
+        self.Close()
+
+
+    def OnMRUFile(self, event):
+        """
+        Opens the appropriate file when it is selected from the file history
+        menu.
+        """
+        n = event.GetId() - wx.ID_FILE1
+        filename = self._docManager.GetHistoryFile(n)
+        if filename:
+            self._docManager.CreateDocument(filename, wx.lib.docview.DOC_SILENT)
         else:
-            self._documentRadioBox.SetSelection(0)
-        def OnDocumentInterfaceSelect(event):
-            if not self._documentInterfaceMessageShown:
-                msgTitle = wx.GetApp().GetAppName()
-                if not msgTitle:
-                    msgTitle = _("Document Options")
-                wx.MessageBox("Document interface changes will not appear until the application is restarted.",
-                              msgTitle,
-                              wx.OK | wx.ICON_INFORMATION,
-                              self.GetParent())
-                self._documentInterfaceMessageShown = True            
-        wx.EVT_RADIOBOX(self, self._documentRadioBox.GetId(), OnDocumentInterfaceSelect)
-        optionsBorderSizer = wx.BoxSizer(wx.VERTICAL)
-        optionsSizer = wx.BoxSizer(wx.VERTICAL)
-        optionsSizer.Add(self._showTipsCheckBox, 0, wx.ALL, HALF_SPACE)
-        optionsSizer.Add(self._documentRadioBox, 0, wx.ALL, HALF_SPACE)
-        optionsBorderSizer.Add(optionsSizer, 0, wx.ALL, SPACE)
-        self.SetSizer(optionsBorderSizer)
-        self.Layout()
-        self._documentInterfaceMessageShown = False
-        parent.AddPage(self, _("Options"))
+            self._docManager.RemoveFileFromHistory(n)
+            msgTitle = wx.GetApp().GetAppName()
+            if not msgTitle:
+                msgTitle = _("File Error")
+            wx.MessageBox("The file '%s' doesn't exist and couldn't be opened.\nIt has been removed from the most recently used files list" % FileNameFromPath(file),
+                          msgTitle,
+                          wx.OK | wx.ICON_EXCLAMATION,
+                          self)
 
-    def OnOK(self, optionsDialog):
+
+    def OnSize(self, event):
         """
-        Updates the config based on the selections in the options panel.
+        Called when the frame is resized and lays out the client window.
         """
-        config = wx.ConfigBase_Get()
-        config.WriteInt("ShowTipAtStartup", self._showTipsCheckBox.GetValue())
-        config.WriteInt("UseMDI", self._documentRadioBox.GetSelection())
+        # Needed in case there are splitpanels around the mdi frame
+        self._LayoutFrame()
 
 
-class DocApp(wx.PySimpleApp):
+    def OnCloseWindow(self, event):
+        """
+        Called when the frame is closed.  Remembers the frame size.
+        """
+        self.SaveEmbeddedWindowSizes()
+
+        # save and close services last
+        for service in wx.GetApp().GetServices():
+            if not service.OnCloseFrame(event):
+                return
+
+        # From docview.MDIParentFrame
+        if self._docManager.Clear(not event.CanVeto()):
+            self.Destroy()
+        else:
+            event.Veto()
+            
+
+class DocMDIChildFrame(wx.MDIChildFrame):
     """
-    The DocApp class serves as the base class for pydocview applications and offers
-    functionality such as services, creation of SDI and MDI frames, show tips,
-    and a splash screen.
+    The wxDocMDIChildFrame class provides a default frame for displaying
+    documents on separate windows. This class can only be used for MDI child
+    frames.
+
+    The class is part of the document/view framework supported by wxWindows,
+    and cooperates with the wxView, wxDocument, wxDocManager and wxDocTemplate
+    classes.
     """
 
 
-    def OnInit(self):
+    def __init__(self, doc, view, frame, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "frame"):
         """
-        Initializes the DocApp.
+        Constructor.  Note that the event table must be rebuilt for the
+        frame since the EvtHandler is not virtual.
         """
-        self._services = []
-        self._defaultIcon = None
-        self._registeredCloseEvent = False
-        if not hasattr(self, "_debug"):  # only set if not already initialized
-            self._debug = False
-        if not hasattr(self, "_singleInstance"):  # only set if not already initialized
-            self._singleInstance = True
-            
-        # if _singleInstance is TRUE only allow one single instance of app to run.
-        # When user tries to run a second instance of the app, abort startup,
-        # But if user also specifies files to open in command line, send message to running app to open those files
-        if self._singleInstance:
-            # create shared memory temporary file
-            if wx.Platform == '__WXMSW__':
-                tfile = tempfile.TemporaryFile(prefix="ag", suffix="tmp")
-                fno = tfile.fileno()
-                self._sharedMemory = mmap.mmap(fno, 1024, "shared_memory")
+        wx.MDIChildFrame.__init__(self, frame, id, title, pos, size, style, name)
+        self._childDocument = doc
+        self._childView = view
+        if view:
+            view.SetFrame(self)
+        # self.Create(doc, view, frame, id, title, pos, size, style, name)
+        self._activeEvent = None
+        self._activated = 0
+        wx.EVT_ACTIVATE(self, self.OnActivate)
+        wx.EVT_CLOSE(self, self.OnCloseWindow)
+
+        if frame:  # wxBug: For some reason the EVT_ACTIVATE event is not getting triggered for the first mdi client window that is opened so we have to do it manually
+            mdiChildren = filter(lambda x: isinstance(x, wx.MDIChildFrame), frame.GetChildren())
+            if len(mdiChildren) == 1:
+                self.Activate()
+
+
+##    # Couldn't get this to work, but seems to work fine with single stage construction
+##    def Create(self, doc, view, frame, id, title, pos, size, style, name):
+##        self._childDocument = doc
+##        self._childView = view
+##        if wx.MDIChildFrame.Create(self, frame, id, title, pos, size, style, name):
+##            if view:
+##                view.SetFrame(self)
+##                return True
+##        return False
+
+
+
+    def Activate(self):  # Need this in case there are embedded sash windows and such, OnActivate is not getting called
+        """
+        Activates the current view.
+        """
+        if self._childView:
+            self._childView.Activate(True)
+
+
+    def ProcessEvent(event):
+        """
+        Processes an event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        if self._activeEvent == event:
+            return False
+
+        self._activeEvent = event  # Break recursion loops
+
+        if self._childView:
+            self._childView.Activate(True)
+
+        if not self._childView or not self._childView.ProcessEvent(event):
+            if not isinstance(event, wx.CommandEvent) or not self.GetParent() or not self.GetParent().ProcessEvent(event):
+                ret = False
             else:
-                tfile = file(os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() + getpass.getuser() + "AGSharedMemory"), 'w+b')
-                tfile.write("*")
-                tfile.seek(1024)
-                tfile.write(" ")
-                tfile.flush()
-                fno = tfile.fileno()
-                self._sharedMemory = mmap.mmap(fno, 1024)
+                ret = True
+        else:
+            ret = True
 
-            self._singleInstanceChecker = wx.SingleInstanceChecker(self.GetAppName() + '-' + wx.GetUserId())
-            if self._singleInstanceChecker.IsAnotherRunning():
-                # have running single instance open file arguments
-                foundArgs = False
-                args = sys.argv[1:]
-                for arg in args:
-                    if arg[0] != '/' and arg[0] != '-':
-                        foundArgs = True
-                        break
-                          
-                if foundArgs:                      
-                    data = pickle.dumps(args)
-                    while 1:
-                        self._sharedMemory.seek(0)
-                        marker = self._sharedMemory.read_byte()
-                        if marker == '\0' or marker == '*':        # available buffer
-                            self._sharedMemory.seek(0)
-                            self._sharedMemory.write_byte('-')     # set writing marker
-                            self._sharedMemory.write(data)  # write files we tried to open to shared memory
-                            self._sharedMemory.seek(0)
-                            self._sharedMemory.write_byte('+')     # set finished writing marker
-                            self._sharedMemory.flush()
-                            break
-                        else:
-                            time.sleep(1)  # give enough time for buffer to be available
-                        
-                return False
+        self._activeEvent = None
+        return ret
+
+
+    def OnActivate(self, event):
+        """
+        Sets the currently active view to be the frame's view. You may need to
+        override (but still call) this function in order to set the keyboard
+        focus for your subwindow.
+        """
+        if self._activated != 0:
+            return True
+        self._activated += 1
+        wx.MDIChildFrame.Activate(self)
+        if event.GetActive() and self._childView:
+            self._childView.Activate(event.GetActive())
+        self._activated = 0
+
+
+    def OnCloseWindow(self, event):
+        """
+        Closes and deletes the current view and document.
+        """
+        if self._childView:
+            ans = False
+            if not event.CanVeto():
+                ans = True
             else:
-                self._timer = wx.PyTimer(self.DoBackgroundListenAndLoad)
-                self._timer.Start(250)
+                ans = self._childView.Close(deleteWindow = False)
+
+            if ans:
+                self._childView.Activate(False)
+                self._childView.Destroy()
+                self._childView = None
+                if self._childDocument:
+                    self._childDocument.Destroy()  # This isn't in the wxWindows codebase but the document needs to be disposed of somehow
+                self._childDocument = None
+                self.Destroy()
+            else:
+                event.Veto()
+        else:
+            event.Veto()
+
+
+    def GetDocument(self):
+        """
+        Returns the document associated with this frame.
+        """
+        return self._childDocument
+
+
+    def SetDocument(self, document):
+        """
+        Sets the document for this frame.
+        """
+        self._childDocument = document
+
+
+    def GetView(self):
+        """
+        Returns the view associated with this frame.
+        """
+        return self._childView
 
-        return True
-        
 
-    def DoBackgroundListenAndLoad(self):
+    def SetView(self, view):
         """
-        Open any files specified in the given command line argument passed in via shared memory
+        Sets the view for this frame.
         """
+        self._childView = view
+
 
-        self._sharedMemory.seek(0)
-        if self._sharedMemory.read_byte() == '+':  # available data
-            data = self._sharedMemory.read(1024-1)
-            self._sharedMemory.seek(0)
-            self._sharedMemory.write_byte("*")     # finished reading, set buffer free marker
-            self._sharedMemory.flush()
-            args = pickle.loads(data)
-            for arg in args:
-                if arg[0] != '/' and arg[0] != '-':
-                    self.GetDocumentManager().CreateDocument(arg, wx.lib.docview.DOC_SILENT)
-            
-            # force display of running app
-            topWindow = wx.GetApp().GetTopWindow()
-            if topWindow.IsIconized():
-                topWindow.Iconize(False)
-            else:
-                topWindow.Raise()
-            
-        
-        self._timer.Start(1000) # 1 second interval
 
 
-    def OpenCommandLineArgs(self):
-        """
-        Called to open files that have been passed to the application from the
-        command line.
-        """
-        args = sys.argv[1:]
-        for arg in args:
-            if arg[0] != '/' and arg[0] != '-':
-                self.GetDocumentManager().CreateDocument(arg, wx.lib.docview.DOC_SILENT)
+
+class DocService(wx.EvtHandler):
+    """
+    An abstract class used to add reusable services to a docview application.
+    """
+
+
+    def __init__(self):
+        """Initializes the DocService."""
+        pass
 
 
     def GetDocumentManager(self):
-        """
-        Returns the document manager associated to the DocApp.
-        """
+        """Returns the DocManager for the docview application."""
         return self._docManager
 
 
     def SetDocumentManager(self, docManager):
-        """
-        Sets the document manager associated with the DocApp and loads the
-        DocApp's file history into the document manager.
-        """
+        """Sets the DocManager for the docview application."""
         self._docManager = docManager
-        config = wx.ConfigBase_Get()
-        self.GetDocumentManager().FileHistoryLoad(config)
+
+
+    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
+        """Called to install controls into the menubar and toolbar of a SDI or MDI window.  Override this method for a particular service."""
+        pass
 
 
     def ProcessEventBeforeWindows(self, event):
         """
-        Enables services to process an event before the main window has a chance to
-        process the window. 
+        Processes an event before the main window has a chance to process the window. 
+        Override this method for a particular service.
         """
-        for service in self._services:
-            if service.ProcessEventBeforeWindows(event):
-                return True
         return False
 
 
     def ProcessUpdateUIEventBeforeWindows(self, event):
         """
-        Enables services to process a UI event before the main window has a chance
-        to process the window.
+        Processes a UI event before the main window has a chance to process the window.
+        Override this method for a particular service.
         """
-        for service in self._services:
-            if service.ProcessUpdateUIEventBeforeWindows(event):
-                return True
         return False
 
 
@@ -502,9 +1198,6 @@ class DocApp(wx.PySimpleApp):
         method is called from the wxPython docview framework directly since
         wxPython does not have a virtual ProcessEvent function.
         """
-        for service in self._services:
-            if service.ProcessEvent(event):
-                return True
         return False
 
 
@@ -515,952 +1208,933 @@ class DocApp(wx.PySimpleApp):
         method is called from the wxPython docview framework directly since
         wxPython does not have a virtual ProcessEvent function.
         """
-        for service in self._services:
-            if service.ProcessUpdateUIEvent(event):
-                return True
         return False
 
 
-    def InstallService(self, service):
+    def OnCloseFrame(self, event):
         """
-        Installs an instance of a DocService into the DocApp.
+        Called when the a docview frame is being closed.  Override this method
+        so a service can either do cleanup or veto the frame being closed by
+        returning false.
         """
-        service.SetDocumentManager(self._docManager)
-        self._services.append(service)
-        return service
+        return True
 
 
-    def GetServices(self):
+    def OnExit(self):
         """
-        Returns the DocService instances that have been installed into the DocApp.
+        Called when the the docview application is being closed.  Override this method
+        so a service can either do cleanup or veto the frame being closed by
+        returning false.
         """
-        return self._services
+        pass
 
 
-    def GetService(self, type):
+    def GetMenuItemPos(self, menu, id):
         """
-        Returns the instance of a particular type of service that has been installed
-        into the DocApp.  For example, "wx.GetApp().GetService(pydocview.OptionsService)"
-        returns the isntance of the OptionsService that is running within the DocApp.
+        Utility method used to find the position of a menu item so that services can
+        easily find where to insert a menu item in InstallControls.
+        """
+        menuItems = menu.GetMenuItems()
+        for i, menuItem in enumerate(menuItems):
+            if menuItem.GetId() == id:
+                return i
+        return i
+
+
+    def GetView(self):
+        """
+        Called by WindowMenuService to get views for services that don't
+        have dedicated documents such as the Outline Service.
         """
-        for service in self._services:
-            if isinstance(service, type):
-                return service
         return None
 
 
-    def OnExit(self):
+class DocOptionsService(DocService):
+    """
+    A service that implements an options menu item and an options dialog with
+    notebook tabs.  New tabs can be added by other services by calling the
+    "AddOptionsPanel" method.
+    """
+
+
+    def __init__(self, showGeneralOptions=True, allowModeChanges=True):
         """
-        Called when the DocApp is exited, enables the installed DocServices to exit
-        and saves the DocManager's file history.
+        Initializes the options service with the option of suppressing the default
+        general options pane that is included with the options service by setting
+        showGeneralOptions to False.  It allowModeChanges is set to False, the
+        default general options pane will allow users to change the document
+        interface mode between SDI and MDI modes.
         """
-        for service in self._services:
-            service.OnExit()
-        config = wx.ConfigBase_Get()
-        self._docManager.FileHistorySave(config)
-        del self._singleInstanceChecker
+        DocService.__init__(self)
+        self.ClearOptionsPanels()
+        self._allowModeChanges = allowModeChanges
+        self._toolOptionsID = wx.NewId()
+        if showGeneralOptions:
+            self.AddOptionsPanel(GeneralOptionsPanel)
 
-    
-    def GetDefaultDocManagerFlags(self):
+
+    def InstallControls(self, frame, menuBar = None, toolBar = None, statusBar = None, document = None):
         """
-        Returns the default flags to use when creating the DocManager.
+        Installs a "Tools" menu with an "Options" menu item.
         """
-        config = wx.ConfigBase_Get()
-        if config.ReadInt("UseMDI", True):
-            flags = wx.lib.docview.DOC_MDI | wx.lib.docview.DOC_OPEN_ONCE
+        toolsMenuIndex = menuBar.FindMenu(_("&Tools"))
+        if toolsMenuIndex > -1:
+            toolsMenu = menuBar.GetMenu(toolsMenuIndex)
         else:
-            flags = wx.lib.docview.DOC_SDI | wx.lib.docview.DOC_OPEN_ONCE
-        return flags
-
+            toolsMenu = wx.Menu()
+        if toolsMenuIndex == -1:
+            formatMenuIndex = menuBar.FindMenu(_("&Format"))
+            menuBar.Insert(formatMenuIndex + 1, toolsMenu, _("&Tools"))
+        if toolsMenu:
+            if toolsMenu.GetMenuItemCount():
+                toolsMenu.AppendSeparator()
+            toolsMenu.Append(self._toolOptionsID, _("&Options..."), _("Sets options"))
+            wx.EVT_MENU(frame, self._toolOptionsID, frame.ProcessEvent)
+            
 
-    def ShowTip(self, frame, tipProvider):
+    def ProcessEvent(self, event):
         """
-        Shows the tip window, generally this is called when an application starts.
-        A wx.TipProvider must be passed.
+        Checks to see if the "Options" menu item has been selected.
         """
-        config = wx.ConfigBase_Get()
-        showTip = config.ReadInt("ShowTipAtStartup", 1)
-        if showTip:
-            index = config.ReadInt("TipIndex", 0)
-            showTipResult = wx.ShowTip(frame, tipProvider, showAtStartup = showTip)
-            if showTipResult != showTip:
-                config.WriteInt("ShowTipAtStartup", showTipResult)
+        id = event.GetId()
+        if id == self._toolOptionsID:
+            self.OnOptions(event)
+            return True
+        else:
+            return False
 
 
-    def GetEditMenu(self, frame):
+    def GetAllowModeChanges(self):
         """
-        Utility method that finds the Edit menu within the menubar of a frame.
+        Return true if the default general options pane should allow users to
+        change the document interface mode between SDI and MDI modes.
         """
-        menuBar = frame.GetMenuBar()
-        if not menuBar:
-            return None
-        editMenuIndex = menuBar.FindMenu(_("&Edit"))
-        if editMenuIndex == -1:
-            return None
-        return menuBar.GetMenu(editMenuIndex)
+        return self._allowModeChanges        
 
 
-    def CreateDocumentFrame(self, view, doc, flags, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
+    def SetAllowModeChanges(self, allowModeChanges):
         """
-        Called by the DocManager to create and return a new Frame for a Document. 
-        Chooses whether to create an MDIChildFrame or SDI Frame based on the
-        DocManager's flags.
+        Set to true if the default general options pane should allow users to
+        change the document interface mode between SDI and MDI modes.
         """
-        docflags = self.GetDocumentManager().GetFlags()
-        if docflags & wx.lib.docview.DOC_SDI:
-            frame = self.CreateSDIDocumentFrame(doc, view, id, title, pos, size, style)
-            frame.Show()
+        self._allowModeChanges = allowModeChanges
 
-            # wxBug: operating system bug, first window is set to the position of last window closed, ignoring passed in position on frame creation
-            #        also, initial size is incorrect for the same reasons
-            if frame.GetPosition() != pos:
-                frame.Move(pos)
-            if frame.GetSize() != size:
-                frame.SetSize(size)
 
-            if doc and doc.GetCommandProcessor():
-                doc.GetCommandProcessor().SetEditMenu(self.GetEditMenu(frame))
-        elif docflags & wx.lib.docview.DOC_MDI:
-            frame = self.CreateMDIDocumentFrame(doc, view, id, title, pos, size, style)
-            if doc and doc.GetDocumentTemplate().GetIcon():
-                frame.SetIcon(doc.GetDocumentTemplate().GetIcon())
-            if doc and doc.GetCommandProcessor():
-                doc.GetCommandProcessor().SetEditMenu(self.GetEditMenu(wx.GetApp().GetTopWindow()))
-        if not frame.GetIcon() and self._defaultIcon:
-            frame.SetIcon(self.GetDefaultIcon())
-        view.SetFrame(frame)
-        return frame
+    def ClearOptionsPanels(self):
+        """
+        Clears all of the options panels that have been added into the
+        options dialog.
+        """
+        self._optionsPanels = []
 
 
-    def CreateSDIDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
+    def AddOptionsPanel(self, optionsPanel):
         """
-        Creates and returns an SDI Document Frame.
+        Adds an options panel to the options dialog. 
         """
-        frame = DocSDIFrame(doc, view, None, id, title, pos, size, style)
-        return frame
+        self._optionsPanels.append(optionsPanel)
 
 
-    def CreateMDIDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
+    def OnOptions(self, event):
         """
-        Creates and returns an MDI Document Frame.
+        Shows the options dialog, called when the "Options" menu item is selected.
         """
-        # if any child windows are maximized, then user must want any new children maximized
-        # if no children exist, then use the default value from registry
-        # wxBug:  Only current window is maximized, so need to check every child frame
-        parentFrame = wx.GetApp().GetTopWindow()
-        childrenMaximized = filter(lambda child: isinstance(child, wx.MDIChildFrame) and child.IsMaximized(), parentFrame.GetChildren())
-        if childrenMaximized:
-            maximize = True
-        else:
-            children = filter(lambda child: isinstance(child, wx.MDIChildFrame), parentFrame.GetChildren())
-            if children:
-                # other windows exist and none are maximized
-                maximize = False
-            else:
-                # get default setting from registry
-                maximize = wx.ConfigBase_Get().ReadInt("MDIChildFrameMaximized", False)
+        if len(self._optionsPanels) == 0:
+            return
+        optionsDialog = OptionsDialog(wx.GetApp().GetTopWindow(), self._optionsPanels, self._docManager)
+        if optionsDialog.ShowModal() == wx.ID_OK:
+            optionsDialog.OnOK(optionsDialog)  # wxBug: wxDialog should be calling this automatically but doesn't
+        optionsDialog.Destroy()
+
+
+class OptionsDialog(wx.Dialog):
+    """
+    A default options dialog used by the OptionsService that hosts a notebook
+    tab of options panels.
+    """
 
-        frame = wx.lib.docview.DocMDIChildFrame(doc, view, wx.GetApp().GetTopWindow(), id, title, pos, size, style)
-        if maximize:  # wxBug: Should already be maximizing new child frames if one is maximized but it's not so we have to force it to
-            frame.Maximize(True)
 
-##        wx.EVT_MAXIMIZE(frame, self.OnMaximize) # wxBug: This doesn't work, need to save MDIChildFrameMaximized state on close of windows instead
-        wx.EVT_CLOSE(frame, self.OnCloseChildWindow)
-        if not self._registeredCloseEvent:
-            wx.EVT_CLOSE(parentFrame, self.OnCloseMainWindow) # need to check on this, but only once
-            self._registeredCloseEvent = True
+    def __init__(self, parent, optionsPanelClasses, docManager):
+        """
+        Initializes the options dialog with a notebook page that contains new
+        instances of the passed optionsPanelClasses.
+        """
+        wx.Dialog.__init__(self, parent, -1, _("Options"), size = (310, 400))
 
-        return frame
+        self._optionsPanels = []
+        self._docManager = docManager
+
+        HALF_SPACE = 5
+        SPACE = 10
 
+        sizer = wx.BoxSizer(wx.VERTICAL)
 
-    def SaveMDIDocumentFrameMaximizedState(self, maximized):
+        optionsNotebook = wx.Notebook(self, -1, size = (310, 375))
+        sizer.Add(optionsNotebook, 0, wx.ALL | wx.EXPAND, SPACE)
+        for optionsPanelClass in optionsPanelClasses:
+            optionsPanel = optionsPanelClass(optionsNotebook, -1)
+            self._optionsPanels.append(optionsPanel)
+        sizer.Add(self.CreateButtonSizer(wx.OK | wx.CANCEL), 0, wx.ALIGN_RIGHT | wx.RIGHT | wx.BOTTOM, HALF_SPACE)
+        self.SetSizer(sizer)
+        self.Layout()
+        self.Fit()
+        wx.CallAfter(self.DoRefresh)
+
+
+    def DoRefresh(self):
         """
-        Remember in the config whether the MDI Frame is maximized so that it can be restored
-        on open.
+        wxBug: On Windows XP when using a multiline notebook the default page doesn't get
+        drawn, but it works when using a single line notebook.
         """
-        config = wx.ConfigBase_Get()
-        maximizeFlag = config.ReadInt("MDIChildFrameMaximized", False)
-        if maximized != maximizeFlag:
-            config.WriteInt("MDIChildFrameMaximized", maximized)
+        self.Refresh()
 
 
-    def OnCloseChildWindow(self, event):
+    def GetDocManager(self):
         """
-        Called when an MDI Child Frame is closed.  Calls SaveMDIDocumentFrameMaximizedState to
-        remember whether the MDI Frame is maximized so that it can be restored on open.
+        Returns the document manager passed to the OptionsDialog constructor.
         """
-        self.SaveMDIDocumentFrameMaximizedState(event.GetEventObject().IsMaximized())
-        event.Skip()
+        return self._docManager
 
 
-    def OnCloseMainWindow(self, event):
+    def OnOK(self, event):
         """
-        Called when the MDI Parent Frame is closed.  Remembers whether the MDI Parent Frame is
-        maximized.
+        Calls the OnOK method of all of the OptionDialog's embedded panels
         """
-        children = event.GetEventObject().GetChildren()
-        childrenMaximized = filter(lambda child: isinstance(child, wx.MDIChildFrame)and child.IsMaximized(), children)
-        if childrenMaximized:
-            self.SaveMDIDocumentFrameMaximizedState(True)
-        else:
-            childrenNotMaximized = filter(lambda child: isinstance(child, wx.MDIChildFrame), children)
+        for optionsPanel in self._optionsPanels:
+            optionsPanel.OnOK(event)
 
-            if childrenNotMaximized:
-                # other windows exist and none are maximized
-                self.SaveMDIDocumentFrameMaximizedState(False)
 
-        event.Skip()
+class GeneralOptionsPanel(wx.Panel):
+    """
+    A general options panel that is used in the OptionDialog to configure the
+    generic properties of a pydocview application, such as "show tips at startup"
+    and whether to use SDI or MDI for the application.
+    """
 
 
-    def GetDefaultIcon(self):
+    def __init__(self, parent, id):
         """
-        Returns the application's default icon.
+        Initializes the panel by adding an "Options" folder tab to the parent notebook and
+        populating the panel with the generic properties of a pydocview application. 
         """
-        return self._defaultIcon
+        wx.Panel.__init__(self, parent, id)
+        SPACE = 10
+        HALF_SPACE = 5
+        config = wx.ConfigBase_Get()
+        self._showTipsCheckBox = wx.CheckBox(self, -1, _("Show tips at start up"))
+        self._showTipsCheckBox.SetValue(config.ReadInt("ShowTipAtStartup", True))
+        if wx.GetApp().GetService(DocOptionsService).GetAllowModeChanges():
+            choices = [_("Show each document in its own window"), _("Show all documents in a single window with tabs")]
+            if wx.Platform == "__WXMSW__":
+                choices.append(_("Show all documents in a single window with child windows"))
+            self._documentRadioBox = wx.RadioBox(self, -1, _("Document Interface"),
+                                          choices = choices,
+                                          majorDimension=1,
+                                          )
+            if config.ReadInt("UseWinMDI", False):
+                self._documentRadioBox.SetSelection(2)
+            elif config.ReadInt("UseMDI", True):
+                self._documentRadioBox.SetSelection(1)
+            else:
+                self._documentRadioBox.SetSelection(0)
+            def OnDocumentInterfaceSelect(event):
+                if not self._documentInterfaceMessageShown:
+                    msgTitle = wx.GetApp().GetAppName()
+                    if not msgTitle:
+                        msgTitle = _("Document Options")
+                    wx.MessageBox("Document interface changes will not appear until the application is restarted.",
+                                  msgTitle,
+                                  wx.OK | wx.ICON_INFORMATION,
+                                  self.GetParent())
+                    self._documentInterfaceMessageShown = True
+            wx.EVT_RADIOBOX(self, self._documentRadioBox.GetId(), OnDocumentInterfaceSelect)
+        optionsBorderSizer = wx.BoxSizer(wx.VERTICAL)
+        optionsSizer = wx.BoxSizer(wx.VERTICAL)
+        if wx.GetApp().GetService(DocOptionsService).GetAllowModeChanges():
+            optionsSizer.Add(self._documentRadioBox, 0, wx.ALL, HALF_SPACE)
+        optionsSizer.Add(self._showTipsCheckBox, 0, wx.ALL, HALF_SPACE)
+        optionsBorderSizer.Add(optionsSizer, 0, wx.ALL, SPACE)
+        self.SetSizer(optionsBorderSizer)
+        self.Layout()
+        self._documentInterfaceMessageShown = False
+        parent.AddPage(self, _("Options"))
 
 
-    def SetDefaultIcon(self, icon):
+    def OnOK(self, optionsDialog):
         """
-        Sets the application's default icon.
+        Updates the config based on the selections in the options panel.
         """
-        self._defaultIcon = icon
+        config = wx.ConfigBase_Get()
+        config.WriteInt("ShowTipAtStartup", self._showTipsCheckBox.GetValue())
+        if wx.GetApp().GetService(DocOptionsService).GetAllowModeChanges():
+            config.WriteInt("UseMDI", (self._documentRadioBox.GetSelection() == 1))
+            config.WriteInt("UseWinMDI", (self._documentRadioBox.GetSelection() == 2))
 
 
-    def GetDebug(self):
+class DocApp(wx.PySimpleApp):
+    """
+    The DocApp class serves as the base class for pydocview applications and offers
+    functionality such as services, creation of SDI and MDI frames, show tips,
+    and a splash screen.
+    """
+
+
+    def OnInit(self):
         """
-        Returns True if the application is in debug mode.
+        Initializes the DocApp.
         """
-        return self._debug
+        self._services = []
+        self._defaultIcon = None
+        self._registeredCloseEvent = False
+        self._useTabbedMDI = True
+
+        if not hasattr(self, "_debug"):  # only set if not already initialized
+            self._debug = False
+        if not hasattr(self, "_singleInstance"):  # only set if not already initialized
+            self._singleInstance = True
+            
+        # if _singleInstance is TRUE only allow one single instance of app to run.
+        # When user tries to run a second instance of the app, abort startup,
+        # But if user also specifies files to open in command line, send message to running app to open those files
+        if self._singleInstance:
+            # create shared memory temporary file
+            if wx.Platform == '__WXMSW__':
+                tfile = tempfile.TemporaryFile(prefix="ag", suffix="tmp")
+                fno = tfile.fileno()
+                self._sharedMemory = mmap.mmap(fno, 1024, "shared_memory")
+            else:
+                tfile = file(os.path.join(tempfile.gettempdir(), tempfile.gettempprefix() + self.GetAppName() + '-' + wx.GetUserId() + "AGSharedMemory"), 'w+b')
+                tfile.write("*")
+                tfile.seek(1024)
+                tfile.write(" ")
+                tfile.flush()
+                fno = tfile.fileno()
+                self._sharedMemory = mmap.mmap(fno, 1024)
+
+            self._singleInstanceChecker = wx.SingleInstanceChecker(self.GetAppName() + '-' + wx.GetUserId(), tempfile.gettempdir())
+            if self._singleInstanceChecker.IsAnotherRunning():
+                # have running single instance open file arguments
+                data = pickle.dumps(sys.argv[1:])
+                while 1:
+                    self._sharedMemory.seek(0)
+                    marker = self._sharedMemory.read_byte()
+                    if marker == '\0' or marker == '*':        # available buffer
+                        self._sharedMemory.seek(0)
+                        self._sharedMemory.write_byte('-')     # set writing marker
+                        self._sharedMemory.write(data)  # write files we tried to open to shared memory
+                        self._sharedMemory.seek(0)
+                        self._sharedMemory.write_byte('+')     # set finished writing marker
+                        self._sharedMemory.flush()
+                        break
+                    else:
+                        time.sleep(1)  # give enough time for buffer to be available
+                        
+                return False
+            else:
+                self._timer = wx.PyTimer(self.DoBackgroundListenAndLoad)
+                self._timer.Start(250)
+
+        return True
+        
 
+    def OpenMainFrame(self):
+        docManager = self.GetDocumentManager()
+        if docManager.GetFlags() & wx.lib.docview.DOC_MDI:
+            if self.GetUseTabbedMDI():
+                frame = wx.lib.pydocview.DocTabbedParentFrame(docManager, None, -1, self.GetAppName())
+            else:
+                frame = wx.lib.pydocview.DocMDIParentFrame(docManager, None, -1, self.GetAppName())                
+            frame.Show(True)
 
-    def SetDebug(self, debug):
+        
+    def DoBackgroundListenAndLoad(self):
         """
-        Sets the application's debug mode.
+        Open any files specified in the given command line argument passed in via shared memory
         """
-        self._debug = debug
+        self._timer.Stop()
+
+        self._sharedMemory.seek(0)
+        if self._sharedMemory.read_byte() == '+':  # available data
+            data = self._sharedMemory.read(1024-1)
+            self._sharedMemory.seek(0)
+            self._sharedMemory.write_byte("*")     # finished reading, set buffer free marker
+            self._sharedMemory.flush()
+            args = pickle.loads(data)
+            for arg in args:
+                if arg[0] != '/' and arg[0] != '-' and os.path.exists(arg):
+                    self.GetDocumentManager().CreateDocument(arg, wx.lib.docview.DOC_SILENT)
+            
+            # force display of running app
+            topWindow = wx.GetApp().GetTopWindow()
+            if topWindow.IsIconized():
+                topWindow.Iconize(False)
+            else:
+                topWindow.Raise()
+            
+        
+        self._timer.Start(1000) # 1 second interval
 
 
-    def GetSingleInstance(self):
+    def OpenCommandLineArgs(self):
         """
-        Returns True if the application is in single instance mode.  Used to determine if multiple instances of the application is allowed to launch.
+        Called to open files that have been passed to the application from the
+        command line.
         """
-        return self._singleInstance
+        args = sys.argv[1:]
+        for arg in args:
+            if arg[0] != '/' and arg[0] != '-' and os.path.exists(arg):
+                self.GetDocumentManager().CreateDocument(arg, wx.lib.docview.DOC_SILENT)
 
 
-    def SetSingleInstance(self, singleInstance):
+    def GetDocumentManager(self):
         """
-        Sets application's single instance mode.
+        Returns the document manager associated to the DocApp.
         """
-        self._singleInstance = singleInstance
-
+        return self._docManager
 
 
-    def CreateChildDocument(self, parentDocument, documentType, objectToEdit, path = ''):
+    def SetDocumentManager(self, docManager):
         """
-        Creates a child window of a document that edits an object.  The child window
-        is managed by the parent document frame, so it will be prompted to close if its
-        parent is closed, etc.  Child Documents are useful when there are complicated 
-        Views of a Document and users will need to tunnel into the View.
+        Sets the document manager associated with the DocApp and loads the
+        DocApp's file history into the document manager.
         """
-        for document in self.GetDocumentManager().GetDocuments()[:]:  # Cloning list to make sure we go through all docs even as they are deleted
-            if isinstance(document, ChildDocument) and document.GetParentDocument() == parentDocument:
-                if document.GetData() == objectToEdit:
-                    if hasattr(document.GetFirstView().GetFrame(), "SetFocus"):
-                        document.GetFirstView().GetFrame().SetFocus()
-                    return document
-        for temp in wx.GetApp().GetDocumentManager().GetTemplates():
-            if temp.GetDocumentType() == documentType:
-                break
-            temp = None
-        newDoc = temp.CreateDocument(path, 0, data = objectToEdit, parentDocument = parentDocument)
-        newDoc.SetDocumentName(temp.GetDocumentName())
-        newDoc.SetDocumentTemplate(temp)
-        if path == '':
-            newDoc.OnNewDocument()
-        else:
-            if not newDoc.OnOpenDocument(path):
-                newDoc.DeleteAllViews()  # Implicitly deleted by DeleteAllViews
-                return None
-        return newDoc
+        self._docManager = docManager
+        config = wx.ConfigBase_Get()
+        self.GetDocumentManager().FileHistoryLoad(config)
 
 
-    def CloseChildDocuments(self, parentDocument):
+    def ProcessEventBeforeWindows(self, event):
         """
-        Closes the child windows of a Document.
+        Enables services to process an event before the main window has a chance to
+        process the window. 
         """
-        for document in self.GetDocumentManager().GetDocuments()[:]:  # Cloning list to make sure we go through all docs even as they are deleted
-            if isinstance(document, ChildDocument) and document.GetParentDocument() == parentDocument:
-                if document.GetFirstView().GetFrame():
-                    document.GetFirstView().GetFrame().SetFocus()
-                if document.GetFirstView().OnClose(deleteWindow = False):
-                    if document.GetFirstView().GetFrame():
-                        document.GetFirstView().GetFrame().Close()  # wxBug: Need to do this for some random reason
-                else:
-                    return False
-        return True
+        for service in self._services:
+            if service.ProcessEventBeforeWindows(event):
+                return True
+        return False
 
 
-    def IsMDI(self):
+    def ProcessUpdateUIEventBeforeWindows(self, event):
         """
-        Returns True if the application is in MDI mode.
+        Enables services to process a UI event before the main window has a chance
+        to process the window.
         """
-        return self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_MDI
+        for service in self._services:
+            if service.ProcessUpdateUIEventBeforeWindows(event):
+                return True
+        return False
 
 
-    def IsSDI(self):
+    def ProcessEvent(self, event):
         """
-        Returns True if the application is in SDI mode.
+        Processes an event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
         """
-        return self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI
+        for service in self._services:
+            if service.ProcessEvent(event):
+                return True
+        return False
 
 
-    def ShowSplash(self, image):
+    def ProcessUpdateUIEvent(self, event):
         """
-        Shows a splash window with the given image.  Input parameter 'image' can either be a wx.Bitmap or a filename.
+        Processes a UI event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
         """
-        if isinstance(image, wx.Bitmap):
-            splash_bmp = image
-        else:
-            splash_bmp = wx.Image(image).ConvertToBitmap()
-        self._splash = wx.SplashScreen(splash_bmp,wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_NO_TIMEOUT,0, None, -1) 
-        self._splash.Show()
+        for service in self._services:
+            if service.ProcessUpdateUIEvent(event):
+                return True
+        return False
 
 
-    def CloseSplash(self):
+    def InstallService(self, service):
         """
-        Closes the splash window.
+        Installs an instance of a DocService into the DocApp.
         """
-        if self._splash:
-            self._splash.Close(True)
-        
-    
-class _DocFrameFileDropTarget(wx.FileDropTarget):
-    """
-    Class used to handle drops into the document frame.
-    """
+        service.SetDocumentManager(self._docManager)
+        self._services.append(service)
+        return service
 
-    def __init__(self, docManager, docFrame):
+
+    def GetServices(self):
         """
-        Initializes the FileDropTarget class with the active docManager and the docFrame.
+        Returns the DocService instances that have been installed into the DocApp.
         """
-        wx.FileDropTarget.__init__(self)
-        self._docManager = docManager
-        self._docFrame = docFrame
+        return self._services
 
 
-    def OnDropFiles(self, x, y, filenames):
+    def GetService(self, type):
         """
-        Called when files are dropped in the drop target and tells the docManager to open
-        the files.
+        Returns the instance of a particular type of service that has been installed
+        into the DocApp.  For example, "wx.GetApp().GetService(pydocview.OptionsService)"
+        returns the isntance of the OptionsService that is running within the DocApp.
         """
-        try:
-            for file in filenames:
-                self._docManager.CreateDocument(file, wx.lib.docview.DOC_SILENT)
-        except:
-            msgTitle = wx.GetApp().GetAppName()
-            if not msgTitle:
-                msgTitle = _("File Error")
-            wx.MessageBox("Could not open '%s'.  '%s'" % (docview.FileNameFromPath(file), sys.exc_value),
-                          msgTitle,
-                          wx.OK | wx.ICON_EXCLAMATION,
-                          self._docManager.FindSuitableParent())
-
+        for service in self._services:
+            if isinstance(service, type):
+                return service
+        return None
 
-class DocMDIParentFrame(wx.lib.docview.DocMDIParentFrame):
-    """
-    The DocMDIParentFrame is the primary frame which the DocApp uses to host MDI child windows.  It offers
-    features such as a default menubar, toolbar, and status bar, and a mechanism to manage embedded windows
-    on the edges of the DocMDIParentFrame.
-    """
-    
 
-    def __init__(self, docManager, parent, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "DocMDIFrame", embeddedWindows = 0):
+    def OnExit(self):
         """
-        Initializes the DocMDIParentFrame with the default menubar, toolbar, and status bar.  Use the
-        optional embeddedWindows parameter with the embedded window constants to create embedded
-        windows around the edges of the DocMDIParentFrame.
+        Called when the DocApp is exited, enables the installed DocServices to exit
+        and saves the DocManager's file history.
         """
+        for service in self._services:
+            service.OnExit()
         config = wx.ConfigBase_Get()
-        if pos == wx.DefaultPosition and size == wx.DefaultSize and config.ReadInt("MDIFrameMaximized", False):
-            pos = [0, 0]
-            size = wx.DisplaySize()
-            # wxBug: Need to set to fill screen to get around bug where maximize is leaving shadow of statusbar, check out maximize call at end of this function
-        else:
-            if pos == wx.DefaultPosition:
-                pos = config.ReadInt("MDIFrameXLoc", -1), config.ReadInt("MDIFrameYLoc", -1)
-
-            if wx.Display_GetFromPoint(pos) == -1:  # Check if the frame position is offscreen
-                pos = wx.DefaultPosition
-                
-            if size == wx.DefaultSize:
-                size = wx.Size(config.ReadInt("MDIFrameXSize", 450), config.ReadInt("MDIFrameYSize", 300))
-
-        wx.lib.docview.DocMDIParentFrame.__init__(self, docManager, parent, id, title, pos, size, style, name)
-        self._embeddedWindows = []
-        self.SetDropTarget(_DocFrameFileDropTarget(docManager, self))
-
-        if wx.GetApp().GetDefaultIcon():
-            self.SetIcon(wx.GetApp().GetDefaultIcon())
-
-        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
-        wx.EVT_SIZE(self, self.OnSize)
-
-        self.InitializePrintData()
-
-        toolBar = self.CreateDefaultToolBar()
-        self.SetToolBar(toolBar)
-        menuBar = self.CreateDefaultMenuBar()
-        statusBar = self.CreateDefaultStatusBar()
-
-        if config.ReadInt("MDIFrameMaximized", False):
-            # wxBug: On maximize, statusbar leaves a residual that needs to be refereshed, happens even when user does it
-            self.Maximize()
-
-        self.CreateEmbeddedWindows(embeddedWindows)
-
-        wx.GetApp().SetTopWindow(self)  # Need to do this here in case the services are looking for wx.GetApp().GetTopWindow()
-        for service in wx.GetApp().GetServices():
-            service.InstallControls(self, menuBar = menuBar, toolBar = toolBar, statusBar = statusBar)
-            if hasattr(service, "ShowWindow"):
-                service.ShowWindow()  # instantiate service windows for correct positioning, we'll hide/show them later based on user preference
-
-        self.SetMenuBar(menuBar)  # wxBug: Have to set the menubar at the very end or the automatic MDI "window" menu doesn't get put in the right place when the services add new menus to the menubar
-
+        self._docManager.FileHistorySave(config)
+        
+        if hasattr(self, "_singleInstanceChecker"):
+            del self._singleInstanceChecker
 
-    def CreateEmbeddedWindows(self, windows = 0):
+    
+    def GetDefaultDocManagerFlags(self):
         """
-        Create the specified embedded windows around the edges of the DocMDIParentFrame.
+        Returns the default flags to use when creating the DocManager.
         """
-        frameSize = self.GetSize()   # TODO: GetClientWindow.GetSize is still returning 0,0 since the frame isn't fully constructed yet, so using full frame size
-        defaultHSize = int(frameSize[0] / 6)
-        defaultVSize = int(frameSize[1] / 7)
-        defaultSubVSize = int(frameSize[1] / 2)
-        #print defaultHSize, defaultVSize, defaultSubVSize
         config = wx.ConfigBase_Get()
-        if windows & (EMBEDDED_WINDOW_LEFT | EMBEDDED_WINDOW_TOPLEFT | EMBEDDED_WINDOW_BOTTOMLEFT):
-            self._leftEmbWindow = self._CreateEmbeddedWindow(self, (config.ReadInt("MDIEmbedLeftSize", defaultHSize), -1), wx.LAYOUT_VERTICAL, wx.LAYOUT_LEFT, visible = config.ReadInt("MDIEmbedLeftVisible", 1), sash = wx.SASH_RIGHT)
-        else:
-            self._leftEmbWindow = None
-        if windows & EMBEDDED_WINDOW_TOPLEFT:
-            self._topLeftEmbWindow = self._CreateEmbeddedWindow(self._leftEmbWindow, (-1, config.ReadInt("MDIEmbedTopLeftSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_TOP, visible = config.ReadInt("MDIEmbedTopLeftVisible", 1), sash = wx.SASH_BOTTOM)
-        else:
-            self._topLeftEmbWindow = None
-        if windows & EMBEDDED_WINDOW_BOTTOMLEFT:
-            self._bottomLeftEmbWindow = self._CreateEmbeddedWindow(self._leftEmbWindow, (-1, config.ReadInt("MDIEmbedBottomLeftSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_BOTTOM, visible = config.ReadInt("MDIEmbedBottomLeftVisible", 1))
-        else:
-            self._bottomLeftEmbWindow = None
-        if windows & (EMBEDDED_WINDOW_RIGHT | EMBEDDED_WINDOW_TOPRIGHT | EMBEDDED_WINDOW_BOTTOMRIGHT):
-            self._rightEmbWindow = self._CreateEmbeddedWindow(self, (config.ReadInt("MDIEmbedRightSize", defaultHSize), -1), wx.LAYOUT_VERTICAL, wx.LAYOUT_RIGHT, visible = config.ReadInt("MDIEmbedRightVisible", 1), sash = wx.SASH_LEFT)
-        else:
-            self._rightEmbWindow = None
-        if windows & EMBEDDED_WINDOW_TOPRIGHT:
-            self._topRightEmbWindow = self._CreateEmbeddedWindow(self._rightEmbWindow, (-1, config.ReadInt("MDIEmbedTopRightSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_TOP, visible = config.ReadInt("MDIEmbedTopRightVisible", 1), sash = wx.SASH_BOTTOM)
-        else:
-            self._topRightEmbWindow = None
-        if windows & EMBEDDED_WINDOW_BOTTOMRIGHT:
-            self._bottomRightEmbWindow = self._CreateEmbeddedWindow(self._rightEmbWindow, (-1, config.ReadInt("MDIEmbedBottomRightSize", defaultSubVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_BOTTOM, visible = config.ReadInt("MDIEmbedBottomRightVisible", 1))
-        else:
-            self._bottomRightEmbWindow = None
-        if windows & EMBEDDED_WINDOW_TOP:
-            self._topEmbWindow = self._CreateEmbeddedWindow(self, (-1, config.ReadInt("MDIEmbedTopSize", defaultVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_TOP, visible = config.ReadInt("MDIEmbedTopVisible", 1), sash = wx.SASH_BOTTOM)
-        else:
-            self._topEmbWindow = None
-        if windows & EMBEDDED_WINDOW_BOTTOM:
-            self._bottomEmbWindow = self._CreateEmbeddedWindow(self, (-1, config.ReadInt("MDIEmbedBottomSize", defaultVSize)), wx.LAYOUT_HORIZONTAL, wx.LAYOUT_BOTTOM, visible = config.ReadInt("MDIEmbedBottomVisible", 1), sash = wx.SASH_TOP)
+        if config.ReadInt("UseMDI", True) or config.ReadInt("UseWinMDI", False):
+            flags = wx.lib.docview.DOC_MDI | wx.lib.docview.DOC_OPEN_ONCE
+            if config.ReadInt("UseWinMDI", False):
+                self.SetUseTabbedMDI(False)
         else:
-            self._bottomEmbWindow = None
-        wx.LayoutAlgorithm().LayoutMDIFrame(self)
-        self.GetClientWindow().Refresh()
+            flags = wx.lib.docview.DOC_SDI | wx.lib.docview.DOC_OPEN_ONCE
+        return flags
 
 
-    def SaveEmbeddedWindowSizes(self):
+    def ShowTip(self, frame, tipProvider):
         """
-        Saves the sizes of the embedded windows.
+        Shows the tip window, generally this is called when an application starts.
+        A wx.TipProvider must be passed.
         """
         config = wx.ConfigBase_Get()
-        if self._leftEmbWindow:
-            config.WriteInt("MDIEmbedLeftSize", self._leftEmbWindow.GetSize()[0])
-            config.WriteInt("MDIEmbedLeftVisible", self._leftEmbWindow.IsShown())
-        if self._topLeftEmbWindow:
-            if self._topLeftEmbWindow._sizeBeforeHidden:
-                size = self._topLeftEmbWindow._sizeBeforeHidden[1]
-            else:
-                size = self._topLeftEmbWindow.GetSize()[1]
-            config.WriteInt("MDIEmbedTopLeftSize", size)
-            config.WriteInt("MDIEmbedTopLeftVisible", self._topLeftEmbWindow.IsShown())
-        if self._bottomLeftEmbWindow:
-            if self._bottomLeftEmbWindow._sizeBeforeHidden:
-                size = self._bottomLeftEmbWindow._sizeBeforeHidden[1]
-            else:
-                size = self._bottomLeftEmbWindow.GetSize()[1]
-            config.WriteInt("MDIEmbedBottomLeftSize", size)
-            config.WriteInt("MDIEmbedBottomLeftVisible", self._bottomLeftEmbWindow.IsShown())
-        if self._rightEmbWindow:
-            config.WriteInt("MDIEmbedRightSize", self._rightEmbWindow.GetSize()[0])
-            config.WriteInt("MDIEmbedRightVisible", self._rightEmbWindow.IsShown())
-        if self._topRightEmbWindow:
-            if self._topRightEmbWindow._sizeBeforeHidden:
-                size = self._topRightEmbWindow._sizeBeforeHidden[1]
-            else:
-                size = self._topRightEmbWindow.GetSize()[1]
-            config.WriteInt("MDIEmbedTopRightSize", size)
-            config.WriteInt("MDIEmbedTopRightVisible", self._topRightEmbWindow.IsShown())
-        if self._bottomRightEmbWindow:
-            if self._bottomRightEmbWindow._sizeBeforeHidden:
-                size = self._bottomRightEmbWindow._sizeBeforeHidden[1]
-            else:
-                size = self._bottomRightEmbWindow.GetSize()[1]
-            config.WriteInt("MDIEmbedBottomRightSize", size)
-            config.WriteInt("MDIEmbedBottomRightVisible", self._bottomRightEmbWindow.IsShown())
-        if self._topEmbWindow:
-            config.WriteInt("MDIEmbedTopSize", self._topEmbWindow.GetSize()[1])
-            config.WriteInt("MDIEmbedTopVisible", self._topEmbWindow.IsShown())
-        if self._bottomEmbWindow:
-            config.WriteInt("MDIEmbedBottomSize", self._bottomEmbWindow.GetSize()[1])
-            config.WriteInt("MDIEmbedBottomVisible", self._bottomEmbWindow.IsShown())
+        showTip = config.ReadInt("ShowTipAtStartup", 1)
+        if showTip:
+            index = config.ReadInt("TipIndex", 0)
+            showTipResult = wx.ShowTip(wx.GetApp().GetTopWindow(), tipProvider, showAtStartup = showTip)
+            if showTipResult != showTip:
+                config.WriteInt("ShowTipAtStartup", showTipResult)
 
 
-    def GetEmbeddedWindow(self, loc):
-        """
-        Returns the instance of the embedded window specified by the embedded window location constant.
+    def GetEditMenu(self, frame):
         """
-        if loc == EMBEDDED_WINDOW_TOP:
-            return self._topEmbWindow
-        elif loc == EMBEDDED_WINDOW_BOTTOM:
-            return self._bottomEmbWindow
-        elif loc == EMBEDDED_WINDOW_LEFT:
-            return self._leftEmbWindow
-        elif loc == EMBEDDED_WINDOW_RIGHT:
-            return self._rightEmbWindow
-        elif loc == EMBEDDED_WINDOW_TOPLEFT:
-            return self._topLeftEmbWindow
-        elif loc == EMBEDDED_WINDOW_BOTTOMLEFT:
-            return self._bottomLeftEmbWindow
-        elif loc == EMBEDDED_WINDOW_TOPRIGHT:
-            return self._topRightEmbWindow
-        elif loc == EMBEDDED_WINDOW_BOTTOMRIGHT:
-            return self._bottomRightEmbWindow
-        return None
+        Utility method that finds the Edit menu within the menubar of a frame.
+        """
+        menuBar = frame.GetMenuBar()
+        if not menuBar:
+            return None
+        editMenuIndex = menuBar.FindMenu(_("&Edit"))
+        if editMenuIndex == -1:
+            return None
+        return menuBar.GetMenu(editMenuIndex)
 
 
-    def _CreateEmbeddedWindow(self, parent, size, orientation, alignment, visible = True, sash = None):
+    def GetUseTabbedMDI(self):
         """
-        Creates the embedded window with the specified size, orientation, and alignment.  If the 
-        window is not visible it will retain the size with which it was last viewed.
+        Returns True if Windows MDI should use folder tabs instead of child windows.
         """
-        window = wx.SashLayoutWindow(parent, wx.NewId(), style = wx.NO_BORDER | wx.SW_3D)
-        window.SetDefaultSize(size)
-        window.SetOrientation(orientation)
-        window.SetAlignment(alignment)
-        if sash != None:  # wx.SASH_TOP is 0 so check for None instead of just doing "if sash:"
-            window.SetSashVisible(sash, True)
-        ####
-        def OnEmbeddedWindowSashDrag(event):
-            if event.GetDragStatus() == wx.SASH_STATUS_OUT_OF_RANGE:
-                return
-            sashWindow = event.GetEventObject()
-            if sashWindow.GetAlignment() == wx.LAYOUT_TOP or sashWindow.GetAlignment() == wx.LAYOUT_BOTTOM:
-                size = wx.Size(-1, event.GetDragRect().height)
-            else:
-                size = wx.Size(event.GetDragRect().width, -1)
-            event.GetEventObject().SetDefaultSize(size)
-            wx.LayoutAlgorithm().LayoutMDIFrame(self)
-            self.GetClientWindow().Refresh()
-            if isinstance(sashWindow.GetParent(), wx.SashLayoutWindow):
-                sashWindow.Show()
-                parentSashWindow = sashWindow.GetParent()  # Force a refresh
-                parentSashWindow.Layout()
-                parentSashWindow.Refresh()
-                parentSashWindow.SetSize((parentSashWindow.GetSize().width + 1, parentSashWindow.GetSize().height + 1))
-        ####
-        wx.EVT_SASH_DRAGGED(window, window.GetId(), OnEmbeddedWindowSashDrag)
-        window._sizeBeforeHidden = None
-        if not visible:
-            window.Show(False)
-            if isinstance(parent, wx.SashLayoutWindow): # It's a window embedded in another sash window so remember its actual size to show it again
-                window._sizeBeforeHidden = size
-        return window
-
+        return self._useTabbedMDI
+        
 
-    def ShowEmbeddedWindow(self, window, show = True):
+    def SetUseTabbedMDI(self, useTabbedMDI):
         """
-        Shows or hides the embedded window specified by the embedded window location constant.
+        Set to True if Windows MDI should use folder tabs instead of child windows.
         """
-        window.Show(show)
-        if isinstance(window.GetParent(), wx.SashLayoutWindow):  # It is a parent sashwindow with multiple embedded sashwindows
-            parentSashWindow = window.GetParent()
-            if show:  # Make sure it is visible in case all of the subwindows were hidden
-                parentSashWindow.Show()                
-            if show and window._sizeBeforeHidden:
-                if window._sizeBeforeHidden[1] == parentSashWindow.GetClientSize()[1]:
-                    if window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).IsShown():
-                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).GetSize()[1]))
-                    elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).IsShown():
-                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).GetSize()[1]))
-                    elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).IsShown():
-                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).GetSize()[1]))
-                    elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT) and self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).IsShown():
-                        window.SetDefaultSize((window._sizeBeforeHidden[0], window._sizeBeforeHidden[0] - self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).GetSize()[1]))
-                    print window.GetSize()
-                else:
-                    window.SetDefaultSize(window._sizeBeforeHidden)
-                    # If it is not the size of the full parent sashwindow set the other window's size so that if it gets shown it will have a cooresponding size
-                    print "Parent size, size before hidden ", parentSashWindow.GetClientSize()[1], window._sizeBeforeHidden[1]
-                    if window._sizeBeforeHidden[1] < parentSashWindow.GetClientSize()[1]:
-                        otherWindowSize = (-1, parentSashWindow.GetClientSize()[1] - window._sizeBeforeHidden[1])
-                        print "Other", otherWindowSize
-                        if window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT):
-                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).SetDefaultSize(otherWindowSize)
-                        elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT):
-                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).SetDefaultSize(otherWindowSize)
-                        elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT):
-                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).SetDefaultSize(otherWindowSize)
-                        elif window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT):
-                            self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).SetDefaultSize(otherWindowSize)
-                    
-            if not show:
-                if window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT).IsShown() \
-                    or window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT).IsShown() \
-                    or window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT).IsShown() \
-                    or window == self.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT) and not self.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT).IsShown():
-                    parentSashWindow.Hide()  # Hide the parent sashwindow if all of the children are hidden
-            parentSashWindow.Layout()   # Force a refresh
-            parentSashWindow.Refresh()
-            parentSashWindow.SetSize((parentSashWindow.GetSize().width + 1, parentSashWindow.GetSize().height + 1))
-        wx.LayoutAlgorithm().LayoutMDIFrame(self)
-        self.GetClientWindow().Refresh()
+        self._useTabbedMDI = useTabbedMDI
 
 
-    def HideEmbeddedWindow(self):
+    def CreateDocumentFrame(self, view, doc, flags, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
         """
-        Hides the embedded window specified by the embedded window location constant.
+        Called by the DocManager to create and return a new Frame for a Document. 
+        Chooses whether to create an MDIChildFrame or SDI Frame based on the
+        DocManager's flags.
         """
-        self.ShowEmbeddedWindow(show = False)
+        docflags = self.GetDocumentManager().GetFlags()
+        if docflags & wx.lib.docview.DOC_SDI:
+            frame = self.CreateSDIDocumentFrame(doc, view, id, title, pos, size, style)
+            frame.Show()
 
+            # wxBug: operating system bug, first window is set to the position of last window closed, ignoring passed in position on frame creation
+            #        also, initial size is incorrect for the same reasons
+            if frame.GetPosition() != pos:
+                frame.Move(pos)
+            if frame.GetSize() != size:
+                frame.SetSize(size)
 
-    def GetDocumentManager(self):
+            if doc and doc.GetCommandProcessor():
+                doc.GetCommandProcessor().SetEditMenu(self.GetEditMenu(frame))
+        elif docflags & wx.lib.docview.DOC_MDI:
+            if self.GetUseTabbedMDI():
+                frame = self.CreateTabbedDocumentFrame(doc, view, id, title, pos, size, style)
+            else:
+                frame = self.CreateMDIDocumentFrame(doc, view, id, title, pos, size, style)
+                if doc:
+                    if doc.GetDocumentTemplate().GetIcon():
+                        frame.SetIcon(doc.GetDocumentTemplate().GetIcon())
+                    elif wx.GetApp().GetTopWindow().GetIcon():
+                        frame.SetIcon(wx.GetApp().GetTopWindow().GetIcon())
+            if doc and doc.GetCommandProcessor():
+                doc.GetCommandProcessor().SetEditMenu(self.GetEditMenu(wx.GetApp().GetTopWindow()))
+        if not frame.GetIcon() and self._defaultIcon:
+            frame.SetIcon(self.GetDefaultIcon())
+        view.SetFrame(frame)
+        return frame
+
+
+    def CreateSDIDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
         """
-        Returns the document manager associated with the DocMDIParentFrame.
+        Creates and returns an SDI Document Frame.
         """
-        return self._docManager
+        frame = DocSDIFrame(doc, view, None, id, title, pos, size, style)
+        return frame
 
 
-    def InitializePrintData(self):
+    def CreateTabbedDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
         """
-        Initializes the PrintData that is used when printing.
+        Creates and returns an MDI Document Frame for a Tabbed MDI view
         """
-        self._printData = wx.PrintData()
-        self._printData.SetPaperId(wx.PAPER_LETTER)
+        frame = DocTabbedChildFrame(doc, view, wx.GetApp().GetTopWindow(), id, title, pos, size, style)
+        return frame
 
 
-    def CreateDefaultStatusBar(self):
+    def CreateMDIDocumentFrame(self, doc, view, id = -1, title = "", pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE):
         """
-        Creates the default StatusBar.
+        Creates and returns an MDI Document Frame.
         """
-        self.CreateStatusBar()
-        self.GetStatusBar().Show(wx.ConfigBase_Get().ReadInt("ViewStatusBar", True))
-        self.UpdateStatus()
-        return self.GetStatusBar()
+        # if any child windows are maximized, then user must want any new children maximized
+        # if no children exist, then use the default value from registry
+        # wxBug:  Only current window is maximized, so need to check every child frame
+        parentFrame = wx.GetApp().GetTopWindow()
+        childrenMaximized = filter(lambda child: isinstance(child, wx.MDIChildFrame) and child.IsMaximized(), parentFrame.GetChildren())
+        if childrenMaximized:
+            maximize = True
+        else:
+            children = filter(lambda child: isinstance(child, wx.MDIChildFrame), parentFrame.GetChildren())
+            if children:
+                # other windows exist and none are maximized
+                maximize = False
+            else:
+                # get default setting from registry
+                maximize = wx.ConfigBase_Get().ReadInt("MDIChildFrameMaximized", False)
+
+        frame = wx.lib.docview.DocMDIChildFrame(doc, view, wx.GetApp().GetTopWindow(), id, title, pos, size, style)
+        if maximize:  # wxBug: Should already be maximizing new child frames if one is maximized but it's not so we have to force it to
+            frame.Maximize(True)
 
+##        wx.EVT_MAXIMIZE(frame, self.OnMaximize) # wxBug: This doesn't work, need to save MDIChildFrameMaximized state on close of windows instead
+        wx.EVT_CLOSE(frame, self.OnCloseChildWindow)
+        if not self._registeredCloseEvent:
+            wx.EVT_CLOSE(parentFrame, self.OnCloseMainWindow) # need to check on this, but only once
+            self._registeredCloseEvent = True
 
-    def CreateDefaultToolBar(self):
+        return frame
+
+
+    def SaveMDIDocumentFrameMaximizedState(self, maximized):
         """
-        Creates the default ToolBar.
+        Remember in the config whether the MDI Frame is maximized so that it can be restored
+        on open.
         """
-        self._toolBar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
-        self._toolBar.AddSimpleTool(wx.ID_NEW, getNewBitmap(), _("New"), _("Creates a new document"))
-        self._toolBar.AddSimpleTool(wx.ID_OPEN, getOpenBitmap(), _("Open"), _("Opens an existing document"))
-        self._toolBar.AddSimpleTool(wx.ID_SAVE, getSaveBitmap(), _("Save"), _("Saves the active document"))
-        self._toolBar.AddSimpleTool(SAVEALL_ID, getSaveAllBitmap(), _("Save All"), _("Saves all the active documents"))
-        self._toolBar.AddSeparator()
-        self._toolBar.AddSimpleTool(wx.ID_PRINT, getPrintBitmap(), _("Print"), _("Displays full pages"))
-        self._toolBar.AddSimpleTool(wx.ID_PREVIEW, getPrintPreviewBitmap(), _("Print Preview"), _("Prints the active document"))
-        self._toolBar.AddSeparator()
-        self._toolBar.AddSimpleTool(wx.ID_CUT, getCutBitmap(), _("Cut"), _("Cuts the selection and puts it on the Clipboard"))
-        self._toolBar.AddSimpleTool(wx.ID_COPY, getCopyBitmap(), _("Copy"), _("Copies the selection and puts it on the Clipboard"))
-        self._toolBar.AddSimpleTool(wx.ID_PASTE, getPasteBitmap(), _("Paste"), _("Inserts Clipboard contents"))
-        self._toolBar.AddSimpleTool(wx.ID_UNDO, getUndoBitmap(), _("Undo"), _("Reverses the last action"))
-        self._toolBar.AddSimpleTool(wx.ID_REDO, getRedoBitmap(), _("Redo"), _("Reverses the last undo"))
-        self._toolBar.Realize()
-        self._toolBar.Show(wx.ConfigBase_Get().ReadInt("ViewToolBar", True))
-
-        return self._toolBar
+        config = wx.ConfigBase_Get()
+        maximizeFlag = config.ReadInt("MDIChildFrameMaximized", False)
+        if maximized != maximizeFlag:
+            config.WriteInt("MDIChildFrameMaximized", maximized)
 
 
-    def CreateDefaultMenuBar(self):
+    def OnCloseChildWindow(self, event):
         """
-        Creates the default MenuBar.  Contains File, Edit, View, Tools, and Help menus.
+        Called when an MDI Child Frame is closed.  Calls SaveMDIDocumentFrameMaximizedState to
+        remember whether the MDI Frame is maximized so that it can be restored on open.
         """
-        menuBar = wx.MenuBar()
+        self.SaveMDIDocumentFrameMaximizedState(event.GetEventObject().IsMaximized())
+        event.Skip()
 
-        fileMenu = wx.Menu()
-        fileMenu.Append(wx.ID_NEW, _("&New...\tCtrl+N"), _("Creates a new document"))
-        fileMenu.Append(wx.ID_OPEN, _("&Open...\tCtrl+O"), _("Opens an existing document"))
-        fileMenu.Append(wx.ID_CLOSE, _("&Close"), _("Closes the active document"))
-        fileMenu.Append(wx.ID_CLOSE_ALL, _("Close A&ll"), _("Closes all open documents"))
-        fileMenu.AppendSeparator()
-        fileMenu.Append(wx.ID_SAVE, _("&Save\tCtrl+S"), _("Saves the active document"))
-        fileMenu.Append(wx.ID_SAVEAS, _("Save &As..."), _("Saves the active document with a new name"))
-        fileMenu.Append(SAVEALL_ID, _("Save All\tCtrl+Shift+A"), _("Saves the all active documents"))
-        wx.EVT_MENU(self, SAVEALL_ID, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, SAVEALL_ID, self.ProcessUpdateUIEvent)
-        fileMenu.AppendSeparator()
-        fileMenu.Append(wx.ID_PRINT, _("&Print\tCtrl+P"), _("Prints the active document"))
-        fileMenu.Append(wx.ID_PREVIEW, _("Print Pre&view"), _("Displays full pages"))
-        fileMenu.Append(wx.ID_PRINT_SETUP, _("Page Set&up"), _("Changes page layout settings"))
-        fileMenu.AppendSeparator()
-        if wx.Platform == '__WXMAC__':
-            fileMenu.Append(wx.ID_EXIT, _("&Quit"), _("Closes this program"))
+
+    def OnCloseMainWindow(self, event):
+        """
+        Called when the MDI Parent Frame is closed.  Remembers whether the MDI Parent Frame is
+        maximized.
+        """
+        children = event.GetEventObject().GetChildren()
+        childrenMaximized = filter(lambda child: isinstance(child, wx.MDIChildFrame)and child.IsMaximized(), children)
+        if childrenMaximized:
+            self.SaveMDIDocumentFrameMaximizedState(True)
         else:
-            fileMenu.Append(wx.ID_EXIT, _("E&xit"), _("Closes this program"))
-        self._docManager.FileHistoryUseMenu(fileMenu)
-        self._docManager.FileHistoryAddFilesToMenu()
-        menuBar.Append(fileMenu, _("&File"));
+            childrenNotMaximized = filter(lambda child: isinstance(child, wx.MDIChildFrame), children)
+
+            if childrenNotMaximized:
+                # other windows exist and none are maximized
+                self.SaveMDIDocumentFrameMaximizedState(False)
+
+        event.Skip()
 
-        editMenu = wx.Menu()
-        editMenu.Append(wx.ID_UNDO, _("&Undo\tCtrl+Z"), _("Reverses the last action"))
-        editMenu.Append(wx.ID_REDO, _("&Redo\tCtrl+Y"), _("Reverses the last undo"))
-        editMenu.AppendSeparator()
-        #item = wxMenuItem(self.editMenu, wxID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard"))
-        #item.SetBitmap(getCutBitmap())
-        #editMenu.AppendItem(item)
-        editMenu.Append(wx.ID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard"))
-        wx.EVT_MENU(self, wx.ID_CUT, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_CUT, self.ProcessUpdateUIEvent)
-        editMenu.Append(wx.ID_COPY, _("&Copy\tCtrl+C"), _("Copies the selection and puts it on the Clipboard"))
-        wx.EVT_MENU(self, wx.ID_COPY, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_COPY, self.ProcessUpdateUIEvent)
-        editMenu.Append(wx.ID_PASTE, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents"))
-        wx.EVT_MENU(self, wx.ID_PASTE, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_PASTE, self.ProcessUpdateUIEvent)
-        editMenu.Append(wx.ID_CLEAR, _("Cle&ar\tDel"), _("Erases the selection"))
-        wx.EVT_MENU(self, wx.ID_CLEAR, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_CLEAR, self.ProcessUpdateUIEvent)
-        editMenu.AppendSeparator()
-        editMenu.Append(wx.ID_SELECTALL, _("Select A&ll\tCtrl+A"), _("Selects all available data"))
-        wx.EVT_MENU(self, wx.ID_SELECTALL, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_SELECTALL, self.ProcessUpdateUIEvent)
-        menuBar.Append(editMenu, _("&Edit"))
 
-        viewMenu = wx.Menu()
-        viewMenu.AppendCheckItem(VIEW_TOOLBAR_ID, _("&Toolbar"), _("Shows or hides the toolbar"))
-        wx.EVT_MENU(self, VIEW_TOOLBAR_ID, self.OnViewToolBar)
-        wx.EVT_UPDATE_UI(self, VIEW_TOOLBAR_ID, self.OnUpdateViewToolBar)
-        viewMenu.AppendCheckItem(VIEW_STATUSBAR_ID, _("&Status Bar"), _("Shows or hides the status bar"))
-        wx.EVT_MENU(self, VIEW_STATUSBAR_ID, self.OnViewStatusBar)
-        wx.EVT_UPDATE_UI(self, VIEW_STATUSBAR_ID, self.OnUpdateViewStatusBar)
-        menuBar.Append(viewMenu, _("&View"))
+    def GetDefaultIcon(self):
+        """
+        Returns the application's default icon.
+        """
+        return self._defaultIcon
 
-        helpMenu = wx.Menu()
-        helpMenu.Append(wx.ID_ABOUT, _("&About" + " " + wx.GetApp().GetAppName()), _("Displays program information, version number, and copyright"))
-        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
-        menuBar.Append(helpMenu, _("&Help"))
 
-##        windowMenu = wx.Menu()
-##        menuBar.Append(windowMenu, _("&Window"))
-##        # self.SetWindowMenu(windowMenu)
-##
-        wx.EVT_UPDATE_UI(self, wx.ID_ABOUT, self.ProcessUpdateUIEvent)  # Using ID_ABOUT to update the window menu, the window menu items are not triggering
+    def SetDefaultIcon(self, icon):
+        """
+        Sets the application's default icon.
+        """
+        self._defaultIcon = icon
 
-        return menuBar
 
-##        accelTable = wx.AcceleratorTable([
-##            eval(_("wx.ACCEL_CTRL, ord('Z'), wx.ID_UNDO")),
-##            eval(_("wx.ACCEL_CTRL, ord('Y'), wx.ID_REDO")),
-##            eval(_("wx.ACCEL_CTRL, ord('X'), wx.ID_CUT")),
-##            eval(_("wx.ACCEL_CTRL, ord('C'), wx.ID_COPY")),
-##            eval(_("wx.ACCEL_CTRL, ord('V'), wx.ID_PASTE")),
-##            (wx.ACCEL_NORMAL, wx.WXK_DELETE, wx.ID_CLEAR),
-##            eval(_("wx.ACCEL_CTRL, ord('A'), wx.ID_SELECTALL")),
-##            eval(_("wx.ACCEL_CTRL, ord('N'), wx.ID_NEW")),
-##            eval(_("wx.ACCEL_CTRL, ord('O'), wx.ID_OPEN")),
-##            eval(_("wx.ACCEL_CTRL, ord('S'), wx.ID_SAVE"))
-##            ])
-##        self.SetAcceleratorTable(accelTable)
+    def GetDebug(self):
+        """
+        Returns True if the application is in debug mode.
+        """
+        return self._debug
 
 
-    def ProcessEvent(self, event):
+    def SetDebug(self, debug):
         """
-        Processes an event, searching event tables and calling zero or more
-        suitable event handler function(s).  Note that the ProcessEvent
-        method is called from the wxPython docview framework directly since
-        wxPython does not have a virtual ProcessEvent function.
+        Sets the application's debug mode.
         """
-        if wx.GetApp().ProcessEventBeforeWindows(event):
-            return True
-        if wx.lib.docview.DocMDIParentFrame.ProcessEvent(self, event):
-            return True
-            
-        id = event.GetId()
-        if id == SAVEALL_ID:
-            self.OnFileSaveAll(event)
-            return True
-            
-        return wx.GetApp().ProcessEvent(event)
+        self._debug = debug
 
 
-    def ProcessUpdateUIEvent(self, event):
+    def GetSingleInstance(self):
         """
-        Processes a UI event, searching event tables and calling zero or more
-        suitable event handler function(s).  Note that the ProcessEvent
-        method is called from the wxPython docview framework directly since
-        wxPython does not have a virtual ProcessEvent function.
+        Returns True if the application is in single instance mode.  Used to determine if multiple instances of the application is allowed to launch.
         """
-        if wx.GetApp().ProcessUpdateUIEventBeforeWindows(event):
-            return True
-        if wx.lib.docview.DocMDIParentFrame.ProcessUpdateUIEvent(self, event):  # Let the views handle the event before the services
-            return True
-        id = event.GetId()
-        if id == wx.ID_CUT:
-            event.Enable(False)
-            return True
-        elif id == wx.ID_COPY:
-            event.Enable(False)
-            return True
-        elif id == wx.ID_PASTE:
-            event.Enable(False)
-            return True
-        elif id == wx.ID_CLEAR:
-            event.Enable(False)
-            return True
-        elif id == wx.ID_SELECTALL:
-            event.Enable(False)
-            return True
-        elif id == wx.ID_ABOUT:  # Using ID_ABOUT to update the window menu, the window menu items are not triggering
-            self.UpdateWindowMenu()
-            return True
-        elif id == SAVEALL_ID:
-            filesModified = False
-            docs = wx.GetApp().GetDocumentManager().GetDocuments()
-            for doc in docs:
-                if doc.IsModified():
-                    filesModified = True
-                    break
-                
-            event.Enable(filesModified)
-            return True
+        return self._singleInstance
+
+
+    def SetSingleInstance(self, singleInstance):
+        """
+        Sets application's single instance mode.
+        """
+        self._singleInstance = singleInstance
+
+
+
+    def CreateChildDocument(self, parentDocument, documentType, objectToEdit, path = ''):
+        """
+        Creates a child window of a document that edits an object.  The child window
+        is managed by the parent document frame, so it will be prompted to close if its
+        parent is closed, etc.  Child Documents are useful when there are complicated 
+        Views of a Document and users will need to tunnel into the View.
+        """
+        for document in self.GetDocumentManager().GetDocuments()[:]:  # Cloning list to make sure we go through all docs even as they are deleted
+            if isinstance(document, ChildDocument) and document.GetParentDocument() == parentDocument:
+                if document.GetData() == objectToEdit:
+                    if hasattr(document.GetFirstView().GetFrame(), "SetFocus"):
+                        document.GetFirstView().GetFrame().SetFocus()
+                    return document
+        for temp in wx.GetApp().GetDocumentManager().GetTemplates():
+            if temp.GetDocumentType() == documentType:
+                break
+            temp = None
+        newDoc = temp.CreateDocument(path, 0, data = objectToEdit, parentDocument = parentDocument)
+        newDoc.SetDocumentName(temp.GetDocumentName())
+        newDoc.SetDocumentTemplate(temp)
+        if path == '':
+            newDoc.OnNewDocument()
         else:
-            return wx.GetApp().ProcessUpdateUIEvent(event)
+            if not newDoc.OnOpenDocument(path):
+                newDoc.DeleteAllViews()  # Implicitly deleted by DeleteAllViews
+                return None
+        return newDoc
 
 
-    def UpdateWindowMenu(self):
+    def CloseChildDocuments(self, parentDocument):
         """
-        Updates the WindowMenu on Windows platforms.
+        Closes the child windows of a Document.
         """
-        if wx.Platform == '__WXMSW__':
-            children = filter(lambda child: isinstance(child, wx.MDIChildFrame), self.GetChildren())
-            windowCount = len(children)
-            hasWindow = windowCount >= 1
-            has2OrMoreWindows = windowCount >= 2
+        for document in self.GetDocumentManager().GetDocuments()[:]:  # Cloning list to make sure we go through all docs even as they are deleted
+            if isinstance(document, ChildDocument) and document.GetParentDocument() == parentDocument:
+                if document.GetFirstView().GetFrame():
+                    document.GetFirstView().GetFrame().SetFocus()
+                if document.GetFirstView().OnClose(deleteWindow = False):
+                    if document.GetFirstView().GetFrame():
+                        document.GetFirstView().GetFrame().Close()  # wxBug: Need to do this for some random reason
+                else:
+                    return False
+        return True
 
-            windowMenu = self.GetWindowMenu()
-            windowMenu.Enable(wx.IDM_WINDOWTILE, hasWindow)
-            windowMenu.Enable(wx.IDM_WINDOWTILEHOR, hasWindow)
-            windowMenu.Enable(wx.IDM_WINDOWCASCADE, hasWindow)
-            windowMenu.Enable(wx.IDM_WINDOWICONS, hasWindow)
-            windowMenu.Enable(wx.IDM_WINDOWTILEVERT, hasWindow)
-            wx.IDM_WINDOWPREV = 4006  # wxBug: Not defined for some reason
-            windowMenu.Enable(wx.IDM_WINDOWPREV, has2OrMoreWindows)
-            windowMenu.Enable(wx.IDM_WINDOWNEXT, has2OrMoreWindows)
+
+    def IsMDI(self):
+        """
+        Returns True if the application is in MDI mode.
+        """
+        return self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_MDI
 
 
-    def OnFileSaveAll(self, event):
+    def IsSDI(self):
         """
-        Saves all of the currently open documents.
+        Returns True if the application is in SDI mode.
         """
-        docs = wx.GetApp().GetDocumentManager().GetDocuments()
-        for doc in docs:
-            doc.Save()
-            
+        return self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI
 
-    def OnCloseWindow(self, event):
+
+    def ShowSplash(self, image):
         """
-        Called when the DocMDIParentFrame is closed.  Remembers the frame size.
+        Shows a splash window with the given image.  Input parameter 'image' can either be a wx.Bitmap or a filename.
         """
-        config = wx.ConfigBase_Get()
-        if not self.IsMaximized():
-            config.WriteInt("MDIFrameXLoc", self.GetPositionTuple()[0])
-            config.WriteInt("MDIFrameYLoc", self.GetPositionTuple()[1])
-            config.WriteInt("MDIFrameXSize", self.GetSizeTuple()[0])
-            config.WriteInt("MDIFrameYSize", self.GetSizeTuple()[1])
-        config.WriteInt("MDIFrameMaximized", self.IsMaximized())
-        config.WriteInt("ViewToolBar", self._toolBar.IsShown())
-        config.WriteInt("ViewStatusBar", self.GetStatusBar().IsShown())
+        if isinstance(image, wx.Bitmap):
+            splash_bmp = image
+        else:
+            splash_bmp = wx.Image(image).ConvertToBitmap()
+        self._splash = wx.SplashScreen(splash_bmp,wx.SPLASH_CENTRE_ON_SCREEN | wx.SPLASH_NO_TIMEOUT,0, None, -1) 
+        self._splash.Show()
 
-        self.SaveEmbeddedWindowSizes()
 
-        # save and close services last.
-        for service in wx.GetApp().GetServices():
-            if not service.OnCloseFrame(event):
-                return
+    def CloseSplash(self):
+        """
+        Closes the splash window.
+        """
+        if self._splash:
+            self._splash.Close(True)
+        
+    
+class _DocFrameFileDropTarget(wx.FileDropTarget):
+    """
+    Class used to handle drops into the document frame.
+    """
 
-        # save and close documents
-        # documents with a common view, e.g. project view, should save the document, but not close the window
-        # and let the service close the window.
-        wx.lib.docview.DocMDIParentFrame.OnCloseWindow(self, event)
+    def __init__(self, docManager, docFrame):
+        """
+        Initializes the FileDropTarget class with the active docManager and the docFrame.
+        """
+        wx.FileDropTarget.__init__(self)
+        self._docManager = docManager
+        self._docFrame = docFrame
 
 
-    def OnAbout(self, event):
+    def OnDropFiles(self, x, y, filenames):
         """
-        Invokes the about dialog.
+        Called when files are dropped in the drop target and tells the docManager to open
+        the files.
         """
-        aboutService = wx.GetApp().GetService(AboutService)
-        if aboutService:
-            aboutService.ShowAbout()
+        try:
+            for file in filenames:
+                self._docManager.CreateDocument(file, wx.lib.docview.DOC_SILENT)
+        except:
+            msgTitle = wx.GetApp().GetAppName()
+            if not msgTitle:
+                msgTitle = _("File Error")
+            wx.MessageBox("Could not open '%s'.  '%s'" % (docview.FileNameFromPath(file), sys.exc_value),
+                          msgTitle,
+                          wx.OK | wx.ICON_EXCLAMATION,
+                          self._docManager.FindSuitableParent())
 
 
-    def OnViewToolBar(self, event):
+class DocMDIParentFrame(wx.lib.docview.DocMDIParentFrame, DocFrameMixIn, DocMDIParentFrameMixIn):
+    """
+    The DocMDIParentFrame is the primary frame which the DocApp uses to host MDI child windows.  It offers
+    features such as a default menubar, toolbar, and status bar, and a mechanism to manage embedded windows
+    on the edges of the DocMDIParentFrame.
+    """
+    
+
+    def __init__(self, docManager, parent, id, title, pos = wx.DefaultPosition, size = wx.DefaultSize, style = wx.DEFAULT_FRAME_STYLE, name = "DocMDIFrame", embeddedWindows = 0):
         """
-        Toggles whether the ToolBar is visible.
+        Initializes the DocMDIParentFrame with the default menubar, toolbar, and status bar.  Use the
+        optional embeddedWindows parameter with the embedded window constants to create embedded
+        windows around the edges of the DocMDIParentFrame.
+        """
+        pos, size = self._GetPosSizeFromConfig(pos, size)
+        wx.lib.docview.DocMDIParentFrame.__init__(self, docManager, parent, id, title, pos, size, style, name)
+        self._InitFrame(embeddedWindows)
+
+
+    def _LayoutFrame(self):
+        """
+        Lays out the frame.
         """
-        self._toolBar.Show(not self._toolBar.IsShown())
         wx.LayoutAlgorithm().LayoutMDIFrame(self)
         self.GetClientWindow().Refresh()
+        
+
+    def ProcessEvent(self, event):
+        """
+        Processes an event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
+        """
+        if wx.GetApp().ProcessEventBeforeWindows(event):
+            return True
+        if wx.lib.docview.DocMDIParentFrame.ProcessEvent(self, event):
+            return True
+        return DocMDIParentFrameMixIn.ProcessEvent(self, event)
 
 
-    def OnUpdateViewToolBar(self, event):
+    def ProcessUpdateUIEvent(self, event):
         """
-        Updates the View ToolBar menu item.
+        Processes a UI event, searching event tables and calling zero or more
+        suitable event handler function(s).  Note that the ProcessEvent
+        method is called from the wxPython docview framework directly since
+        wxPython does not have a virtual ProcessEvent function.
         """
-        event.Check(self.GetToolBar().IsShown())
+        if wx.GetApp().ProcessUpdateUIEventBeforeWindows(event):
+            return True
+        if wx.lib.docview.DocMDIParentFrame.ProcessUpdateUIEvent(self, event):  # Let the views handle the event before the services
+            return True
+        if event.GetId() == wx.ID_ABOUT:  # Using ID_ABOUT to update the window menu, the window menu items are not triggering
+            self.UpdateWindowMenu()
+            return True
+        return DocMDIParentFrameMixIn.ProcessUpdateUIEvent(self, event)
 
 
-    def OnViewStatusBar(self, event):
+    def UpdateWindowMenu(self):
         """
-        Toggles whether the StatusBar is visible.
+        Updates the WindowMenu on Windows platforms.
         """
-        self.GetStatusBar().Show(not self.GetStatusBar().IsShown())
-        self.Layout()
-        wx.LayoutAlgorithm().LayoutMDIFrame(self)
-        self.GetClientWindow().Refresh()
+        if wx.Platform == '__WXMSW__':
+            children = filter(lambda child: isinstance(child, wx.MDIChildFrame), self.GetChildren())
+            windowCount = len(children)
+            hasWindow = windowCount >= 1
+            has2OrMoreWindows = windowCount >= 2
+
+            windowMenu = self.GetWindowMenu()
+            if windowMenu:
+                windowMenu.Enable(wx.IDM_WINDOWTILE, hasWindow)
+                windowMenu.Enable(wx.IDM_WINDOWTILEHOR, hasWindow)
+                windowMenu.Enable(wx.IDM_WINDOWCASCADE, hasWindow)
+                windowMenu.Enable(wx.IDM_WINDOWICONS, hasWindow)
+                windowMenu.Enable(wx.IDM_WINDOWTILEVERT, hasWindow)
+                wx.IDM_WINDOWPREV = 4006  # wxBug: Not defined for some reason
+                windowMenu.Enable(wx.IDM_WINDOWPREV, has2OrMoreWindows)
+                windowMenu.Enable(wx.IDM_WINDOWNEXT, has2OrMoreWindows)
+                
 
 
-    def OnUpdateViewStatusBar(self, event):
+    def OnSize(self, event):
         """
-        Updates the View StatusBar menu item.
+        Called when the DocMDIParentFrame is resized and lays out the MDI client window.
         """
-        event.Check(self.GetStatusBar().IsShown())
+        # Needed in case there are splitpanels around the mdi frame
+        self._LayoutFrame()
 
 
-    def UpdateStatus(self, message = _("Ready")):
+    def OnCloseWindow(self, event):
         """
-        Updates the StatusBar.
+        Called when the DocMDIParentFrame is closed.  Remembers the frame size.
         """
-        # wxBug: Menubar and toolbar help strings don't pop the status text back
-        if self.GetStatusBar().GetStatusText() != message:
-            self.GetStatusBar().PushStatusText(message)
+        self.SaveEmbeddedWindowSizes()
 
+        # save and close services last.
+        for service in wx.GetApp().GetServices():
+            if not service.OnCloseFrame(event):
+                return
 
-    def OnSize(self, event):
-        """
-        Called when the DocMDIParentFrame is resized and lays out the MDI client window.
-        """
-        # Needed in case there are splitpanels around the mdi frame
-        wx.LayoutAlgorithm().LayoutMDIFrame(self)
-        self.GetClientWindow().Refresh()
+        # save and close documents
+        # documents with a common view, e.g. project view, should save the document, but not close the window
+        # and let the service close the window.
+        wx.lib.docview.DocMDIParentFrame.OnCloseWindow(self, event)
 
 
-class DocSDIFrame(wx.lib.docview.DocChildFrame):
+class DocSDIFrame(wx.lib.docview.DocChildFrame, DocFrameMixIn):
     """
     The DocSDIFrame host DocManager Document windows.  It offers features such as a default menubar,
     toolbar, and status bar.
@@ -1485,7 +2159,7 @@ class DocSDIFrame(wx.lib.docview.DocChildFrame):
 
         self.InitializePrintData()
 
-        menuBar = self.CreateDefaultMenuBar()
+        menuBar = self.CreateDefaultMenuBar(sdi=True)
         toolBar = self.CreateDefaultToolBar()
         self.SetToolBar(toolBar)
         statusBar = self.CreateDefaultStatusBar()
@@ -1496,12 +2170,12 @@ class DocSDIFrame(wx.lib.docview.DocChildFrame):
         self.SetMenuBar(menuBar)  # wxBug: Need to do this in SDI to mimic MDI... because have to set the menubar at the very end or the automatic MDI "window" menu doesn't get put in the right place when the services add new menus to the menubar
 
 
-    def GetDocumentManager(self):
+    def _LayoutFrame(self):
         """
-        Returns the document manager associated with the DocSDIFrame.
+        Lays out the Frame.
         """
-        return self._docManager
-
+        self.Layout()
+        
 
     def OnExit(self, event):
         """
@@ -1533,135 +2207,6 @@ class DocSDIFrame(wx.lib.docview.DocChildFrame):
                           self)
 
 
-    def InitializePrintData(self):
-        """
-        Initializes the PrintData that is used when printing.
-        """
-        self._printData = wx.PrintData()
-        self._printData.SetPaperId(wx.PAPER_LETTER)
-
-
-    def CreateDefaultStatusBar(self):
-        """
-        Creates the default StatusBar.
-        """
-        wx.lib.docview.DocChildFrame.CreateStatusBar(self)
-        self.GetStatusBar().Show(wx.ConfigBase_Get().ReadInt("ViewStatusBar", True))
-        self.UpdateStatus()
-        return self.GetStatusBar()
-
-
-    def CreateDefaultToolBar(self):
-        """
-        Creates the default ToolBar.
-        """
-        self._toolBar = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
-        self._toolBar.AddSimpleTool(wx.ID_NEW, getNewBitmap(), _("New"), _("Creates a new document"))
-        self._toolBar.AddSimpleTool(wx.ID_OPEN, getOpenBitmap(), _("Open"), _("Opens an existing document"))
-        self._toolBar.AddSimpleTool(wx.ID_SAVE, getSaveBitmap(), _("Save"), _("Saves the active document"))
-        self._toolBar.AddSimpleTool(SAVEALL_ID, getSaveAllBitmap(), _("Save All"), _("Saves all the active documents"))
-        self._toolBar.AddSeparator()
-        self._toolBar.AddSimpleTool(wx.ID_PRINT, getPrintBitmap(), _("Print"), _("Displays full pages"))
-        self._toolBar.AddSimpleTool(wx.ID_PREVIEW, getPrintPreviewBitmap(), _("Print Preview"), _("Prints the active document"))
-        self._toolBar.AddSeparator()
-        self._toolBar.AddSimpleTool(wx.ID_CUT, getCutBitmap(), _("Cut"), _("Cuts the selection and puts it on the Clipboard"))
-        self._toolBar.AddSimpleTool(wx.ID_COPY, getCopyBitmap(), _("Copy"), _("Copies the selection and puts it on the Clipboard"))
-        self._toolBar.AddSimpleTool(wx.ID_PASTE, getPasteBitmap(), _("Paste"), _("Inserts Clipboard contents"))
-        self._toolBar.AddSimpleTool(wx.ID_UNDO, getUndoBitmap(), _("Undo"), _("Reverses the last action"))
-        self._toolBar.AddSimpleTool(wx.ID_REDO, getRedoBitmap(), _("Redo"), _("Reverses the last undo"))
-        self._toolBar.Realize()
-        self._toolBar.Show(wx.ConfigBase_Get().ReadInt("ViewToolBar", True))
-        return self._toolBar
-
-
-    def CreateDefaultMenuBar(self):
-        """
-        Creates the default MenuBar.  Contains File, Edit, View, Tools, and Help menus.
-        """
-        menuBar = wx.MenuBar()
-
-        fileMenu = wx.Menu()
-        self._fileMenu = fileMenu
-        fileMenu.Append(wx.ID_NEW, _("&New...\tCtrl+N"), _("Creates a new document"))
-        fileMenu.Append(wx.ID_OPEN, _("&Open...\tCtrl+O"), _("Opens an existing document"))
-        fileMenu.Append(wx.ID_CLOSE, _("&Close"), _("Closes the active document"))
-        # fileMenu.Append(wx.ID_CLOSE_ALL, _("Close A&ll"), _("Closes all open documents"))
-        fileMenu.AppendSeparator()
-        fileMenu.Append(wx.ID_SAVE, _("&Save\tCtrl+S"), _("Saves the active document"))
-        fileMenu.Append(wx.ID_SAVEAS, _("Save &As..."), _("Saves the active document with a new name"))
-        fileMenu.Append(SAVEALL_ID, _("Save All\tCtrl+Shift+A"), _("Saves the all active documents"))
-        wx.EVT_MENU(self, SAVEALL_ID, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, SAVEALL_ID, self.ProcessUpdateUIEvent)
-        fileMenu.AppendSeparator()
-        fileMenu.Append(wx.ID_PRINT, _("&Print\tCtrl+P"), _("Prints the active document"))
-        fileMenu.Append(wx.ID_PREVIEW, _("Print Pre&view"), _("Displays full pages"))
-        fileMenu.Append(wx.ID_PRINT_SETUP, _("Page Set&up"), _("Changes page layout settings"))
-        fileMenu.AppendSeparator()
-        if wx.Platform == '__WXMAC__':
-            fileMenu.Append(wx.ID_EXIT, _("&Quit"), _("Closes this program"))
-        else:
-            fileMenu.Append(wx.ID_EXIT, _("E&xit"), _("Closes this program"))
-        if self._docManager:
-            self._docManager.FileHistoryUseMenu(fileMenu)
-            self._docManager.FileHistoryAddFilesToMenu(fileMenu)
-        menuBar.Append(fileMenu, _("&File"));
-
-        editMenu = wx.Menu()
-        editMenu.Append(wx.ID_UNDO, _("&Undo\tCtrl+Z"), _("Reverses the last action"))
-        editMenu.Append(wx.ID_REDO, _("&Redo\tCtrl+Y"), _("Reverses the last undo"))
-        editMenu.AppendSeparator()
-        editMenu.Append(wx.ID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard"))
-        wx.EVT_MENU(self, wx.ID_CUT, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_CUT, self.ProcessUpdateUIEvent)
-        editMenu.Append(wx.ID_COPY, _("&Copy\tCtrl+C"), _("Copies the selection and puts it on the Clipboard"))
-        wx.EVT_MENU(self, wx.ID_COPY, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_COPY, self.ProcessUpdateUIEvent)
-        editMenu.Append(wx.ID_PASTE, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents"))
-        wx.EVT_MENU(self, wx.ID_PASTE, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_PASTE, self.ProcessUpdateUIEvent)
-        editMenu.Append(wx.ID_CLEAR, _("Cle&ar\tDel"), _("Erases the selection"))
-        wx.EVT_MENU(self, wx.ID_CLEAR, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_CLEAR, self.ProcessUpdateUIEvent)
-        editMenu.AppendSeparator()
-        editMenu.Append(wx.ID_SELECTALL, _("Select A&ll\tCtrl+A"), _("Selects all available data"))
-        wx.EVT_MENU(self, wx.ID_SELECTALL, self.ProcessEvent)
-        wx.EVT_UPDATE_UI(self, wx.ID_SELECTALL, self.ProcessUpdateUIEvent)
-        menuBar.Append(editMenu, _("&Edit"))
-        if self.GetDocument() and self.GetDocument().GetCommandProcessor():
-            self.GetDocument().GetCommandProcessor().SetEditMenu(editMenu)
-
-        viewMenu = wx.Menu()
-        viewMenu.AppendCheckItem(VIEW_TOOLBAR_ID, _("&Toolbar"), _("Shows or hides the toolbar"))
-        wx.EVT_MENU(self, VIEW_TOOLBAR_ID, self.OnViewToolBar)
-        wx.EVT_UPDATE_UI(self, VIEW_TOOLBAR_ID, self.OnUpdateViewToolBar)
-        viewMenu.AppendCheckItem(VIEW_STATUSBAR_ID, _("&Status Bar"), _("Shows or hides the status bar"))
-        wx.EVT_MENU(self, VIEW_STATUSBAR_ID, self.OnViewStatusBar)
-        wx.EVT_UPDATE_UI(self, VIEW_STATUSBAR_ID, self.OnUpdateViewStatusBar)
-        menuBar.Append(viewMenu, _("&View"))
-
-        helpMenu = wx.Menu()
-        helpMenu.Append(wx.ID_ABOUT, _("&About" + " " + wx.GetApp().GetAppName()), _("Displays program information, version number, and copyright"))
-        wx.EVT_MENU(self, wx.ID_ABOUT, self.OnAbout)
-        menuBar.Append(helpMenu, _("&Help"))
-
-        wx.EVT_COMMAND_FIND_CLOSE(self, -1, self.ProcessEvent)
-
-        return menuBar
-##        accelTable = wx.AcceleratorTable([
-##            eval(_("wx.ACCEL_CTRL, ord('N'), wx.ID_NEW")),
-##            eval(_("wx.ACCEL_CTRL, ord('O'), wx.ID_OPEN")),
-##            eval(_("wx.ACCEL_CTRL, ord('S'), wx.ID_SAVE")),
-##            eval(_("wx.ACCEL_CTRL, ord('Z'), wx.ID_UNDO")),
-##            eval(_("wx.ACCEL_CTRL, ord('Y'), wx.ID_REDO")),
-##            eval(_("wx.ACCEL_CTRL, ord('X'), wx.ID_CUT")),
-##            eval(_("wx.ACCEL_CTRL, ord('C'), wx.ID_COPY")),
-##            eval(_("wx.ACCEL_CTRL, ord('Z'), wx.ID_PASTE")),
-##            (wx.ACCEL_NORMAL, wx.WXK_DELETE, wx.ID_CLEAR),
-##            eval(_("wx.ACCEL_CTRL, ord('A'), wx.ID_SELECTALL"))
-##            ])
-##        self.SetAcceleratorTable(accelTable)
-
-
     def ProcessEvent(self, event):
         """
         Processes an event, searching event tables and calling zero or more
@@ -1732,63 +2277,6 @@ class DocSDIFrame(wx.lib.docview.DocChildFrame):
             return wx.GetApp().ProcessUpdateUIEvent(event)
 
 
-    def OnFileSaveAll(self, event):
-        """
-        Saves all of the currently open documents.
-        """
-        docs = wx.GetApp().GetDocumentManager().GetDocuments()
-        for doc in docs:
-            doc.Save()
-
-
-    def OnAbout(self, event):
-        """
-        Invokes the about dialog.
-        """
-        aboutService = wx.GetApp().GetService(AboutService)
-        if aboutService:
-            aboutService.ShowAbout()
-
-
-    def OnViewToolBar(self, event):
-        """
-        Toggles whether the ToolBar is visible.
-        """
-        self._toolBar.Show(not self._toolBar.IsShown())
-        self.Layout()
-
-
-    def OnUpdateViewToolBar(self, event):
-        """
-        Updates the View ToolBar menu item.
-        """
-        event.Check(self.GetToolBar().IsShown())
-
-
-    def OnViewStatusBar(self, event):
-        """
-        Toggles whether the StatusBar is visible.
-        """
-        self.GetStatusBar().Show(not self.GetStatusBar().IsShown())
-        self.Layout()
-
-
-    def OnUpdateViewStatusBar(self, event):
-        """
-        Updates the View StatusBar menu item.
-        """
-        event.Check(self.GetStatusBar().IsShown())
-
-
-    def UpdateStatus(self, message = _("Ready")):
-        """
-        Updates the StatusBar.
-        """
-        # wxBug: Menubar and toolbar help strings don't pop the status text back
-        if self.GetStatusBar().GetStatusText() != message:
-            self.GetStatusBar().PushStatusText(message)
-
-
     def OnCloseWindow(self, event):
         """
         Called when the window is saved.  Enables services to help close the frame.
@@ -1805,21 +2293,26 @@ class AboutService(DocService):
     About Dialog Service that installs under the Help menu to show the properties of the current application.
     """
 
-    def __init__(self, aboutDialog = None):
+    def __init__(self, aboutDialog=None, image=None):
         """
         Initializes the AboutService.
         """
         if aboutDialog:
             self._dlg = aboutDialog
+            self._image = None
         else:
             self._dlg = AboutDialog  # use default AboutDialog
+            self._image = image
         
 
     def ShowAbout(self):
         """
         Show the AboutDialog
         """
-        dlg = self._dlg(wx.GetApp().GetTopWindow())
+        if self._image:
+            dlg = self._dlg(wx.GetApp().GetTopWindow(), self._image)
+        else:
+            dlg = self._dlg(wx.GetApp().GetTopWindow())
         dlg.CenterOnScreen()
         dlg.ShowModal()
         dlg.Destroy()
@@ -1837,18 +2330,17 @@ class AboutDialog(wx.Dialog):
     Opens an AboutDialog.  Shared by DocMDIParentFrame and DocSDIFrame.
     """
     
-    def __init__(self, parent):
+    def __init__(self, parent, image=None):
         """
         Initializes the about dialog.
         """
         wx.Dialog.__init__(self, parent, -1, _("About ") + wx.GetApp().GetAppName(), style = wx.DEFAULT_DIALOG_STYLE)
 
-        self.SetBackgroundColour(wx.WHITE)
         sizer = wx.BoxSizer(wx.VERTICAL)
-        splash_bmp = wx.Image("activegrid/tool/images/splash.jpg").ConvertToBitmap()
-        image = wx.StaticBitmap(self, -1, splash_bmp, (0,0), (splash_bmp.GetWidth(), splash_bmp.GetHeight()))
-        sizer.Add(image, 0, wx.ALIGN_CENTER|wx.ALL, 0)
-        sizer.Add(wx.StaticText(self, -1, wx.GetApp().GetAppName()), 0, wx.ALIGN_LEFT|wx.ALL, 5)
+        if image:
+            imageItem = wx.StaticBitmap(self, -1, image.ConvertToBitmap(), (0,0), (image.GetWidth(), image.GetHeight()))
+            sizer.Add(imageItem, 0, wx.ALIGN_CENTER|wx.ALL, 0)
+        sizer.Add(wx.StaticText(self, -1, wx.GetApp().GetAppName()), 0, wx.ALIGN_CENTRE|wx.ALL, 5)
     
         btn = wx.Button(self, wx.ID_OK)
         sizer.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
@@ -2040,7 +2532,6 @@ class FilePropertiesDialog(wx.Dialog):
         spacerGrid.Add(gridSizer, 0, wx.ALL, SPACE);
         tab.SetSizer(spacerGrid)
         notebook.AddPage(tab, _("General"))
-        notebook.SetPageSize((310,200))
 
         sizer = wx.BoxSizer(wx.VERTICAL)
         sizer.Add(notebook, 0, wx.ALL | wx.EXPAND, SPACE)
@@ -2112,6 +2603,22 @@ class ChildDocument(wx.lib.docview.Document):
         return True
 
 
+    def Save(self):
+        """
+        Called when the ChildDocument is saved and does the minimum such that the
+        ChildDocument looks like a real Document to the framework.
+        """
+        return self.OnSaveDocument(self._documentFile)
+
+
+    def SaveAs(self):
+        """
+        Called when the ChildDocument is saved and does the minimum such that the
+        ChildDocument looks like a real Document to the framework.
+        """
+        return self.OnSaveDocument(self._documentFile)        
+
+
 class ChildDocTemplate(wx.lib.docview.DocTemplate):
     """
     A ChildDocTemplate is a DocTemplate subclass that enables the creation of ChildDocuments
@@ -2181,8 +2688,11 @@ class WindowMenuService(DocService):
         if not self.GetDocumentManager().GetFlags() & wx.lib.docview.DOC_SDI:
             return  # Only need windows menu for SDI mode, MDI frame automatically creates one
 
+        if not _WINDOWS:  # Arrange All and window navigation doesn't work on Linux
+            return
+            
         windowMenu = wx.Menu()
-        windowMenu.Append(self.ARRANGE_WINDOWS_ID, _("&Arrange All"), _("Arrange the open windows"))
+        item = windowMenu.Append(self.ARRANGE_WINDOWS_ID, _("&Arrange All"), _("Arrange the open windows"))
         windowMenu.AppendSeparator()
 
         wx.EVT_MENU(frame, self.ARRANGE_WINDOWS_ID, frame.ProcessEvent)
@@ -2375,6 +2885,7 @@ class WindowMenuService(DocService):
 # File generated by encode_bitmaps.py
 #----------------------------------------------------------------------------
 from wx import ImageFromStream, BitmapFromImage
+from wx import EmptyIcon
 import cStringIO
 
 #----------------------------------------------------------------------
@@ -2594,3 +3105,31 @@ def getRedoBitmap():
 def getRedoImage():
     stream = cStringIO.StringIO(getRedoData())
     return ImageFromStream(stream)
+    
+#----------------------------------------------------------------------------
+
+def getBlankData():
+    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\x00\
+\x85IDATX\x85\xed\x97\xc9\n\xc0 \x0cD3\xda\xff\xffcMo\x96Z\xc4\xa5\x91\x14:9\
+\x8a\xe8\xcb\xd3\xb8\x00!\x8ag\x04\xd7\xd9E\xe4\xa8\x1b4'}3 B\xc4L\x7fs\x03\
+\xb3\t<\x0c\x94\x81tN\x04p%\xae9\xe9\xa8\x89m{`\xd4\x84\xfd\x12\xa8\x16{#\
+\x10\xdb\xab\xa0\x07a\x0e\x00\xe0\xb6\x1fz\x10\xdf;\x07V\xa3U5\xb5\x8d:\xdc\
+\r\x10\x80\x00\x04 \x00\x01\x08@\x80\xe6{\xa0w\x8f[\x85\xbb\x01\xfc\xfeoH\
+\x80\x13>\xf9(3zH\x1e\xfb\x00\x00\x00\x00IEND\xaeB`\x82" 
+
+
+def getBlankBitmap():
+    return BitmapFromImage(getBlankImage())
+
+def getBlankImage():
+    stream = cStringIO.StringIO(getBlankData())
+    return ImageFromStream(stream)
+
+def getBlankIcon():
+    icon = EmptyIcon()
+    icon.CopyFromBitmap(getBlankBitmap())
+    return icon
+    
+