1 """Base frame with menu."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __revision__
= "$Revision$"[11:-2]
8 from version
import VERSION
18 ID_REVERT
= wx
.ID_REVERT
19 ID_CLOSE
= wx
.ID_CLOSE
21 ID_SAVEAS
= wx
.ID_SAVEAS
22 ID_PRINT
= wx
.ID_PRINT
28 ID_PASTE
= wx
.ID_PASTE
29 ID_CLEAR
= wx
.ID_CLEAR
30 ID_SELECTALL
= wx
.ID_SELECTALL
31 ID_ABOUT
= wx
.ID_ABOUT
32 ID_AUTOCOMP
= wx
.NewId()
33 ID_AUTOCOMP_SHOW
= wx
.NewId()
34 ID_AUTOCOMP_MAGIC
= wx
.NewId()
35 ID_AUTOCOMP_SINGLE
= wx
.NewId()
36 ID_AUTOCOMP_DOUBLE
= wx
.NewId()
37 ID_CALLTIPS
= wx
.NewId()
38 ID_CALLTIPS_SHOW
= wx
.NewId()
39 ID_COPY_PLUS
= wx
.NewId()
40 ID_NAMESPACE
= wx
.NewId()
41 ID_PASTE_PLUS
= wx
.NewId()
45 class Frame(wx
.Frame
):
46 """Frame with standard menu items."""
48 revision
= __revision__
50 def __init__(self
, parent
=None, id=-1, title
='Editor',
51 pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,
52 style
=wx
.DEFAULT_FRAME_STYLE
):
53 """Create a Frame instance."""
54 wx
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
55 self
.CreateStatusBar()
56 self
.SetStatusText('Frame')
58 self
.SetIcon(images
.getPyIcon())
60 wx
.EVT_CLOSE(self
, self
.OnClose
)
62 def OnClose(self
, event
):
63 """Event handler for closing."""
66 def __createMenus(self
):
67 m
= self
.fileMenu
= wx
.Menu()
68 m
.Append(ID_NEW
, '&New \tCtrl+N',
70 m
.Append(ID_OPEN
, '&Open... \tCtrl+O',
73 m
.Append(ID_REVERT
, '&Revert \tCtrl+R',
74 'Revert to last saved version')
75 m
.Append(ID_CLOSE
, '&Close \tCtrl+W',
78 m
.Append(ID_SAVE
, '&Save... \tCtrl+S',
80 m
.Append(ID_SAVEAS
, 'Save &As \tShift+Ctrl+S',
81 'Save file with new name')
83 m
.Append(ID_PRINT
, '&Print... \tCtrl+P',
86 m
.Append(ID_NAMESPACE
, '&Update Namespace \tShift+Ctrl+N',
87 'Update namespace for autocompletion and calltips')
89 m
.Append(ID_EXIT
, 'E&xit', 'Exit Program')
91 m
= self
.editMenu
= wx
.Menu()
92 m
.Append(ID_UNDO
, '&Undo \tCtrl+Z',
93 'Undo the last action')
94 m
.Append(ID_REDO
, '&Redo \tCtrl+Y',
95 'Redo the last undone action')
97 m
.Append(ID_CUT
, 'Cu&t \tCtrl+X',
99 m
.Append(ID_COPY
, '&Copy \tCtrl+C',
100 'Copy the selection')
101 m
.Append(ID_COPY_PLUS
, 'Cop&y Plus \tShift+Ctrl+C',
102 'Copy the selection - retaining prompts')
103 m
.Append(ID_PASTE
, '&Paste \tCtrl+V', 'Paste from clipboard')
104 m
.Append(ID_PASTE_PLUS
, 'Past&e Plus \tShift+Ctrl+V',
105 'Paste and run commands')
107 m
.Append(ID_CLEAR
, 'Cle&ar',
108 'Delete the selection')
109 m
.Append(ID_SELECTALL
, 'Select A&ll \tCtrl+A',
112 m
= self
.autocompMenu
= wx
.Menu()
113 m
.Append(ID_AUTOCOMP_SHOW
, 'Show Auto Completion',
114 'Show auto completion list', 1)
115 m
.Append(ID_AUTOCOMP_MAGIC
, 'Include Magic Attributes',
116 'Include attributes visible to __getattr__ and __setattr__',
118 m
.Append(ID_AUTOCOMP_SINGLE
, 'Include Single Underscores',
119 'Include attibutes prefixed by a single underscore', 1)
120 m
.Append(ID_AUTOCOMP_DOUBLE
, 'Include Double Underscores',
121 'Include attibutes prefixed by a double underscore', 1)
123 m
= self
.calltipsMenu
= wx
.Menu()
124 m
.Append(ID_CALLTIPS_SHOW
, 'Show Call Tips',
125 'Show call tips with argument signature and docstring', 1)
127 m
= self
.optionsMenu
= wx
.Menu()
128 m
.AppendMenu(ID_AUTOCOMP
, '&Auto Completion', self
.autocompMenu
,
129 'Auto Completion Options')
130 m
.AppendMenu(ID_CALLTIPS
, '&Call Tips', self
.calltipsMenu
,
132 m
.Append(ID_WRAP
, '&Wrap Lines',
133 'Wrap lines at right edge', 1)
135 m
= self
.helpMenu
= wx
.Menu()
137 m
.Append(ID_ABOUT
, '&About...', 'About this program')
139 b
= self
.menuBar
= wx
.MenuBar()
140 b
.Append(self
.fileMenu
, '&File')
141 b
.Append(self
.editMenu
, '&Edit')
142 b
.Append(self
.optionsMenu
, '&Options')
143 b
.Append(self
.helpMenu
, '&Help')
146 wx
.EVT_MENU(self
, ID_NEW
, self
.OnFileNew
)
147 wx
.EVT_MENU(self
, ID_OPEN
, self
.OnFileOpen
)
148 wx
.EVT_MENU(self
, ID_REVERT
, self
.OnFileRevert
)
149 wx
.EVT_MENU(self
, ID_CLOSE
, self
.OnFileClose
)
150 wx
.EVT_MENU(self
, ID_SAVE
, self
.OnFileSave
)
151 wx
.EVT_MENU(self
, ID_SAVEAS
, self
.OnFileSaveAs
)
152 wx
.EVT_MENU(self
, ID_NAMESPACE
, self
.OnFileUpdateNamespace
)
153 wx
.EVT_MENU(self
, ID_PRINT
, self
.OnFilePrint
)
154 wx
.EVT_MENU(self
, ID_EXIT
, self
.OnExit
)
155 wx
.EVT_MENU(self
, ID_UNDO
, self
.OnUndo
)
156 wx
.EVT_MENU(self
, ID_REDO
, self
.OnRedo
)
157 wx
.EVT_MENU(self
, ID_CUT
, self
.OnCut
)
158 wx
.EVT_MENU(self
, ID_COPY
, self
.OnCopy
)
159 wx
.EVT_MENU(self
, ID_COPY_PLUS
, self
.OnCopyPlus
)
160 wx
.EVT_MENU(self
, ID_PASTE
, self
.OnPaste
)
161 wx
.EVT_MENU(self
, ID_PASTE_PLUS
, self
.OnPastePlus
)
162 wx
.EVT_MENU(self
, ID_CLEAR
, self
.OnClear
)
163 wx
.EVT_MENU(self
, ID_SELECTALL
, self
.OnSelectAll
)
164 wx
.EVT_MENU(self
, ID_ABOUT
, self
.OnAbout
)
165 wx
.EVT_MENU(self
, ID_AUTOCOMP_SHOW
, self
.OnAutoCompleteShow
)
166 wx
.EVT_MENU(self
, ID_AUTOCOMP_MAGIC
, self
.OnAutoCompleteMagic
)
167 wx
.EVT_MENU(self
, ID_AUTOCOMP_SINGLE
, self
.OnAutoCompleteSingle
)
168 wx
.EVT_MENU(self
, ID_AUTOCOMP_DOUBLE
, self
.OnAutoCompleteDouble
)
169 wx
.EVT_MENU(self
, ID_CALLTIPS_SHOW
, self
.OnCallTipsShow
)
170 wx
.EVT_MENU(self
, ID_WRAP
, self
.OnWrap
)
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
)
196 def OnFileNew(self
, event
):
199 def OnFileOpen(self
, event
):
202 def OnFileRevert(self
, event
):
205 def OnFileClose(self
, event
):
208 def OnFileSave(self
, event
):
211 def OnFileSaveAs(self
, event
):
214 def OnFileUpdateNamespace(self
, event
):
215 self
.updateNamespace()
217 def OnFilePrint(self
, event
):
220 def OnExit(self
, event
):
223 def OnUndo(self
, event
):
224 win
= wx
.Window_FindFocus()
227 def OnRedo(self
, event
):
228 win
= wx
.Window_FindFocus()
231 def OnCut(self
, event
):
232 win
= wx
.Window_FindFocus()
235 def OnCopy(self
, event
):
236 win
= wx
.Window_FindFocus()
239 def OnCopyPlus(self
, event
):
240 win
= wx
.Window_FindFocus()
241 win
.CopyWithPrompts()
243 def OnPaste(self
, event
):
244 win
= wx
.Window_FindFocus()
247 def OnPastePlus(self
, event
):
248 win
= wx
.Window_FindFocus()
251 def OnClear(self
, event
):
252 win
= wx
.Window_FindFocus()
255 def OnSelectAll(self
, event
):
256 win
= wx
.Window_FindFocus()
259 def OnAbout(self
, event
):
260 """Display an About window."""
262 text
= 'Your message here.'
263 dialog
= wx
.MessageDialog(self
, text
, title
,
264 wx
.OK | wx
.ICON_INFORMATION
)
268 def OnAutoCompleteShow(self
, event
):
269 win
= wx
.Window_FindFocus()
270 win
.autoComplete
= event
.IsChecked()
272 def OnAutoCompleteMagic(self
, event
):
273 win
= wx
.Window_FindFocus()
274 win
.autoCompleteIncludeMagic
= event
.IsChecked()
276 def OnAutoCompleteSingle(self
, event
):
277 win
= wx
.Window_FindFocus()
278 win
.autoCompleteIncludeSingle
= event
.IsChecked()
280 def OnAutoCompleteDouble(self
, event
):
281 win
= wx
.Window_FindFocus()
282 win
.autoCompleteIncludeDouble
= event
.IsChecked()
284 def OnCallTipsShow(self
, event
):
285 win
= wx
.Window_FindFocus()
286 win
.autoCallTip
= event
.IsChecked()
288 def OnWrap(self
, event
):
289 win
= wx
.Window_FindFocus()
290 win
.SetWrapMode(event
.IsChecked())
292 def OnUpdateMenu(self
, event
):
293 """Update menu items based on current status and context."""
294 win
= wx
.Window_FindFocus()
299 event
.Enable(hasattr(self
, 'bufferNew'))
301 event
.Enable(hasattr(self
, 'bufferOpen'))
302 elif id == ID_REVERT
:
303 event
.Enable(hasattr(self
, 'bufferRevert')
304 and self
.hasBuffer())
306 event
.Enable(hasattr(self
, 'bufferClose')
307 and self
.hasBuffer())
309 event
.Enable(hasattr(self
, 'bufferSave')
310 and self
.bufferHasChanged())
311 elif id == ID_SAVEAS
:
312 event
.Enable(hasattr(self
, 'bufferSaveAs')
313 and self
.hasBuffer())
314 elif id == ID_NAMESPACE
:
315 event
.Enable(hasattr(self
, 'updateNamespace')
316 and self
.hasBuffer())
318 event
.Enable(hasattr(self
, 'bufferPrint')
319 and self
.hasBuffer())
321 event
.Enable(win
.CanUndo())
323 event
.Enable(win
.CanRedo())
325 event
.Enable(win
.CanCut())
327 event
.Enable(win
.CanCopy())
328 elif id == ID_COPY_PLUS
:
329 event
.Enable(win
.CanCopy() and hasattr(win
, 'CopyWithPrompts'))
331 event
.Enable(win
.CanPaste())
332 elif id == ID_PASTE_PLUS
:
333 event
.Enable(win
.CanPaste() and hasattr(win
, 'PasteAndRun'))
335 event
.Enable(win
.CanCut())
336 elif id == ID_SELECTALL
:
337 event
.Enable(hasattr(win
, 'SelectAll'))
338 elif id == ID_AUTOCOMP_SHOW
:
339 event
.Check(win
.autoComplete
)
340 elif id == ID_AUTOCOMP_MAGIC
:
341 event
.Check(win
.autoCompleteIncludeMagic
)
342 elif id == ID_AUTOCOMP_SINGLE
:
343 event
.Check(win
.autoCompleteIncludeSingle
)
344 elif id == ID_AUTOCOMP_DOUBLE
:
345 event
.Check(win
.autoCompleteIncludeDouble
)
346 elif id == ID_CALLTIPS_SHOW
:
347 event
.Check(win
.autoCallTip
)
349 event
.Check(win
.GetWrapMode())
352 except AttributeError:
353 # This menu option is not supported in the current context.