1 #---------------------------------------------------------------------------- 
   3 # Purpose:      Python extensions to the wxWindows docview framework 
   9 # Copyright:    (c) 2003-2004 ActiveGrid, Inc. 
  10 # License:      wxWindows license 
  11 #---------------------------------------------------------------------------- 
  18 from wxPython
.lib
.rcsizer 
import RowColSizer
 
  30 #---------------------------------------------------------------------------- 
  32 #---------------------------------------------------------------------------- 
  34 VIEW_TOOLBAR_ID 
= wx
.NewId() 
  35 VIEW_STATUSBAR_ID 
= wx
.NewId() 
  37 EMBEDDED_WINDOW_TOP 
= 1 
  38 EMBEDDED_WINDOW_BOTTOM 
= 2 
  39 EMBEDDED_WINDOW_LEFT 
= 4 
  40 EMBEDDED_WINDOW_RIGHT 
= 8 
  41 EMBEDDED_WINDOW_TOPLEFT 
= 16 
  42 EMBEDDED_WINDOW_BOTTOMLEFT 
= 32 
  43 EMBEDDED_WINDOW_TOPRIGHT 
= 64 
  44 EMBEDDED_WINDOW_BOTTOMRIGHT 
= 128 
  45 EMBEDDED_WINDOW_ALL 
= EMBEDDED_WINDOW_TOP | EMBEDDED_WINDOW_BOTTOM | EMBEDDED_WINDOW_LEFT | EMBEDDED_WINDOW_RIGHT | \
 
  46                       EMBEDDED_WINDOW_TOPLEFT | EMBEDDED_WINDOW_BOTTOMLEFT | EMBEDDED_WINDOW_TOPRIGHT | EMBEDDED_WINDOW_BOTTOMRIGHT
 
  48 SAVEALL_ID 
= wx
.NewId() 
  50 WINDOW_MENU_NUM_ITEMS 
= 9 
  53 class DocService(wx
.EvtHandler
): 
  55     An abstract class used to add reusable services to a docview application. 
  60         """Initializes the DocService.""" 
  64     def GetDocumentManager(self
): 
  65         """Returns the DocManager for the docview application.""" 
  66         return self
._docManager
 
  69     def SetDocumentManager(self
, docManager
): 
  70         """Sets the DocManager for the docview application.""" 
  71         self
._docManager 
= docManager
 
  74     def InstallControls(self
, frame
, menuBar 
= None, toolBar 
= None, statusBar 
= None, document 
= None): 
  75         """Called to install controls into the menubar and toolbar of a SDI or MDI window.  Override this method for a particular service.""" 
  79     def ProcessEventBeforeWindows(self
, event
): 
  81         Processes an event before the main window has a chance to process the window.  
  82         Override this method for a particular service. 
  87     def ProcessUpdateUIEventBeforeWindows(self
, event
): 
  89         Processes a UI event before the main window has a chance to process the window. 
  90         Override this method for a particular service. 
  95     def ProcessEvent(self
, event
): 
  97         Processes an event, searching event tables and calling zero or more 
  98         suitable event handler function(s).  Note that the ProcessEvent 
  99         method is called from the wxPython docview framework directly since 
 100         wxPython does not have a virtual ProcessEvent function. 
 105     def ProcessUpdateUIEvent(self
, event
): 
 107         Processes a UI event, searching event tables and calling zero or more 
 108         suitable event handler function(s).  Note that the ProcessEvent 
 109         method is called from the wxPython docview framework directly since 
 110         wxPython does not have a virtual ProcessEvent function. 
 115     def OnCloseFrame(self
, event
): 
 117         Called when the a docview frame is being closed.  Override this method 
 118         so a service can either do cleanup or veto the frame being closed by 
 126         Called when the the docview application is being closed.  Override this method 
 127         so a service can either do cleanup or veto the frame being closed by 
 133     def GetMenuItemPos(self
, menu
, id): 
 135         Utility method used to find the position of a menu item so that services can 
 136         easily find where to insert a menu item in InstallControls. 
 138         menuItems 
= menu
.GetMenuItems() 
 139         for i
, menuItem 
in enumerate(menuItems
): 
 140             if menuItem
.GetId() == id: 
 147         Called by WindowMenuService to get views for services that don't 
 148         have dedicated documents such as the Outline Service. 
 153 class DocOptionsService(DocService
): 
 155     A service that implements an options menu item and an options dialog with 
 156     notebook tabs.  New tabs can be added by other services by calling the 
 157     "AddOptionsPanel" method. 
 161     def __init__(self
, showGeneralOptions 
= True): 
 163         Initializes the options service with the option of suppressing the default 
 164         general options pane that is included with the options service by setting 
 165         showGeneralOptions to False. 
 167         DocService
.__init
__(self
) 
 168         self
.ClearOptionsPanels() 
 169         self
._toolOptionsID 
= wx
.NewId() 
 170         if showGeneralOptions
: 
 171             self
.AddOptionsPanel(GeneralOptionsPanel
) 
 174     def InstallControls(self
, frame
, menuBar 
= None, toolBar 
= None, statusBar 
= None, document 
= None): 
 176         Installs a "Tools" menu with an "Options" menu item. 
 178         toolsMenuIndex 
= menuBar
.FindMenu(_("&Tools")) 
 179         if toolsMenuIndex 
> -1: 
 180             toolsMenu 
= menuBar
.GetMenu(toolsMenuIndex
) 
 182             toolsMenu 
= wx
.Menu() 
 183         if toolsMenuIndex 
== -1: 
 184             formatMenuIndex 
= menuBar
.FindMenu(_("&Format")) 
 185             menuBar
.Insert(formatMenuIndex 
+ 1, toolsMenu
, _("&Tools")) 
 187             if toolsMenu
.GetMenuItemCount(): 
 188                 toolsMenu
.AppendSeparator() 
 189             toolsMenu
.Append(self
._toolOptionsID
, _("&Options..."), _("Sets options")) 
 190             wx
.EVT_MENU(frame
, self
._toolOptionsID
, frame
.ProcessEvent
) 
 193     def ProcessEvent(self
, event
): 
 195         Checks to see if the "Options" menu item has been selected. 
 198         if id == self
._toolOptionsID
: 
 199             self
.OnOptions(event
) 
 205     def ClearOptionsPanels(self
): 
 207         Clears all of the options panels that have been added into the 
 210         self
._optionsPanels 
= [] 
 213     def AddOptionsPanel(self
, optionsPanel
): 
 215         Adds an options panel to the options dialog.  
 217         self
._optionsPanels
.append(optionsPanel
) 
 220     def OnOptions(self
, event
): 
 222         Shows the options dialog, called when the "Options" menu item is selected. 
 224         if len(self
._optionsPanels
) == 0: 
 226         optionsDialog 
= OptionsDialog(wx
.GetApp().GetTopWindow(), self
._optionsPanels
, self
._docManager
) 
 227         if optionsDialog
.ShowModal() == wx
.ID_OK
: 
 228             optionsDialog
.OnOK(optionsDialog
)  # wxBug: wxDialog should be calling this automatically but doesn't 
 229         optionsDialog
.Destroy() 
 232 class OptionsDialog(wx
.Dialog
): 
 234     A default options dialog used by the OptionsService that hosts a notebook 
 235     tab of options panels. 
 239     def __init__(self
, parent
, optionsPanelClasses
, docManager
): 
 241         Initializes the options dialog with a notebook page that contains new 
 242         instances of the passed optionsPanelClasses. 
 244         wx
.Dialog
.__init
__(self
, parent
, -1, _("Options"), size 
= (310, 400)) 
 246         self
._optionsPanels 
= [] 
 247         self
._docManager 
= docManager
 
 252         sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 254         optionsNotebook 
= wx
.Notebook(self
, -1, size 
= (310, 375), style 
= wx
.NB_MULTILINE
) 
 255         sizer
.Add(optionsNotebook
, 0, wx
.ALL | wx
.EXPAND
, SPACE
) 
 256         for optionsPanelClass 
in optionsPanelClasses
: 
 257             optionsPanel 
= optionsPanelClass(optionsNotebook
, -1) 
 258             self
._optionsPanels
.append(optionsPanel
) 
 259         sizer
.Add(self
.CreateButtonSizer(wx
.OK | wx
.CANCEL
), 0, wx
.ALIGN_RIGHT | wx
.RIGHT | wx
.BOTTOM
, HALF_SPACE
) 
 263         wx
.CallAfter(self
.DoRefresh
) 
 268         wxBug: On Windows XP when using a multiline notebook the default page doesn't get 
 269         drawn, but it works when using a single line notebook. 
 274     def GetDocManager(self
): 
 276         Returns the document manager passed to the OptionsDialog constructor. 
 278         return self
._docManager
 
 281     def OnOK(self
, event
): 
 283         Calls the OnOK method of all of the OptionDialog's embedded panels 
 285         for optionsPanel 
in self
._optionsPanels
: 
 286             optionsPanel
.OnOK(event
) 
 289 class GeneralOptionsPanel(wx
.Panel
): 
 291     A general options panel that is used in the OptionDialog to configure the 
 292     generic properties of a pydocview application, such as "show tips at startup" 
 293     and whether to use SDI or MDI for the application. 
 297     def __init__(self
, parent
, id): 
 299         Initializes the panel by adding an "Options" folder tab to the parent notebook and 
 300         populating the panel with the generic properties of a pydocview application.  
 302         wx
.Panel
.__init
__(self
, parent
, id) 
 305         backgroundColor 
= wx
.WHITE
 
 306         config 
= wx
.ConfigBase_Get() 
 307         self
._showTipsCheckBox 
= wx
.CheckBox(self
, -1, _("Show tips at start up")) 
 308         self
._showTipsCheckBox
.SetBackgroundColour(backgroundColor
) # wxBUG: uses wrong background color 
 309         self
._showTipsCheckBox
.SetValue(config
.ReadInt("ShowTipAtStartup", True)) 
 310         self
._documentRadioBox 
= wx
.RadioBox(self
, -1, _("Document interface"), 
 311                                       choices 
= [_("Show each document in its own window (SDI)"), 
 312                                                  _("Show All documents in a single window (MDI)")], 
 315         if config
.ReadInt("UseMDI", True): 
 316             self
._documentRadioBox
.SetSelection(1) 
 318             self
._documentRadioBox
.SetSelection(0) 
 319         def OnDocumentInterfaceSelect(event
): 
 320             if not self
._documentInterfaceMessageShown
: 
 321                 msgTitle 
= wx
.GetApp().GetAppName() 
 323                     msgTitle 
= _("Document Options") 
 324                 wx
.MessageBox("Document interface changes will not appear until the application is restarted.", 
 326                               wx
.OK | wx
.ICON_INFORMATION
, 
 328                 self
._documentInterfaceMessageShown 
= True             
 329         wx
.EVT_RADIOBOX(self
, self
._documentRadioBox
.GetId(), OnDocumentInterfaceSelect
) 
 330         optionsBorderSizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 331         optionsSizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 332         optionsSizer
.Add(self
._showTipsCheckBox
, 0, wx
.ALL
, HALF_SPACE
) 
 333         optionsSizer
.Add(self
._documentRadioBox
, 0, wx
.ALL
, HALF_SPACE
) 
 334         optionsBorderSizer
.Add(optionsSizer
, 0, wx
.ALL
, SPACE
) 
 335         self
.SetSizer(optionsBorderSizer
) 
 337         self
._documentInterfaceMessageShown 
= False 
 338         parent
.AddPage(self
, _("Options")) 
 340     def OnOK(self
, optionsDialog
): 
 342         Updates the config based on the selections in the options panel. 
 344         config 
= wx
.ConfigBase_Get() 
 345         config
.WriteInt("ShowTipAtStartup", self
._showTipsCheckBox
.GetValue()) 
 346         config
.WriteInt("UseMDI", self
._documentRadioBox
.GetSelection()) 
 349 class DocApp(wx
.PySimpleApp
): 
 351     The DocApp class serves as the base class for pydocview applications and offers 
 352     functionality such as services, creation of SDI and MDI frames, show tips, 
 359         Initializes the DocApp. 
 362         self
._defaultIcon 
= None 
 363         self
._registeredCloseEvent 
= False 
 364         if not hasattr(self
, "_debug"):  # only set if not already initialized 
 366         if not hasattr(self
, "_singleInstance"):  # only set if not already initialized 
 367             self
._singleInstance 
= True 
 369         # if _singleInstance is TRUE only allow one single instance of app to run. 
 370         # When user tries to run a second instance of the app, abort startup, 
 371         # But if user also specifies files to open in command line, send message to running app to open those files 
 372         if self
._singleInstance
: 
 373             # create shared memory temporary file 
 374             if wx
.Platform 
== '__WXMSW__': 
 375                 tfile 
= tempfile
.TemporaryFile(prefix
="ag", suffix
="tmp") 
 377                 self
._sharedMemory 
= mmap
.mmap(fno
, 1024, "shared_memory") 
 379                 tfile 
= file(os
.path
.join(tempfile
.gettempdir(), tempfile
.gettempprefix() + getpass
.getuser() + "AGSharedMemory"), 'w+b') 
 385                 self
._sharedMemory 
= mmap
.mmap(fno
, 1024) 
 387             self
._singleInstanceChecker 
= wx
.SingleInstanceChecker(self
.GetAppName() + '-' + wx
.GetUserId()) 
 388             if self
._singleInstanceChecker
.IsAnotherRunning(): 
 389                 # have running single instance open file arguments 
 393                     if arg
[0] != '/' and arg
[0] != '-': 
 398                     data 
= pickle
.dumps(args
) 
 400                         self
._sharedMemory
.seek(0) 
 401                         marker 
= self
._sharedMemory
.read_byte() 
 402                         if marker 
== '\0' or marker 
== '*':        # available buffer 
 403                             self
._sharedMemory
.seek(0) 
 404                             self
._sharedMemory
.write_byte('-')     # set writing marker 
 405                             self
._sharedMemory
.write(data
)  # write files we tried to open to shared memory 
 406                             self
._sharedMemory
.seek(0) 
 407                             self
._sharedMemory
.write_byte('+')     # set finished writing marker 
 408                             self
._sharedMemory
.flush() 
 411                             time
.sleep(1)  # give enough time for buffer to be available 
 415                 self
._timer 
= wx
.PyTimer(self
.DoBackgroundListenAndLoad
) 
 416                 self
._timer
.Start(250) 
 421     def DoBackgroundListenAndLoad(self
): 
 423         Open any files specified in the given command line argument passed in via shared memory 
 426         self
._sharedMemory
.seek(0) 
 427         if self
._sharedMemory
.read_byte() == '+':  # available data 
 428             data 
= self
._sharedMemory
.read(1024-1) 
 429             self
._sharedMemory
.seek(0) 
 430             self
._sharedMemory
.write_byte("*")     # finished reading, set buffer free marker 
 431             self
._sharedMemory
.flush() 
 432             args 
= pickle
.loads(data
) 
 434                 if arg
[0] != '/' and arg
[0] != '-': 
 435                     self
.GetDocumentManager().CreateDocument(arg
, wx
.lib
.docview
.DOC_SILENT
) 
 437             # force display of running app 
 438             topWindow 
= wx
.GetApp().GetTopWindow() 
 439             if topWindow
.IsIconized(): 
 440                 topWindow
.Iconize(False) 
 445         self
._timer
.Start(1000) # 1 second interval 
 448     def OpenCommandLineArgs(self
): 
 450         Called to open files that have been passed to the application from the 
 455             if arg
[0] != '/' and arg
[0] != '-': 
 456                 self
.GetDocumentManager().CreateDocument(arg
, wx
.lib
.docview
.DOC_SILENT
) 
 459     def GetDocumentManager(self
): 
 461         Returns the document manager associated to the DocApp. 
 463         return self
._docManager
 
 466     def SetDocumentManager(self
, docManager
): 
 468         Sets the document manager associated with the DocApp and loads the 
 469         DocApp's file history into the document manager. 
 471         self
._docManager 
= docManager
 
 472         config 
= wx
.ConfigBase_Get() 
 473         self
.GetDocumentManager().FileHistoryLoad(config
) 
 476     def ProcessEventBeforeWindows(self
, event
): 
 478         Enables services to process an event before the main window has a chance to 
 481         for service 
in self
._services
: 
 482             if service
.ProcessEventBeforeWindows(event
): 
 487     def ProcessUpdateUIEventBeforeWindows(self
, event
): 
 489         Enables services to process a UI event before the main window has a chance 
 490         to process the window. 
 492         for service 
in self
._services
: 
 493             if service
.ProcessUpdateUIEventBeforeWindows(event
): 
 498     def ProcessEvent(self
, event
): 
 500         Processes an event, searching event tables and calling zero or more 
 501         suitable event handler function(s).  Note that the ProcessEvent 
 502         method is called from the wxPython docview framework directly since 
 503         wxPython does not have a virtual ProcessEvent function. 
 505         for service 
in self
._services
: 
 506             if service
.ProcessEvent(event
): 
 511     def ProcessUpdateUIEvent(self
, event
): 
 513         Processes a UI event, searching event tables and calling zero or more 
 514         suitable event handler function(s).  Note that the ProcessEvent 
 515         method is called from the wxPython docview framework directly since 
 516         wxPython does not have a virtual ProcessEvent function. 
 518         for service 
in self
._services
: 
 519             if service
.ProcessUpdateUIEvent(event
): 
 524     def InstallService(self
, service
): 
 526         Installs an instance of a DocService into the DocApp. 
 528         service
.SetDocumentManager(self
._docManager
) 
 529         self
._services
.append(service
) 
 533     def GetServices(self
): 
 535         Returns the DocService instances that have been installed into the DocApp. 
 537         return self
._services
 
 540     def GetService(self
, type): 
 542         Returns the instance of a particular type of service that has been installed 
 543         into the DocApp.  For example, "wx.GetApp().GetService(pydocview.OptionsService)" 
 544         returns the isntance of the OptionsService that is running within the DocApp. 
 546         for service 
in self
._services
: 
 547             if isinstance(service
, type): 
 554         Called when the DocApp is exited, enables the installed DocServices to exit 
 555         and saves the DocManager's file history. 
 557         for service 
in self
._services
: 
 559         config 
= wx
.ConfigBase_Get() 
 560         self
._docManager
.FileHistorySave(config
) 
 561         del self
._singleInstanceChecker
 
 564     def GetDefaultDocManagerFlags(self
): 
 566         Returns the default flags to use when creating the DocManager. 
 568         config 
= wx
.ConfigBase_Get() 
 569         if config
.ReadInt("UseMDI", True): 
 570             flags 
= wx
.lib
.docview
.DOC_MDI | wx
.lib
.docview
.DOC_OPEN_ONCE
 
 572             flags 
= wx
.lib
.docview
.DOC_SDI | wx
.lib
.docview
.DOC_OPEN_ONCE
 
 576     def ShowTip(self
, frame
, tipProvider
): 
 578         Shows the tip window, generally this is called when an application starts. 
 579         A wx.TipProvider must be passed. 
 581         config 
= wx
.ConfigBase_Get() 
 582         showTip 
= config
.ReadInt("ShowTipAtStartup", 1) 
 584             index 
= config
.ReadInt("TipIndex", 0) 
 585             showTipResult 
= wx
.ShowTip(frame
, tipProvider
, showAtStartup 
= showTip
) 
 586             if showTipResult 
!= showTip
: 
 587                 config
.WriteInt("ShowTipAtStartup", showTipResult
) 
 590     def GetEditMenu(self
, frame
): 
 592         Utility method that finds the Edit menu within the menubar of a frame. 
 594         menuBar 
= frame
.GetMenuBar() 
 597         editMenuIndex 
= menuBar
.FindMenu(_("&Edit")) 
 598         if editMenuIndex 
== -1: 
 600         return menuBar
.GetMenu(editMenuIndex
) 
 603     def CreateDocumentFrame(self
, view
, doc
, flags
, id = -1, title 
= "", pos 
= wx
.DefaultPosition
, size 
= wx
.DefaultSize
, style 
= wx
.DEFAULT_FRAME_STYLE
): 
 605         Called by the DocManager to create and return a new Frame for a Document.  
 606         Chooses whether to create an MDIChildFrame or SDI Frame based on the 
 609         docflags 
= self
.GetDocumentManager().GetFlags() 
 610         if docflags 
& wx
.lib
.docview
.DOC_SDI
: 
 611             frame 
= self
.CreateSDIDocumentFrame(doc
, view
, id, title
, pos
, size
, style
) 
 614             # wxBug: operating system bug, first window is set to the position of last window closed, ignoring passed in position on frame creation 
 615             #        also, initial size is incorrect for the same reasons 
 616             if frame
.GetPosition() != pos
: 
 618             if frame
.GetSize() != size
: 
 621             if doc 
and doc
.GetCommandProcessor(): 
 622                 doc
.GetCommandProcessor().SetEditMenu(self
.GetEditMenu(frame
)) 
 623         elif docflags 
& wx
.lib
.docview
.DOC_MDI
: 
 624             frame 
= self
.CreateMDIDocumentFrame(doc
, view
, id, title
, pos
, size
, style
) 
 625             if doc 
and doc
.GetDocumentTemplate().GetIcon(): 
 626                 frame
.SetIcon(doc
.GetDocumentTemplate().GetIcon()) 
 627             if doc 
and doc
.GetCommandProcessor(): 
 628                 doc
.GetCommandProcessor().SetEditMenu(self
.GetEditMenu(wx
.GetApp().GetTopWindow())) 
 629         if not frame
.GetIcon() and self
._defaultIcon
: 
 630             frame
.SetIcon(self
.GetDefaultIcon()) 
 635     def CreateSDIDocumentFrame(self
, doc
, view
, id = -1, title 
= "", pos 
= wx
.DefaultPosition
, size 
= wx
.DefaultSize
, style 
= wx
.DEFAULT_FRAME_STYLE
): 
 637         Creates and returns an SDI Document Frame. 
 639         frame 
= DocSDIFrame(doc
, view
, None, id, title
, pos
, size
, style
) 
 643     def CreateMDIDocumentFrame(self
, doc
, view
, id = -1, title 
= "", pos 
= wx
.DefaultPosition
, size 
= wx
.DefaultSize
, style 
= wx
.DEFAULT_FRAME_STYLE
): 
 645         Creates and returns an MDI Document Frame. 
 647         # if any child windows are maximized, then user must want any new children maximized 
 648         # if no children exist, then use the default value from registry 
 649         # wxBug:  Only current window is maximized, so need to check every child frame 
 650         parentFrame 
= wx
.GetApp().GetTopWindow() 
 651         childrenMaximized 
= filter(lambda child
: isinstance(child
, wx
.MDIChildFrame
) and child
.IsMaximized(), parentFrame
.GetChildren()) 
 652         if childrenMaximized
: 
 655             children 
= filter(lambda child
: isinstance(child
, wx
.MDIChildFrame
), parentFrame
.GetChildren()) 
 657                 # other windows exist and none are maximized 
 660                 # get default setting from registry 
 661                 maximize 
= wx
.ConfigBase_Get().ReadInt("MDIChildFrameMaximized", False) 
 663         frame 
= wx
.lib
.docview
.DocMDIChildFrame(doc
, view
, wx
.GetApp().GetTopWindow(), id, title
, pos
, size
, style
) 
 664         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 
 667 ##        wx.EVT_MAXIMIZE(frame, self.OnMaximize) # wxBug: This doesn't work, need to save MDIChildFrameMaximized state on close of windows instead 
 668         wx
.EVT_CLOSE(frame
, self
.OnCloseChildWindow
) 
 669         if not self
._registeredCloseEvent
: 
 670             wx
.EVT_CLOSE(parentFrame
, self
.OnCloseMainWindow
) # need to check on this, but only once 
 671             self
._registeredCloseEvent 
= True 
 676     def SaveMDIDocumentFrameMaximizedState(self
, maximized
): 
 678         Remember in the config whether the MDI Frame is maximized so that it can be restored 
 681         config 
= wx
.ConfigBase_Get() 
 682         maximizeFlag 
= config
.ReadInt("MDIChildFrameMaximized", False) 
 683         if maximized 
!= maximizeFlag
: 
 684             config
.WriteInt("MDIChildFrameMaximized", maximized
) 
 687     def OnCloseChildWindow(self
, event
): 
 689         Called when an MDI Child Frame is closed.  Calls SaveMDIDocumentFrameMaximizedState to 
 690         remember whether the MDI Frame is maximized so that it can be restored on open. 
 692         self
.SaveMDIDocumentFrameMaximizedState(event
.GetEventObject().IsMaximized()) 
 696     def OnCloseMainWindow(self
, event
): 
 698         Called when the MDI Parent Frame is closed.  Remembers whether the MDI Parent Frame is 
 701         children 
= event
.GetEventObject().GetChildren() 
 702         childrenMaximized 
= filter(lambda child
: isinstance(child
, wx
.MDIChildFrame
)and child
.IsMaximized(), children
) 
 703         if childrenMaximized
: 
 704             self
.SaveMDIDocumentFrameMaximizedState(True) 
 706             childrenNotMaximized 
= filter(lambda child
: isinstance(child
, wx
.MDIChildFrame
), children
) 
 708             if childrenNotMaximized
: 
 709                 # other windows exist and none are maximized 
 710                 self
.SaveMDIDocumentFrameMaximizedState(False) 
 715     def GetDefaultIcon(self
): 
 717         Returns the application's default icon. 
 719         return self
._defaultIcon
 
 722     def SetDefaultIcon(self
, icon
): 
 724         Sets the application's default icon. 
 726         self
._defaultIcon 
= icon
 
 731         Returns True if the application is in debug mode. 
 736     def SetDebug(self
, debug
): 
 738         Sets the application's debug mode. 
 743     def GetSingleInstance(self
): 
 745         Returns True if the application is in single instance mode.  Used to determine if multiple instances of the application is allowed to launch. 
 747         return self
._singleInstance
 
 750     def SetSingleInstance(self
, singleInstance
): 
 752         Sets application's single instance mode. 
 754         self
._singleInstance 
= singleInstance
 
 758     def CreateChildDocument(self
, parentDocument
, documentType
, objectToEdit
, path 
= ''): 
 760         Creates a child window of a document that edits an object.  The child window 
 761         is managed by the parent document frame, so it will be prompted to close if its 
 762         parent is closed, etc.  Child Documents are useful when there are complicated  
 763         Views of a Document and users will need to tunnel into the View. 
 765         for document 
in self
.GetDocumentManager().GetDocuments()[:]:  # Cloning list to make sure we go through all docs even as they are deleted 
 766             if isinstance(document
, ChildDocument
) and document
.GetParentDocument() == parentDocument
: 
 767                 if document
.GetData() == objectToEdit
: 
 768                     if hasattr(document
.GetFirstView().GetFrame(), "SetFocus"): 
 769                         document
.GetFirstView().GetFrame().SetFocus() 
 771         for temp 
in wx
.GetApp().GetDocumentManager().GetTemplates(): 
 772             if temp
.GetDocumentType() == documentType
: 
 775         newDoc 
= temp
.CreateDocument(path
, 0, data 
= objectToEdit
, parentDocument 
= parentDocument
) 
 776         newDoc
.SetDocumentName(temp
.GetDocumentName()) 
 777         newDoc
.SetDocumentTemplate(temp
) 
 779             newDoc
.OnNewDocument() 
 781             if not newDoc
.OnOpenDocument(path
): 
 782                 newDoc
.DeleteAllViews()  # Implicitly deleted by DeleteAllViews 
 787     def CloseChildDocuments(self
, parentDocument
): 
 789         Closes the child windows of a Document. 
 791         for document 
in self
.GetDocumentManager().GetDocuments()[:]:  # Cloning list to make sure we go through all docs even as they are deleted 
 792             if isinstance(document
, ChildDocument
) and document
.GetParentDocument() == parentDocument
: 
 793                 if document
.GetFirstView().GetFrame(): 
 794                     document
.GetFirstView().GetFrame().SetFocus() 
 795                 if document
.GetFirstView().OnClose(deleteWindow 
= False): 
 796                     if document
.GetFirstView().GetFrame(): 
 797                         document
.GetFirstView().GetFrame().Close()  # wxBug: Need to do this for some random reason 
 805         Returns True if the application is in MDI mode. 
 807         return self
.GetDocumentManager().GetFlags() & wx
.lib
.docview
.DOC_MDI
 
 812         Returns True if the application is in SDI mode. 
 814         return self
.GetDocumentManager().GetFlags() & wx
.lib
.docview
.DOC_SDI
 
 817     def ShowSplash(self
, image
): 
 819         Shows a splash window with the given image.  Input parameter 'image' can either be a wx.Bitmap or a filename. 
 821         if isinstance(image
, wx
.Bitmap
): 
 824             splash_bmp 
= wx
.Image(image
).ConvertToBitmap() 
 825         self
._splash 
= wx
.SplashScreen(splash_bmp
,wx
.SPLASH_CENTRE_ON_SCREEN | wx
.SPLASH_NO_TIMEOUT
,0, None, -1)  
 829     def CloseSplash(self
): 
 831         Closes the splash window. 
 834             self
._splash
.Close(True) 
 837 class _DocFrameFileDropTarget(wx
.FileDropTarget
): 
 839     Class used to handle drops into the document frame. 
 842     def __init__(self
, docManager
, docFrame
): 
 844         Initializes the FileDropTarget class with the active docManager and the docFrame. 
 846         wx
.FileDropTarget
.__init
__(self
) 
 847         self
._docManager 
= docManager
 
 848         self
._docFrame 
= docFrame
 
 851     def OnDropFiles(self
, x
, y
, filenames
): 
 853         Called when files are dropped in the drop target and tells the docManager to open 
 857             for file in filenames
: 
 858                 self
._docManager
.CreateDocument(file, wx
.lib
.docview
.DOC_SILENT
) 
 860             msgTitle 
= wx
.GetApp().GetAppName() 
 862                 msgTitle 
= _("File Error") 
 863             wx
.MessageBox("Could not open '%s'.  '%s'" % (docview
.FileNameFromPath(file), sys
.exc_value
), 
 865                           wx
.OK | wx
.ICON_EXCLAMATION
, 
 866                           self
._docManager
.FindSuitableParent()) 
 869 class DocMDIParentFrame(wx
.lib
.docview
.DocMDIParentFrame
): 
 871     The DocMDIParentFrame is the primary frame which the DocApp uses to host MDI child windows.  It offers 
 872     features such as a default menubar, toolbar, and status bar, and a mechanism to manage embedded windows 
 873     on the edges of the DocMDIParentFrame. 
 877     def __init__(self
, docManager
, parent
, id, title
, pos 
= wx
.DefaultPosition
, size 
= wx
.DefaultSize
, style 
= wx
.DEFAULT_FRAME_STYLE
, name 
= "DocMDIFrame", embeddedWindows 
= 0): 
 879         Initializes the DocMDIParentFrame with the default menubar, toolbar, and status bar.  Use the 
 880         optional embeddedWindows parameter with the embedded window constants to create embedded 
 881         windows around the edges of the DocMDIParentFrame. 
 883         config 
= wx
.ConfigBase_Get() 
 884         if pos 
== wx
.DefaultPosition 
and size 
== wx
.DefaultSize 
and config
.ReadInt("MDIFrameMaximized", False): 
 886             size 
= wx
.DisplaySize() 
 887             # 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 
 889             if pos 
== wx
.DefaultPosition
: 
 890                 pos 
= config
.ReadInt("MDIFrameXLoc", -1), config
.ReadInt("MDIFrameYLoc", -1) 
 892             if wx
.Display_GetFromPoint(pos
) == -1:  # Check if the frame position is offscreen 
 893                 pos 
= wx
.DefaultPosition
 
 895             if size 
== wx
.DefaultSize
: 
 896                 size 
= wx
.Size(config
.ReadInt("MDIFrameXSize", 450), config
.ReadInt("MDIFrameYSize", 300)) 
 898         wx
.lib
.docview
.DocMDIParentFrame
.__init
__(self
, docManager
, parent
, id, title
, pos
, size
, style
, name
) 
 899         self
._embeddedWindows 
= [] 
 900         self
.SetDropTarget(_DocFrameFileDropTarget(docManager
, self
)) 
 902         if wx
.GetApp().GetDefaultIcon(): 
 903             self
.SetIcon(wx
.GetApp().GetDefaultIcon()) 
 905         wx
.EVT_MENU(self
, wx
.ID_ABOUT
, self
.OnAbout
) 
 906         wx
.EVT_SIZE(self
, self
.OnSize
) 
 908         self
.InitializePrintData() 
 910         toolBar 
= self
.CreateDefaultToolBar() 
 911         self
.SetToolBar(toolBar
) 
 912         menuBar 
= self
.CreateDefaultMenuBar() 
 913         statusBar 
= self
.CreateDefaultStatusBar() 
 915         if config
.ReadInt("MDIFrameMaximized", False): 
 916             # wxBug: On maximize, statusbar leaves a residual that needs to be refereshed, happens even when user does it 
 919         self
.CreateEmbeddedWindows(embeddedWindows
) 
 921         wx
.GetApp().SetTopWindow(self
)  # Need to do this here in case the services are looking for wx.GetApp().GetTopWindow() 
 922         for service 
in wx
.GetApp().GetServices(): 
 923             service
.InstallControls(self
, menuBar 
= menuBar
, toolBar 
= toolBar
, statusBar 
= statusBar
) 
 924             if hasattr(service
, "ShowWindow"): 
 925                 service
.ShowWindow()  # instantiate service windows for correct positioning, we'll hide/show them later based on user preference 
 927         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 
 930     def CreateEmbeddedWindows(self
, windows 
= 0): 
 932         Create the specified embedded windows around the edges of the DocMDIParentFrame. 
 934         frameSize 
= self
.GetSize()   # TODO: GetClientWindow.GetSize is still returning 0,0 since the frame isn't fully constructed yet, so using full frame size 
 935         defaultHSize 
= int(frameSize
[0] / 6) 
 936         defaultVSize 
= int(frameSize
[1] / 7) 
 937         defaultSubVSize 
= int(frameSize
[1] / 2) 
 938         #print defaultHSize, defaultVSize, defaultSubVSize 
 939         config 
= wx
.ConfigBase_Get() 
 940         if windows 
& (EMBEDDED_WINDOW_LEFT | EMBEDDED_WINDOW_TOPLEFT | EMBEDDED_WINDOW_BOTTOMLEFT
): 
 941             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
) 
 943             self
._leftEmbWindow 
= None 
 944         if windows 
& EMBEDDED_WINDOW_TOPLEFT
: 
 945             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
) 
 947             self
._topLeftEmbWindow 
= None 
 948         if windows 
& EMBEDDED_WINDOW_BOTTOMLEFT
: 
 949             self
._bottomLeftEmbWindow 
= self
._CreateEmbeddedWindow
(self
._leftEmbWindow
, (-1, config
.ReadInt("MDIEmbedBottomLeftSize", defaultSubVSize
)), wx
.LAYOUT_HORIZONTAL
, wx
.LAYOUT_BOTTOM
, visible 
= config
.ReadInt("MDIEmbedBottomLeftVisible", 1)) 
 951             self
._bottomLeftEmbWindow 
= None 
 952         if windows 
& (EMBEDDED_WINDOW_RIGHT | EMBEDDED_WINDOW_TOPRIGHT | EMBEDDED_WINDOW_BOTTOMRIGHT
): 
 953             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
) 
 955             self
._rightEmbWindow 
= None 
 956         if windows 
& EMBEDDED_WINDOW_TOPRIGHT
: 
 957             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
) 
 959             self
._topRightEmbWindow 
= None 
 960         if windows 
& EMBEDDED_WINDOW_BOTTOMRIGHT
: 
 961             self
._bottomRightEmbWindow 
= self
._CreateEmbeddedWindow
(self
._rightEmbWindow
, (-1, config
.ReadInt("MDIEmbedBottomRightSize", defaultSubVSize
)), wx
.LAYOUT_HORIZONTAL
, wx
.LAYOUT_BOTTOM
, visible 
= config
.ReadInt("MDIEmbedBottomRightVisible", 1)) 
 963             self
._bottomRightEmbWindow 
= None 
 964         if windows 
& EMBEDDED_WINDOW_TOP
: 
 965             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
) 
 967             self
._topEmbWindow 
= None 
 968         if windows 
& EMBEDDED_WINDOW_BOTTOM
: 
 969             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
) 
 971             self
._bottomEmbWindow 
= None 
 972         wx
.LayoutAlgorithm().LayoutMDIFrame(self
) 
 973         self
.GetClientWindow().Refresh() 
 976     def SaveEmbeddedWindowSizes(self
): 
 978         Saves the sizes of the embedded windows. 
 980         config 
= wx
.ConfigBase_Get() 
 981         if self
._leftEmbWindow
: 
 982             config
.WriteInt("MDIEmbedLeftSize", self
._leftEmbWindow
.GetSize()[0]) 
 983             config
.WriteInt("MDIEmbedLeftVisible", self
._leftEmbWindow
.IsShown()) 
 984         if self
._topLeftEmbWindow
: 
 985             if self
._topLeftEmbWindow
._sizeBeforeHidden
: 
 986                 size 
= self
._topLeftEmbWindow
._sizeBeforeHidden
[1] 
 988                 size 
= self
._topLeftEmbWindow
.GetSize()[1] 
 989             config
.WriteInt("MDIEmbedTopLeftSize", size
) 
 990             config
.WriteInt("MDIEmbedTopLeftVisible", self
._topLeftEmbWindow
.IsShown()) 
 991         if self
._bottomLeftEmbWindow
: 
 992             if self
._bottomLeftEmbWindow
._sizeBeforeHidden
: 
 993                 size 
= self
._bottomLeftEmbWindow
._sizeBeforeHidden
[1] 
 995                 size 
= self
._bottomLeftEmbWindow
.GetSize()[1] 
 996             config
.WriteInt("MDIEmbedBottomLeftSize", size
) 
 997             config
.WriteInt("MDIEmbedBottomLeftVisible", self
._bottomLeftEmbWindow
.IsShown()) 
 998         if self
._rightEmbWindow
: 
 999             config
.WriteInt("MDIEmbedRightSize", self
._rightEmbWindow
.GetSize()[0]) 
1000             config
.WriteInt("MDIEmbedRightVisible", self
._rightEmbWindow
.IsShown()) 
1001         if self
._topRightEmbWindow
: 
1002             if self
._topRightEmbWindow
._sizeBeforeHidden
: 
1003                 size 
= self
._topRightEmbWindow
._sizeBeforeHidden
[1] 
1005                 size 
= self
._topRightEmbWindow
.GetSize()[1] 
1006             config
.WriteInt("MDIEmbedTopRightSize", size
) 
1007             config
.WriteInt("MDIEmbedTopRightVisible", self
._topRightEmbWindow
.IsShown()) 
1008         if self
._bottomRightEmbWindow
: 
1009             if self
._bottomRightEmbWindow
._sizeBeforeHidden
: 
1010                 size 
= self
._bottomRightEmbWindow
._sizeBeforeHidden
[1] 
1012                 size 
= self
._bottomRightEmbWindow
.GetSize()[1] 
1013             config
.WriteInt("MDIEmbedBottomRightSize", size
) 
1014             config
.WriteInt("MDIEmbedBottomRightVisible", self
._bottomRightEmbWindow
.IsShown()) 
1015         if self
._topEmbWindow
: 
1016             config
.WriteInt("MDIEmbedTopSize", self
._topEmbWindow
.GetSize()[1]) 
1017             config
.WriteInt("MDIEmbedTopVisible", self
._topEmbWindow
.IsShown()) 
1018         if self
._bottomEmbWindow
: 
1019             config
.WriteInt("MDIEmbedBottomSize", self
._bottomEmbWindow
.GetSize()[1]) 
1020             config
.WriteInt("MDIEmbedBottomVisible", self
._bottomEmbWindow
.IsShown()) 
1023     def GetEmbeddedWindow(self
, loc
): 
1025         Returns the instance of the embedded window specified by the embedded window location constant. 
1027         if loc 
== EMBEDDED_WINDOW_TOP
: 
1028             return self
._topEmbWindow
 
1029         elif loc 
== EMBEDDED_WINDOW_BOTTOM
: 
1030             return self
._bottomEmbWindow
 
1031         elif loc 
== EMBEDDED_WINDOW_LEFT
: 
1032             return self
._leftEmbWindow
 
1033         elif loc 
== EMBEDDED_WINDOW_RIGHT
: 
1034             return self
._rightEmbWindow
 
1035         elif loc 
== EMBEDDED_WINDOW_TOPLEFT
: 
1036             return self
._topLeftEmbWindow
 
1037         elif loc 
== EMBEDDED_WINDOW_BOTTOMLEFT
: 
1038             return self
._bottomLeftEmbWindow
 
1039         elif loc 
== EMBEDDED_WINDOW_TOPRIGHT
: 
1040             return self
._topRightEmbWindow
 
1041         elif loc 
== EMBEDDED_WINDOW_BOTTOMRIGHT
: 
1042             return self
._bottomRightEmbWindow
 
1046     def _CreateEmbeddedWindow(self
, parent
, size
, orientation
, alignment
, visible 
= True, sash 
= None): 
1048         Creates the embedded window with the specified size, orientation, and alignment.  If the  
1049         window is not visible it will retain the size with which it was last viewed. 
1051         window 
= wx
.SashLayoutWindow(parent
, wx
.NewId(), style 
= wx
.NO_BORDER | wx
.SW_3D
) 
1052         window
.SetDefaultSize(size
) 
1053         window
.SetOrientation(orientation
) 
1054         window
.SetAlignment(alignment
) 
1055         if sash 
!= None:  # wx.SASH_TOP is 0 so check for None instead of just doing "if sash:" 
1056             window
.SetSashVisible(sash
, True) 
1058         def OnEmbeddedWindowSashDrag(event
): 
1059             if event
.GetDragStatus() == wx
.SASH_STATUS_OUT_OF_RANGE
: 
1061             sashWindow 
= event
.GetEventObject() 
1062             if sashWindow
.GetAlignment() == wx
.LAYOUT_TOP 
or sashWindow
.GetAlignment() == wx
.LAYOUT_BOTTOM
: 
1063                 size 
= wx
.Size(-1, event
.GetDragRect().height
) 
1065                 size 
= wx
.Size(event
.GetDragRect().width
, -1) 
1066             event
.GetEventObject().SetDefaultSize(size
) 
1067             wx
.LayoutAlgorithm().LayoutMDIFrame(self
) 
1068             self
.GetClientWindow().Refresh() 
1069             if isinstance(sashWindow
.GetParent(), wx
.SashLayoutWindow
): 
1071                 parentSashWindow 
= sashWindow
.GetParent()  # Force a refresh 
1072                 parentSashWindow
.Layout() 
1073                 parentSashWindow
.Refresh() 
1074                 parentSashWindow
.SetSize((parentSashWindow
.GetSize().width 
+ 1, parentSashWindow
.GetSize().height 
+ 1)) 
1076         wx
.EVT_SASH_DRAGGED(window
, window
.GetId(), OnEmbeddedWindowSashDrag
) 
1077         window
._sizeBeforeHidden 
= None 
1080             if isinstance(parent
, wx
.SashLayoutWindow
): # It's a window embedded in another sash window so remember its actual size to show it again 
1081                 window
._sizeBeforeHidden 
= size
 
1085     def ShowEmbeddedWindow(self
, window
, show 
= True): 
1087         Shows or hides the embedded window specified by the embedded window location constant. 
1090         if isinstance(window
.GetParent(), wx
.SashLayoutWindow
):  # It is a parent sashwindow with multiple embedded sashwindows 
1091             parentSashWindow 
= window
.GetParent() 
1092             if show
:  # Make sure it is visible in case all of the subwindows were hidden 
1093                 parentSashWindow
.Show()                 
1094             if show 
and window
._sizeBeforeHidden
: 
1095                 if window
._sizeBeforeHidden
[1] == parentSashWindow
.GetClientSize()[1]: 
1096                     if window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
) and self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
).IsShown(): 
1097                         window
.SetDefaultSize((window
._sizeBeforeHidden
[0], window
._sizeBeforeHidden
[0] - self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
).GetSize()[1])) 
1098                     elif window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
) and self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
).IsShown(): 
1099                         window
.SetDefaultSize((window
._sizeBeforeHidden
[0], window
._sizeBeforeHidden
[0] - self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
).GetSize()[1])) 
1100                     elif window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
) and self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
).IsShown(): 
1101                         window
.SetDefaultSize((window
._sizeBeforeHidden
[0], window
._sizeBeforeHidden
[0] - self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
).GetSize()[1])) 
1102                     elif window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
) and self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
).IsShown(): 
1103                         window
.SetDefaultSize((window
._sizeBeforeHidden
[0], window
._sizeBeforeHidden
[0] - self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
).GetSize()[1])) 
1104                     print window
.GetSize() 
1106                     window
.SetDefaultSize(window
._sizeBeforeHidden
) 
1107                     # 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 
1108                     print "Parent size, size before hidden ", parentSashWindow
.GetClientSize()[1], window
._sizeBeforeHidden
[1] 
1109                     if window
._sizeBeforeHidden
[1] < parentSashWindow
.GetClientSize()[1]: 
1110                         otherWindowSize 
= (-1, parentSashWindow
.GetClientSize()[1] - window
._sizeBeforeHidden
[1]) 
1111                         print "Other", otherWindowSize
 
1112                         if window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
): 
1113                             self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
).SetDefaultSize(otherWindowSize
) 
1114                         elif window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
): 
1115                             self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
).SetDefaultSize(otherWindowSize
) 
1116                         elif window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
): 
1117                             self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
).SetDefaultSize(otherWindowSize
) 
1118                         elif window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
): 
1119                             self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
).SetDefaultSize(otherWindowSize
) 
1122                 if window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
) and not self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
).IsShown() \
 
1123                     or window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPRIGHT
) and not self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMRIGHT
).IsShown() \
 
1124                     or window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
) and not self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
).IsShown() \
 
1125                     or window 
== self
.GetEmbeddedWindow(EMBEDDED_WINDOW_TOPLEFT
) and not self
.GetEmbeddedWindow(EMBEDDED_WINDOW_BOTTOMLEFT
).IsShown(): 
1126                     parentSashWindow
.Hide()  # Hide the parent sashwindow if all of the children are hidden 
1127             parentSashWindow
.Layout()   # Force a refresh 
1128             parentSashWindow
.Refresh() 
1129             parentSashWindow
.SetSize((parentSashWindow
.GetSize().width 
+ 1, parentSashWindow
.GetSize().height 
+ 1)) 
1130         wx
.LayoutAlgorithm().LayoutMDIFrame(self
) 
1131         self
.GetClientWindow().Refresh() 
1134     def HideEmbeddedWindow(self
): 
1136         Hides the embedded window specified by the embedded window location constant. 
1138         self
.ShowEmbeddedWindow(show 
= False) 
1141     def GetDocumentManager(self
): 
1143         Returns the document manager associated with the DocMDIParentFrame. 
1145         return self
._docManager
 
1148     def InitializePrintData(self
): 
1150         Initializes the PrintData that is used when printing. 
1152         self
._printData 
= wx
.PrintData() 
1153         self
._printData
.SetPaperId(wx
.PAPER_LETTER
) 
1156     def CreateDefaultStatusBar(self
): 
1158         Creates the default StatusBar. 
1160         self
.CreateStatusBar() 
1161         self
.GetStatusBar().Show(wx
.ConfigBase_Get().ReadInt("ViewStatusBar", True)) 
1163         return self
.GetStatusBar() 
1166     def CreateDefaultToolBar(self
): 
1168         Creates the default ToolBar. 
1170         self
._toolBar 
= self
.CreateToolBar(wx
.TB_HORIZONTAL | wx
.NO_BORDER | wx
.TB_FLAT
) 
1171         self
._toolBar
.AddSimpleTool(wx
.ID_NEW
, getNewBitmap(), _("New"), _("Creates a new document")) 
1172         self
._toolBar
.AddSimpleTool(wx
.ID_OPEN
, getOpenBitmap(), _("Open"), _("Opens an existing document")) 
1173         self
._toolBar
.AddSimpleTool(wx
.ID_SAVE
, getSaveBitmap(), _("Save"), _("Saves the active document")) 
1174         self
._toolBar
.AddSimpleTool(SAVEALL_ID
, getSaveAllBitmap(), _("Save All"), _("Saves all the active documents")) 
1175         self
._toolBar
.AddSeparator() 
1176         self
._toolBar
.AddSimpleTool(wx
.ID_PRINT
, getPrintBitmap(), _("Print"), _("Displays full pages")) 
1177         self
._toolBar
.AddSimpleTool(wx
.ID_PREVIEW
, getPrintPreviewBitmap(), _("Print Preview"), _("Prints the active document")) 
1178         self
._toolBar
.AddSeparator() 
1179         self
._toolBar
.AddSimpleTool(wx
.ID_CUT
, getCutBitmap(), _("Cut"), _("Cuts the selection and puts it on the Clipboard")) 
1180         self
._toolBar
.AddSimpleTool(wx
.ID_COPY
, getCopyBitmap(), _("Copy"), _("Copies the selection and puts it on the Clipboard")) 
1181         self
._toolBar
.AddSimpleTool(wx
.ID_PASTE
, getPasteBitmap(), _("Paste"), _("Inserts Clipboard contents")) 
1182         self
._toolBar
.AddSimpleTool(wx
.ID_UNDO
, getUndoBitmap(), _("Undo"), _("Reverses the last action")) 
1183         self
._toolBar
.AddSimpleTool(wx
.ID_REDO
, getRedoBitmap(), _("Redo"), _("Reverses the last undo")) 
1184         self
._toolBar
.Realize() 
1185         self
._toolBar
.Show(wx
.ConfigBase_Get().ReadInt("ViewToolBar", True)) 
1187         return self
._toolBar
 
1190     def CreateDefaultMenuBar(self
): 
1192         Creates the default MenuBar.  Contains File, Edit, View, Tools, and Help menus. 
1194         menuBar 
= wx
.MenuBar() 
1196         fileMenu 
= wx
.Menu() 
1197         fileMenu
.Append(wx
.ID_NEW
, _("&New...\tCtrl+N"), _("Creates a new document")) 
1198         fileMenu
.Append(wx
.ID_OPEN
, _("&Open...\tCtrl+O"), _("Opens an existing document")) 
1199         fileMenu
.Append(wx
.ID_CLOSE
, _("&Close"), _("Closes the active document")) 
1200         fileMenu
.Append(wx
.ID_CLOSE_ALL
, _("Close A&ll"), _("Closes all open documents")) 
1201         fileMenu
.AppendSeparator() 
1202         fileMenu
.Append(wx
.ID_SAVE
, _("&Save\tCtrl+S"), _("Saves the active document")) 
1203         fileMenu
.Append(wx
.ID_SAVEAS
, _("Save &As..."), _("Saves the active document with a new name")) 
1204         fileMenu
.Append(SAVEALL_ID
, _("Save All\tCtrl+Shift+A"), _("Saves the all active documents")) 
1205         wx
.EVT_MENU(self
, SAVEALL_ID
, self
.ProcessEvent
) 
1206         wx
.EVT_UPDATE_UI(self
, SAVEALL_ID
, self
.ProcessUpdateUIEvent
) 
1207         fileMenu
.AppendSeparator() 
1208         fileMenu
.Append(wx
.ID_PRINT
, _("&Print\tCtrl+P"), _("Prints the active document")) 
1209         fileMenu
.Append(wx
.ID_PREVIEW
, _("Print Pre&view"), _("Displays full pages")) 
1210         fileMenu
.Append(wx
.ID_PRINT_SETUP
, _("Page Set&up"), _("Changes page layout settings")) 
1211         fileMenu
.AppendSeparator() 
1212         if wx
.Platform 
== '__WXMAC__': 
1213             fileMenu
.Append(wx
.ID_EXIT
, _("&Quit"), _("Closes this program")) 
1215             fileMenu
.Append(wx
.ID_EXIT
, _("E&xit"), _("Closes this program")) 
1216         self
._docManager
.FileHistoryUseMenu(fileMenu
) 
1217         self
._docManager
.FileHistoryAddFilesToMenu() 
1218         menuBar
.Append(fileMenu
, _("&File")); 
1220         editMenu 
= wx
.Menu() 
1221         editMenu
.Append(wx
.ID_UNDO
, _("&Undo\tCtrl+Z"), _("Reverses the last action")) 
1222         editMenu
.Append(wx
.ID_REDO
, _("&Redo\tCtrl+Y"), _("Reverses the last undo")) 
1223         editMenu
.AppendSeparator() 
1224         #item = wxMenuItem(self.editMenu, wxID_CUT, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard")) 
1225         #item.SetBitmap(getCutBitmap()) 
1226         #editMenu.AppendItem(item) 
1227         editMenu
.Append(wx
.ID_CUT
, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard")) 
1228         wx
.EVT_MENU(self
, wx
.ID_CUT
, self
.ProcessEvent
) 
1229         wx
.EVT_UPDATE_UI(self
, wx
.ID_CUT
, self
.ProcessUpdateUIEvent
) 
1230         editMenu
.Append(wx
.ID_COPY
, _("&Copy\tCtrl+C"), _("Copies the selection and puts it on the Clipboard")) 
1231         wx
.EVT_MENU(self
, wx
.ID_COPY
, self
.ProcessEvent
) 
1232         wx
.EVT_UPDATE_UI(self
, wx
.ID_COPY
, self
.ProcessUpdateUIEvent
) 
1233         editMenu
.Append(wx
.ID_PASTE
, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents")) 
1234         wx
.EVT_MENU(self
, wx
.ID_PASTE
, self
.ProcessEvent
) 
1235         wx
.EVT_UPDATE_UI(self
, wx
.ID_PASTE
, self
.ProcessUpdateUIEvent
) 
1236         editMenu
.Append(wx
.ID_CLEAR
, _("Cle&ar\tDel"), _("Erases the selection")) 
1237         wx
.EVT_MENU(self
, wx
.ID_CLEAR
, self
.ProcessEvent
) 
1238         wx
.EVT_UPDATE_UI(self
, wx
.ID_CLEAR
, self
.ProcessUpdateUIEvent
) 
1239         editMenu
.AppendSeparator() 
1240         editMenu
.Append(wx
.ID_SELECTALL
, _("Select A&ll\tCtrl+A"), _("Selects all available data")) 
1241         wx
.EVT_MENU(self
, wx
.ID_SELECTALL
, self
.ProcessEvent
) 
1242         wx
.EVT_UPDATE_UI(self
, wx
.ID_SELECTALL
, self
.ProcessUpdateUIEvent
) 
1243         menuBar
.Append(editMenu
, _("&Edit")) 
1245         viewMenu 
= wx
.Menu() 
1246         viewMenu
.AppendCheckItem(VIEW_TOOLBAR_ID
, _("&Toolbar"), _("Shows or hides the toolbar")) 
1247         wx
.EVT_MENU(self
, VIEW_TOOLBAR_ID
, self
.OnViewToolBar
) 
1248         wx
.EVT_UPDATE_UI(self
, VIEW_TOOLBAR_ID
, self
.OnUpdateViewToolBar
) 
1249         viewMenu
.AppendCheckItem(VIEW_STATUSBAR_ID
, _("&Status Bar"), _("Shows or hides the status bar")) 
1250         wx
.EVT_MENU(self
, VIEW_STATUSBAR_ID
, self
.OnViewStatusBar
) 
1251         wx
.EVT_UPDATE_UI(self
, VIEW_STATUSBAR_ID
, self
.OnUpdateViewStatusBar
) 
1252         menuBar
.Append(viewMenu
, _("&View")) 
1254         helpMenu 
= wx
.Menu() 
1255         helpMenu
.Append(wx
.ID_ABOUT
, _("&About" + " " + wx
.GetApp().GetAppName()), _("Displays program information, version number, and copyright")) 
1256         wx
.EVT_MENU(self
, wx
.ID_ABOUT
, self
.OnAbout
) 
1257         menuBar
.Append(helpMenu
, _("&Help")) 
1259 ##        windowMenu = wx.Menu() 
1260 ##        menuBar.Append(windowMenu, _("&Window")) 
1261 ##        # self.SetWindowMenu(windowMenu) 
1263         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 
1267 ##        accelTable = wx.AcceleratorTable([ 
1268 ##            eval(_("wx.ACCEL_CTRL, ord('Z'), wx.ID_UNDO")), 
1269 ##            eval(_("wx.ACCEL_CTRL, ord('Y'), wx.ID_REDO")), 
1270 ##            eval(_("wx.ACCEL_CTRL, ord('X'), wx.ID_CUT")), 
1271 ##            eval(_("wx.ACCEL_CTRL, ord('C'), wx.ID_COPY")), 
1272 ##            eval(_("wx.ACCEL_CTRL, ord('V'), wx.ID_PASTE")), 
1273 ##            (wx.ACCEL_NORMAL, wx.WXK_DELETE, wx.ID_CLEAR), 
1274 ##            eval(_("wx.ACCEL_CTRL, ord('A'), wx.ID_SELECTALL")), 
1275 ##            eval(_("wx.ACCEL_CTRL, ord('N'), wx.ID_NEW")), 
1276 ##            eval(_("wx.ACCEL_CTRL, ord('O'), wx.ID_OPEN")), 
1277 ##            eval(_("wx.ACCEL_CTRL, ord('S'), wx.ID_SAVE")) 
1279 ##        self.SetAcceleratorTable(accelTable) 
1282     def ProcessEvent(self
, event
): 
1284         Processes an event, searching event tables and calling zero or more 
1285         suitable event handler function(s).  Note that the ProcessEvent 
1286         method is called from the wxPython docview framework directly since 
1287         wxPython does not have a virtual ProcessEvent function. 
1289         if wx
.GetApp().ProcessEventBeforeWindows(event
): 
1291         if wx
.lib
.docview
.DocMDIParentFrame
.ProcessEvent(self
, event
): 
1295         if id == SAVEALL_ID
: 
1296             self
.OnFileSaveAll(event
) 
1299         return wx
.GetApp().ProcessEvent(event
) 
1302     def ProcessUpdateUIEvent(self
, event
): 
1304         Processes a UI event, searching event tables and calling zero or more 
1305         suitable event handler function(s).  Note that the ProcessEvent 
1306         method is called from the wxPython docview framework directly since 
1307         wxPython does not have a virtual ProcessEvent function. 
1309         if wx
.GetApp().ProcessUpdateUIEventBeforeWindows(event
): 
1311         if wx
.lib
.docview
.DocMDIParentFrame
.ProcessUpdateUIEvent(self
, event
):  # Let the views handle the event before the services 
1317         elif id == wx
.ID_COPY
: 
1320         elif id == wx
.ID_PASTE
: 
1323         elif id == wx
.ID_CLEAR
: 
1326         elif id == wx
.ID_SELECTALL
: 
1329         elif id == wx
.ID_ABOUT
:  # Using ID_ABOUT to update the window menu, the window menu items are not triggering 
1330             self
.UpdateWindowMenu() 
1332         elif id == SAVEALL_ID
: 
1333             filesModified 
= False 
1334             docs 
= wx
.GetApp().GetDocumentManager().GetDocuments() 
1336                 if doc
.IsModified(): 
1337                     filesModified 
= True 
1340             event
.Enable(filesModified
) 
1343             return wx
.GetApp().ProcessUpdateUIEvent(event
) 
1346     def UpdateWindowMenu(self
): 
1348         Updates the WindowMenu on Windows platforms. 
1350         if wx
.Platform 
== '__WXMSW__': 
1351             children 
= filter(lambda child
: isinstance(child
, wx
.MDIChildFrame
), self
.GetChildren()) 
1352             windowCount 
= len(children
) 
1353             hasWindow 
= windowCount 
>= 1 
1354             has2OrMoreWindows 
= windowCount 
>= 2 
1356             windowMenu 
= self
.GetWindowMenu() 
1357             windowMenu
.Enable(wx
.IDM_WINDOWTILE
, hasWindow
) 
1358             windowMenu
.Enable(wx
.IDM_WINDOWTILEHOR
, hasWindow
) 
1359             windowMenu
.Enable(wx
.IDM_WINDOWCASCADE
, hasWindow
) 
1360             windowMenu
.Enable(wx
.IDM_WINDOWICONS
, hasWindow
) 
1361             windowMenu
.Enable(wx
.IDM_WINDOWTILEVERT
, hasWindow
) 
1362             wx
.IDM_WINDOWPREV 
= 4006  # wxBug: Not defined for some reason 
1363             windowMenu
.Enable(wx
.IDM_WINDOWPREV
, has2OrMoreWindows
) 
1364             windowMenu
.Enable(wx
.IDM_WINDOWNEXT
, has2OrMoreWindows
) 
1367     def OnFileSaveAll(self
, event
): 
1369         Saves all of the currently open documents. 
1371         docs 
= wx
.GetApp().GetDocumentManager().GetDocuments() 
1376     def OnCloseWindow(self
, event
): 
1378         Called when the DocMDIParentFrame is closed.  Remembers the frame size. 
1380         config 
= wx
.ConfigBase_Get() 
1381         if not self
.IsMaximized(): 
1382             config
.WriteInt("MDIFrameXLoc", self
.GetPositionTuple()[0]) 
1383             config
.WriteInt("MDIFrameYLoc", self
.GetPositionTuple()[1]) 
1384             config
.WriteInt("MDIFrameXSize", self
.GetSizeTuple()[0]) 
1385             config
.WriteInt("MDIFrameYSize", self
.GetSizeTuple()[1]) 
1386         config
.WriteInt("MDIFrameMaximized", self
.IsMaximized()) 
1387         config
.WriteInt("ViewToolBar", self
._toolBar
.IsShown()) 
1388         config
.WriteInt("ViewStatusBar", self
.GetStatusBar().IsShown()) 
1390         self
.SaveEmbeddedWindowSizes() 
1392         # save and close services last. 
1393         for service 
in wx
.GetApp().GetServices(): 
1394             if not service
.OnCloseFrame(event
): 
1397         # save and close documents 
1398         # documents with a common view, e.g. project view, should save the document, but not close the window 
1399         # and let the service close the window. 
1400         wx
.lib
.docview
.DocMDIParentFrame
.OnCloseWindow(self
, event
) 
1403     def OnAbout(self
, event
): 
1405         Invokes the about dialog. 
1407         aboutService 
= wx
.GetApp().GetService(AboutService
) 
1409             aboutService
.ShowAbout() 
1412     def OnViewToolBar(self
, event
): 
1414         Toggles whether the ToolBar is visible. 
1416         self
._toolBar
.Show(not self
._toolBar
.IsShown()) 
1417         wx
.LayoutAlgorithm().LayoutMDIFrame(self
) 
1418         self
.GetClientWindow().Refresh() 
1421     def OnUpdateViewToolBar(self
, event
): 
1423         Updates the View ToolBar menu item. 
1425         event
.Check(self
.GetToolBar().IsShown()) 
1428     def OnViewStatusBar(self
, event
): 
1430         Toggles whether the StatusBar is visible. 
1432         self
.GetStatusBar().Show(not self
.GetStatusBar().IsShown()) 
1434         wx
.LayoutAlgorithm().LayoutMDIFrame(self
) 
1435         self
.GetClientWindow().Refresh() 
1438     def OnUpdateViewStatusBar(self
, event
): 
1440         Updates the View StatusBar menu item. 
1442         event
.Check(self
.GetStatusBar().IsShown()) 
1445     def UpdateStatus(self
, message 
= _("Ready")): 
1447         Updates the StatusBar. 
1449         # wxBug: Menubar and toolbar help strings don't pop the status text back 
1450         if self
.GetStatusBar().GetStatusText() != message
: 
1451             self
.GetStatusBar().PushStatusText(message
) 
1454     def OnSize(self
, event
): 
1456         Called when the DocMDIParentFrame is resized and lays out the MDI client window. 
1458         # Needed in case there are splitpanels around the mdi frame 
1459         wx
.LayoutAlgorithm().LayoutMDIFrame(self
) 
1460         self
.GetClientWindow().Refresh() 
1463 class DocSDIFrame(wx
.lib
.docview
.DocChildFrame
): 
1465     The DocSDIFrame host DocManager Document windows.  It offers features such as a default menubar, 
1466     toolbar, and status bar. 
1470     def __init__(self
, doc
, view
, parent
, id, title
, pos 
= wx
.DefaultPosition
, size 
= wx
.DefaultSize
, style 
= wx
.DEFAULT_FRAME_STYLE
, name 
= "DocSDIFrame"): 
1472         Initializes the DocSDIFrame with the default menubar, toolbar, and status bar. 
1474         wx
.lib
.docview
.DocChildFrame
.__init
__(self
, doc
, view
, parent
, id, title
, pos
, size
, style
, name
) 
1475         self
._fileMenu 
= None 
1477             self
._docManager 
= doc
.GetDocumentManager() 
1479             self
._docManager 
= None 
1480         self
.SetDropTarget(_DocFrameFileDropTarget(self
._docManager
, self
)) 
1482         wx
.EVT_MENU(self
, wx
.ID_ABOUT
, self
.OnAbout
) 
1483         wx
.EVT_MENU(self
, wx
.ID_EXIT
, self
.OnExit
) 
1484         wx
.EVT_MENU_RANGE(self
, wx
.ID_FILE1
, wx
.ID_FILE9
, self
.OnMRUFile
) 
1486         self
.InitializePrintData() 
1488         menuBar 
= self
.CreateDefaultMenuBar() 
1489         toolBar 
= self
.CreateDefaultToolBar() 
1490         self
.SetToolBar(toolBar
) 
1491         statusBar 
= self
.CreateDefaultStatusBar() 
1493         for service 
in wx
.GetApp().GetServices(): 
1494             service
.InstallControls(self
, menuBar 
= menuBar
, toolBar 
= toolBar
, statusBar 
= statusBar
, document 
= doc
) 
1496         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 
1499     def GetDocumentManager(self
): 
1501         Returns the document manager associated with the DocSDIFrame. 
1503         return self
._docManager
 
1506     def OnExit(self
, event
): 
1508         Called when the application is exitting. 
1510         if self
._childView
.GetDocumentManager().Clear(force 
= False): 
1516     def OnMRUFile(self
, event
): 
1518         Opens the appropriate file when it is selected from the file history 
1521         n 
= event
.GetId() - wx
.ID_FILE1
 
1522         filename 
= self
._docManager
.GetHistoryFile(n
) 
1524             self
._docManager
.CreateDocument(filename
, wx
.lib
.docview
.DOC_SILENT
) 
1526             self
._docManager
.RemoveFileFromHistory(n
) 
1527             msgTitle 
= wx
.GetApp().GetAppName() 
1529                 msgTitle 
= _("File Error") 
1530             wx
.MessageBox("The file '%s' doesn't exist and couldn't be opened.\nIt has been removed from the most recently used files list" % docview
.FileNameFromPath(file), 
1532                           wx
.OK | wx
.ICON_EXCLAMATION
, 
1536     def InitializePrintData(self
): 
1538         Initializes the PrintData that is used when printing. 
1540         self
._printData 
= wx
.PrintData() 
1541         self
._printData
.SetPaperId(wx
.PAPER_LETTER
) 
1544     def CreateDefaultStatusBar(self
): 
1546         Creates the default StatusBar. 
1548         wx
.lib
.docview
.DocChildFrame
.CreateStatusBar(self
) 
1549         self
.GetStatusBar().Show(wx
.ConfigBase_Get().ReadInt("ViewStatusBar", True)) 
1551         return self
.GetStatusBar() 
1554     def CreateDefaultToolBar(self
): 
1556         Creates the default ToolBar. 
1558         self
._toolBar 
= self
.CreateToolBar(wx
.TB_HORIZONTAL | wx
.NO_BORDER | wx
.TB_FLAT
) 
1559         self
._toolBar
.AddSimpleTool(wx
.ID_NEW
, getNewBitmap(), _("New"), _("Creates a new document")) 
1560         self
._toolBar
.AddSimpleTool(wx
.ID_OPEN
, getOpenBitmap(), _("Open"), _("Opens an existing document")) 
1561         self
._toolBar
.AddSimpleTool(wx
.ID_SAVE
, getSaveBitmap(), _("Save"), _("Saves the active document")) 
1562         self
._toolBar
.AddSimpleTool(SAVEALL_ID
, getSaveAllBitmap(), _("Save All"), _("Saves all the active documents")) 
1563         self
._toolBar
.AddSeparator() 
1564         self
._toolBar
.AddSimpleTool(wx
.ID_PRINT
, getPrintBitmap(), _("Print"), _("Displays full pages")) 
1565         self
._toolBar
.AddSimpleTool(wx
.ID_PREVIEW
, getPrintPreviewBitmap(), _("Print Preview"), _("Prints the active document")) 
1566         self
._toolBar
.AddSeparator() 
1567         self
._toolBar
.AddSimpleTool(wx
.ID_CUT
, getCutBitmap(), _("Cut"), _("Cuts the selection and puts it on the Clipboard")) 
1568         self
._toolBar
.AddSimpleTool(wx
.ID_COPY
, getCopyBitmap(), _("Copy"), _("Copies the selection and puts it on the Clipboard")) 
1569         self
._toolBar
.AddSimpleTool(wx
.ID_PASTE
, getPasteBitmap(), _("Paste"), _("Inserts Clipboard contents")) 
1570         self
._toolBar
.AddSimpleTool(wx
.ID_UNDO
, getUndoBitmap(), _("Undo"), _("Reverses the last action")) 
1571         self
._toolBar
.AddSimpleTool(wx
.ID_REDO
, getRedoBitmap(), _("Redo"), _("Reverses the last undo")) 
1572         self
._toolBar
.Realize() 
1573         self
._toolBar
.Show(wx
.ConfigBase_Get().ReadInt("ViewToolBar", True)) 
1574         return self
._toolBar
 
1577     def CreateDefaultMenuBar(self
): 
1579         Creates the default MenuBar.  Contains File, Edit, View, Tools, and Help menus. 
1581         menuBar 
= wx
.MenuBar() 
1583         fileMenu 
= wx
.Menu() 
1584         self
._fileMenu 
= fileMenu
 
1585         fileMenu
.Append(wx
.ID_NEW
, _("&New...\tCtrl+N"), _("Creates a new document")) 
1586         fileMenu
.Append(wx
.ID_OPEN
, _("&Open...\tCtrl+O"), _("Opens an existing document")) 
1587         fileMenu
.Append(wx
.ID_CLOSE
, _("&Close"), _("Closes the active document")) 
1588         # fileMenu.Append(wx.ID_CLOSE_ALL, _("Close A&ll"), _("Closes all open documents")) 
1589         fileMenu
.AppendSeparator() 
1590         fileMenu
.Append(wx
.ID_SAVE
, _("&Save\tCtrl+S"), _("Saves the active document")) 
1591         fileMenu
.Append(wx
.ID_SAVEAS
, _("Save &As..."), _("Saves the active document with a new name")) 
1592         fileMenu
.Append(SAVEALL_ID
, _("Save All\tCtrl+Shift+A"), _("Saves the all active documents")) 
1593         wx
.EVT_MENU(self
, SAVEALL_ID
, self
.ProcessEvent
) 
1594         wx
.EVT_UPDATE_UI(self
, SAVEALL_ID
, self
.ProcessUpdateUIEvent
) 
1595         fileMenu
.AppendSeparator() 
1596         fileMenu
.Append(wx
.ID_PRINT
, _("&Print\tCtrl+P"), _("Prints the active document")) 
1597         fileMenu
.Append(wx
.ID_PREVIEW
, _("Print Pre&view"), _("Displays full pages")) 
1598         fileMenu
.Append(wx
.ID_PRINT_SETUP
, _("Page Set&up"), _("Changes page layout settings")) 
1599         fileMenu
.AppendSeparator() 
1600         if wx
.Platform 
== '__WXMAC__': 
1601             fileMenu
.Append(wx
.ID_EXIT
, _("&Quit"), _("Closes this program")) 
1603             fileMenu
.Append(wx
.ID_EXIT
, _("E&xit"), _("Closes this program")) 
1604         if self
._docManager
: 
1605             self
._docManager
.FileHistoryUseMenu(fileMenu
) 
1606             self
._docManager
.FileHistoryAddFilesToMenu(fileMenu
) 
1607         menuBar
.Append(fileMenu
, _("&File")); 
1609         editMenu 
= wx
.Menu() 
1610         editMenu
.Append(wx
.ID_UNDO
, _("&Undo\tCtrl+Z"), _("Reverses the last action")) 
1611         editMenu
.Append(wx
.ID_REDO
, _("&Redo\tCtrl+Y"), _("Reverses the last undo")) 
1612         editMenu
.AppendSeparator() 
1613         editMenu
.Append(wx
.ID_CUT
, _("Cu&t\tCtrl+X"), _("Cuts the selection and puts it on the Clipboard")) 
1614         wx
.EVT_MENU(self
, wx
.ID_CUT
, self
.ProcessEvent
) 
1615         wx
.EVT_UPDATE_UI(self
, wx
.ID_CUT
, self
.ProcessUpdateUIEvent
) 
1616         editMenu
.Append(wx
.ID_COPY
, _("&Copy\tCtrl+C"), _("Copies the selection and puts it on the Clipboard")) 
1617         wx
.EVT_MENU(self
, wx
.ID_COPY
, self
.ProcessEvent
) 
1618         wx
.EVT_UPDATE_UI(self
, wx
.ID_COPY
, self
.ProcessUpdateUIEvent
) 
1619         editMenu
.Append(wx
.ID_PASTE
, _("&Paste\tCtrl+V"), _("Inserts Clipboard contents")) 
1620         wx
.EVT_MENU(self
, wx
.ID_PASTE
, self
.ProcessEvent
) 
1621         wx
.EVT_UPDATE_UI(self
, wx
.ID_PASTE
, self
.ProcessUpdateUIEvent
) 
1622         editMenu
.Append(wx
.ID_CLEAR
, _("Cle&ar\tDel"), _("Erases the selection")) 
1623         wx
.EVT_MENU(self
, wx
.ID_CLEAR
, self
.ProcessEvent
) 
1624         wx
.EVT_UPDATE_UI(self
, wx
.ID_CLEAR
, self
.ProcessUpdateUIEvent
) 
1625         editMenu
.AppendSeparator() 
1626         editMenu
.Append(wx
.ID_SELECTALL
, _("Select A&ll\tCtrl+A"), _("Selects all available data")) 
1627         wx
.EVT_MENU(self
, wx
.ID_SELECTALL
, self
.ProcessEvent
) 
1628         wx
.EVT_UPDATE_UI(self
, wx
.ID_SELECTALL
, self
.ProcessUpdateUIEvent
) 
1629         menuBar
.Append(editMenu
, _("&Edit")) 
1630         if self
.GetDocument() and self
.GetDocument().GetCommandProcessor(): 
1631             self
.GetDocument().GetCommandProcessor().SetEditMenu(editMenu
) 
1633         viewMenu 
= wx
.Menu() 
1634         viewMenu
.AppendCheckItem(VIEW_TOOLBAR_ID
, _("&Toolbar"), _("Shows or hides the toolbar")) 
1635         wx
.EVT_MENU(self
, VIEW_TOOLBAR_ID
, self
.OnViewToolBar
) 
1636         wx
.EVT_UPDATE_UI(self
, VIEW_TOOLBAR_ID
, self
.OnUpdateViewToolBar
) 
1637         viewMenu
.AppendCheckItem(VIEW_STATUSBAR_ID
, _("&Status Bar"), _("Shows or hides the status bar")) 
1638         wx
.EVT_MENU(self
, VIEW_STATUSBAR_ID
, self
.OnViewStatusBar
) 
1639         wx
.EVT_UPDATE_UI(self
, VIEW_STATUSBAR_ID
, self
.OnUpdateViewStatusBar
) 
1640         menuBar
.Append(viewMenu
, _("&View")) 
1642         helpMenu 
= wx
.Menu() 
1643         helpMenu
.Append(wx
.ID_ABOUT
, _("&About" + " " + wx
.GetApp().GetAppName()), _("Displays program information, version number, and copyright")) 
1644         wx
.EVT_MENU(self
, wx
.ID_ABOUT
, self
.OnAbout
) 
1645         menuBar
.Append(helpMenu
, _("&Help")) 
1647         wx
.EVT_COMMAND_FIND_CLOSE(self
, -1, self
.ProcessEvent
) 
1650 ##        accelTable = wx.AcceleratorTable([ 
1651 ##            eval(_("wx.ACCEL_CTRL, ord('N'), wx.ID_NEW")), 
1652 ##            eval(_("wx.ACCEL_CTRL, ord('O'), wx.ID_OPEN")), 
1653 ##            eval(_("wx.ACCEL_CTRL, ord('S'), wx.ID_SAVE")), 
1654 ##            eval(_("wx.ACCEL_CTRL, ord('Z'), wx.ID_UNDO")), 
1655 ##            eval(_("wx.ACCEL_CTRL, ord('Y'), wx.ID_REDO")), 
1656 ##            eval(_("wx.ACCEL_CTRL, ord('X'), wx.ID_CUT")), 
1657 ##            eval(_("wx.ACCEL_CTRL, ord('C'), wx.ID_COPY")), 
1658 ##            eval(_("wx.ACCEL_CTRL, ord('Z'), wx.ID_PASTE")), 
1659 ##            (wx.ACCEL_NORMAL, wx.WXK_DELETE, wx.ID_CLEAR), 
1660 ##            eval(_("wx.ACCEL_CTRL, ord('A'), wx.ID_SELECTALL")) 
1662 ##        self.SetAcceleratorTable(accelTable) 
1665     def ProcessEvent(self
, event
): 
1667         Processes an event, searching event tables and calling zero or more 
1668         suitable event handler function(s).  Note that the ProcessEvent 
1669         method is called from the wxPython docview framework directly since 
1670         wxPython does not have a virtual ProcessEvent function. 
1672         if wx
.GetApp().ProcessEventBeforeWindows(event
): 
1675             self
._childView
.Activate(True) 
1678         if id == SAVEALL_ID
: 
1679             self
.OnFileSaveAll(event
) 
1682         if hasattr(self
._childView
, "GetDocumentManager") and self
._childView
.GetDocumentManager().ProcessEvent(event
):  # Need to call docmanager here since super class relies on DocParentFrame which we are not using 
1685             return wx
.GetApp().ProcessEvent(event
) 
1688     def ProcessUpdateUIEvent(self
, event
): 
1690         Processes a UI event, searching event tables and calling zero or more 
1691         suitable event handler function(s).  Note that the ProcessEvent 
1692         method is called from the wxPython docview framework directly since 
1693         wxPython does not have a virtual ProcessEvent function. 
1695         if wx
.GetApp().ProcessUpdateUIEventBeforeWindows(event
): 
1698             if hasattr(self
._childView
, "GetDocumentManager"): 
1699                 docMgr 
= self
._childView
.GetDocumentManager() 
1701                     if docMgr
.GetCurrentDocument() != self
._childView
.GetDocument(): 
1703                     if docMgr
.ProcessUpdateUIEvent(event
):  # Let the views handle the event before the services 
1709         elif id == wx
.ID_COPY
: 
1712         elif id == wx
.ID_PASTE
: 
1715         elif id == wx
.ID_CLEAR
: 
1718         elif id == wx
.ID_SELECTALL
: 
1721         elif id == SAVEALL_ID
: 
1722             filesModified 
= False 
1723             docs 
= wx
.GetApp().GetDocumentManager().GetDocuments() 
1725                 if doc
.IsModified(): 
1726                     filesModified 
= True 
1729             event
.Enable(filesModified
) 
1732             return wx
.GetApp().ProcessUpdateUIEvent(event
) 
1735     def OnFileSaveAll(self
, event
): 
1737         Saves all of the currently open documents. 
1739         docs 
= wx
.GetApp().GetDocumentManager().GetDocuments() 
1744     def OnAbout(self
, event
): 
1746         Invokes the about dialog. 
1748         aboutService 
= wx
.GetApp().GetService(AboutService
) 
1750             aboutService
.ShowAbout() 
1753     def OnViewToolBar(self
, event
): 
1755         Toggles whether the ToolBar is visible. 
1757         self
._toolBar
.Show(not self
._toolBar
.IsShown()) 
1761     def OnUpdateViewToolBar(self
, event
): 
1763         Updates the View ToolBar menu item. 
1765         event
.Check(self
.GetToolBar().IsShown()) 
1768     def OnViewStatusBar(self
, event
): 
1770         Toggles whether the StatusBar is visible. 
1772         self
.GetStatusBar().Show(not self
.GetStatusBar().IsShown()) 
1776     def OnUpdateViewStatusBar(self
, event
): 
1778         Updates the View StatusBar menu item. 
1780         event
.Check(self
.GetStatusBar().IsShown()) 
1783     def UpdateStatus(self
, message 
= _("Ready")): 
1785         Updates the StatusBar. 
1787         # wxBug: Menubar and toolbar help strings don't pop the status text back 
1788         if self
.GetStatusBar().GetStatusText() != message
: 
1789             self
.GetStatusBar().PushStatusText(message
) 
1792     def OnCloseWindow(self
, event
): 
1794         Called when the window is saved.  Enables services to help close the frame. 
1796         for service 
in wx
.GetApp().GetServices(): 
1797             service
.OnCloseFrame(event
) 
1798         wx
.lib
.docview
.DocChildFrame
.OnCloseWindow(self
, event
) 
1799         if self
._fileMenu 
and self
._docManager
: 
1800             self
._docManager
.FileHistoryRemoveMenu(self
._fileMenu
) 
1803 class AboutService(DocService
): 
1805     About Dialog Service that installs under the Help menu to show the properties of the current application. 
1808     def __init__(self
, aboutDialog 
= None): 
1810         Initializes the AboutService. 
1813             self
._dlg 
= aboutDialog
 
1815             self
._dlg 
= AboutDialog  
# use default AboutDialog 
1818     def ShowAbout(self
): 
1820         Show the AboutDialog 
1822         dlg 
= self
._dlg
(wx
.GetApp().GetTopWindow()) 
1823         dlg
.CenterOnScreen() 
1828     def SetAboutDialog(self
, dlg
): 
1830         Customize the AboutDialog 
1835 class AboutDialog(wx
.Dialog
): 
1837     Opens an AboutDialog.  Shared by DocMDIParentFrame and DocSDIFrame. 
1840     def __init__(self
, parent
): 
1842         Initializes the about dialog. 
1844         wx
.Dialog
.__init
__(self
, parent
, -1, _("About ") + wx
.GetApp().GetAppName(), style 
= wx
.DEFAULT_DIALOG_STYLE
) 
1846         self
.SetBackgroundColour(wx
.WHITE
) 
1847         sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
1848         splash_bmp 
= wx
.Image("activegrid/tool/images/splash.jpg").ConvertToBitmap() 
1849         image 
= wx
.StaticBitmap(self
, -1, splash_bmp
, (0,0), (splash_bmp
.GetWidth(), splash_bmp
.GetHeight())) 
1850         sizer
.Add(image
, 0, wx
.ALIGN_CENTER|wx
.ALL
, 0) 
1851         sizer
.Add(wx
.StaticText(self
, -1, wx
.GetApp().GetAppName()), 0, wx
.ALIGN_LEFT|wx
.ALL
, 5) 
1853         btn 
= wx
.Button(self
, wx
.ID_OK
) 
1854         sizer
.Add(btn
, 0, wx
.ALIGN_CENTRE|wx
.ALL
, 5) 
1856         self
.SetSizer(sizer
) 
1857         self
.SetAutoLayout(True) 
1862 class FilePropertiesService(DocService
): 
1864     Service that installs under the File menu to show the properties of the file associated 
1865     with the current document. 
1868     PROPERTIES_ID 
= wx
.NewId() 
1873         Initializes the PropertyService. 
1875         self
._customEventHandlers 
= [] 
1878     def InstallControls(self
, frame
, menuBar 
= None, toolBar 
= None, statusBar 
= None, document 
= None): 
1880         Installs a File/Properties menu item. 
1882         fileMenu 
= menuBar
.GetMenu(menuBar
.FindMenu(_("&File"))) 
1883         exitMenuItemPos 
= self
.GetMenuItemPos(fileMenu
, wx
.ID_EXIT
) 
1884         fileMenu
.InsertSeparator(exitMenuItemPos
) 
1885         fileMenu
.Insert(exitMenuItemPos
, FilePropertiesService
.PROPERTIES_ID
, _("&Properties"), _("Show file properties")) 
1886         wx
.EVT_MENU(frame
, FilePropertiesService
.PROPERTIES_ID
, self
.ProcessEvent
) 
1887         wx
.EVT_UPDATE_UI(frame
, FilePropertiesService
.PROPERTIES_ID
, self
.ProcessUpdateUIEvent
) 
1890     def ProcessEvent(self
, event
): 
1892         Detects when the File/Properties menu item is selected. 
1895         if id == FilePropertiesService
.PROPERTIES_ID
: 
1896             for eventHandler 
in self
._customEventHandlers
: 
1897                 if eventHandler
.ProcessEvent(event
): 
1900             self
.ShowPropertiesDialog() 
1906     def ProcessUpdateUIEvent(self
, event
): 
1908         Updates the File/Properties menu item. 
1911         if id == FilePropertiesService
.PROPERTIES_ID
: 
1912             for eventHandler 
in self
._customEventHandlers
: 
1913                 if eventHandler
.ProcessUpdateUIEvent(event
): 
1916             event
.Enable(wx
.GetApp().GetDocumentManager().GetCurrentDocument() != None) 
1922     def ShowPropertiesDialog(self
, filename 
= None): 
1924         Shows the PropertiesDialog for the specified file. 
1927             filename 
= wx
.GetApp().GetDocumentManager().GetCurrentDocument().GetFilename() 
1929         filePropertiesDialog 
= FilePropertiesDialog(wx
.GetApp().GetTopWindow(), filename
) 
1930         if filePropertiesDialog
.ShowModal() == wx
.ID_OK
: 
1932         filePropertiesDialog
.Destroy() 
1935     def GetCustomEventHandlers(self
): 
1937         Returns the custom event handlers for the PropertyService. 
1939         return self
._customEventHandlers
 
1942     def AddCustomEventHandler(self
, handler
): 
1944         Adds a custom event handlers for the PropertyService.  A custom event handler enables 
1945         a different dialog to be provided for a particular file. 
1947         self
._customEventHandlers
.append(handler
) 
1950     def RemoveCustomEventHandler(self
, handler
): 
1952         Removes a custom event handler from the PropertyService. 
1954         self
._customEventHandlers
.remove(handler
) 
1957     def chopPath(self
, text
, length 
= 36): 
1959         Simple version of textwrap.  textwrap.fill() unfortunately chops lines at spaces 
1960         and creates odd word boundaries.  Instead, we will chop the path without regard to 
1961         spaces, but pay attention to path delimiters. 
1967         while start 
< textLen
: 
1968             end 
= start 
+ length
 
1972             # see if we can find a delimiter to chop the path 
1974                 lastSep 
= text
.rfind(os
.sep
, start
, end 
+ 1) 
1975                 if lastSep 
!= -1 and lastSep 
!= start
: 
1979                 chopped 
= chopped 
+ '\n' + text
[start
:end
] 
1981                 chopped 
= text
[start
:end
] 
1988 class FilePropertiesDialog(wx
.Dialog
): 
1990     Dialog that shows the properties of a file.  Invoked by the PropertiesService. 
1994     def __init__(self
, parent
, filename
): 
1996         Initializes the properties dialog. 
1998         wx
.Dialog
.__init
__(self
, parent
, -1, _("File Properties"), size 
= (310, 330)) 
2003         filePropertiesService 
= wx
.GetApp().GetService(FilePropertiesService
) 
2005         fileExists 
= os
.path
.exists(filename
) 
2007         notebook 
= wx
.Notebook(self
, -1) 
2008         tab 
= wx
.Panel(notebook
, -1) 
2010         gridSizer 
= RowColSizer() 
2012         gridSizer
.Add(wx
.StaticText(tab
, -1, _("Filename:")), flag
=wx
.RIGHT
, border
=HALF_SPACE
, row
=0, col
=0) 
2013         gridSizer
.Add(wx
.StaticText(tab
, -1, os
.path
.basename(filename
)), row
=0, col
=1) 
2015         gridSizer
.Add(wx
.StaticText(tab
, -1, _("Location:")), flag
=wx
.RIGHT
, border
=HALF_SPACE
, row
=1, col
=0) 
2016         gridSizer
.Add(wx
.StaticText(tab
, -1, filePropertiesService
.chopPath(os
.path
.dirname(filename
))), flag
=wx
.BOTTOM
, border
=SPACE
, row
=1, col
=1) 
2018         gridSizer
.Add(wx
.StaticText(tab
, -1, _("Size:")), flag
=wx
.RIGHT
, border
=HALF_SPACE
, row
=2, col
=0) 
2020             gridSizer
.Add(wx
.StaticText(tab
, -1, str(os
.path
.getsize(filename
)) + ' ' + _("bytes")), row
=2, col
=1) 
2022         lineSizer 
= wx
.BoxSizer(wx
.VERTICAL
)    # let the line expand horizontally without vertical expansion 
2023         lineSizer
.Add(wx
.StaticLine(tab
, -1, size 
= (10,-1)), 0, wx
.EXPAND
) 
2024         gridSizer
.Add(lineSizer
, flag
=wx
.EXPAND|wx
.ALIGN_CENTER_VERTICAL|wx
.TOP
, border
=HALF_SPACE
, row
=3, col
=0, colspan
=2) 
2026         gridSizer
.Add(wx
.StaticText(tab
, -1, _("Created:")), flag
=wx
.RIGHT
, border
=HALF_SPACE
, row
=4, col
=0) 
2028             gridSizer
.Add(wx
.StaticText(tab
, -1, time
.ctime(os
.path
.getctime(filename
))), row
=4, col
=1) 
2030         gridSizer
.Add(wx
.StaticText(tab
, -1, _("Modified:")), flag
=wx
.RIGHT
, border
=HALF_SPACE
, row
=5, col
=0) 
2032             gridSizer
.Add(wx
.StaticText(tab
, -1, time
.ctime(os
.path
.getmtime(filename
))), row
=5, col
=1) 
2034         gridSizer
.Add(wx
.StaticText(tab
, -1, _("Accessed:")), flag
=wx
.RIGHT
, border
=HALF_SPACE
, row
=6, col
=0) 
2036             gridSizer
.Add(wx
.StaticText(tab
, -1, time
.ctime(os
.path
.getatime(filename
))), row
=6, col
=1) 
2038         # add a border around the inside of the tab 
2039         spacerGrid 
= wx
.BoxSizer(wx
.VERTICAL
) 
2040         spacerGrid
.Add(gridSizer
, 0, wx
.ALL
, SPACE
); 
2041         tab
.SetSizer(spacerGrid
) 
2042         notebook
.AddPage(tab
, _("General")) 
2043         notebook
.SetPageSize((310,200)) 
2045         sizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
2046         sizer
.Add(notebook
, 0, wx
.ALL | wx
.EXPAND
, SPACE
) 
2047         sizer
.Add(self
.CreateButtonSizer(wx
.OK
), 0, wx
.ALIGN_RIGHT | wx
.RIGHT | wx
.BOTTOM
, HALF_SPACE
) 
2050         self
.SetDimensions(-1, -1, 310, -1, wx
.SIZE_USE_EXISTING
) 
2051         self
.SetSizer(sizer
) 
2055 class ChildDocument(wx
.lib
.docview
.Document
): 
2057     A ChildDocument is a document that represents a portion of a Document.  The child 
2058     document is managed by the parent document, so it will be prompted to close if its 
2059     parent is closed, etc.  Child Documents are useful when there are complicated  
2060     Views of a Document and users will need to tunnel into the View. 
2066         Returns the data that the ChildDocument contains. 
2071     def SetData(self
, data
): 
2073         Sets the data that the ChildDocument contains. 
2078     def GetParentDocument(self
): 
2080         Returns the parent Document of the ChildDocument. 
2082         return self
._parentDocument
 
2085     def SetParentDocument(self
, parentDocument
): 
2087         Sets the parent Document of the ChildDocument. 
2089         self
._parentDocument 
= parentDocument
 
2092     def OnSaveDocument(self
, filename
): 
2094         Called when the ChildDocument is saved and does the minimum such that the 
2095         ChildDocument looks like a real Document to the framework. 
2097         self
.SetFilename(filename
, True) 
2099         self
.SetDocumentSaved(True) 
2103     def OnOpenDocument(self
, filename
): 
2105         Called when the ChildDocument is opened and does the minimum such that the 
2106         ChildDocument looks like a real Document to the framework. 
2108         self
.SetFilename(filename
, True) 
2110         self
.SetDocumentSaved(True) 
2111         self
.UpdateAllViews() 
2115 class ChildDocTemplate(wx
.lib
.docview
.DocTemplate
): 
2117     A ChildDocTemplate is a DocTemplate subclass that enables the creation of ChildDocuments 
2118     that represents a portion of a Document.  The child document is managed by the parent document, 
2119     so it will be prompted to close if its parent is closed, etc.  Child Documents are useful 
2120     when there are complicated  Views of a Document and users will need to tunnel into the View. 
2124     def __init__(self
, manager
, description
, filter, dir, ext
, docTypeName
, viewTypeName
, docType
, viewType
, flags 
= wx
.lib
.docview
.TEMPLATE_INVISIBLE
, icon 
= None): 
2126         Initializes the ChildDocTemplate. 
2128         wx
.lib
.docview
.DocTemplate
.__init
__(self
, manager
, description
, filter, dir, ext
, docTypeName
, viewTypeName
, docType
, viewType
, flags 
= flags
, icon 
= icon
) 
2131     def CreateDocument(self
, path
, flags
, data 
= None, parentDocument 
= None): 
2133         Called when a ChildDocument is to be created and does the minimum such that the 
2134         ChildDocument looks like a real Document to the framework. 
2136         doc 
= self
._docType
() 
2137         doc
.SetFilename(path
) 
2139         doc
.SetParentDocument(parentDocument
) 
2140         doc
.SetDocumentTemplate(self
) 
2141         self
.GetDocumentManager().AddDocument(doc
) 
2142         doc
.SetCommandProcessor(doc
.OnCreateCommandProcessor()) 
2143         if doc
.OnCreate(path
, flags
): 
2146             if doc 
in self
.GetDocumentManager().GetDocuments(): 
2147                 doc
.DeleteAllViews() 
2151 class WindowMenuService(DocService
): 
2153     The WindowMenuService is a service that implements a standard Window menu that is used 
2154     by the DocSDIFrame.  The MDIFrame automatically includes a Window menu and does not use 
2155     the WindowMenuService. 
2161         Initializes the WindowMenu and its globals. 
2163         self
.ARRANGE_WINDOWS_ID 
= wx
.NewId() 
2164         self
.SELECT_WINDOW_1_ID 
= wx
.NewId() 
2165         self
.SELECT_WINDOW_2_ID 
= wx
.NewId() 
2166         self
.SELECT_WINDOW_3_ID 
= wx
.NewId() 
2167         self
.SELECT_WINDOW_4_ID 
= wx
.NewId() 
2168         self
.SELECT_WINDOW_5_ID 
= wx
.NewId() 
2169         self
.SELECT_WINDOW_6_ID 
= wx
.NewId() 
2170         self
.SELECT_WINDOW_7_ID 
= wx
.NewId() 
2171         self
.SELECT_WINDOW_8_ID 
= wx
.NewId() 
2172         self
.SELECT_WINDOW_9_ID 
= wx
.NewId() 
2173         self
.SELECT_MORE_WINDOWS_ID 
= wx
.NewId() 
2176     def InstallControls(self
, frame
, menuBar 
= None, toolBar 
= None, statusBar 
= None, document 
= None): 
2178         Installs the Window menu. 
2181         if not self
.GetDocumentManager().GetFlags() & wx
.lib
.docview
.DOC_SDI
: 
2182             return  # Only need windows menu for SDI mode, MDI frame automatically creates one 
2184         windowMenu 
= wx
.Menu() 
2185         windowMenu
.Append(self
.ARRANGE_WINDOWS_ID
, _("&Arrange All"), _("Arrange the open windows")) 
2186         windowMenu
.AppendSeparator() 
2188         wx
.EVT_MENU(frame
, self
.ARRANGE_WINDOWS_ID
, frame
.ProcessEvent
) 
2189         wx
.EVT_UPDATE_UI(frame
, self
.ARRANGE_WINDOWS_ID
, frame
.ProcessUpdateUIEvent
) 
2190         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_1_ID
, frame
.ProcessEvent
)  # wxNewId may have been nonsequential, so can't use EVT_MENU_RANGE 
2191         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_2_ID
, frame
.ProcessEvent
) 
2192         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_3_ID
, frame
.ProcessEvent
) 
2193         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_4_ID
, frame
.ProcessEvent
) 
2194         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_5_ID
, frame
.ProcessEvent
) 
2195         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_6_ID
, frame
.ProcessEvent
) 
2196         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_7_ID
, frame
.ProcessEvent
) 
2197         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_8_ID
, frame
.ProcessEvent
) 
2198         wx
.EVT_MENU(frame
, self
.SELECT_WINDOW_9_ID
, frame
.ProcessEvent
) 
2199         wx
.EVT_MENU(frame
, self
.SELECT_MORE_WINDOWS_ID
, frame
.ProcessEvent
) 
2201         helpMenuIndex 
= menuBar
.FindMenu(_("&Help")) 
2202         menuBar
.Insert(helpMenuIndex
, windowMenu
, _("&Window")) 
2204         self
._lastFrameUpdated 
= None 
2207     def ProcessEvent(self
, event
): 
2209         Processes a Window menu event. 
2212         if id == self
.ARRANGE_WINDOWS_ID
: 
2213             self
.OnArrangeWindows(event
) 
2215         elif id == self
.SELECT_MORE_WINDOWS_ID
: 
2216             self
.OnSelectMoreWindows(event
) 
2218         elif id == self
.SELECT_WINDOW_1_ID 
or id == self
.SELECT_WINDOW_2_ID 
or id == self
.SELECT_WINDOW_3_ID 
or id == self
.SELECT_WINDOW_4_ID 
or id == self
.SELECT_WINDOW_5_ID 
or id == self
.SELECT_WINDOW_6_ID 
or id == self
.SELECT_WINDOW_7_ID 
or id == self
.SELECT_WINDOW_8_ID 
or id == self
.SELECT_WINDOW_9_ID
: 
2219             self
.OnSelectWindowMenu(event
) 
2225     def ProcessUpdateUIEvent(self
, event
): 
2227         Updates the Window menu items. 
2230         if id == self
.ARRANGE_WINDOWS_ID
: 
2231             frame 
= event
.GetEventObject() 
2232             if not self
._lastFrameUpdated 
or self
._lastFrameUpdated 
!= frame
: 
2233                 self
.BuildWindowMenu(frame
)  # It's a new frame, so update the windows menu... this is as if the View::OnActivateMethod had been invoked 
2234                 self
._lastFrameUpdated 
= frame
 
2240     def BuildWindowMenu(self
, currentFrame
): 
2242         Builds the Window menu and adds menu items for all of the open documents in the DocManager. 
2244         windowMenuIndex 
= currentFrame
.GetMenuBar().FindMenu(_("&Window")) 
2245         windowMenu 
= currentFrame
.GetMenuBar().GetMenu(windowMenuIndex
) 
2246         ids 
= self
._GetWindowMenuIDList
() 
2247         frames 
= self
._GetWindowMenuFrameList
(currentFrame
) 
2248         max = WINDOW_MENU_NUM_ITEMS
 
2249         if max > len(frames
): 
2252         for i 
in range(0, max): 
2254             item 
= windowMenu
.FindItemById(ids
[i
]) 
2255             label 
= '&' + str(i 
+ 1) + ' ' + frame
.GetTitle() 
2257                 item 
= windowMenu
.AppendCheckItem(ids
[i
], label
) 
2259                 windowMenu
.SetLabel(ids
[i
], label
) 
2260             windowMenu
.Check(ids
[i
], (frame 
== currentFrame
)) 
2261         if len(frames
) > WINDOW_MENU_NUM_ITEMS
:  # Add the more items item 
2262             if not windowMenu
.FindItemById(self
.SELECT_MORE_WINDOWS_ID
): 
2263                 windowMenu
.Append(self
.SELECT_MORE_WINDOWS_ID
, _("&More Windows...")) 
2264         else:  # Remove any extra items 
2265             if windowMenu
.FindItemById(self
.SELECT_MORE_WINDOWS_ID
): 
2266                 windowMenu
.Remove(self
.SELECT_MORE_WINDOWS_ID
) 
2270             for j 
in range(i 
+ 1, WINDOW_MENU_NUM_ITEMS
): 
2271                 if windowMenu
.FindItemById(ids
[j
]): 
2272                     windowMenu
.Remove(ids
[j
]) 
2275     def _GetWindowMenuIDList(self
): 
2277         Returns a list of the Window menu item IDs. 
2279         return [self
.SELECT_WINDOW_1_ID
, self
.SELECT_WINDOW_2_ID
, self
.SELECT_WINDOW_3_ID
, self
.SELECT_WINDOW_4_ID
, self
.SELECT_WINDOW_5_ID
, self
.SELECT_WINDOW_6_ID
, self
.SELECT_WINDOW_7_ID
, self
.SELECT_WINDOW_8_ID
, self
.SELECT_WINDOW_9_ID
] 
2282     def _GetWindowMenuFrameList(self
, currentFrame 
= None): 
2284         Returns the Frame associated with each menu item in the Window menu. 
2287         # get list of windows for documents 
2288         for doc 
in self
._docManager
.GetDocuments(): 
2289             for view 
in doc
.GetViews(): 
2290                 frame 
= view
.GetFrame() 
2291                 if frame 
not in frameList
: 
2292                     if frame 
== currentFrame 
and len(frameList
) >= WINDOW_MENU_NUM_ITEMS
: 
2293                         frameList
.insert(WINDOW_MENU_NUM_ITEMS 
- 1, frame
) 
2295                         frameList
.append(frame
) 
2296         # get list of windows for general services 
2297         for service 
in wx
.GetApp().GetServices(): 
2298             view 
= service
.GetView() 
2300                 frame 
= view
.GetFrame() 
2301                 if frame 
not in frameList
: 
2302                     if frame 
== currentFrame 
and len(frameList
) >= WINDOW_MENU_NUM_ITEMS
: 
2303                         frameList
.insert(WINDOW_MENU_NUM_ITEMS 
- 1, frame
) 
2305                         frameList
.append(frame
) 
2310     def OnArrangeWindows(self
, event
): 
2312         Called by Window/Arrange and tiles the frames on the desktop. 
2314         currentFrame 
= event
.GetEventObject() 
2316         tempFrame 
= wx
.Frame(None, -1, "", pos 
= wx
.DefaultPosition
, size 
= wx
.DefaultSize
) 
2317         sizex 
= tempFrame
.GetSize()[0] 
2318         sizey 
= tempFrame
.GetSize()[1] 
2324         frames 
= self
._GetWindowMenuFrameList
() 
2325         frames
.remove(currentFrame
) 
2326         frames
.append(currentFrame
) # Make the current frame the last frame so that it is the last one to appear 
2327         for frame 
in frames
: 
2329                 delta 
= frame
.GetClientAreaOrigin()[1] 
2330             frame
.SetPosition((posx
, posy
)) 
2331             frame
.SetSize((sizex
, sizey
)) 
2332             # TODO: Need to loop around if posx + delta + size > displaysize 
2336             if posx 
+ sizex 
> wx
.DisplaySize()[0] or posy 
+ sizey 
> wx
.DisplaySize()[1]: 
2339         currentFrame
.SetFocus() 
2342     def OnSelectWindowMenu(self
, event
): 
2344         Called when the Window menu item representing a Frame is selected and brings the selected 
2345         Frame to the front of the desktop. 
2348         index 
= self
._GetWindowMenuIDList
().index(id) 
2350             currentFrame 
= event
.GetEventObject() 
2351             frame 
= self
._GetWindowMenuFrameList
(currentFrame
)[index
] 
2353                 wx
.CallAfter(frame
.Raise
) 
2356     def OnSelectMoreWindows(self
, event
): 
2358         Called when the "Window/Select More Windows..." menu item is selected and enables user to 
2359         select from the Frames that do not in the Window list.  Useful when there are more than 
2360         10 open frames in the application. 
2362         frames 
= self
._GetWindowMenuFrameList
()  # TODO - make the current window the first one 
2363         strings 
= map(lambda frame
: frame
.GetTitle(), frames
) 
2364         # Should preselect the current window, but not supported by wx.GetSingleChoice 
2365         res 
= wx
.GetSingleChoiceIndex(_("Select a window to show:"), 
2371         frames
[res
].SetFocus() 
2374 #---------------------------------------------------------------------------- 
2375 # File generated by encode_bitmaps.py 
2376 #---------------------------------------------------------------------------- 
2377 from wx 
import ImageFromStream
, BitmapFromImage
 
2380 #---------------------------------------------------------------------- 
2383 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2384 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2385 \x00\x00[IDAT8\x8d\xed\x93\xb1\n\x001\x08C\x13{\xff\xff\xc7mn\xb8El\x91\x16\ 
2386 \x97\x0e\x97M\x90\x97\x88JZCE\x8f/4\xba\xb2fZc\n\x00\x00i\xcd \t\x8d\xae\x08\ 
2387 \xb1\xad\x9c\x0e\x1eS\x1e\x01\xc8\xcf\xdcC\xa6\x112\xf7\x08:N\xb0\xd2\x0f\ 
2388 \xb8\x010\xdd\x81\xdf\xf1\x8eX\xfd\xc6\xf2\x08/D\xbd\x19(\xc8\xa5\xd9\xfa\ 
2389 \x00\x00\x00\x00IEND\xaeB`\x82'  
2392     return BitmapFromImage(getNewImage()) 
2395     stream 
= cStringIO
.StringIO(getNewData()) 
2396     return ImageFromStream(stream
) 
2398 #---------------------------------------------------------------------- 
2401 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2402 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2403 \x00\x00\x95IDAT8\x8d\xa5\x92\xc1\x12\x03!\x08C\x13\xec\x87\xfb\xe3B\x0f.]\ 
2404 \xb0\x8e[m.\xea\x0c/\x06\x06R\n\xfe\xd1\xeb\xd7B\xd5f~\x17)\xdc2Pm\x16!\x7f\ 
2405 \xab6\xe3i\x0b\x9e\xe8\x93\xc0BD\x86\xdfV0\x00\x90R`\xda\xcc\x0c\x00\x0c\x00\ 
2406 \xc1\x05>\x9a\x87\x19t\x180\x981\xbd\xfd\xe4\xc4Y\x82\xf7\x14\xca\xe7\xb7\ 
2407 \xa6\t\xee6\x1c\xba\xe18\xab\xc1 \xc3\xb5N?L\xaa5\xb5\xd0\x8dw`JaJ\xb0\x0b\ 
2408 \x03!\xc1\t\xdc\xb9k\x0f\x9e\xd1\x0b\x18\xf6\xe0x\x95]\xf2\\\xb2\xd6\x1b}\ 
2409 \x14BL\xb9{t\xc7\x00\x00\x00\x00IEND\xaeB`\x82'  
2411 def getOpenBitmap(): 
2412     return BitmapFromImage(getOpenImage()) 
2415     stream 
= cStringIO
.StringIO(getOpenData()) 
2416     return ImageFromStream(stream
) 
2418 #---------------------------------------------------------------------- 
2421 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2422 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2423 \x00\x00\x9fIDAT8\x8d\xa5\x93\xdb\x0e\x830\x0cC\xed\x84\xdfF\xeb\xb4\xef\xa6\ 
2424 \xde\x030z\t\x94\tK\x91z\xcb\x01\xbb*i\x8e\'\x9a\x00@yQ\xb4Is\x8e\x00\xb6\ 
2425 \x0f$Uu\x05\x0e\x01\x91$\r!\xa49\x94\x17I\x02\xc9_\xe3:Nq\x93}XL|\xeb\xe9\ 
2426 \x05\xa4p\rH\xa29h^[ Y\xd5\xb9\xb5\x17\x94gu\x19DA\x96\xe0c\xfe^\xcf\xe7Y\ 
2427 \x95\x05\x00M\xf5\x16Z;\x7f\xfdAd\xcf\xee\x1cj\xc1%|\xdan"LL\x19\xda\xe1}\ 
2428 \x90:\x00#\x95_l5\x04\xec\x89\x9f\xef?|\x8d\x97o\xe1\x8e\xbeJ\xfc\xb1\xde\ 
2429 \xea\xf8\xb9\xc4\x00\x00\x00\x00IEND\xaeB`\x82'  
2431 def getCopyBitmap(): 
2432     return BitmapFromImage(getCopyImage()) 
2435     stream 
= cStringIO
.StringIO(getCopyData()) 
2436     return ImageFromStream(stream
) 
2438 #---------------------------------------------------------------------- 
2441 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2442 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2443 \x00\x00\xa1IDAT8\x8d\xa5\x93\xd9\x0e\xc3 \x0c\x04\xc7\xa6\xbf]\xc5U\xbf\xbb\ 
2444 \xd9>$4\\9\xaa\xacd\t\x0c\x1e/H6\xf3\xc4\x1d=FI\xcd\x1f\x95{\xf3d{\x003O]\ 
2445 \x01\x80\x94/\x0c\x8a\n\xa0\x01\x8a\x88\xdfaD m\x85y\xdd\xde\xc9\x10/\xc9\ 
2446 \xf9\xc0S2\xf3%\xf2\xba\x04\x94\xea\xfe`\xf4\x9c#U\x80\xbd.\x97\x015\xec&\ 
2447 \x00@\x9a\xba\x9c\xd9\x0b\x08\xe0\r4\x9fxU\xd2\x84\xe6\xa7N\x1dl\x1dkGe\xee\ 
2448 \x14\xd0>\xa3\x85\xfc\xe5`\x08]\x87I}\x84\x8e\x04!\xf3\xb48\x18\r\x8bf4\xea\ 
2449 \xde;\xbc9\xce_!\\\\T\xf75'\xd6\x00\x00\x00\x00IEND\xaeB`\x82"  
2451 def getPasteBitmap(): 
2452     return BitmapFromImage(getPasteImage()) 
2454 def getPasteImage(): 
2455     stream 
= cStringIO
.StringIO(getPasteData()) 
2456     return ImageFromStream(stream
) 
2458 #---------------------------------------------------------------------- 
2461 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2462 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2463 \x00\x00lIDAT8\x8d\xc5\x93\xe1\n\xc0 \x08\x84=\xed\xc1}\xf1\xcd\xfd\x18B\x98\ 
2464 mX\x83\x1d\x04\x11\xfayV\x02,\xb4#\xde\xca&\xa2\xe6\x1b;\x0f\xab$\x82\x05\ 
2465 \x83\x03U\xbdaf\xe9\xea\x13]\xe5\x16\xa2\xd32\xc0].\x03\xa2Z<PU\x02\x90\xc5\ 
2466 \x0e\xd5S\xc0,p\xa6\xef[xs\xb0t\x89`A|\xff\x12\xe0\x11\xde\x0fS\xe5;\xbb#\ 
2467 \xfc>\x8d\x17\x18\xfd(\xb72\xc2\x06\x00\x00\x00\x00\x00IEND\xaeB`\x82'  
2469 def getSaveBitmap(): 
2470     return BitmapFromImage(getSaveImage()) 
2473     stream 
= cStringIO
.StringIO(getSaveData()) 
2474     return ImageFromStream(stream
) 
2476 #---------------------------------------------------------------------- 
2477 def getSaveAllData(): 
2479 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2480 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2481 \x00\x01\tIDAT8\x8d\xa5\x93\xe1m\x830\x10\x85\xdfA\xd7H\x827\xf0\x02\xado\ 
2482 \x04\x8f`Fh\xfb\xb7\xad\xcd&$Y\x80\x11\xcc\x06\x8c\xe0E\xd2\xeb\x8f\x16\x04!\ 
2483 8R\xf3\xa4\x93Nw\xd2\xf3\xa7g\x9b\xa8(\xf1\x88\x9er\xcb\xc3~\')%x\xef\xa7Y\ 
2484 \x8c\x11J)\x00\xc0\xf1t&PQn\x163\x0b\x00\x99\xcb{/\x00\xc49\'T\x94(\xfe\x83\ 
2485 \x1dB\x98\xfa\x95\xc1a\xbf\x13\xf9\xbe\xc8\xd7\xe7\x87\x18c\xe0\xbd\x073\xa3\ 
2486 \xaek\x10\x11\xfa\xbe\xcfgPU\x15RJ\x8bSB\x08h\x9af1\xdb$\xc8aw]\x87\xae\xeb\ 
2487 \xd6\x04\xd7i\x1bc\xc0\xccPJ\xa1m[03\x98\x19Z\xeb\x951QQ\xc2\xbc<K\x8c\x11"\ 
2488 \x92\xc5N)M\xbd\xd6\x1a\xafo\xef\x94}\x07#6\x00Xk\x7f\xef\xfdO\xc7\xd3\x19\ 
2489 \xc0,\x83\x10\x02\x88h\xaa1m\xad\xf5M\xf4E\x06s\x93-\xcd\xf1\xef\x1a\x8c\'^c\ 
2490 \xdf5\x18\x95C\xbei`\xad\xc50\x0cp\xce-\x96[\xd8s\xd1\xa3\xdf\xf9\x075\xf1v>\ 
2491 \x92\xcb\xbc\xdd\x00\x00\x00\x00IEND\xaeB`\x82'  
2493 def getSaveAllBitmap(): 
2494     return BitmapFromImage(getSaveAllImage()) 
2496 def getSaveAllImage(): 
2497     stream 
= cStringIO
.StringIO(getSaveAllData()) 
2498     return ImageFromStream(stream
) 
2500 #---------------------------------------------------------------------- 
2503 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2504 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2505 \x00\x00\xa1IDAT8\x8d\xa5S[\x0e\x02!\x0c\xec\xd0\xbd\xb6\x1a\xf5\xda\x96\xd9\ 
2506 \x0f\xa1V\x96\x00\xbaMHI\xd3y\xf0(\x90T\xce\xc4\xd6+2\x1bg@$E\x97\x80\xd9H\ 
2507 \x8e\xf1\x00\xc6\x0e\xda&''\x05\x80\xab\x1f\x08\xa2\xfa\xcc\xc5\xd0\xc1H\xbd\ 
2508 \n\x89\xbc\xef\xc1\tV\xd5\x91\x14\xcc\xc6\x9a\xa5<#WV\xed\x8d\x18\x94\xc2\ 
2509 \xd1s'\xa2\xb2\xe7\xc2\xf4STAf\xe3\x16\x0bm\xdc\xae\x17'\xbf?\x9e\x0e\x8an\ 
2510 \x86G\xc8\xf6\xf9\x91I\xf5\x8b\xa0\n\xff}\x04w\x80\xa4ng\x06l/QD\x04u\x1aW\ 
2511 \x06(:\xf0\xfd\x99q\xce\xf6\xe2\x0e\xa5\xa2~.\x00=\xb5t\x00\x00\x00\x00IEND\ 
2514 def getPrintBitmap(): 
2515     return BitmapFromImage(getPrintImage()) 
2517 def getPrintImage(): 
2518     stream 
= cStringIO
.StringIO(getPrintData()) 
2519     return ImageFromStream(stream
) 
2521 #---------------------------------------------------------------------- 
2522 def getPrintPreviewData(): 
2524 '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2525 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2526 \x00\x00\xa8IDAT8\x8d\x9d\x93K\x0e\xc30\x08Dg \xd7n\xcd\xc1\x9b\xd2E\x83E\\\ 
2527 \xffT$/\x82\xc5\x83\x19\x13\x02p,\x82\xa2\x1c\xde\x01p\xf71\x83\xe4\x14"\xab\ 
2528 \xeeQ\xec\xef\xb3\xdbe{\x82\x0c\xcb\xdf\xc7\xaa{\x86\xb7\xb0-@\xaf(\xc7\xd4\ 
2529 \x03\x9203P\x94\x14\xa5\x99\xa1\xf5b\x08\x88b+\x05~\xbejQ\x0f\xe2\xbd\x00\ 
2530 \xe0\x14\x05\xdc\x9d\xa2\xa0(\xcc\xec\x9b\xbb\xee(\xba~F\xea15a\n(\xcfG\x1d5\ 
2531 d\xe4\xdcTB\xc8\x88\xb1CB\x9b\x9b\x02\x02\x92O@\xaa\x0fXl\xe2\xcd\x0f\xf2g\ 
2532 \xad\x89\x8d\xbf\xf1\x06\xb9V9 \x0c\x1d\xff\xc6\x07\x8aF\x9e\x04\x12\xb5\xf9\ 
2533 O\x00\x00\x00\x00IEND\xaeB`\x82'  
2535 def getPrintPreviewBitmap(): 
2536     return BitmapFromImage(getPrintPreviewImage()) 
2538 def getPrintPreviewImage(): 
2539     stream 
= cStringIO
.StringIO(getPrintPreviewData()) 
2540     return ImageFromStream(stream
) 
2542 #---------------------------------------------------------------------- 
2545 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2546 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2547 \x00\x00rIDAT8\x8d\xad\x93\xc1\x0e\xc0 \x08CW\xdco{\xf2\xbb';\xb18\x07\x9d\ 
2548 \x0b\xe3\xa2\x98\xe6\xb5$\x02H\xd92%\xde\xa3\xf6CY\xff\nH'\xf8\x05`\xb1Y\xfc\ 
2549 \x10\x00)`\xfdR\x82\x15w\n0W\xe6N\x01\xda\xab\x8e\xe7g\xc0\xe8\xae\xbdj\x04\ 
2550 \xda#\xe7;\xa8] \xbb\xbb\tL0\x8bX\xa5?\xd2c\x84\xb9 \r6\x96\x97\x0c\xf362\ 
2551 \xb1k\x90]\xe7\x13\x85\xca7&\xcf\xda\xcdU\x00\x00\x00\x00IEND\xaeB`\x82"  
2554     return BitmapFromImage(getCutImage()) 
2557     stream 
= cStringIO
.StringIO(getCutData()) 
2558     return ImageFromStream(stream
) 
2560 #---------------------------------------------------------------------- 
2563 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2564 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2565 \x00\x00lIDAT8\x8d\xed\x92Q\x0b\x800\x08\x84\xd5\xf5\xb7\x07W\xfdo\xed!\xaca\ 
2566 \xb2\x11{\xe9!a\xa0\xc7\xeec\x1ec\x96B3%S\xeeO\x00\x96\xd1\x05\xd3j\xed\x0c\ 
2567 \x10\xad\xdb\xce\x97\xc0R\xe8\x0c\x12\xe6\xbd\xcfQs\x1d\xb8\xf5\xd4\x90\x19#\ 
2568 \xc4\xfbG\x06\xa6\xd5X\x9a'\x0e*\r1\xee\xfd\x1a\xd0\x83\x98V\x03\x1a\xa1\xb7\ 
2569 k<@\x12\xec\xff\x95\xe7\x01\x07L\x0e(\xe5\xa4\xff\x1c\x88\x00\x00\x00\x00IEN\ 
2572 def getUndoBitmap(): 
2573     return BitmapFromImage(getUndoImage()) 
2576     stream 
= cStringIO
.StringIO(getUndoData()) 
2577     return ImageFromStream(stream
) 
2579 #---------------------------------------------------------------------- 
2582 "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\ 
2583 \x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\ 
2584 \x00\x00jIDAT8\x8d\xed\x92\xcd\n\xc0 \x0c\x83\x9bv\xaf\xed\x16\xf0\xbd\xd7]&\ 
2585 \xf8\x8f\xe0e\x87\t9$\xb6\x1f\xb5\x08\xa8\xc9\xce\xd1\xad\xeeO\x00\x8e\xdc\\\ 
2586 gp\xb2,\x80FL\tP\x13\xa8\tI\x17\xa1'\x9f$\xd2\xe6\xb9\xef\x86=\xa5\xfb\x1a\ 
2587 \xb8\xbc\x03h\x84\xdf\xc1\xeb|\x19\xd0k.\x00\xe4\xb8h\x94\xbf\xa3\x95\xef$\ 
2588 \xe7\xbbh\xf4\x7f\xe5}\xc0\x03&\x1b&\xe5\xc2\x03!\xa6\x00\x00\x00\x00IEND\ 
2591 def getRedoBitmap(): 
2592     return BitmapFromImage(getRedoImage()) 
2595     stream 
= cStringIO
.StringIO(getRedoData()) 
2596     return ImageFromStream(stream
)