1 """Base frame with menu.""" 
   3 __author__ 
= "Patrick K. O'Brien <pobrien@orbtech.com>" 
   5 __revision__ 
= "$Revision$"[11:-2] 
   8 from version 
import VERSION
 
  13 ID_REVERT 
= wx
.ID_REVERT
 
  14 ID_CLOSE 
= wx
.ID_CLOSE
 
  16 ID_SAVEAS 
= wx
.ID_SAVEAS
 
  17 ID_PRINT 
= wx
.ID_PRINT
 
  23 ID_PASTE 
= wx
.ID_PASTE
 
  24 ID_CLEAR 
= wx
.ID_CLEAR
 
  25 ID_SELECTALL 
= wx
.ID_SELECTALL
 
  26 ID_ABOUT 
= wx
.ID_ABOUT
 
  27 ID_AUTOCOMP 
= wx
.NewId() 
  28 ID_AUTOCOMP_SHOW 
= wx
.NewId() 
  29 ID_AUTOCOMP_MAGIC 
= wx
.NewId() 
  30 ID_AUTOCOMP_SINGLE 
= wx
.NewId() 
  31 ID_AUTOCOMP_DOUBLE 
= wx
.NewId() 
  32 ID_CALLTIPS 
= wx
.NewId() 
  33 ID_CALLTIPS_SHOW 
= wx
.NewId() 
  34 ID_COPY_PLUS 
= wx
.NewId() 
  35 ID_NAMESPACE 
= wx
.NewId() 
  36 ID_PASTE_PLUS 
= wx
.NewId() 
  41 class Frame(wx
.Frame
): 
  42     """Frame with standard menu items.""" 
  44     revision 
= __revision__
 
  46     def __init__(self
, parent
=None, id=-1, title
='Editor', 
  47                  pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,  
  48                  style
=wx
.DEFAULT_FRAME_STYLE
): 
  49         """Create a Frame instance.""" 
  50         wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
) 
  51         self
.CreateStatusBar() 
  52         self
.SetStatusText('Frame') 
  54         self
.SetIcon(images
.getPyIcon()) 
  56         wx
.EVT_CLOSE(self
, self
.OnClose
) 
  58     def OnClose(self
, event
): 
  59         """Event handler for closing.""" 
  62     def __createMenus(self
): 
  63         m 
= self
.fileMenu 
= wx
.Menu() 
  64         m
.Append(ID_NEW
, '&New \tCtrl+N', 
  66         m
.Append(ID_OPEN
, '&Open... \tCtrl+O', 
  69         m
.Append(ID_REVERT
, '&Revert \tCtrl+R', 
  70                  'Revert to last saved version') 
  71         m
.Append(ID_CLOSE
, '&Close \tCtrl+W', 
  74         m
.Append(ID_SAVE
, '&Save... \tCtrl+S', 
  76         m
.Append(ID_SAVEAS
, 'Save &As \tShift+Ctrl+S', 
  77                  'Save file with new name') 
  79         m
.Append(ID_PRINT
, '&Print... \tCtrl+P', 
  82         m
.Append(ID_NAMESPACE
, '&Update Namespace \tShift+Ctrl+N', 
  83                  'Update namespace for autocompletion and calltips') 
  85         m
.Append(ID_EXIT
, 'E&xit', 'Exit Program') 
  87         m 
= self
.editMenu 
= wx
.Menu() 
  88         m
.Append(ID_UNDO
, '&Undo \tCtrl+Z', 
  89                  'Undo the last action') 
  90         m
.Append(ID_REDO
, '&Redo \tCtrl+Y', 
  91                  'Redo the last undone action') 
  93         m
.Append(ID_CUT
, 'Cu&t \tCtrl+X', 
  95         m
.Append(ID_COPY
, '&Copy \tCtrl+C', 
  97         m
.Append(ID_COPY_PLUS
, 'Cop&y Plus \tShift+Ctrl+C', 
  98                  'Copy the selection - retaining prompts') 
  99         m
.Append(ID_PASTE
, '&Paste \tCtrl+V', 'Paste from clipboard') 
 100         m
.Append(ID_PASTE_PLUS
, 'Past&e Plus \tShift+Ctrl+V', 
 101                  'Paste and run commands') 
 103         m
.Append(ID_CLEAR
, 'Cle&ar', 
 104                  'Delete the selection') 
 105         m
.Append(ID_SELECTALL
, 'Select A&ll \tCtrl+A', 
 108         m 
= self
.autocompMenu 
= wx
.Menu() 
 109         m
.Append(ID_AUTOCOMP_SHOW
, 'Show Auto Completion', 
 110                  'Show auto completion list', wx
.ITEM_CHECK
) 
 111         m
.Append(ID_AUTOCOMP_MAGIC
, 'Include Magic Attributes', 
 112                  'Include attributes visible to __getattr__ and __setattr__', 
 114         m
.Append(ID_AUTOCOMP_SINGLE
, 'Include Single Underscores', 
 115                  'Include attibutes prefixed by a single underscore', wx
.ITEM_CHECK
) 
 116         m
.Append(ID_AUTOCOMP_DOUBLE
, 'Include Double Underscores', 
 117                  'Include attibutes prefixed by a double underscore', wx
.ITEM_CHECK
) 
 119         m 
= self
.calltipsMenu 
= wx
.Menu() 
 120         m
.Append(ID_CALLTIPS_SHOW
, 'Show Call Tips', 
 121                  'Show call tips with argument signature and docstring', wx
.ITEM_CHECK
) 
 123         m 
= self
.optionsMenu 
= wx
.Menu() 
 124         m
.AppendMenu(ID_AUTOCOMP
, '&Auto Completion', self
.autocompMenu
, 
 125                      'Auto Completion Options') 
 126         m
.AppendMenu(ID_CALLTIPS
, '&Call Tips', self
.calltipsMenu
, 
 128         m
.Append(ID_WRAP
, '&Wrap Lines', 
 129                  'Wrap lines at right edge', wx
.ITEM_CHECK
) 
 130         if wx
.Platform 
== "__WXMAC__": 
 131             m
.Append(ID_USEAA
, '&Use AntiAliasing', 
 132                      'Use anti-aliased fonts', wx
.ITEM_CHECK
) 
 134         m 
= self
.helpMenu 
= wx
.Menu() 
 136         m
.Append(ID_ABOUT
, '&About...', 'About this program') 
 138         b 
= self
.menuBar 
= wx
.MenuBar() 
 139         b
.Append(self
.fileMenu
, '&File') 
 140         b
.Append(self
.editMenu
, '&Edit') 
 141         b
.Append(self
.optionsMenu
, '&Options') 
 142         b
.Append(self
.helpMenu
, '&Help') 
 145         wx
.EVT_MENU(self
, ID_NEW
, self
.OnFileNew
) 
 146         wx
.EVT_MENU(self
, ID_OPEN
, self
.OnFileOpen
) 
 147         wx
.EVT_MENU(self
, ID_REVERT
, self
.OnFileRevert
) 
 148         wx
.EVT_MENU(self
, ID_CLOSE
, self
.OnFileClose
) 
 149         wx
.EVT_MENU(self
, ID_SAVE
, self
.OnFileSave
) 
 150         wx
.EVT_MENU(self
, ID_SAVEAS
, self
.OnFileSaveAs
) 
 151         wx
.EVT_MENU(self
, ID_NAMESPACE
, self
.OnFileUpdateNamespace
) 
 152         wx
.EVT_MENU(self
, ID_PRINT
, self
.OnFilePrint
) 
 153         wx
.EVT_MENU(self
, ID_EXIT
, self
.OnExit
) 
 154         wx
.EVT_MENU(self
, ID_UNDO
, self
.OnUndo
) 
 155         wx
.EVT_MENU(self
, ID_REDO
, self
.OnRedo
) 
 156         wx
.EVT_MENU(self
, ID_CUT
, self
.OnCut
) 
 157         wx
.EVT_MENU(self
, ID_COPY
, self
.OnCopy
) 
 158         wx
.EVT_MENU(self
, ID_COPY_PLUS
, self
.OnCopyPlus
) 
 159         wx
.EVT_MENU(self
, ID_PASTE
, self
.OnPaste
) 
 160         wx
.EVT_MENU(self
, ID_PASTE_PLUS
, self
.OnPastePlus
) 
 161         wx
.EVT_MENU(self
, ID_CLEAR
, self
.OnClear
) 
 162         wx
.EVT_MENU(self
, ID_SELECTALL
, self
.OnSelectAll
) 
 163         wx
.EVT_MENU(self
, ID_ABOUT
, self
.OnAbout
) 
 164         wx
.EVT_MENU(self
, ID_AUTOCOMP_SHOW
, self
.OnAutoCompleteShow
) 
 165         wx
.EVT_MENU(self
, ID_AUTOCOMP_MAGIC
, self
.OnAutoCompleteMagic
) 
 166         wx
.EVT_MENU(self
, ID_AUTOCOMP_SINGLE
, self
.OnAutoCompleteSingle
) 
 167         wx
.EVT_MENU(self
, ID_AUTOCOMP_DOUBLE
, self
.OnAutoCompleteDouble
) 
 168         wx
.EVT_MENU(self
, ID_CALLTIPS_SHOW
, self
.OnCallTipsShow
) 
 169         wx
.EVT_MENU(self
, ID_WRAP
, self
.OnWrap
) 
 170         wx
.EVT_MENU(self
, ID_USEAA
, self
.OnUseAA
) 
 172         wx
.EVT_UPDATE_UI(self
, ID_NEW
, self
.OnUpdateMenu
) 
 173         wx
.EVT_UPDATE_UI(self
, ID_OPEN
, self
.OnUpdateMenu
) 
 174         wx
.EVT_UPDATE_UI(self
, ID_REVERT
, self
.OnUpdateMenu
) 
 175         wx
.EVT_UPDATE_UI(self
, ID_CLOSE
, self
.OnUpdateMenu
) 
 176         wx
.EVT_UPDATE_UI(self
, ID_SAVE
, self
.OnUpdateMenu
) 
 177         wx
.EVT_UPDATE_UI(self
, ID_SAVEAS
, self
.OnUpdateMenu
) 
 178         wx
.EVT_UPDATE_UI(self
, ID_NAMESPACE
, self
.OnUpdateMenu
) 
 179         wx
.EVT_UPDATE_UI(self
, ID_PRINT
, self
.OnUpdateMenu
) 
 180         wx
.EVT_UPDATE_UI(self
, ID_UNDO
, self
.OnUpdateMenu
) 
 181         wx
.EVT_UPDATE_UI(self
, ID_REDO
, self
.OnUpdateMenu
) 
 182         wx
.EVT_UPDATE_UI(self
, ID_CUT
, self
.OnUpdateMenu
) 
 183         wx
.EVT_UPDATE_UI(self
, ID_COPY
, self
.OnUpdateMenu
) 
 184         wx
.EVT_UPDATE_UI(self
, ID_COPY_PLUS
, self
.OnUpdateMenu
) 
 185         wx
.EVT_UPDATE_UI(self
, ID_PASTE
, self
.OnUpdateMenu
) 
 186         wx
.EVT_UPDATE_UI(self
, ID_PASTE_PLUS
, self
.OnUpdateMenu
) 
 187         wx
.EVT_UPDATE_UI(self
, ID_CLEAR
, self
.OnUpdateMenu
) 
 188         wx
.EVT_UPDATE_UI(self
, ID_SELECTALL
, self
.OnUpdateMenu
) 
 189         wx
.EVT_UPDATE_UI(self
, ID_AUTOCOMP_SHOW
, self
.OnUpdateMenu
) 
 190         wx
.EVT_UPDATE_UI(self
, ID_AUTOCOMP_MAGIC
, self
.OnUpdateMenu
) 
 191         wx
.EVT_UPDATE_UI(self
, ID_AUTOCOMP_SINGLE
, self
.OnUpdateMenu
) 
 192         wx
.EVT_UPDATE_UI(self
, ID_AUTOCOMP_DOUBLE
, self
.OnUpdateMenu
) 
 193         wx
.EVT_UPDATE_UI(self
, ID_CALLTIPS_SHOW
, self
.OnUpdateMenu
) 
 194         wx
.EVT_UPDATE_UI(self
, ID_WRAP
, self
.OnUpdateMenu
) 
 195         wx
.EVT_UPDATE_UI(self
, ID_USEAA
, self
.OnUpdateMenu
) 
 197     def OnFileNew(self
, event
): 
 200     def OnFileOpen(self
, event
): 
 203     def OnFileRevert(self
, event
): 
 206     def OnFileClose(self
, event
): 
 209     def OnFileSave(self
, event
): 
 212     def OnFileSaveAs(self
, event
): 
 215     def OnFileUpdateNamespace(self
, event
): 
 216         self
.updateNamespace() 
 218     def OnFilePrint(self
, event
): 
 221     def OnExit(self
, event
): 
 224     def OnUndo(self
, event
): 
 225         win 
= wx
.Window_FindFocus() 
 228     def OnRedo(self
, event
): 
 229         win 
= wx
.Window_FindFocus() 
 232     def OnCut(self
, event
): 
 233         win 
= wx
.Window_FindFocus() 
 236     def OnCopy(self
, event
): 
 237         win 
= wx
.Window_FindFocus() 
 240     def OnCopyPlus(self
, event
): 
 241         win 
= wx
.Window_FindFocus() 
 242         win
.CopyWithPrompts() 
 244     def OnPaste(self
, event
): 
 245         win 
= wx
.Window_FindFocus() 
 248     def OnPastePlus(self
, event
): 
 249         win 
= wx
.Window_FindFocus() 
 252     def OnClear(self
, event
): 
 253         win 
= wx
.Window_FindFocus() 
 256     def OnSelectAll(self
, event
): 
 257         win 
= wx
.Window_FindFocus() 
 260     def OnAbout(self
, event
): 
 261         """Display an About window.""" 
 263         text 
= 'Your message here.' 
 264         dialog 
= wx
.MessageDialog(self
, text
, title
, 
 265                                   wx
.OK | wx
.ICON_INFORMATION
) 
 269     def OnAutoCompleteShow(self
, event
): 
 270         win 
= wx
.Window_FindFocus() 
 271         win
.autoComplete 
= event
.IsChecked() 
 273     def OnAutoCompleteMagic(self
, event
): 
 274         win 
= wx
.Window_FindFocus() 
 275         win
.autoCompleteIncludeMagic 
= event
.IsChecked() 
 277     def OnAutoCompleteSingle(self
, event
): 
 278         win 
= wx
.Window_FindFocus() 
 279         win
.autoCompleteIncludeSingle 
= event
.IsChecked() 
 281     def OnAutoCompleteDouble(self
, event
): 
 282         win 
= wx
.Window_FindFocus() 
 283         win
.autoCompleteIncludeDouble 
= event
.IsChecked() 
 285     def OnCallTipsShow(self
, event
): 
 286         win 
= wx
.Window_FindFocus() 
 287         win
.autoCallTip 
= event
.IsChecked() 
 289     def OnWrap(self
, event
): 
 290         win 
= wx
.Window_FindFocus() 
 291         win
.SetWrapMode(event
.IsChecked()) 
 293     def OnUseAA(self
, event
): 
 294         win 
= wx
.Window_FindFocus() 
 295         win
.SetUseAntiAliasing(event
.IsChecked()) 
 298     def OnUpdateMenu(self
, event
): 
 299         """Update menu items based on current status and context.""" 
 300         win 
= wx
.Window_FindFocus() 
 305                 event
.Enable(hasattr(self
, 'bufferNew')) 
 307                 event
.Enable(hasattr(self
, 'bufferOpen')) 
 308             elif id == ID_REVERT
: 
 309                 event
.Enable(hasattr(self
, 'bufferRevert') 
 310                              and self
.hasBuffer()) 
 312                 event
.Enable(hasattr(self
, 'bufferClose') 
 313                              and self
.hasBuffer()) 
 315                 event
.Enable(hasattr(self
, 'bufferSave') 
 316                              and self
.bufferHasChanged()) 
 317             elif id == ID_SAVEAS
: 
 318                 event
.Enable(hasattr(self
, 'bufferSaveAs') 
 319                              and self
.hasBuffer()) 
 320             elif id == ID_NAMESPACE
: 
 321                 event
.Enable(hasattr(self
, 'updateNamespace') 
 322                              and self
.hasBuffer()) 
 324                 event
.Enable(hasattr(self
, 'bufferPrint') 
 325                              and self
.hasBuffer()) 
 327                 event
.Enable(win
.CanUndo()) 
 329                 event
.Enable(win
.CanRedo()) 
 331                 event
.Enable(win
.CanCut()) 
 333                 event
.Enable(win
.CanCopy()) 
 334             elif id == ID_COPY_PLUS
: 
 335                 event
.Enable(win
.CanCopy() and hasattr(win
, 'CopyWithPrompts')) 
 337                 event
.Enable(win
.CanPaste()) 
 338             elif id == ID_PASTE_PLUS
: 
 339                 event
.Enable(win
.CanPaste() and hasattr(win
, 'PasteAndRun')) 
 341                 event
.Enable(win
.CanCut()) 
 342             elif id == ID_SELECTALL
: 
 343                 event
.Enable(hasattr(win
, 'SelectAll')) 
 344             elif id == ID_AUTOCOMP_SHOW
: 
 345                 event
.Check(win
.autoComplete
) 
 346             elif id == ID_AUTOCOMP_MAGIC
: 
 347                 event
.Check(win
.autoCompleteIncludeMagic
) 
 348             elif id == ID_AUTOCOMP_SINGLE
: 
 349                 event
.Check(win
.autoCompleteIncludeSingle
) 
 350             elif id == ID_AUTOCOMP_DOUBLE
: 
 351                 event
.Check(win
.autoCompleteIncludeDouble
) 
 352             elif id == ID_CALLTIPS_SHOW
: 
 353                 event
.Check(win
.autoCallTip
) 
 355                 event
.Check(win
.GetWrapMode()) 
 357                 event
.Check(win
.GetUseAntiAliasing()) 
 360         except AttributeError: 
 361             # This menu option is not supported in the current context.