1 """Base frame with menu."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __revision__
= "$Revision$"[11:-2]
9 from version
import VERSION
14 ID_REVERT
= wx
.ID_REVERT
15 ID_CLOSE
= wx
.ID_CLOSE
17 ID_SAVEAS
= wx
.ID_SAVEAS
18 ID_PRINT
= wx
.ID_PRINT
24 ID_PASTE
= wx
.ID_PASTE
25 ID_CLEAR
= wx
.ID_CLEAR
26 ID_SELECTALL
= wx
.ID_SELECTALL
27 ID_EMPTYBUFFER
= wx
.NewId()
28 ID_ABOUT
= wx
.ID_ABOUT
30 ID_AUTOCOMP
= wx
.NewId()
31 ID_AUTOCOMP_SHOW
= wx
.NewId()
32 ID_AUTOCOMP_MAGIC
= wx
.NewId()
33 ID_AUTOCOMP_SINGLE
= wx
.NewId()
34 ID_AUTOCOMP_DOUBLE
= wx
.NewId()
35 ID_CALLTIPS
= wx
.NewId()
36 ID_CALLTIPS_SHOW
= wx
.NewId()
37 ID_CALLTIPS_INSERT
= wx
.NewId()
38 ID_COPY_PLUS
= wx
.NewId()
39 ID_NAMESPACE
= wx
.NewId()
40 ID_PASTE_PLUS
= wx
.NewId()
42 ID_TOGGLE_MAXIMIZE
= wx
.NewId()
44 ID_SHOW_LINENUMBERS
= wx
.NewId()
45 ID_AUTO_SAVESETTINGS
= wx
.NewId()
46 ID_SAVEHISTORY
= wx
.NewId()
47 ID_SAVESETTINGS
= wx
.NewId()
48 ID_DELSETTINGSFILE
= wx
.NewId()
49 ID_EDITSTARTUPSCRIPT
= wx
.NewId()
50 ID_EXECSTARTUPSCRIPT
= wx
.NewId()
51 ID_STARTUP
= wx
.NewId()
52 ID_SETTINGS
= wx
.NewId()
54 ID_FINDNEXT
= wx
.NewId()
58 class Frame(wx
.Frame
):
59 """Frame with standard menu items."""
61 revision
= __revision__
63 def __init__(self
, parent
=None, id=-1, title
='Editor',
64 pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,
65 style
=wx
.DEFAULT_FRAME_STYLE
):
66 """Create a Frame instance."""
67 wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
68 self
.CreateStatusBar()
69 self
.SetStatusText('Frame')
71 self
.SetIcon(images
.getPyIcon())
76 self
.findData
= wx
.FindReplaceData()
77 self
.findData
.SetFlags(wx
.FR_DOWN
)
79 self
.Bind(wx
.EVT_CLOSE
, self
.OnClose
)
80 self
.Bind(wx
.EVT_ICONIZE
, self
.OnIconize
)
83 def OnIconize(self
, event
):
84 """Event handler for Iconize."""
85 self
.iconized
= event
.Iconized()
88 def OnClose(self
, event
):
89 """Event handler for closing."""
93 def __createMenus(self
):
95 m
= self
.fileMenu
= wx
.Menu()
96 m
.Append(ID_NEW
, '&New \tCtrl+N',
98 m
.Append(ID_OPEN
, '&Open... \tCtrl+O',
101 m
.Append(ID_REVERT
, '&Revert \tCtrl+R',
102 'Revert to last saved version')
103 m
.Append(ID_CLOSE
, '&Close \tCtrl+W',
106 m
.Append(ID_SAVE
, '&Save... \tCtrl+S',
108 m
.Append(ID_SAVEAS
, 'Save &As \tCtrl+Shift+S',
109 'Save file with new name')
111 m
.Append(ID_PRINT
, '&Print... \tCtrl+P',
114 m
.Append(ID_NAMESPACE
, '&Update Namespace \tCtrl+Shift+N',
115 'Update namespace for autocompletion and calltips')
117 m
.Append(ID_EXIT
, 'E&xit\tCtrl+Q', 'Exit Program')
120 m
= self
.editMenu
= wx
.Menu()
121 m
.Append(ID_UNDO
, '&Undo \tCtrl+Z',
122 'Undo the last action')
123 m
.Append(ID_REDO
, '&Redo \tCtrl+Y',
124 'Redo the last undone action')
126 m
.Append(ID_CUT
, 'Cu&t \tCtrl+X',
128 m
.Append(ID_COPY
, '&Copy \tCtrl+C',
129 'Copy the selection')
130 m
.Append(ID_COPY_PLUS
, 'Cop&y Plus \tCtrl+Shift+C',
131 'Copy the selection - retaining prompts')
132 m
.Append(ID_PASTE
, '&Paste \tCtrl+V', 'Paste from clipboard')
133 m
.Append(ID_PASTE_PLUS
, 'Past&e Plus \tCtrl+Shift+V',
134 'Paste and run commands')
136 m
.Append(ID_CLEAR
, 'Cle&ar',
137 'Delete the selection')
138 m
.Append(ID_SELECTALL
, 'Select A&ll \tCtrl+A',
141 m
.Append(ID_EMPTYBUFFER
, 'E&mpty Buffer',
142 'Delete all the contents of the edit buffer')
143 m
.Append(ID_FIND
, '&Find Text \tCtrl+F',
144 'Search for text in the edit buffer')
145 m
.Append(ID_FINDNEXT
, 'Find &Next \tF3',
146 'Find next/previous instance of the search text')
149 m
= self
.viewMenu
= wx
.Menu()
150 m
.Append(ID_WRAP
, '&Wrap Lines\tCtrl+Shift+W',
151 'Wrap lines at right edge', wx
.ITEM_CHECK
)
152 m
.Append(ID_SHOW_LINENUMBERS
, '&Show Line Numbers\tCtrl+Shift+L', 'Show Line Numbers', wx
.ITEM_CHECK
)
153 m
.Append(ID_TOGGLE_MAXIMIZE
, '&Toggle Maximize\tF11', 'Maximize/Restore Application')
156 m
= self
.autocompMenu
= wx
.Menu()
157 m
.Append(ID_AUTOCOMP_SHOW
, 'Show &Auto Completion\tCtrl+Shift+A',
158 'Show auto completion list', wx
.ITEM_CHECK
)
159 m
.Append(ID_AUTOCOMP_MAGIC
, 'Include &Magic Attributes\tCtrl+Shift+M',
160 'Include attributes visible to __getattr__ and __setattr__',
162 m
.Append(ID_AUTOCOMP_SINGLE
, 'Include Single &Underscores\tCtrl+Shift+U',
163 'Include attibutes prefixed by a single underscore', wx
.ITEM_CHECK
)
164 m
.Append(ID_AUTOCOMP_DOUBLE
, 'Include &Double Underscores\tCtrl+Shift+D',
165 'Include attibutes prefixed by a double underscore', wx
.ITEM_CHECK
)
166 m
= self
.calltipsMenu
= wx
.Menu()
167 m
.Append(ID_CALLTIPS_SHOW
, 'Show Call &Tips\tCtrl+Shift+T',
168 'Show call tips with argument signature and docstring', wx
.ITEM_CHECK
)
169 m
.Append(ID_CALLTIPS_INSERT
, '&Insert Call Tips\tCtrl+Shift+I',
170 '&Insert Call Tips', wx
.ITEM_CHECK
)
172 m
= self
.optionsMenu
= wx
.Menu()
173 m
.AppendMenu(ID_AUTOCOMP
, '&Auto Completion', self
.autocompMenu
,
174 'Auto Completion Options')
175 m
.AppendMenu(ID_CALLTIPS
, '&Call Tips', self
.calltipsMenu
,
178 if wx
.Platform
== "__WXMAC__":
179 m
.Append(ID_USEAA
, '&Use AntiAliasing',
180 'Use anti-aliased fonts', wx
.ITEM_CHECK
)
183 m
.Append(ID_SAVEHISTORY
, '&Save History',
184 'Automatically save history on close', wx
.ITEM_CHECK
)
185 self
.startupMenu
= wx
.Menu()
186 self
.startupMenu
.Append(ID_EXECSTARTUPSCRIPT
,
187 'E&xecute Startup Script',
188 'Execute Startup Script', wx
.ITEM_CHECK
)
189 self
.startupMenu
.Append(ID_EDITSTARTUPSCRIPT
,
190 '&Edit Startup Script',
191 'Edit Startup Script')
192 m
.AppendMenu(ID_STARTUP
, '&Startup', self
.startupMenu
, 'Startup Options')
194 self
.settingsMenu
= wx
.Menu()
195 self
.settingsMenu
.Append(ID_AUTO_SAVESETTINGS
,
196 '&Auto Save Settings',
197 'Automatically save settings on close', wx
.ITEM_CHECK
)
198 self
.settingsMenu
.Append(ID_SAVESETTINGS
,
201 self
.settingsMenu
.Append(ID_DELSETTINGSFILE
,
202 '&Revert to default',
203 'Revert to the default settings')
204 m
.AppendMenu(ID_SETTINGS
, '&Settings', self
.settingsMenu
, 'Settings Options')
206 m
= self
.helpMenu
= wx
.Menu()
207 m
.Append(ID_HELP
, '&Help\tF1', 'Help!')
209 m
.Append(ID_ABOUT
, '&About...', 'About this program')
211 b
= self
.menuBar
= wx
.MenuBar()
212 b
.Append(self
.fileMenu
, '&File')
213 b
.Append(self
.editMenu
, '&Edit')
214 b
.Append(self
.viewMenu
, '&View')
215 b
.Append(self
.optionsMenu
, '&Options')
216 b
.Append(self
.helpMenu
, '&Help')
219 self
.Bind(wx
.EVT_MENU
, self
.OnFileNew
, id=ID_NEW
)
220 self
.Bind(wx
.EVT_MENU
, self
.OnFileOpen
, id=ID_OPEN
)
221 self
.Bind(wx
.EVT_MENU
, self
.OnFileRevert
, id=ID_REVERT
)
222 self
.Bind(wx
.EVT_MENU
, self
.OnFileClose
, id=ID_CLOSE
)
223 self
.Bind(wx
.EVT_MENU
, self
.OnFileSave
, id=ID_SAVE
)
224 self
.Bind(wx
.EVT_MENU
, self
.OnFileSaveAs
, id=ID_SAVEAS
)
225 self
.Bind(wx
.EVT_MENU
, self
.OnFileUpdateNamespace
, id=ID_NAMESPACE
)
226 self
.Bind(wx
.EVT_MENU
, self
.OnFilePrint
, id=ID_PRINT
)
227 self
.Bind(wx
.EVT_MENU
, self
.OnExit
, id=ID_EXIT
)
228 self
.Bind(wx
.EVT_MENU
, self
.OnUndo
, id=ID_UNDO
)
229 self
.Bind(wx
.EVT_MENU
, self
.OnRedo
, id=ID_REDO
)
230 self
.Bind(wx
.EVT_MENU
, self
.OnCut
, id=ID_CUT
)
231 self
.Bind(wx
.EVT_MENU
, self
.OnCopy
, id=ID_COPY
)
232 self
.Bind(wx
.EVT_MENU
, self
.OnCopyPlus
, id=ID_COPY_PLUS
)
233 self
.Bind(wx
.EVT_MENU
, self
.OnPaste
, id=ID_PASTE
)
234 self
.Bind(wx
.EVT_MENU
, self
.OnPastePlus
, id=ID_PASTE_PLUS
)
235 self
.Bind(wx
.EVT_MENU
, self
.OnClear
, id=ID_CLEAR
)
236 self
.Bind(wx
.EVT_MENU
, self
.OnSelectAll
, id=ID_SELECTALL
)
237 self
.Bind(wx
.EVT_MENU
, self
.OnEmptyBuffer
, id=ID_EMPTYBUFFER
)
238 self
.Bind(wx
.EVT_MENU
, self
.OnAbout
, id=ID_ABOUT
)
239 self
.Bind(wx
.EVT_MENU
, self
.OnHelp
, id=ID_HELP
)
240 self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteShow
, id=ID_AUTOCOMP_SHOW
)
241 self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteMagic
, id=ID_AUTOCOMP_MAGIC
)
242 self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteSingle
, id=ID_AUTOCOMP_SINGLE
)
243 self
.Bind(wx
.EVT_MENU
, self
.OnAutoCompleteDouble
, id=ID_AUTOCOMP_DOUBLE
)
244 self
.Bind(wx
.EVT_MENU
, self
.OnCallTipsShow
, id=ID_CALLTIPS_SHOW
)
245 self
.Bind(wx
.EVT_MENU
, self
.OnCallTipsInsert
, id=ID_CALLTIPS_INSERT
)
246 self
.Bind(wx
.EVT_MENU
, self
.OnWrap
, id=ID_WRAP
)
247 self
.Bind(wx
.EVT_MENU
, self
.OnUseAA
, id=ID_USEAA
)
248 self
.Bind(wx
.EVT_MENU
, self
.OnToggleMaximize
, id=ID_TOGGLE_MAXIMIZE
)
249 self
.Bind(wx
.EVT_MENU
, self
.OnShowLineNumbers
, id=ID_SHOW_LINENUMBERS
)
250 self
.Bind(wx
.EVT_MENU
, self
.OnAutoSaveSettings
, id=ID_AUTO_SAVESETTINGS
)
251 self
.Bind(wx
.EVT_MENU
, self
.OnSaveHistory
, id=ID_SAVEHISTORY
)
252 self
.Bind(wx
.EVT_MENU
, self
.OnSaveSettings
, id=ID_SAVESETTINGS
)
253 self
.Bind(wx
.EVT_MENU
, self
.OnDelSettingsFile
, id=ID_DELSETTINGSFILE
)
254 self
.Bind(wx
.EVT_MENU
, self
.OnEditStartupScript
, id=ID_EDITSTARTUPSCRIPT
)
255 self
.Bind(wx
.EVT_MENU
, self
.OnExecStartupScript
, id=ID_EXECSTARTUPSCRIPT
)
256 self
.Bind(wx
.EVT_MENU
, self
.OnFindText
, id=ID_FIND
)
257 self
.Bind(wx
.EVT_MENU
, self
.OnFindNext
, id=ID_FINDNEXT
)
259 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_NEW
)
260 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_OPEN
)
261 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_REVERT
)
262 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CLOSE
)
263 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVE
)
264 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVEAS
)
265 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_NAMESPACE
)
266 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_PRINT
)
267 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_UNDO
)
268 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_REDO
)
269 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CUT
)
270 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_COPY
)
271 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_COPY_PLUS
)
272 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_PASTE
)
273 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_PASTE_PLUS
)
274 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CLEAR
)
275 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SELECTALL
)
276 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_EMPTYBUFFER
)
277 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_SHOW
)
278 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_MAGIC
)
279 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_SINGLE
)
280 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTOCOMP_DOUBLE
)
281 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CALLTIPS_SHOW
)
282 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_CALLTIPS_INSERT
)
283 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_WRAP
)
284 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_USEAA
)
285 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SHOW_LINENUMBERS
)
286 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_AUTO_SAVESETTINGS
)
287 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVESETTINGS
)
288 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_DELSETTINGSFILE
)
289 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_EXECSTARTUPSCRIPT
)
290 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_SAVEHISTORY
)
291 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_EDITSTARTUPSCRIPT
)
292 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_FIND
)
293 self
.Bind(wx
.EVT_UPDATE_UI
, self
.OnUpdateMenu
, id=ID_FINDNEXT
)
295 self
.Bind(wx
.EVT_ACTIVATE
, self
.OnActivate
)
296 self
.Bind(wx
.EVT_FIND
, self
.OnFindNext
)
297 self
.Bind(wx
.EVT_FIND_NEXT
, self
.OnFindNext
)
298 self
.Bind(wx
.EVT_FIND_CLOSE
, self
.OnFindClose
)
302 def OnShowLineNumbers(self
, event
):
303 win
= wx
.Window
.FindFocus()
304 if hasattr(win
, 'lineNumbers'):
305 win
.lineNumbers
= event
.IsChecked()
306 win
.setDisplayLineNumbers(win
.lineNumbers
)
308 def OnToggleMaximize(self
, event
):
309 self
.Maximize(not self
.IsMaximized())
311 def OnFileNew(self
, event
):
314 def OnFileOpen(self
, event
):
317 def OnFileRevert(self
, event
):
320 def OnFileClose(self
, event
):
323 def OnFileSave(self
, event
):
326 def OnFileSaveAs(self
, event
):
329 def OnFileUpdateNamespace(self
, event
):
330 self
.updateNamespace()
332 def OnFilePrint(self
, event
):
335 def OnExit(self
, event
):
338 def OnUndo(self
, event
):
339 win
= wx
.Window
.FindFocus()
342 def OnRedo(self
, event
):
343 win
= wx
.Window
.FindFocus()
346 def OnCut(self
, event
):
347 win
= wx
.Window
.FindFocus()
350 def OnCopy(self
, event
):
351 win
= wx
.Window
.FindFocus()
354 def OnCopyPlus(self
, event
):
355 win
= wx
.Window
.FindFocus()
356 win
.CopyWithPrompts()
358 def OnPaste(self
, event
):
359 win
= wx
.Window
.FindFocus()
362 def OnPastePlus(self
, event
):
363 win
= wx
.Window
.FindFocus()
366 def OnClear(self
, event
):
367 win
= wx
.Window
.FindFocus()
370 def OnEmptyBuffer(self
, event
):
371 win
= wx
.Window
.FindFocus()
372 d
= wx
.MessageDialog(self
,
373 "Are you sure you want to clear the edit buffer,\n"
374 "deleting all the text?",
375 "Empty Buffer", wx
.OK | wx
.CANCEL | wx
.ICON_QUESTION
)
376 answer
= d
.ShowModal()
378 if (answer
== wx
.ID_OK
):
380 if hasattr(win
,'prompt'):
383 def OnSelectAll(self
, event
):
384 win
= wx
.Window
.FindFocus()
387 def OnAbout(self
, event
):
388 """Display an About window."""
390 text
= 'Your message here.'
391 dialog
= wx
.MessageDialog(self
, text
, title
,
392 wx
.OK | wx
.ICON_INFORMATION
)
396 def OnHelp(self
, event
):
397 """Display a Help window."""
399 text
= "Type 'shell.help()' in the shell window."
400 dialog
= wx
.MessageDialog(self
, text
, title
,
401 wx
.OK | wx
.ICON_INFORMATION
)
405 def OnAutoCompleteShow(self
, event
):
406 win
= wx
.Window
.FindFocus()
407 win
.autoComplete
= event
.IsChecked()
409 def OnAutoCompleteMagic(self
, event
):
410 win
= wx
.Window
.FindFocus()
411 win
.autoCompleteIncludeMagic
= event
.IsChecked()
413 def OnAutoCompleteSingle(self
, event
):
414 win
= wx
.Window
.FindFocus()
415 win
.autoCompleteIncludeSingle
= event
.IsChecked()
417 def OnAutoCompleteDouble(self
, event
):
418 win
= wx
.Window
.FindFocus()
419 win
.autoCompleteIncludeDouble
= event
.IsChecked()
421 def OnCallTipsShow(self
, event
):
422 win
= wx
.Window
.FindFocus()
423 win
.autoCallTip
= event
.IsChecked()
425 def OnCallTipsInsert(self
, event
):
426 win
= wx
.Window
.FindFocus()
427 win
.callTipInsert
= event
.IsChecked()
429 def OnWrap(self
, event
):
430 win
= wx
.Window
.FindFocus()
431 win
.SetWrapMode(event
.IsChecked())
432 wx
.FutureCall(1, self
.shell
.EnsureCaretVisible
)
434 def OnUseAA(self
, event
):
435 win
= wx
.Window
.FindFocus()
436 win
.SetUseAntiAliasing(event
.IsChecked())
438 def OnSaveHistory(self
, event
):
439 self
.saveHistory
= event
.IsChecked()
441 def OnAutoSaveSettings(self
, event
):
442 self
.autoSaveSettings
= event
.IsChecked()
444 def OnSaveSettings(self
, event
):
445 self
.DoSaveSettings()
447 def OnDelSettingsFile(self
, event
):
448 if self
.config
is not None:
449 d
= wx
.MessageDialog(
450 self
, "Do you want to revert to the default settings?\n" +
451 "A restart is needed for the change to take effect",
452 "Warning", wx
.OK | wx
.CANCEL | wx
.ICON_QUESTION
)
453 answer
= d
.ShowModal()
455 if (answer
== wx
.ID_OK
):
456 self
.config
.DeleteAll()
460 def OnEditStartupScript(self
, event
):
461 if hasattr(self
, 'EditStartupScript'):
462 self
.EditStartupScript()
464 def OnExecStartupScript(self
, event
):
465 self
.execStartupScript
= event
.IsChecked()
468 def OnFindText(self
, event
):
469 if self
.findDlg
is not None:
471 win
= wx
.Window
.FindFocus()
472 self
.findDlg
= wx
.FindReplaceDialog(win
, self
.findData
, "Find",
476 def OnFindNext(self
, event
):
477 if isinstance(event
, wx
.FindDialogEvent
):
478 win
= self
.findDlg
.GetParent()
480 win
= wx
.Window
.FindFocus()
481 win
.DoFindNext(self
.findData
, self
.findDlg
)
483 def OnFindClose(self
, event
):
484 self
.findDlg
.Destroy()
489 def OnUpdateMenu(self
, event
):
490 """Update menu items based on current status and context."""
491 win
= wx
.Window
.FindFocus()
496 event
.Enable(hasattr(self
, 'bufferNew'))
498 event
.Enable(hasattr(self
, 'bufferOpen'))
499 elif id == ID_REVERT
:
500 event
.Enable(hasattr(self
, 'bufferRevert')
501 and self
.hasBuffer())
503 event
.Enable(hasattr(self
, 'bufferClose')
504 and self
.hasBuffer())
506 event
.Enable(hasattr(self
, 'bufferSave')
507 and self
.bufferHasChanged())
508 elif id == ID_SAVEAS
:
509 event
.Enable(hasattr(self
, 'bufferSaveAs')
510 and self
.hasBuffer())
511 elif id == ID_NAMESPACE
:
512 event
.Enable(hasattr(self
, 'updateNamespace')
513 and self
.hasBuffer())
515 event
.Enable(hasattr(self
, 'bufferPrint')
516 and self
.hasBuffer())
518 event
.Enable(win
.CanUndo())
520 event
.Enable(win
.CanRedo())
522 event
.Enable(win
.CanCut())
524 event
.Enable(win
.CanCopy())
525 elif id == ID_COPY_PLUS
:
526 event
.Enable(win
.CanCopy() and hasattr(win
, 'CopyWithPrompts'))
528 event
.Enable(win
.CanPaste())
529 elif id == ID_PASTE_PLUS
:
530 event
.Enable(win
.CanPaste() and hasattr(win
, 'PasteAndRun'))
532 event
.Enable(win
.CanCut())
533 elif id == ID_SELECTALL
:
534 event
.Enable(hasattr(win
, 'SelectAll'))
535 elif id == ID_EMPTYBUFFER
:
536 event
.Enable(hasattr(win
, 'ClearAll') and not win
.GetReadOnly())
537 elif id == ID_AUTOCOMP_SHOW
:
538 event
.Check(win
.autoComplete
)
539 elif id == ID_AUTOCOMP_MAGIC
:
540 event
.Check(win
.autoCompleteIncludeMagic
)
541 elif id == ID_AUTOCOMP_SINGLE
:
542 event
.Check(win
.autoCompleteIncludeSingle
)
543 elif id == ID_AUTOCOMP_DOUBLE
:
544 event
.Check(win
.autoCompleteIncludeDouble
)
545 elif id == ID_CALLTIPS_SHOW
:
546 event
.Check(win
.autoCallTip
)
547 elif id == ID_CALLTIPS_INSERT
:
548 event
.Check(win
.callTipInsert
)
550 event
.Check(win
.GetWrapMode())
552 event
.Check(win
.GetUseAntiAliasing())
554 elif id == ID_SHOW_LINENUMBERS
:
555 event
.Check(win
.lineNumbers
)
556 elif id == ID_AUTO_SAVESETTINGS
:
557 event
.Check(self
.autoSaveSettings
)
558 event
.Enable(self
.config
is not None)
559 elif id == ID_SAVESETTINGS
:
560 event
.Enable(self
.config
is not None and
561 hasattr(self
, 'DoSaveSettings'))
562 elif id == ID_DELSETTINGSFILE
:
563 event
.Enable(self
.config
is not None)
565 elif id == ID_EXECSTARTUPSCRIPT
:
566 event
.Check(self
.execStartupScript
)
567 event
.Enable(self
.config
is not None)
569 elif id == ID_SAVEHISTORY
:
570 event
.Check(self
.saveHistory
)
571 event
.Enable(self
.dataDir
is not None)
572 elif id == ID_EDITSTARTUPSCRIPT
:
573 event
.Enable(hasattr(self
, 'EditStartupScript'))
574 event
.Enable(self
.dataDir
is not None)
577 event
.Enable(hasattr(win
, 'DoFindNext'))
578 elif id == ID_FINDNEXT
:
579 event
.Enable(hasattr(win
, 'DoFindNext') and
580 self
.findData
.GetFindString() != '')
584 except AttributeError:
585 # This menu option is not supported in the current context.
589 def OnActivate(self
, event
):
591 Event Handler for losing the focus of the Frame. Should close
592 Autocomplete listbox, if shown.
594 if not event
.GetActive():
595 # If autocomplete active, cancel it. Otherwise, the
596 # autocomplete list will stay visible on top of the
597 # z-order after switching to another application
598 win
= wx
.Window
.FindFocus()
599 if hasattr(win
, 'AutoCompActive') and win
.AutoCompActive():
605 def LoadSettings(self
, config
):
606 """Called be derived classes to load settings specific to the Frame"""
607 pos
= wx
.Point(config
.ReadInt('Window/PosX', -1),
608 config
.ReadInt('Window/PosY', -1))
610 size
= wx
.Size(config
.ReadInt('Window/Width', -1),
611 config
.ReadInt('Window/Height', -1))
617 def SaveSettings(self
, config
):
618 """Called by derived classes to save Frame settings to a wx.Config object"""
620 # TODO: track position/size so we can save it even if the
621 # frame is maximized or iconized.
622 if not self
.iconized
and not self
.IsMaximized():
623 w
, h
= self
.GetSize()
624 config
.WriteInt('Window/Width', w
)
625 config
.WriteInt('Window/Height', h
)
627 px
, py
= self
.GetPosition()
628 config
.WriteInt('Window/PosX', px
)
629 config
.WriteInt('Window/PosY', py
)
634 class ShellFrameMixin
:
636 A mix-in class for frames that will have a Shell or a Crust window
637 and that want to add history, startupScript and other common
640 def __init__(self
, config
, dataDir
):
642 self
.dataDir
= dataDir
643 self
.startupScript
= os
.environ
.get('PYTHONSTARTUP')
644 if not self
.startupScript
and self
.dataDir
:
645 self
.startupScript
= os
.path
.join(self
.dataDir
, 'startup')
647 self
.autoSaveSettings
= False
648 self
.saveHistory
= False
650 # We need this one before we have a chance to load the settings...
651 self
.execStartupScript
= True
653 self
.execStartupScript
= self
.config
.ReadBool('Options/ExecStartupScript', True)
656 def OnHelp(self
, event
):
657 """Display a Help window."""
658 import wx
.lib
.dialogs
659 title
= 'Help on key bindings'
661 text
= wx
.py
.shell
.HELP_TEXT
663 dlg
= wx
.lib
.dialogs
.ScrolledMessageDialog(self
, text
, title
, size
= ((700, 540)))
664 fnt
= wx
.Font(10, wx
.TELETYPE
, wx
.NORMAL
, wx
.NORMAL
)
665 dlg
.GetChildren()[0].SetFont(fnt
)
666 dlg
.GetChildren()[0].SetInsertionPoint(0)
671 def LoadSettings(self
):
672 if self
.config
is not None:
673 self
.autoSaveSettings
= self
.config
.ReadBool('Options/AutoSaveSettings', False)
674 self
.execStartupScript
= self
.config
.ReadBool('Options/ExecStartupScript', True)
675 self
.saveHistory
= self
.config
.ReadBool('Options/SaveHistory', False)
679 def SaveSettings(self
):
680 if self
.config
is not None:
681 # always save this one
682 self
.config
.WriteBool('Options/AutoSaveSettings', self
.autoSaveSettings
)
683 if self
.autoSaveSettings
:
684 self
.config
.WriteBool('Options/SaveHistory', self
.saveHistory
)
685 self
.config
.WriteBool('Options/ExecStartupScript', self
.execStartupScript
)
690 def SaveHistory(self
):
693 # always open the file so that when we are not
694 # saving the history, the old file is emptied.
695 name
= os
.path
.join(self
.dataDir
, 'history')
698 hist
= '\n'.join(self
.shell
.history
)
702 d
= wx
.MessageDialog(self
, "Error saving history file.",
703 "Error", wx
.ICON_EXCLAMATION
)
708 def LoadHistory(self
):
710 name
= os
.path
.join(self
.dataDir
, 'history')
711 if os
.path
.exists(name
):
716 self
.shell
.history
= hist
.split('\n')
718 d
= wx
.MessageDialog(self
, "Error loading history file.",
719 "Error", wx
.ICON_EXCLAMATION
)
724 def bufferHasChanged(self
):
725 # the shell buffers can always be saved
728 def bufferSave(self
):
730 appname
= wx
.GetApp().GetAppName()
731 default
= appname
+ '-' + time
.strftime("%Y%m%d-%H%M.py")
732 fileName
= wx
.FileSelector("Save File As", "Saving",
733 default_filename
=default
,
734 default_extension
="py",
736 flags
= wx
.SAVE | wx
.OVERWRITE_PROMPT
)
740 text
= self
.shell
.GetText()
742 ## This isn't working currently...
743 ## 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)
744 ## yes_no = d.ShowModal()
745 ## if yes_no == wx.ID_YES:
746 ## m = re.findall('^[>\.]{3,3} (.*)\r', text, re.MULTILINE | re.LOCALE)
747 ## text = '\n'.join(m)
751 f
= open(fileName
, "w")
755 d
= wx
.MessageDialog(self
, u
'Error saving session',u
'Error',
756 wx
.OK | wx
.ICON_ERROR
)
761 def EditStartupScript(self
):
762 if os
.path
.exists(self
.startupScript
):
763 text
= file(self
.startupScript
, 'U').read()
767 dlg
= EditStartupScriptDialog(self
, self
.startupScript
, text
)
768 if dlg
.ShowModal() == wx
.ID_OK
:
771 f
= file(self
.startupScript
, 'w')
775 d
= wx
.MessageDialog(self
, "Error saving startup file.",
776 "Error", wx
.ICON_EXCLAMATION
)
782 class EditStartupScriptDialog(wx
.Dialog
):
783 def __init__(self
, parent
, fileName
, text
):
784 wx
.Dialog
.__init
__(self
, parent
, size
=(425,350),
785 title
="Edit Startup Script",
786 style
=wx
.DEFAULT_DIALOG_STYLE|wx
.RESIZE_BORDER
)
788 pst
= wx
.StaticText(self
, -1, "Path:")
789 ptx
= wx
.TextCtrl(self
, -1, fileName
, style
=wx
.TE_READONLY
)
790 self
.editor
= editwindow
.EditWindow(self
)
791 self
.editor
.SetText(text
)
792 wx
.CallAfter(self
.editor
.SetFocus
)
794 ok
= wx
.Button(self
, wx
.ID_OK
)
795 cancel
= wx
.Button(self
, wx
.ID_CANCEL
)
797 mainSizer
= wx
.BoxSizer(wx
.VERTICAL
)
799 pthSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
800 pthSizer
.Add(pst
, flag
=wx
.ALIGN_CENTER_VERTICAL
)
803 mainSizer
.Add(pthSizer
, 0, wx
.EXPAND|wx
.ALL
, 10)
805 mainSizer
.Add(self
.editor
, 1, wx
.EXPAND|wx
.LEFT|wx
.RIGHT
, 10)
807 btnSizer
= wx
.BoxSizer(wx
.HORIZONTAL
)
808 btnSizer
.Add((5,5), 1)
810 btnSizer
.Add((5,5), 1)
812 btnSizer
.Add((5,5), 1)
813 mainSizer
.Add(btnSizer
, 0, wx
.EXPAND|wx
.ALL
, 10)
815 self
.SetSizer(mainSizer
)
820 return self
.editor
.GetText()