1 """Base frame with menu.""" 
   3 __author__ 
= "Patrick K. O'Brien <pobrien@orbtech.com>" 
   5 __revision__ 
= "$Revision$"[11:-2] 
   9 from version 
import VERSION
 
  15 ID_REVERT 
= wx
.ID_REVERT
 
  16 ID_CLOSE 
= wx
.ID_CLOSE
 
  18 ID_SAVEAS 
= wx
.ID_SAVEAS
 
  19 ID_PRINT 
= wx
.ID_PRINT
 
  25 ID_PASTE 
= wx
.ID_PASTE
 
  26 ID_CLEAR 
= wx
.ID_CLEAR
 
  27 ID_SELECTALL 
= wx
.ID_SELECTALL
 
  28 ID_EMPTYBUFFER 
= wx
.NewId() 
  29 ID_ABOUT 
= wx
.ID_ABOUT
 
  31 ID_AUTOCOMP 
= wx
.NewId() 
  32 ID_AUTOCOMP_SHOW 
= wx
.NewId() 
  33 ID_AUTOCOMP_MAGIC 
= wx
.NewId() 
  34 ID_AUTOCOMP_SINGLE 
= wx
.NewId() 
  35 ID_AUTOCOMP_DOUBLE 
= wx
.NewId() 
  36 ID_CALLTIPS 
= wx
.NewId() 
  37 ID_CALLTIPS_SHOW 
= wx
.NewId() 
  38 ID_CALLTIPS_INSERT 
= wx
.NewId() 
  39 ID_COPY_PLUS 
= wx
.NewId() 
  40 ID_NAMESPACE 
= wx
.NewId() 
  41 ID_PASTE_PLUS 
= wx
.NewId() 
  43 ID_TOGGLE_MAXIMIZE 
= wx
.NewId() 
  45 ID_SHOW_LINENUMBERS 
= wx
.NewId() 
  46 ID_AUTO_SAVESETTINGS 
= wx
.NewId() 
  47 ID_SAVEHISTORY 
= wx
.NewId() 
  48 ID_SAVEHISTORYNOW 
= wx
.NewId() 
  49 ID_CLEARHISTORY 
= wx
.NewId() 
  50 ID_SAVESETTINGS 
= wx
.NewId() 
  51 ID_DELSETTINGSFILE 
= wx
.NewId() 
  52 ID_EDITSTARTUPSCRIPT 
= wx
.NewId() 
  53 ID_EXECSTARTUPSCRIPT 
= wx
.NewId() 
  54 ID_STARTUP 
= wx
.NewId() 
  55 ID_SETTINGS 
= wx
.NewId() 
  57 ID_FINDNEXT 
= wx
.NewId() 
  61 class Frame(wx
.Frame
): 
  62     """Frame with standard menu items.""" 
  64     revision 
= __revision__
 
  66     def __init__(self
, parent
=None, id=-1, title
='Editor', 
  67                  pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,  
  68                  style
=wx
.DEFAULT_FRAME_STYLE
): 
  69         """Create a Frame instance.""" 
  70         wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
) 
  71         self
.CreateStatusBar() 
  72         self
.SetStatusText('Frame') 
  74         self
.SetIcon(images
.getPyIcon()) 
  79         self
.findData 
= wx
.FindReplaceData() 
  80         self
.findData
.SetFlags(wx
.FR_DOWN
) 
  82         self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
) 
  83         self
.Bind(wx
.EVT_ICONIZE
, self
.OnIconize
) 
  86     def OnIconize(self
, event
): 
  87         """Event handler for Iconize.""" 
  88         self
.iconized 
= event
.Iconized() 
  91     def OnClose(self
, event
): 
  92         """Event handler for closing.""" 
  96     def __createMenus(self
): 
  98         m 
= self
.fileMenu 
= wx
.Menu() 
  99         m
.Append(ID_NEW
, '&New \tCtrl+N', 
 101         m
.Append(ID_OPEN
, '&Open... \tCtrl+O', 
 104         m
.Append(ID_REVERT
, '&Revert \tCtrl+R', 
 105                  'Revert to last saved version') 
 106         m
.Append(ID_CLOSE
, '&Close \tCtrl+W', 
 109         m
.Append(ID_SAVE
, '&Save... \tCtrl+S', 
 111         m
.Append(ID_SAVEAS
, 'Save &As \tCtrl+Shift+S', 
 112                  'Save file with new name') 
 114         m
.Append(ID_PRINT
, '&Print... \tCtrl+P', 
 117         m
.Append(ID_NAMESPACE
, '&Update Namespace \tCtrl+Shift+N', 
 118                  'Update namespace for autocompletion and calltips') 
 120         m
.Append(ID_EXIT
, 'E&xit\tCtrl+Q', 'Exit Program') 
 123         m 
= self
.editMenu 
= wx
.Menu() 
 124         m
.Append(ID_UNDO
, '&Undo \tCtrl+Z', 
 125                  'Undo the last action') 
 126         m
.Append(ID_REDO
, '&Redo \tCtrl+Y', 
 127                  'Redo the last undone action') 
 129         m
.Append(ID_CUT
, 'Cu&t \tCtrl+X', 
 131         m
.Append(ID_COPY
, '&Copy \tCtrl+C', 
 132                  'Copy the selection') 
 133         m
.Append(ID_COPY_PLUS
, 'Cop&y Plus \tCtrl+Shift+C', 
 134                  'Copy the selection - retaining prompts') 
 135         m
.Append(ID_PASTE
, '&Paste \tCtrl+V', 'Paste from clipboard') 
 136         m
.Append(ID_PASTE_PLUS
, 'Past&e Plus \tCtrl+Shift+V', 
 137                  'Paste and run commands') 
 139         m
.Append(ID_CLEAR
, 'Cle&ar', 
 140                  'Delete the selection') 
 141         m
.Append(ID_SELECTALL
, 'Select A&ll \tCtrl+A', 
 144         m
.Append(ID_EMPTYBUFFER
, 'E&mpty Buffer...', 
 145                  'Delete all the contents of the edit buffer') 
 146         m
.Append(ID_FIND
, '&Find Text... \tCtrl+F', 
 147                  'Search for text in the edit buffer') 
 148         m
.Append(ID_FINDNEXT
, 'Find &Next \tF3', 
 149                  'Find next/previous instance of the search text') 
 152         m 
= self
.viewMenu 
= wx
.Menu() 
 153         m
.Append(ID_WRAP
, '&Wrap Lines\tCtrl+Shift+W', 
 154                  'Wrap lines at right edge', wx
.ITEM_CHECK
) 
 155         m
.Append(ID_SHOW_LINENUMBERS
, '&Show Line Numbers\tCtrl+Shift+L', 'Show Line Numbers', wx
.ITEM_CHECK
) 
 156         m
.Append(ID_TOGGLE_MAXIMIZE
, '&Toggle Maximize\tF11', 'Maximize/Restore Application') 
 159         m 
= self
.autocompMenu 
= wx
.Menu() 
 160         m
.Append(ID_AUTOCOMP_SHOW
, 'Show &Auto Completion\tCtrl+Shift+A', 
 161                  'Show auto completion list', wx
.ITEM_CHECK
) 
 162         m
.Append(ID_AUTOCOMP_MAGIC
, 'Include &Magic Attributes\tCtrl+Shift+M', 
 163                  'Include attributes visible to __getattr__ and __setattr__', 
 165         m
.Append(ID_AUTOCOMP_SINGLE
, 'Include Single &Underscores\tCtrl+Shift+U', 
 166                  'Include attibutes prefixed by a single underscore', wx
.ITEM_CHECK
) 
 167         m
.Append(ID_AUTOCOMP_DOUBLE
, 'Include &Double Underscores\tCtrl+Shift+D', 
 168                  'Include attibutes prefixed by a double underscore', wx
.ITEM_CHECK
) 
 169         m 
= self
.calltipsMenu 
= wx
.Menu() 
 170         m
.Append(ID_CALLTIPS_SHOW
, 'Show Call &Tips\tCtrl+Shift+T', 
 171                  'Show call tips with argument signature and docstring', wx
.ITEM_CHECK
) 
 172         m
.Append(ID_CALLTIPS_INSERT
, '&Insert Call Tips\tCtrl+Shift+I', 
 173                  '&Insert Call Tips', wx
.ITEM_CHECK
) 
 175         m 
= self
.optionsMenu 
= wx
.Menu() 
 176         m
.AppendMenu(ID_AUTOCOMP
, '&Auto Completion', self
.autocompMenu
, 
 177                      'Auto Completion Options') 
 178         m
.AppendMenu(ID_CALLTIPS
, '&Call Tips', self
.calltipsMenu
, 
 181         if wx
.Platform 
== "__WXMAC__": 
 182             m
.Append(ID_USEAA
, '&Use AntiAliasing', 
 183                      'Use anti-aliased fonts', wx
.ITEM_CHECK
) 
 187         self
.historyMenu 
= wx
.Menu() 
 188         self
.historyMenu
.Append(ID_SAVEHISTORY
, '&Autosave History', 
 189                  'Automatically save history on close', wx
.ITEM_CHECK
) 
 190         self
.historyMenu
.Append(ID_SAVEHISTORYNOW
, '&Save History Now', 
 192         self
.historyMenu
.Append(ID_CLEARHISTORY
, '&Clear History ', 
 194         m
.AppendMenu(-1, "&History", self
.historyMenu
, "History Options") 
 196         self
.startupMenu 
= wx
.Menu() 
 197         self
.startupMenu
.Append(ID_EXECSTARTUPSCRIPT
, 
 198                                 'E&xecute Startup Script', 
 199                                 'Execute Startup Script', wx
.ITEM_CHECK
) 
 200         self
.startupMenu
.Append(ID_EDITSTARTUPSCRIPT
, 
 201                                 '&Edit Startup Script...', 
 202                                 'Edit Startup Script') 
 203         m
.AppendMenu(ID_STARTUP
, '&Startup', self
.startupMenu
, 'Startup Options') 
 205         self
.settingsMenu 
= wx
.Menu() 
 206         self
.settingsMenu
.Append(ID_AUTO_SAVESETTINGS
, 
 207                                  '&Auto Save Settings', 
 208                                  'Automatically save settings on close', wx
.ITEM_CHECK
) 
 209         self
.settingsMenu
.Append(ID_SAVESETTINGS
, 
 212         self
.settingsMenu
.Append(ID_DELSETTINGSFILE
, 
 213                                  '&Revert to default', 
 214                                  'Revert to the default settings') 
 215         m
.AppendMenu(ID_SETTINGS
, '&Settings', self
.settingsMenu
, 'Settings Options')            
 217         m 
= self
.helpMenu 
= wx
.Menu() 
 218         m
.Append(ID_HELP
, '&Help\tF1', 'Help!') 
 220         m
.Append(ID_ABOUT
, '&About...', 'About this program') 
 222         b 
= self
.menuBar 
= wx
.MenuBar() 
 223         b
.Append(self
.fileMenu
, '&File') 
 224         b
.Append(self
.editMenu
, '&Edit') 
 225         b
.Append(self
.viewMenu
, '&View') 
 226         b
.Append(self
.optionsMenu
, '&Options') 
 227         b
.Append(self
.helpMenu
, '&Help') 
 230         self
.Bind(wx
.EVT_MENU
, self
.OnFileNew
, id=ID_NEW
) 
 231         self
.Bind(wx
.EVT_MENU
, self
.OnFileOpen
, id=ID_OPEN
) 
 232         self
.Bind(wx
.EVT_MENU
, self
.OnFileRevert
, id=ID_REVERT
) 
 233         self
.Bind(wx
.EVT_MENU
, self
.OnFileClose
, id=ID_CLOSE
) 
 234         self
.Bind(wx
.EVT_MENU
, self
.OnFileSave
, id=ID_SAVE
) 
 235         self
.Bind(wx
.EVT_MENU
, self
.OnFileSaveAs
, id=ID_SAVEAS
) 
 236         self
.Bind(wx
.EVT_MENU
, self
.OnFileUpdateNamespace
, id=ID_NAMESPACE
) 
 237         self
.Bind(wx
.EVT_MENU
, self
.OnFilePrint
, id=ID_PRINT
) 
 238         self
.Bind(wx
.EVT_MENU
, self
.OnExit
, id=ID_EXIT
) 
 239         self
.Bind(wx
.EVT_MENU
, self
.OnUndo
, id=ID_UNDO
) 
 240         self
.Bind(wx
.EVT_MENU
, self
.OnRedo
, id=ID_REDO
) 
 241         self
.Bind(wx
.EVT_MENU
, self
.OnCut
, id=ID_CUT
) 
 242         self
.Bind(wx
.EVT_MENU
, self
.OnCopy
, id=ID_COPY
) 
 243         self
.Bind(wx
.EVT_MENU
, self
.OnCopyPlus
, id=ID_COPY_PLUS
) 
 244         self
.Bind(wx
.EVT_MENU
, self
.OnPaste
, id=ID_PASTE
) 
 245         self
.Bind(wx
.EVT_MENU
, self
.OnPastePlus
, id=ID_PASTE_PLUS
) 
 246         self
.Bind(wx
.EVT_MENU
, self
.OnClear
, id=ID_CLEAR
) 
 247         self
.Bind(wx
.EVT_MENU
, self
.OnSelectAll
, id=ID_SELECTALL
) 
 248         self
.Bind(wx
.EVT_MENU
, self
.OnEmptyBuffer
, id=ID_EMPTYBUFFER
) 
 249         self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, id=ID_ABOUT
) 
 250         self
.Bind(wx
.EVT_MENU
, self
.OnHelp
, id=ID_HELP
) 
 251         self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteShow
, id=ID_AUTOCOMP_SHOW
) 
 252         self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteMagic
, id=ID_AUTOCOMP_MAGIC
) 
 253         self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteSingle
, id=ID_AUTOCOMP_SINGLE
) 
 254         self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteDouble
, id=ID_AUTOCOMP_DOUBLE
) 
 255         self
.Bind(wx
.EVT_MENU
, self
.OnCallTipsShow
, id=ID_CALLTIPS_SHOW
) 
 256         self
.Bind(wx
.EVT_MENU
, self
.OnCallTipsInsert
, id=ID_CALLTIPS_INSERT
) 
 257         self
.Bind(wx
.EVT_MENU
, self
.OnWrap
, id=ID_WRAP
) 
 258         self
.Bind(wx
.EVT_MENU
, self
.OnUseAA
, id=ID_USEAA
) 
 259         self
.Bind(wx
.EVT_MENU
, self
.OnToggleMaximize
, id=ID_TOGGLE_MAXIMIZE
) 
 260         self
.Bind(wx
.EVT_MENU
, self
.OnShowLineNumbers
, id=ID_SHOW_LINENUMBERS
) 
 261         self
.Bind(wx
.EVT_MENU
, self
.OnAutoSaveSettings
, id=ID_AUTO_SAVESETTINGS
) 
 262         self
.Bind(wx
.EVT_MENU
, self
.OnSaveHistory
, id=ID_SAVEHISTORY
) 
 263         self
.Bind(wx
.EVT_MENU
, self
.OnSaveHistoryNow
, id=ID_SAVEHISTORYNOW
) 
 264         self
.Bind(wx
.EVT_MENU
, self
.OnClearHistory
, id=ID_CLEARHISTORY
) 
 265         self
.Bind(wx
.EVT_MENU
, self
.OnSaveSettings
, id=ID_SAVESETTINGS
) 
 266         self
.Bind(wx
.EVT_MENU
, self
.OnDelSettingsFile
, id=ID_DELSETTINGSFILE
) 
 267         self
.Bind(wx
.EVT_MENU
, self
.OnEditStartupScript
, id=ID_EDITSTARTUPSCRIPT
) 
 268         self
.Bind(wx
.EVT_MENU
, self
.OnExecStartupScript
, id=ID_EXECSTARTUPSCRIPT
) 
 269         self
.Bind(wx
.EVT_MENU
, self
.OnFindText
, id=ID_FIND
) 
 270         self
.Bind(wx
.EVT_MENU
, self
.OnFindNext
, id=ID_FINDNEXT
) 
 272         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_NEW
) 
 273         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_OPEN
) 
 274         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_REVERT
) 
 275         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CLOSE
) 
 276         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVE
) 
 277         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVEAS
) 
 278         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_NAMESPACE
) 
 279         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_PRINT
) 
 280         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_UNDO
) 
 281         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_REDO
) 
 282         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CUT
) 
 283         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_COPY
) 
 284         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_COPY_PLUS
) 
 285         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_PASTE
) 
 286         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_PASTE_PLUS
) 
 287         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CLEAR
) 
 288         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SELECTALL
) 
 289         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_EMPTYBUFFER
) 
 290         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_SHOW
) 
 291         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_MAGIC
) 
 292         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_SINGLE
) 
 293         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_DOUBLE
) 
 294         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CALLTIPS_SHOW
) 
 295         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CALLTIPS_INSERT
) 
 296         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_WRAP
) 
 297         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_USEAA
) 
 298         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SHOW_LINENUMBERS
) 
 299         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTO_SAVESETTINGS
) 
 300         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVESETTINGS
) 
 301         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_DELSETTINGSFILE
) 
 302         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_EXECSTARTUPSCRIPT
) 
 303         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVEHISTORY
) 
 304         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVEHISTORYNOW
) 
 305         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CLEARHISTORY
) 
 306         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_EDITSTARTUPSCRIPT
) 
 307         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_FIND
) 
 308         self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_FINDNEXT
) 
 310         self
.Bind(wx
.EVT_ACTIVATE
, self
.OnActivate
) 
 311         self
.Bind(wx
.EVT_FIND
, self
.OnFindNext
) 
 312         self
.Bind(wx
.EVT_FIND_NEXT
, self
.OnFindNext
) 
 313         self
.Bind(wx
.EVT_FIND_CLOSE
, self
.OnFindClose
) 
 317     def OnShowLineNumbers(self
, event
): 
 318         win 
= wx
.Window
.FindFocus() 
 319         if hasattr(win
, 'lineNumbers'): 
 320             win
.lineNumbers 
= event
.IsChecked() 
 321             win
.setDisplayLineNumbers(win
.lineNumbers
) 
 323     def OnToggleMaximize(self
, event
): 
 324         self
.Maximize(not self
.IsMaximized()) 
 326     def OnFileNew(self
, event
): 
 329     def OnFileOpen(self
, event
): 
 332     def OnFileRevert(self
, event
): 
 335     def OnFileClose(self
, event
): 
 338     def OnFileSave(self
, event
): 
 341     def OnFileSaveAs(self
, event
): 
 344     def OnFileUpdateNamespace(self
, event
): 
 345         self
.updateNamespace() 
 347     def OnFilePrint(self
, event
): 
 350     def OnExit(self
, event
): 
 353     def OnUndo(self
, event
): 
 354         win 
= wx
.Window
.FindFocus() 
 357     def OnRedo(self
, event
): 
 358         win 
= wx
.Window
.FindFocus() 
 361     def OnCut(self
, event
): 
 362         win 
= wx
.Window
.FindFocus() 
 365     def OnCopy(self
, event
): 
 366         win 
= wx
.Window
.FindFocus() 
 369     def OnCopyPlus(self
, event
): 
 370         win 
= wx
.Window
.FindFocus() 
 371         win
.CopyWithPrompts() 
 373     def OnPaste(self
, event
): 
 374         win 
= wx
.Window
.FindFocus() 
 377     def OnPastePlus(self
, event
): 
 378         win 
= wx
.Window
.FindFocus() 
 381     def OnClear(self
, event
): 
 382         win 
= wx
.Window
.FindFocus() 
 385     def OnEmptyBuffer(self
, event
): 
 386         win 
= wx
.Window
.FindFocus() 
 387         d 
= wx
.MessageDialog(self
, 
 388                              "Are you sure you want to clear the edit buffer,\n" 
 389                              "deleting all the text?", 
 390                              "Empty Buffer", wx
.OK | wx
.CANCEL | wx
.ICON_QUESTION
) 
 391         answer 
= d
.ShowModal() 
 393         if (answer 
== wx
.ID_OK
): 
 395             if hasattr(win
,'prompt'): 
 398     def OnSelectAll(self
, event
): 
 399         win 
= wx
.Window
.FindFocus() 
 402     def OnAbout(self
, event
): 
 403         """Display an About window.""" 
 405         text 
= 'Your message here.' 
 406         dialog 
= wx
.MessageDialog(self
, text
, title
, 
 407                                   wx
.OK | wx
.ICON_INFORMATION
) 
 411     def OnHelp(self
, event
): 
 412         """Display a Help window.""" 
 414         text 
= "Type 'shell.help()' in the shell window." 
 415         dialog 
= wx
.MessageDialog(self
, text
, title
, 
 416                                   wx
.OK | wx
.ICON_INFORMATION
) 
 420     def OnAutoCompleteShow(self
, event
): 
 421         win 
= wx
.Window
.FindFocus() 
 422         win
.autoComplete 
= event
.IsChecked() 
 424     def OnAutoCompleteMagic(self
, event
): 
 425         win 
= wx
.Window
.FindFocus() 
 426         win
.autoCompleteIncludeMagic 
= event
.IsChecked() 
 428     def OnAutoCompleteSingle(self
, event
): 
 429         win 
= wx
.Window
.FindFocus() 
 430         win
.autoCompleteIncludeSingle 
= event
.IsChecked() 
 432     def OnAutoCompleteDouble(self
, event
): 
 433         win 
= wx
.Window
.FindFocus() 
 434         win
.autoCompleteIncludeDouble 
= event
.IsChecked() 
 436     def OnCallTipsShow(self
, event
): 
 437         win 
= wx
.Window
.FindFocus() 
 438         win
.autoCallTip 
= event
.IsChecked() 
 440     def OnCallTipsInsert(self
, event
): 
 441         win 
= wx
.Window
.FindFocus() 
 442         win
.callTipInsert 
= event
.IsChecked() 
 444     def OnWrap(self
, event
): 
 445         win 
= wx
.Window
.FindFocus() 
 446         win
.SetWrapMode(event
.IsChecked()) 
 447         wx
.FutureCall(1, self
.shell
.EnsureCaretVisible
) 
 449     def OnUseAA(self
, event
): 
 450         win 
= wx
.Window
.FindFocus() 
 451         win
.SetUseAntiAliasing(event
.IsChecked()) 
 453     def OnSaveHistory(self
, event
): 
 454         self
.autoSaveHistory 
= event
.IsChecked() 
 456     def OnSaveHistoryNow(self
, event
): 
 459     def OnClearHistory(self
, event
): 
 460         self
.shell
.clearHistory() 
 462     def OnAutoSaveSettings(self
, event
): 
 463         self
.autoSaveSettings 
= event
.IsChecked() 
 465     def OnSaveSettings(self
, event
): 
 466         self
.DoSaveSettings() 
 468     def OnDelSettingsFile(self
, event
): 
 469         if self
.config 
is not None: 
 470             d 
= wx
.MessageDialog( 
 471                 self
, "Do you want to revert to the default settings?\n" +  
 472                 "A restart is needed for the change to take effect", 
 473                 "Warning", wx
.OK | wx
.CANCEL | wx
.ICON_QUESTION
) 
 474             answer 
= d
.ShowModal() 
 476             if (answer 
== wx
.ID_OK
): 
 477                 self
.config
.DeleteAll() 
 481     def OnEditStartupScript(self
, event
): 
 482         if hasattr(self
, 'EditStartupScript'): 
 483             self
.EditStartupScript() 
 485     def OnExecStartupScript(self
, event
): 
 486         self
.execStartupScript 
= event
.IsChecked() 
 489     def OnFindText(self
, event
): 
 490         if self
.findDlg 
is not None: 
 492         win 
= wx
.Window
.FindFocus() 
 493         self
.findDlg 
= wx
.FindReplaceDialog(win
, self
.findData
, "Find", 
 497     def OnFindNext(self
, event
): 
 498         if not self
.findData
.GetFindString(): 
 499             self
.OnFindText(event
) 
 501         if isinstance(event
, wx
.FindDialogEvent
): 
 502             win 
= self
.findDlg
.GetParent() 
 504             win 
= wx
.Window
.FindFocus() 
 505         win
.DoFindNext(self
.findData
, self
.findDlg
) 
 506         if self
.findDlg 
is not None: 
 507             self
.OnFindClose(None) 
 509     def OnFindClose(self
, event
): 
 510         self
.findDlg
.Destroy() 
 515     def OnUpdateMenu(self
, event
): 
 516         """Update menu items based on current status and context.""" 
 517         win 
= wx
.Window
.FindFocus() 
 522                 event
.Enable(hasattr(self
, 'bufferNew')) 
 524                 event
.Enable(hasattr(self
, 'bufferOpen')) 
 525             elif id == ID_REVERT
: 
 526                 event
.Enable(hasattr(self
, 'bufferRevert') 
 527                              and self
.hasBuffer()) 
 529                 event
.Enable(hasattr(self
, 'bufferClose') 
 530                              and self
.hasBuffer()) 
 532                 event
.Enable(hasattr(self
, 'bufferSave') 
 533                              and self
.bufferHasChanged()) 
 534             elif id == ID_SAVEAS
: 
 535                 event
.Enable(hasattr(self
, 'bufferSaveAs') 
 536                              and self
.hasBuffer()) 
 537             elif id == ID_NAMESPACE
: 
 538                 event
.Enable(hasattr(self
, 'updateNamespace') 
 539                              and self
.hasBuffer()) 
 541                 event
.Enable(hasattr(self
, 'bufferPrint') 
 542                              and self
.hasBuffer()) 
 544                 event
.Enable(win
.CanUndo()) 
 546                 event
.Enable(win
.CanRedo()) 
 548                 event
.Enable(win
.CanCut()) 
 550                 event
.Enable(win
.CanCopy()) 
 551             elif id == ID_COPY_PLUS
: 
 552                 event
.Enable(win
.CanCopy() and hasattr(win
, 'CopyWithPrompts')) 
 554                 event
.Enable(win
.CanPaste()) 
 555             elif id == ID_PASTE_PLUS
: 
 556                 event
.Enable(win
.CanPaste() and hasattr(win
, 'PasteAndRun')) 
 558                 event
.Enable(win
.CanCut()) 
 559             elif id == ID_SELECTALL
: 
 560                 event
.Enable(hasattr(win
, 'SelectAll')) 
 561             elif id == ID_EMPTYBUFFER
: 
 562                 event
.Enable(hasattr(win
, 'ClearAll') and not win
.GetReadOnly()) 
 563             elif id == ID_AUTOCOMP_SHOW
: 
 564                 event
.Check(win
.autoComplete
) 
 565             elif id == ID_AUTOCOMP_MAGIC
: 
 566                 event
.Check(win
.autoCompleteIncludeMagic
) 
 567             elif id == ID_AUTOCOMP_SINGLE
: 
 568                 event
.Check(win
.autoCompleteIncludeSingle
) 
 569             elif id == ID_AUTOCOMP_DOUBLE
: 
 570                 event
.Check(win
.autoCompleteIncludeDouble
) 
 571             elif id == ID_CALLTIPS_SHOW
: 
 572                 event
.Check(win
.autoCallTip
) 
 573             elif id == ID_CALLTIPS_INSERT
: 
 574                 event
.Check(win
.callTipInsert
) 
 576                 event
.Check(win
.GetWrapMode()) 
 578                 event
.Check(win
.GetUseAntiAliasing()) 
 580             elif id == ID_SHOW_LINENUMBERS
: 
 581                 event
.Check(win
.lineNumbers
) 
 582             elif id == ID_AUTO_SAVESETTINGS
: 
 583                 event
.Check(self
.autoSaveSettings
) 
 584                 event
.Enable(self
.config 
is not None) 
 585             elif id == ID_SAVESETTINGS
: 
 586                 event
.Enable(self
.config 
is not None and 
 587                              hasattr(self
, 'DoSaveSettings')) 
 588             elif id == ID_DELSETTINGSFILE
: 
 589                 event
.Enable(self
.config 
is not None) 
 591             elif id == ID_EXECSTARTUPSCRIPT
: 
 592                 event
.Check(self
.execStartupScript
) 
 593                 event
.Enable(self
.config 
is not None) 
 595             elif id == ID_SAVEHISTORY
: 
 596                 event
.Check(self
.autoSaveHistory
) 
 597                 event
.Enable(self
.dataDir 
is not None) 
 598             elif id == ID_SAVEHISTORYNOW
: 
 599                 event
.Enable(self
.dataDir 
is not None and 
 600                              hasattr(self
, 'SaveHistory')) 
 601             elif id == ID_CLEARHISTORY
: 
 602                 event
.Enable(self
.dataDir 
is not None) 
 604             elif id == ID_EDITSTARTUPSCRIPT
: 
 605                 event
.Enable(hasattr(self
, 'EditStartupScript')) 
 606                 event
.Enable(self
.dataDir 
is not None) 
 609                 event
.Enable(hasattr(win
, 'DoFindNext')) 
 610             elif id == ID_FINDNEXT
: 
 611                 event
.Enable(hasattr(win
, 'DoFindNext')) 
 615         except AttributeError: 
 616             # This menu option is not supported in the current context. 
 620     def OnActivate(self
, event
): 
 622         Event Handler for losing the focus of the Frame. Should close 
 623         Autocomplete listbox, if shown. 
 625         if not event
.GetActive(): 
 626             # If autocomplete active, cancel it.  Otherwise, the 
 627             # autocomplete list will stay visible on top of the 
 628             # z-order after switching to another application 
 629             win 
= wx
.Window
.FindFocus() 
 630             if hasattr(win
, 'AutoCompActive') and win
.AutoCompActive(): 
 636     def LoadSettings(self
, config
): 
 637         """Called be derived classes to load settings specific to the Frame""" 
 638         pos  
= wx
.Point(config
.ReadInt('Window/PosX', -1), 
 639                         config
.ReadInt('Window/PosY', -1)) 
 641         size 
= wx
.Size(config
.ReadInt('Window/Width', -1), 
 642                        config
.ReadInt('Window/Height', -1)) 
 648     def SaveSettings(self
, config
): 
 649         """Called by derived classes to save Frame settings to a wx.Config object""" 
 651         # TODO: track position/size so we can save it even if the 
 652         # frame is maximized or iconized. 
 653         if not self
.iconized 
and not self
.IsMaximized(): 
 654             w
, h 
= self
.GetSize() 
 655             config
.WriteInt('Window/Width', w
) 
 656             config
.WriteInt('Window/Height', h
) 
 658             px
, py 
= self
.GetPosition() 
 659             config
.WriteInt('Window/PosX', px
) 
 660             config
.WriteInt('Window/PosY', py
) 
 665 class ShellFrameMixin
: 
 667     A mix-in class for frames that will have a Shell or a Crust window 
 668     and that want to add history, startupScript and other common 
 671     def __init__(self
, config
, dataDir
): 
 673         self
.dataDir 
= dataDir
 
 674         self
.startupScript 
= os
.environ
.get('PYTHONSTARTUP') 
 675         if not self
.startupScript 
and self
.dataDir
: 
 676             self
.startupScript 
= os
.path
.join(self
.dataDir
, 'startup') 
 678         self
.autoSaveSettings 
= False 
 679         self
.autoSaveHistory 
= False 
 681         # We need this one before we have a chance to load the settings... 
 682         self
.execStartupScript 
= True 
 684             self
.execStartupScript 
= self
.config
.ReadBool('Options/ExecStartupScript', True) 
 687     def OnHelp(self
, event
): 
 688         """Display a Help window.""" 
 689         import  wx
.lib
.dialogs
 
 690         title 
= 'Help on key bindings' 
 692         text 
= wx
.py
.shell
.HELP_TEXT
 
 694         dlg 
= wx
.lib
.dialogs
.ScrolledMessageDialog(self
, text
, title
, size 
= ((700, 540))) 
 695         fnt 
= wx
.Font(10, wx
.TELETYPE
, wx
.NORMAL
, wx
.NORMAL
) 
 696         dlg
.GetChildren()[0].SetFont(fnt
) 
 697         dlg
.GetChildren()[0].SetInsertionPoint(0) 
 702     def LoadSettings(self
): 
 703         if self
.config 
is not None: 
 704             self
.autoSaveSettings 
= self
.config
.ReadBool('Options/AutoSaveSettings', False) 
 705             self
.execStartupScript 
= self
.config
.ReadBool('Options/ExecStartupScript', True) 
 706             self
.autoSaveHistory  
= self
.config
.ReadBool('Options/AutoSaveHistory', False) 
 710     def SaveSettings(self
): 
 711         if self
.config 
is not None: 
 712             # always save this one 
 713             self
.config
.WriteBool('Options/AutoSaveSettings', self
.autoSaveSettings
) 
 714             if self
.autoSaveSettings
: 
 715                 self
.config
.WriteBool('Options/AutoSaveHistory', self
.autoSaveHistory
) 
 716                 self
.config
.WriteBool('Options/ExecStartupScript', self
.execStartupScript
) 
 717             if self
.autoSaveHistory
: 
 722     def SaveHistory(self
): 
 725                 name 
= os
.path
.join(self
.dataDir
, 'history') 
 727                 hist 
= '\x00\n'.join(self
.shell
.history
) 
 731                 d 
= wx
.MessageDialog(self
, "Error saving history file.", 
 732                                      "Error", wx
.ICON_EXCLAMATION
) 
 737     def LoadHistory(self
): 
 739             name 
= os
.path
.join(self
.dataDir
, 'history') 
 740             if os
.path
.exists(name
): 
 745                     self
.shell
.history 
= hist
.split('\x00\n') 
 746                     dispatcher
.send(signal
="Shell.loadHistory", history
=self
.shell
.history
) 
 748                     d 
= wx
.MessageDialog(self
, "Error loading history file.", 
 749                                          "Error", wx
.ICON_EXCLAMATION
) 
 754     def bufferHasChanged(self
): 
 755         # the shell buffers can always be saved 
 758     def bufferSave(self
): 
 760         appname 
= wx
.GetApp().GetAppName() 
 761         default 
= appname 
+ '-' + time
.strftime("%Y%m%d-%H%M.py") 
 762         fileName 
= wx
.FileSelector("Save File As", "Saving", 
 763                                   default_filename
=default
, 
 764                                   default_extension
="py", 
 766                                   flags 
= wx
.SAVE | wx
.OVERWRITE_PROMPT
) 
 770         text 
= self
.shell
.GetText() 
 772 ## This isn't working currently... 
 773 ##         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) 
 774 ##         yes_no = d.ShowModal() 
 775 ##         if yes_no == wx.ID_YES: 
 776 ##             m = re.findall('^[>\.]{3,3} (.*)\r', text, re.MULTILINE | re.LOCALE) 
 777 ##             text = '\n'.join(m) 
 781             f 
= open(fileName
, "w") 
 785             d 
= wx
.MessageDialog(self
, u
'Error saving session',u
'Error', 
 786                                  wx
.OK | wx
.ICON_ERROR
) 
 791     def EditStartupScript(self
): 
 792         if os
.path
.exists(self
.startupScript
): 
 793             text 
= file(self
.startupScript
, 'U').read() 
 797         dlg 
= EditStartupScriptDialog(self
, self
.startupScript
, text
) 
 798         if dlg
.ShowModal() == wx
.ID_OK
: 
 801                 f 
= file(self
.startupScript
, 'w') 
 805                 d 
= wx
.MessageDialog(self
, "Error saving startup file.", 
 806                                      "Error", wx
.ICON_EXCLAMATION
) 
 812 class EditStartupScriptDialog(wx
.Dialog
): 
 813     def __init__(self
, parent
, fileName
, text
): 
 814         wx
.Dialog
.__init
__(self
, parent
, size
=(425,350), 
 815                            title
="Edit Startup Script", 
 816                            style
=wx
.DEFAULT_DIALOG_STYLE|wx
.RESIZE_BORDER
) 
 818         pst 
= wx
.StaticText(self
, -1, "Path:") 
 819         ptx 
= wx
.TextCtrl(self
, -1, fileName
, style
=wx
.TE_READONLY
) 
 820         self
.editor 
= editwindow
.EditWindow(self
) 
 821         self
.editor
.SetText(text
) 
 822         wx
.CallAfter(self
.editor
.SetFocus
) 
 824         ok 
= wx
.Button(self
, wx
.ID_OK
) 
 825         cancel 
= wx
.Button(self
, wx
.ID_CANCEL
) 
 827         mainSizer 
= wx
.BoxSizer(wx
.VERTICAL
) 
 829         pthSizer 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 830         pthSizer
.Add(pst
, flag
=wx
.ALIGN_CENTER_VERTICAL
) 
 833         mainSizer
.Add(pthSizer
, 0, wx
.EXPAND|wx
.ALL
, 10) 
 835         mainSizer
.Add(self
.editor
, 1, wx
.EXPAND|wx
.LEFT|wx
.RIGHT
, 10) 
 837         btnSizer 
= wx
.BoxSizer(wx
.HORIZONTAL
) 
 838         btnSizer
.Add((5,5), 1) 
 840         btnSizer
.Add((5,5), 1) 
 842         btnSizer
.Add((5,5), 1) 
 843         mainSizer
.Add(btnSizer
, 0, wx
.EXPAND|wx
.ALL
, 10) 
 845         self
.SetSizer(mainSizer
) 
 850         return self
.editor
.GetText()