2003-11-12 16:34:20 -05:00
""" Base frame with menu. """
2003-07-02 19:13:10 -04:00
2003-11-12 16:34:20 -05:00
__author__ = " Patrick K. O ' Brien <pobrien@orbtech.com> "
__cvsid__ = " $Id$ "
__revision__ = " $Revision$ " [ 11 : - 2 ]
2003-07-02 19:13:10 -04:00
2003-11-12 16:34:20 -05:00
import wx
2005-12-30 18:02:03 -05:00
import os
2003-11-12 16:34:20 -05:00
from version import VERSION
2005-12-30 18:02:03 -05:00
import editwindow
2006-02-23 20:21:26 -05:00
import dispatcher
2003-11-12 16:34:20 -05:00
ID_NEW = wx . ID_NEW
ID_OPEN = wx . ID_OPEN
ID_REVERT = wx . ID_REVERT
ID_CLOSE = wx . ID_CLOSE
ID_SAVE = wx . ID_SAVE
ID_SAVEAS = wx . ID_SAVEAS
ID_PRINT = wx . ID_PRINT
ID_EXIT = wx . ID_EXIT
ID_UNDO = wx . ID_UNDO
ID_REDO = wx . ID_REDO
ID_CUT = wx . ID_CUT
ID_COPY = wx . ID_COPY
ID_PASTE = wx . ID_PASTE
ID_CLEAR = wx . ID_CLEAR
ID_SELECTALL = wx . ID_SELECTALL
2005-12-30 18:02:03 -05:00
ID_EMPTYBUFFER = wx . NewId ( )
2003-11-12 16:34:20 -05:00
ID_ABOUT = wx . ID_ABOUT
2005-12-30 18:02:03 -05:00
ID_HELP = wx . NewId ( )
2003-11-12 16:34:20 -05:00
ID_AUTOCOMP = wx . NewId ( )
ID_AUTOCOMP_SHOW = wx . NewId ( )
ID_AUTOCOMP_MAGIC = wx . NewId ( )
ID_AUTOCOMP_SINGLE = wx . NewId ( )
ID_AUTOCOMP_DOUBLE = wx . NewId ( )
ID_CALLTIPS = wx . NewId ( )
ID_CALLTIPS_SHOW = wx . NewId ( )
2005-12-30 18:02:03 -05:00
ID_CALLTIPS_INSERT = wx . NewId ( )
2003-11-12 16:34:20 -05:00
ID_COPY_PLUS = wx . NewId ( )
ID_NAMESPACE = wx . NewId ( )
ID_PASTE_PLUS = wx . NewId ( )
ID_WRAP = wx . NewId ( )
2005-12-30 18:02:03 -05:00
ID_TOGGLE_MAXIMIZE = wx . NewId ( )
2004-02-23 17:36:24 -05:00
ID_USEAA = wx . NewId ( )
2005-12-30 18:02:03 -05:00
ID_SHOW_LINENUMBERS = wx . NewId ( )
ID_AUTO_SAVESETTINGS = wx . NewId ( )
ID_SAVEHISTORY = wx . NewId ( )
2006-02-23 20:21:26 -05:00
ID_SAVEHISTORYNOW = wx . NewId ( )
ID_CLEARHISTORY = wx . NewId ( )
2005-12-30 18:02:03 -05:00
ID_SAVESETTINGS = wx . NewId ( )
ID_DELSETTINGSFILE = wx . NewId ( )
ID_EDITSTARTUPSCRIPT = wx . NewId ( )
ID_EXECSTARTUPSCRIPT = wx . NewId ( )
ID_STARTUP = wx . NewId ( )
ID_SETTINGS = wx . NewId ( )
ID_FIND = wx . ID_FIND
ID_FINDNEXT = wx . NewId ( )
2003-11-12 16:34:20 -05:00
class Frame ( wx . Frame ) :
""" Frame with standard menu items. """
revision = __revision__
def __init__ ( self , parent = None , id = - 1 , title = ' Editor ' ,
pos = wx . DefaultPosition , size = wx . DefaultSize ,
style = wx . DEFAULT_FRAME_STYLE ) :
""" Create a Frame instance. """
wx . Frame . __init__ ( self , parent , id , title , pos , size , style )
self . CreateStatusBar ( )
self . SetStatusText ( ' Frame ' )
import images
self . SetIcon ( images . getPyIcon ( ) )
self . __createMenus ( )
2005-12-30 18:02:03 -05:00
self . iconized = False
self . findDlg = None
self . findData = wx . FindReplaceData ( )
self . findData . SetFlags ( wx . FR_DOWN )
self . Bind ( wx . EVT_CLOSE , self . OnClose )
self . Bind ( wx . EVT_ICONIZE , self . OnIconize )
def OnIconize ( self , event ) :
""" Event handler for Iconize. """
self . iconized = event . Iconized ( )
2003-11-12 16:34:20 -05:00
def OnClose ( self , event ) :
""" Event handler for closing. """
self . Destroy ( )
2005-12-30 18:02:03 -05:00
2003-11-12 16:34:20 -05:00
def __createMenus ( self ) :
2005-12-30 18:02:03 -05:00
# File Menu
2003-11-12 16:34:20 -05:00
m = self . fileMenu = wx . Menu ( )
m . Append ( ID_NEW , ' &New \t Ctrl+N ' ,
' New file ' )
m . Append ( ID_OPEN , ' &Open... \t Ctrl+O ' ,
' Open file ' )
m . AppendSeparator ( )
m . Append ( ID_REVERT , ' &Revert \t Ctrl+R ' ,
' Revert to last saved version ' )
m . Append ( ID_CLOSE , ' &Close \t Ctrl+W ' ,
' Close file ' )
m . AppendSeparator ( )
m . Append ( ID_SAVE , ' &Save... \t Ctrl+S ' ,
' Save file ' )
2005-12-30 18:02:03 -05:00
m . Append ( ID_SAVEAS , ' Save &As \t Ctrl+Shift+S ' ,
2003-11-12 16:34:20 -05:00
' Save file with new name ' )
m . AppendSeparator ( )
m . Append ( ID_PRINT , ' &Print... \t Ctrl+P ' ,
' Print file ' )
m . AppendSeparator ( )
2005-12-30 18:02:03 -05:00
m . Append ( ID_NAMESPACE , ' &Update Namespace \t Ctrl+Shift+N ' ,
2003-11-12 16:34:20 -05:00
' Update namespace for autocompletion and calltips ' )
m . AppendSeparator ( )
2005-12-30 18:02:03 -05:00
m . Append ( ID_EXIT , ' E&xit \t Ctrl+Q ' , ' Exit Program ' )
2003-11-12 16:34:20 -05:00
2005-12-30 18:02:03 -05:00
# Edit
2003-11-12 16:34:20 -05:00
m = self . editMenu = wx . Menu ( )
m . Append ( ID_UNDO , ' &Undo \t Ctrl+Z ' ,
' Undo the last action ' )
m . Append ( ID_REDO , ' &Redo \t Ctrl+Y ' ,
' Redo the last undone action ' )
m . AppendSeparator ( )
m . Append ( ID_CUT , ' Cu&t \t Ctrl+X ' ,
' Cut the selection ' )
m . Append ( ID_COPY , ' &Copy \t Ctrl+C ' ,
' Copy the selection ' )
2005-12-30 18:02:03 -05:00
m . Append ( ID_COPY_PLUS , ' Cop&y Plus \t Ctrl+Shift+C ' ,
2003-11-12 16:34:20 -05:00
' Copy the selection - retaining prompts ' )
m . Append ( ID_PASTE , ' &Paste \t Ctrl+V ' , ' Paste from clipboard ' )
2005-12-30 18:02:03 -05:00
m . Append ( ID_PASTE_PLUS , ' Past&e Plus \t Ctrl+Shift+V ' ,
2003-11-12 16:34:20 -05:00
' Paste and run commands ' )
m . AppendSeparator ( )
m . Append ( ID_CLEAR , ' Cle&ar ' ,
' Delete the selection ' )
m . Append ( ID_SELECTALL , ' Select A&ll \t Ctrl+A ' ,
' Select all text ' )
2005-12-30 18:02:03 -05:00
m . AppendSeparator ( )
2006-02-23 20:21:26 -05:00
m . Append ( ID_EMPTYBUFFER , ' E&mpty Buffer... ' ,
2005-12-30 18:02:03 -05:00
' Delete all the contents of the edit buffer ' )
2006-02-23 20:21:26 -05:00
m . Append ( ID_FIND , ' &Find Text... \t Ctrl+F ' ,
2005-12-30 18:02:03 -05:00
' Search for text in the edit buffer ' )
m . Append ( ID_FINDNEXT , ' Find &Next \t F3 ' ,
' Find next/previous instance of the search text ' )
# View
m = self . viewMenu = wx . Menu ( )
m . Append ( ID_WRAP , ' &Wrap Lines \t Ctrl+Shift+W ' ,
' Wrap lines at right edge ' , wx . ITEM_CHECK )
m . Append ( ID_SHOW_LINENUMBERS , ' &Show Line Numbers \t Ctrl+Shift+L ' , ' Show Line Numbers ' , wx . ITEM_CHECK )
m . Append ( ID_TOGGLE_MAXIMIZE , ' &Toggle Maximize \t F11 ' , ' Maximize/Restore Application ' )
2003-11-12 16:34:20 -05:00
2005-12-30 18:02:03 -05:00
# Options
2003-11-12 16:34:20 -05:00
m = self . autocompMenu = wx . Menu ( )
2005-12-30 18:02:03 -05:00
m . Append ( ID_AUTOCOMP_SHOW , ' Show &Auto Completion \t Ctrl+Shift+A ' ,
2004-02-23 17:36:24 -05:00
' Show auto completion list ' , wx . ITEM_CHECK )
2005-12-30 18:02:03 -05:00
m . Append ( ID_AUTOCOMP_MAGIC , ' Include &Magic Attributes \t Ctrl+Shift+M ' ,
2003-11-12 16:34:20 -05:00
' Include attributes visible to __getattr__ and __setattr__ ' ,
2004-02-23 17:36:24 -05:00
wx . ITEM_CHECK )
2005-12-30 18:02:03 -05:00
m . Append ( ID_AUTOCOMP_SINGLE , ' Include Single &Underscores \t Ctrl+Shift+U ' ,
2004-02-23 17:36:24 -05:00
' Include attibutes prefixed by a single underscore ' , wx . ITEM_CHECK )
2005-12-30 18:02:03 -05:00
m . Append ( ID_AUTOCOMP_DOUBLE , ' Include &Double Underscores \t Ctrl+Shift+D ' ,
2004-02-23 17:36:24 -05:00
' Include attibutes prefixed by a double underscore ' , wx . ITEM_CHECK )
2003-11-12 16:34:20 -05:00
m = self . calltipsMenu = wx . Menu ( )
2005-12-30 18:02:03 -05:00
m . Append ( ID_CALLTIPS_SHOW , ' Show Call &Tips \t Ctrl+Shift+T ' ,
2004-02-23 17:36:24 -05:00
' Show call tips with argument signature and docstring ' , wx . ITEM_CHECK )
2005-12-30 18:02:03 -05:00
m . Append ( ID_CALLTIPS_INSERT , ' &Insert Call Tips \t Ctrl+Shift+I ' ,
' &Insert Call Tips ' , wx . ITEM_CHECK )
2003-11-12 16:34:20 -05:00
m = self . optionsMenu = wx . Menu ( )
m . AppendMenu ( ID_AUTOCOMP , ' &Auto Completion ' , self . autocompMenu ,
' Auto Completion Options ' )
m . AppendMenu ( ID_CALLTIPS , ' &Call Tips ' , self . calltipsMenu ,
' Call Tip Options ' )
2005-12-30 18:02:03 -05:00
2004-02-23 17:36:24 -05:00
if wx . Platform == " __WXMAC__ " :
2006-01-09 16:09:57 -05:00
m . Append ( ID_USEAA , ' &Use AntiAliasing ' ,
2004-02-23 17:36:24 -05:00
' Use anti-aliased fonts ' , wx . ITEM_CHECK )
2005-12-30 18:02:03 -05:00
m . AppendSeparator ( )
2006-02-23 20:21:26 -05:00
self . historyMenu = wx . Menu ( )
self . historyMenu . Append ( ID_SAVEHISTORY , ' &Autosave History ' ,
2006-01-09 16:09:57 -05:00
' Automatically save history on close ' , wx . ITEM_CHECK )
2006-02-23 20:21:26 -05:00
self . historyMenu . Append ( ID_SAVEHISTORYNOW , ' &Save History Now ' ,
' Save history ' )
self . historyMenu . Append ( ID_CLEARHISTORY , ' &Clear History ' ,
' Clear history ' )
m . AppendMenu ( - 1 , " &History " , self . historyMenu , " History Options " )
2005-12-30 18:02:03 -05:00
self . startupMenu = wx . Menu ( )
2006-01-09 16:09:57 -05:00
self . startupMenu . Append ( ID_EXECSTARTUPSCRIPT ,
' E&xecute Startup Script ' ,
' Execute Startup Script ' , wx . ITEM_CHECK )
self . startupMenu . Append ( ID_EDITSTARTUPSCRIPT ,
2006-02-23 20:21:26 -05:00
' &Edit Startup Script... ' ,
2006-01-09 16:09:57 -05:00
' Edit Startup Script ' )
2005-12-30 18:02:03 -05:00
m . AppendMenu ( ID_STARTUP , ' &Startup ' , self . startupMenu , ' Startup Options ' )
self . settingsMenu = wx . Menu ( )
2006-01-09 16:09:57 -05:00
self . settingsMenu . Append ( ID_AUTO_SAVESETTINGS ,
' &Auto Save Settings ' ,
' Automatically save settings on close ' , wx . ITEM_CHECK )
self . settingsMenu . Append ( ID_SAVESETTINGS ,
' &Save Settings ' ,
' Save settings now ' )
self . settingsMenu . Append ( ID_DELSETTINGSFILE ,
' &Revert to default ' ,
' Revert to the default settings ' )
2005-12-30 18:02:03 -05:00
m . AppendMenu ( ID_SETTINGS , ' &Settings ' , self . settingsMenu , ' Settings Options ' )
2003-11-12 16:34:20 -05:00
m = self . helpMenu = wx . Menu ( )
2005-12-30 18:02:03 -05:00
m . Append ( ID_HELP , ' &Help \t F1 ' , ' Help! ' )
2003-11-12 16:34:20 -05:00
m . AppendSeparator ( )
2006-01-09 16:09:57 -05:00
m . Append ( ID_ABOUT , ' &About... ' , ' About this program ' )
2003-11-12 16:34:20 -05:00
b = self . menuBar = wx . MenuBar ( )
b . Append ( self . fileMenu , ' &File ' )
b . Append ( self . editMenu , ' &Edit ' )
2005-12-30 18:02:03 -05:00
b . Append ( self . viewMenu , ' &View ' )
2003-11-12 16:34:20 -05:00
b . Append ( self . optionsMenu , ' &Options ' )
b . Append ( self . helpMenu , ' &Help ' )
self . SetMenuBar ( b )
2005-12-30 18:02:03 -05:00
self . Bind ( wx . EVT_MENU , self . OnFileNew , id = ID_NEW )
self . Bind ( wx . EVT_MENU , self . OnFileOpen , id = ID_OPEN )
self . Bind ( wx . EVT_MENU , self . OnFileRevert , id = ID_REVERT )
self . Bind ( wx . EVT_MENU , self . OnFileClose , id = ID_CLOSE )
self . Bind ( wx . EVT_MENU , self . OnFileSave , id = ID_SAVE )
self . Bind ( wx . EVT_MENU , self . OnFileSaveAs , id = ID_SAVEAS )
self . Bind ( wx . EVT_MENU , self . OnFileUpdateNamespace , id = ID_NAMESPACE )
self . Bind ( wx . EVT_MENU , self . OnFilePrint , id = ID_PRINT )
self . Bind ( wx . EVT_MENU , self . OnExit , id = ID_EXIT )
self . Bind ( wx . EVT_MENU , self . OnUndo , id = ID_UNDO )
self . Bind ( wx . EVT_MENU , self . OnRedo , id = ID_REDO )
self . Bind ( wx . EVT_MENU , self . OnCut , id = ID_CUT )
self . Bind ( wx . EVT_MENU , self . OnCopy , id = ID_COPY )
self . Bind ( wx . EVT_MENU , self . OnCopyPlus , id = ID_COPY_PLUS )
self . Bind ( wx . EVT_MENU , self . OnPaste , id = ID_PASTE )
self . Bind ( wx . EVT_MENU , self . OnPastePlus , id = ID_PASTE_PLUS )
self . Bind ( wx . EVT_MENU , self . OnClear , id = ID_CLEAR )
self . Bind ( wx . EVT_MENU , self . OnSelectAll , id = ID_SELECTALL )
self . Bind ( wx . EVT_MENU , self . OnEmptyBuffer , id = ID_EMPTYBUFFER )
self . Bind ( wx . EVT_MENU , self . OnAbout , id = ID_ABOUT )
self . Bind ( wx . EVT_MENU , self . OnHelp , id = ID_HELP )
self . Bind ( wx . EVT_MENU , self . OnAutoCompleteShow , id = ID_AUTOCOMP_SHOW )
self . Bind ( wx . EVT_MENU , self . OnAutoCompleteMagic , id = ID_AUTOCOMP_MAGIC )
self . Bind ( wx . EVT_MENU , self . OnAutoCompleteSingle , id = ID_AUTOCOMP_SINGLE )
self . Bind ( wx . EVT_MENU , self . OnAutoCompleteDouble , id = ID_AUTOCOMP_DOUBLE )
self . Bind ( wx . EVT_MENU , self . OnCallTipsShow , id = ID_CALLTIPS_SHOW )
self . Bind ( wx . EVT_MENU , self . OnCallTipsInsert , id = ID_CALLTIPS_INSERT )
self . Bind ( wx . EVT_MENU , self . OnWrap , id = ID_WRAP )
self . Bind ( wx . EVT_MENU , self . OnUseAA , id = ID_USEAA )
self . Bind ( wx . EVT_MENU , self . OnToggleMaximize , id = ID_TOGGLE_MAXIMIZE )
self . Bind ( wx . EVT_MENU , self . OnShowLineNumbers , id = ID_SHOW_LINENUMBERS )
self . Bind ( wx . EVT_MENU , self . OnAutoSaveSettings , id = ID_AUTO_SAVESETTINGS )
self . Bind ( wx . EVT_MENU , self . OnSaveHistory , id = ID_SAVEHISTORY )
2006-02-23 20:21:26 -05:00
self . Bind ( wx . EVT_MENU , self . OnSaveHistoryNow , id = ID_SAVEHISTORYNOW )
self . Bind ( wx . EVT_MENU , self . OnClearHistory , id = ID_CLEARHISTORY )
2005-12-30 18:02:03 -05:00
self . Bind ( wx . EVT_MENU , self . OnSaveSettings , id = ID_SAVESETTINGS )
self . Bind ( wx . EVT_MENU , self . OnDelSettingsFile , id = ID_DELSETTINGSFILE )
self . Bind ( wx . EVT_MENU , self . OnEditStartupScript , id = ID_EDITSTARTUPSCRIPT )
self . Bind ( wx . EVT_MENU , self . OnExecStartupScript , id = ID_EXECSTARTUPSCRIPT )
self . Bind ( wx . EVT_MENU , self . OnFindText , id = ID_FIND )
self . Bind ( wx . EVT_MENU , self . OnFindNext , id = ID_FINDNEXT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_NEW )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_OPEN )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_REVERT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_CLOSE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SAVE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SAVEAS )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_NAMESPACE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_PRINT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_UNDO )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_REDO )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_CUT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_COPY )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_COPY_PLUS )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_PASTE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_PASTE_PLUS )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_CLEAR )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SELECTALL )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_EMPTYBUFFER )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_AUTOCOMP_SHOW )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_AUTOCOMP_MAGIC )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_AUTOCOMP_SINGLE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_AUTOCOMP_DOUBLE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_CALLTIPS_SHOW )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_CALLTIPS_INSERT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_WRAP )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_USEAA )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SHOW_LINENUMBERS )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_AUTO_SAVESETTINGS )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SAVESETTINGS )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_DELSETTINGSFILE )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_EXECSTARTUPSCRIPT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SAVEHISTORY )
2006-02-23 20:21:26 -05:00
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_SAVEHISTORYNOW )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_CLEARHISTORY )
2005-12-30 18:02:03 -05:00
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_EDITSTARTUPSCRIPT )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_FIND )
self . Bind ( wx . EVT_UPDATE_UI , self . OnUpdateMenu , id = ID_FINDNEXT )
self . Bind ( wx . EVT_ACTIVATE , self . OnActivate )
self . Bind ( wx . EVT_FIND , self . OnFindNext )
self . Bind ( wx . EVT_FIND_NEXT , self . OnFindNext )
self . Bind ( wx . EVT_FIND_CLOSE , self . OnFindClose )
def OnShowLineNumbers ( self , event ) :
win = wx . Window . FindFocus ( )
if hasattr ( win , ' lineNumbers ' ) :
win . lineNumbers = event . IsChecked ( )
win . setDisplayLineNumbers ( win . lineNumbers )
def OnToggleMaximize ( self , event ) :
self . Maximize ( not self . IsMaximized ( ) )
2003-11-12 16:34:20 -05:00
def OnFileNew ( self , event ) :
self . bufferNew ( )
def OnFileOpen ( self , event ) :
self . bufferOpen ( )
def OnFileRevert ( self , event ) :
self . bufferRevert ( )
def OnFileClose ( self , event ) :
self . bufferClose ( )
def OnFileSave ( self , event ) :
self . bufferSave ( )
def OnFileSaveAs ( self , event ) :
self . bufferSaveAs ( )
def OnFileUpdateNamespace ( self , event ) :
self . updateNamespace ( )
def OnFilePrint ( self , event ) :
self . bufferPrint ( )
def OnExit ( self , event ) :
self . Close ( False )
def OnUndo ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . Undo ( )
def OnRedo ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . Redo ( )
def OnCut ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . Cut ( )
def OnCopy ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . Copy ( )
def OnCopyPlus ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . CopyWithPrompts ( )
def OnPaste ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . Paste ( )
def OnPastePlus ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . PasteAndRun ( )
def OnClear ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . Clear ( )
2005-12-30 18:02:03 -05:00
def OnEmptyBuffer ( self , event ) :
win = wx . Window . FindFocus ( )
d = wx . MessageDialog ( self ,
" Are you sure you want to clear the edit buffer, \n "
" deleting all the text? " ,
" Empty Buffer " , wx . OK | wx . CANCEL | wx . ICON_QUESTION )
answer = d . ShowModal ( )
d . Destroy ( )
if ( answer == wx . ID_OK ) :
win . ClearAll ( )
if hasattr ( win , ' prompt ' ) :
win . prompt ( )
2003-11-12 16:34:20 -05:00
def OnSelectAll ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . SelectAll ( )
def OnAbout ( self , event ) :
""" Display an About window. """
title = ' About '
text = ' Your message here. '
dialog = wx . MessageDialog ( self , text , title ,
wx . OK | wx . ICON_INFORMATION )
dialog . ShowModal ( )
dialog . Destroy ( )
2005-12-30 18:02:03 -05:00
def OnHelp ( self , event ) :
""" Display a Help window. """
title = ' Help '
text = " Type ' shell.help() ' in the shell window. "
dialog = wx . MessageDialog ( self , text , title ,
wx . OK | wx . ICON_INFORMATION )
dialog . ShowModal ( )
dialog . Destroy ( )
2003-11-12 16:34:20 -05:00
def OnAutoCompleteShow ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . autoComplete = event . IsChecked ( )
def OnAutoCompleteMagic ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . autoCompleteIncludeMagic = event . IsChecked ( )
def OnAutoCompleteSingle ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . autoCompleteIncludeSingle = event . IsChecked ( )
def OnAutoCompleteDouble ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . autoCompleteIncludeDouble = event . IsChecked ( )
def OnCallTipsShow ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . autoCallTip = event . IsChecked ( )
2005-12-30 18:02:03 -05:00
def OnCallTipsInsert ( self , event ) :
win = wx . Window . FindFocus ( )
win . callTipInsert = event . IsChecked ( )
2003-11-12 16:34:20 -05:00
def OnWrap ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
win . SetWrapMode ( event . IsChecked ( ) )
2005-12-30 18:02:03 -05:00
wx . FutureCall ( 1 , self . shell . EnsureCaretVisible )
2003-11-12 16:34:20 -05:00
2004-02-23 17:36:24 -05:00
def OnUseAA ( self , event ) :
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2004-02-23 17:36:24 -05:00
win . SetUseAntiAliasing ( event . IsChecked ( ) )
2005-12-30 18:02:03 -05:00
def OnSaveHistory ( self , event ) :
2006-02-23 20:21:26 -05:00
self . autoSaveHistory = event . IsChecked ( )
def OnSaveHistoryNow ( self , event ) :
self . SaveHistory ( )
def OnClearHistory ( self , event ) :
self . shell . clearHistory ( )
2005-12-30 18:02:03 -05:00
def OnAutoSaveSettings ( self , event ) :
self . autoSaveSettings = event . IsChecked ( )
def OnSaveSettings ( self , event ) :
self . DoSaveSettings ( )
def OnDelSettingsFile ( self , event ) :
if self . config is not None :
d = wx . MessageDialog (
self , " Do you want to revert to the default settings? \n " +
" A restart is needed for the change to take effect " ,
" Warning " , wx . OK | wx . CANCEL | wx . ICON_QUESTION )
answer = d . ShowModal ( )
d . Destroy ( )
if ( answer == wx . ID_OK ) :
self . config . DeleteAll ( )
self . LoadSettings ( )
def OnEditStartupScript ( self , event ) :
if hasattr ( self , ' EditStartupScript ' ) :
self . EditStartupScript ( )
def OnExecStartupScript ( self , event ) :
self . execStartupScript = event . IsChecked ( )
def OnFindText ( self , event ) :
if self . findDlg is not None :
return
win = wx . Window . FindFocus ( )
self . findDlg = wx . FindReplaceDialog ( win , self . findData , " Find " ,
wx . FR_NOWHOLEWORD )
self . findDlg . Show ( )
2004-02-23 17:36:24 -05:00
2005-12-30 18:02:03 -05:00
def OnFindNext ( self , event ) :
2006-02-23 20:21:26 -05:00
if not self . findData . GetFindString ( ) :
self . OnFindText ( event )
return
2005-12-30 18:02:03 -05:00
if isinstance ( event , wx . FindDialogEvent ) :
win = self . findDlg . GetParent ( )
else :
win = wx . Window . FindFocus ( )
win . DoFindNext ( self . findData , self . findDlg )
2006-02-24 13:14:24 -05:00
if self . findDlg is not None :
self . OnFindClose ( None )
2005-12-30 18:02:03 -05:00
def OnFindClose ( self , event ) :
self . findDlg . Destroy ( )
self . findDlg = None
2004-02-23 17:36:24 -05:00
2003-11-12 16:34:20 -05:00
def OnUpdateMenu ( self , event ) :
""" Update menu items based on current status and context. """
2005-12-30 18:02:03 -05:00
win = wx . Window . FindFocus ( )
2003-11-12 16:34:20 -05:00
id = event . GetId ( )
event . Enable ( True )
try :
if id == ID_NEW :
event . Enable ( hasattr ( self , ' bufferNew ' ) )
elif id == ID_OPEN :
event . Enable ( hasattr ( self , ' bufferOpen ' ) )
elif id == ID_REVERT :
event . Enable ( hasattr ( self , ' bufferRevert ' )
and self . hasBuffer ( ) )
elif id == ID_CLOSE :
event . Enable ( hasattr ( self , ' bufferClose ' )
and self . hasBuffer ( ) )
elif id == ID_SAVE :
event . Enable ( hasattr ( self , ' bufferSave ' )
and self . bufferHasChanged ( ) )
elif id == ID_SAVEAS :
event . Enable ( hasattr ( self , ' bufferSaveAs ' )
and self . hasBuffer ( ) )
elif id == ID_NAMESPACE :
event . Enable ( hasattr ( self , ' updateNamespace ' )
and self . hasBuffer ( ) )
elif id == ID_PRINT :
event . Enable ( hasattr ( self , ' bufferPrint ' )
and self . hasBuffer ( ) )
elif id == ID_UNDO :
event . Enable ( win . CanUndo ( ) )
elif id == ID_REDO :
event . Enable ( win . CanRedo ( ) )
elif id == ID_CUT :
event . Enable ( win . CanCut ( ) )
elif id == ID_COPY :
event . Enable ( win . CanCopy ( ) )
elif id == ID_COPY_PLUS :
event . Enable ( win . CanCopy ( ) and hasattr ( win , ' CopyWithPrompts ' ) )
elif id == ID_PASTE :
event . Enable ( win . CanPaste ( ) )
elif id == ID_PASTE_PLUS :
event . Enable ( win . CanPaste ( ) and hasattr ( win , ' PasteAndRun ' ) )
elif id == ID_CLEAR :
event . Enable ( win . CanCut ( ) )
elif id == ID_SELECTALL :
event . Enable ( hasattr ( win , ' SelectAll ' ) )
2005-12-30 18:02:03 -05:00
elif id == ID_EMPTYBUFFER :
event . Enable ( hasattr ( win , ' ClearAll ' ) and not win . GetReadOnly ( ) )
2003-11-12 16:34:20 -05:00
elif id == ID_AUTOCOMP_SHOW :
event . Check ( win . autoComplete )
elif id == ID_AUTOCOMP_MAGIC :
event . Check ( win . autoCompleteIncludeMagic )
elif id == ID_AUTOCOMP_SINGLE :
event . Check ( win . autoCompleteIncludeSingle )
elif id == ID_AUTOCOMP_DOUBLE :
event . Check ( win . autoCompleteIncludeDouble )
elif id == ID_CALLTIPS_SHOW :
event . Check ( win . autoCallTip )
2005-12-30 18:02:03 -05:00
elif id == ID_CALLTIPS_INSERT :
event . Check ( win . callTipInsert )
2003-11-12 16:34:20 -05:00
elif id == ID_WRAP :
event . Check ( win . GetWrapMode ( ) )
2004-02-23 17:36:24 -05:00
elif id == ID_USEAA :
event . Check ( win . GetUseAntiAliasing ( ) )
2005-12-30 18:02:03 -05:00
elif id == ID_SHOW_LINENUMBERS :
event . Check ( win . lineNumbers )
elif id == ID_AUTO_SAVESETTINGS :
event . Check ( self . autoSaveSettings )
2006-01-06 02:05:15 -05:00
event . Enable ( self . config is not None )
2005-12-30 18:02:03 -05:00
elif id == ID_SAVESETTINGS :
event . Enable ( self . config is not None and
hasattr ( self , ' DoSaveSettings ' ) )
elif id == ID_DELSETTINGSFILE :
event . Enable ( self . config is not None )
elif id == ID_EXECSTARTUPSCRIPT :
event . Check ( self . execStartupScript )
2006-01-06 02:05:15 -05:00
event . Enable ( self . config is not None )
2005-12-30 18:02:03 -05:00
elif id == ID_SAVEHISTORY :
2006-02-23 20:21:26 -05:00
event . Check ( self . autoSaveHistory )
2006-01-06 02:05:15 -05:00
event . Enable ( self . dataDir is not None )
2006-02-23 20:21:26 -05:00
elif id == ID_SAVEHISTORYNOW :
event . Enable ( self . dataDir is not None and
hasattr ( self , ' SaveHistory ' ) )
elif id == ID_CLEARHISTORY :
event . Enable ( self . dataDir is not None )
2005-12-30 18:02:03 -05:00
elif id == ID_EDITSTARTUPSCRIPT :
event . Enable ( hasattr ( self , ' EditStartupScript ' ) )
2006-01-06 02:05:15 -05:00
event . Enable ( self . dataDir is not None )
2005-12-30 18:02:03 -05:00
elif id == ID_FIND :
event . Enable ( hasattr ( win , ' DoFindNext ' ) )
elif id == ID_FINDNEXT :
2006-02-23 20:21:26 -05:00
event . Enable ( hasattr ( win , ' DoFindNext ' ) )
2003-11-12 16:34:20 -05:00
else :
event . Enable ( False )
except AttributeError :
# This menu option is not supported in the current context.
event . Enable ( False )
2005-12-30 18:02:03 -05:00
def OnActivate ( self , event ) :
"""
Event Handler for losing the focus of the Frame . Should close
Autocomplete listbox , if shown .
"""
if not event . GetActive ( ) :
# If autocomplete active, cancel it. Otherwise, the
# autocomplete list will stay visible on top of the
# z-order after switching to another application
win = wx . Window . FindFocus ( )
if hasattr ( win , ' AutoCompActive ' ) and win . AutoCompActive ( ) :
win . AutoCompCancel ( )
event . Skip ( )
def LoadSettings ( self , config ) :
""" Called be derived classes to load settings specific to the Frame """
pos = wx . Point ( config . ReadInt ( ' Window/PosX ' , - 1 ) ,
config . ReadInt ( ' Window/PosY ' , - 1 ) )
size = wx . Size ( config . ReadInt ( ' Window/Width ' , - 1 ) ,
config . ReadInt ( ' Window/Height ' , - 1 ) )
self . SetSize ( size )
self . Move ( pos )
def SaveSettings ( self , config ) :
""" Called by derived classes to save Frame settings to a wx.Config object """
# TODO: track position/size so we can save it even if the
# frame is maximized or iconized.
if not self . iconized and not self . IsMaximized ( ) :
w , h = self . GetSize ( )
config . WriteInt ( ' Window/Width ' , w )
config . WriteInt ( ' Window/Height ' , h )
px , py = self . GetPosition ( )
config . WriteInt ( ' Window/PosX ' , px )
config . WriteInt ( ' Window/PosY ' , py )
class ShellFrameMixin :
"""
A mix - in class for frames that will have a Shell or a Crust window
and that want to add history , startupScript and other common
functionality .
"""
def __init__ ( self , config , dataDir ) :
self . config = config
self . dataDir = dataDir
self . startupScript = os . environ . get ( ' PYTHONSTARTUP ' )
if not self . startupScript and self . dataDir :
self . startupScript = os . path . join ( self . dataDir , ' startup ' )
self . autoSaveSettings = False
2006-02-23 20:21:26 -05:00
self . autoSaveHistory = False
2005-12-30 18:02:03 -05:00
# We need this one before we have a chance to load the settings...
self . execStartupScript = True
if self . config :
self . execStartupScript = self . config . ReadBool ( ' Options/ExecStartupScript ' , True )
def OnHelp ( self , event ) :
""" Display a Help window. """
import wx . lib . dialogs
title = ' Help on key bindings '
text = wx . py . shell . HELP_TEXT
dlg = wx . lib . dialogs . ScrolledMessageDialog ( self , text , title , size = ( ( 700 , 540 ) ) )
fnt = wx . Font ( 10 , wx . TELETYPE , wx . NORMAL , wx . NORMAL )
dlg . GetChildren ( ) [ 0 ] . SetFont ( fnt )
dlg . GetChildren ( ) [ 0 ] . SetInsertionPoint ( 0 )
dlg . ShowModal ( )
dlg . Destroy ( )
def LoadSettings ( self ) :
if self . config is not None :
self . autoSaveSettings = self . config . ReadBool ( ' Options/AutoSaveSettings ' , False )
self . execStartupScript = self . config . ReadBool ( ' Options/ExecStartupScript ' , True )
2006-02-23 20:21:26 -05:00
self . autoSaveHistory = self . config . ReadBool ( ' Options/AutoSaveHistory ' , False )
2005-12-30 18:02:03 -05:00
self . LoadHistory ( )
def SaveSettings ( self ) :
if self . config is not None :
# always save this one
self . config . WriteBool ( ' Options/AutoSaveSettings ' , self . autoSaveSettings )
if self . autoSaveSettings :
2006-02-23 20:21:26 -05:00
self . config . WriteBool ( ' Options/AutoSaveHistory ' , self . autoSaveHistory )
2005-12-30 18:02:03 -05:00
self . config . WriteBool ( ' Options/ExecStartupScript ' , self . execStartupScript )
2006-02-23 20:21:26 -05:00
if self . autoSaveHistory :
2005-12-30 18:02:03 -05:00
self . SaveHistory ( )
def SaveHistory ( self ) :
if self . dataDir :
try :
name = os . path . join ( self . dataDir , ' history ' )
f = file ( name , ' w ' )
2006-02-23 20:21:26 -05:00
hist = ' \x00 \n ' . join ( self . shell . history )
f . write ( hist )
2005-12-30 18:02:03 -05:00
f . close ( )
except :
d = wx . MessageDialog ( self , " Error saving history file. " ,
" Error " , wx . ICON_EXCLAMATION )
d . ShowModal ( )
d . Destroy ( )
2006-02-23 20:21:26 -05:00
raise
2005-12-30 18:02:03 -05:00
def LoadHistory ( self ) :
if self . dataDir :
name = os . path . join ( self . dataDir , ' history ' )
if os . path . exists ( name ) :
try :
f = file ( name , ' U ' )
hist = f . read ( )
f . close ( )
2006-02-23 20:21:26 -05:00
self . shell . history = hist . split ( ' \x00 \n ' )
dispatcher . send ( signal = " Shell.loadHistory " , history = self . shell . history )
2005-12-30 18:02:03 -05:00
except :
d = wx . MessageDialog ( self , " Error loading history file. " ,
" Error " , wx . ICON_EXCLAMATION )
d . ShowModal ( )
d . Destroy ( )
def bufferHasChanged ( self ) :
# the shell buffers can always be saved
return True
def bufferSave ( self ) :
import time
appname = wx . GetApp ( ) . GetAppName ( )
default = appname + ' - ' + time . strftime ( " % Y % m %d - % H % M.py " )
fileName = wx . FileSelector ( " Save File As " , " Saving " ,
default_filename = default ,
default_extension = " py " ,
wildcard = " *.py " ,
flags = wx . SAVE | wx . OVERWRITE_PROMPT )
if not fileName :
return
text = self . shell . GetText ( )
## This isn't working currently...
## d = wx.MessageDialog(self,u'Save source code only?\nAnswering yes will only save lines starting with >>> and ...',u'Question', wx.YES_NO | wx.ICON_QUESTION)
## yes_no = d.ShowModal()
## if yes_no == wx.ID_YES:
## m = re.findall('^[>\.]{3,3} (.*)\r', text, re.MULTILINE | re.LOCALE)
## text = '\n'.join(m)
## d.Destroy()
try :
f = open ( fileName , " w " )
f . write ( text )
f . close ( )
except :
d = wx . MessageDialog ( self , u ' Error saving session ' , u ' Error ' ,
wx . OK | wx . ICON_ERROR )
d . ShowModal ( )
d . Destroy ( )
def EditStartupScript ( self ) :
if os . path . exists ( self . startupScript ) :
text = file ( self . startupScript , ' U ' ) . read ( )
else :
text = ' '
dlg = EditStartupScriptDialog ( self , self . startupScript , text )
if dlg . ShowModal ( ) == wx . ID_OK :
text = dlg . GetText ( )
try :
f = file ( self . startupScript , ' w ' )
f . write ( text )
f . close ( )
except :
d = wx . MessageDialog ( self , " Error saving startup file. " ,
" Error " , wx . ICON_EXCLAMATION )
d . ShowModal ( )
d . Destroy ( )
class EditStartupScriptDialog ( wx . Dialog ) :
def __init__ ( self , parent , fileName , text ) :
wx . Dialog . __init__ ( self , parent , size = ( 425 , 350 ) ,
title = " Edit Startup Script " ,
style = wx . DEFAULT_DIALOG_STYLE | wx . RESIZE_BORDER )
pst = wx . StaticText ( self , - 1 , " Path: " )
ptx = wx . TextCtrl ( self , - 1 , fileName , style = wx . TE_READONLY )
self . editor = editwindow . EditWindow ( self )
self . editor . SetText ( text )
wx . CallAfter ( self . editor . SetFocus )
ok = wx . Button ( self , wx . ID_OK )
cancel = wx . Button ( self , wx . ID_CANCEL )
mainSizer = wx . BoxSizer ( wx . VERTICAL )
pthSizer = wx . BoxSizer ( wx . HORIZONTAL )
pthSizer . Add ( pst , flag = wx . ALIGN_CENTER_VERTICAL )
pthSizer . Add ( ( 5 , 5 ) )
pthSizer . Add ( ptx , 1 )
mainSizer . Add ( pthSizer , 0 , wx . EXPAND | wx . ALL , 10 )
mainSizer . Add ( self . editor , 1 , wx . EXPAND | wx . LEFT | wx . RIGHT , 10 )
btnSizer = wx . BoxSizer ( wx . HORIZONTAL )
btnSizer . Add ( ( 5 , 5 ) , 1 )
btnSizer . Add ( ok )
btnSizer . Add ( ( 5 , 5 ) , 1 )
btnSizer . Add ( cancel )
btnSizer . Add ( ( 5 , 5 ) , 1 )
mainSizer . Add ( btnSizer , 0 , wx . EXPAND | wx . ALL , 10 )
self . SetSizer ( mainSizer )
self . Layout ( )
def GetText ( self ) :
return self . editor . GetText ( )