]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/py/frame.py
Fix test broken by change in package name from PyCrust to py.
[wxWidgets.git] / wxPython / wx / py / frame.py
CommitLineData
d14a1e28 1"""Base frame with menu."""
1fded56b 2
d14a1e28
RD
3__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4__cvsid__ = "$Id$"
5__revision__ = "$Revision$"[11:-2]
1fded56b 6
d14a1e28
RD
7import wx
8from version import VERSION
9
d14a1e28
RD
10
11ID_NEW = wx.ID_NEW
12ID_OPEN = wx.ID_OPEN
13ID_REVERT = wx.ID_REVERT
14ID_CLOSE = wx.ID_CLOSE
15ID_SAVE = wx.ID_SAVE
16ID_SAVEAS = wx.ID_SAVEAS
17ID_PRINT = wx.ID_PRINT
18ID_EXIT = wx.ID_EXIT
19ID_UNDO = wx.ID_UNDO
20ID_REDO = wx.ID_REDO
21ID_CUT = wx.ID_CUT
22ID_COPY = wx.ID_COPY
23ID_PASTE = wx.ID_PASTE
24ID_CLEAR = wx.ID_CLEAR
25ID_SELECTALL = wx.ID_SELECTALL
26ID_ABOUT = wx.ID_ABOUT
27ID_AUTOCOMP = wx.NewId()
28ID_AUTOCOMP_SHOW = wx.NewId()
29ID_AUTOCOMP_MAGIC = wx.NewId()
30ID_AUTOCOMP_SINGLE = wx.NewId()
31ID_AUTOCOMP_DOUBLE = wx.NewId()
32ID_CALLTIPS = wx.NewId()
33ID_CALLTIPS_SHOW = wx.NewId()
34ID_COPY_PLUS = wx.NewId()
35ID_NAMESPACE = wx.NewId()
36ID_PASTE_PLUS = wx.NewId()
37ID_WRAP = wx.NewId()
38
39
40class Frame(wx.Frame):
41 """Frame with standard menu items."""
42
43 revision = __revision__
44
45 def __init__(self, parent=None, id=-1, title='Editor',
46 pos=wx.DefaultPosition, size=wx.DefaultSize,
47 style=wx.DEFAULT_FRAME_STYLE):
48 """Create a Frame instance."""
49 wx.Frame.__init__(self, parent, id, title, pos, size, style)
50 self.CreateStatusBar()
51 self.SetStatusText('Frame')
52 import images
53 self.SetIcon(images.getPyIcon())
54 self.__createMenus()
55 wx.EVT_CLOSE(self, self.OnClose)
56
57 def OnClose(self, event):
58 """Event handler for closing."""
59 self.Destroy()
60
61 def __createMenus(self):
62 m = self.fileMenu = wx.Menu()
63 m.Append(ID_NEW, '&New \tCtrl+N',
64 'New file')
65 m.Append(ID_OPEN, '&Open... \tCtrl+O',
66 'Open file')
67 m.AppendSeparator()
68 m.Append(ID_REVERT, '&Revert \tCtrl+R',
69 'Revert to last saved version')
70 m.Append(ID_CLOSE, '&Close \tCtrl+W',
71 'Close file')
72 m.AppendSeparator()
73 m.Append(ID_SAVE, '&Save... \tCtrl+S',
74 'Save file')
75 m.Append(ID_SAVEAS, 'Save &As \tShift+Ctrl+S',
76 'Save file with new name')
77 m.AppendSeparator()
78 m.Append(ID_PRINT, '&Print... \tCtrl+P',
79 'Print file')
80 m.AppendSeparator()
81 m.Append(ID_NAMESPACE, '&Update Namespace \tShift+Ctrl+N',
82 'Update namespace for autocompletion and calltips')
83 m.AppendSeparator()
84 m.Append(ID_EXIT, 'E&xit', 'Exit Program')
85
86 m = self.editMenu = wx.Menu()
87 m.Append(ID_UNDO, '&Undo \tCtrl+Z',
88 'Undo the last action')
89 m.Append(ID_REDO, '&Redo \tCtrl+Y',
90 'Redo the last undone action')
91 m.AppendSeparator()
92 m.Append(ID_CUT, 'Cu&t \tCtrl+X',
93 'Cut the selection')
94 m.Append(ID_COPY, '&Copy \tCtrl+C',
95 'Copy the selection')
96 m.Append(ID_COPY_PLUS, 'Cop&y Plus \tShift+Ctrl+C',
97 'Copy the selection - retaining prompts')
98 m.Append(ID_PASTE, '&Paste \tCtrl+V', 'Paste from clipboard')
99 m.Append(ID_PASTE_PLUS, 'Past&e Plus \tShift+Ctrl+V',
100 'Paste and run commands')
101 m.AppendSeparator()
102 m.Append(ID_CLEAR, 'Cle&ar',
103 'Delete the selection')
104 m.Append(ID_SELECTALL, 'Select A&ll \tCtrl+A',
105 'Select all text')
106
107 m = self.autocompMenu = wx.Menu()
108 m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion',
109 'Show auto completion list', 1)
110 m.Append(ID_AUTOCOMP_MAGIC, 'Include Magic Attributes',
111 'Include attributes visible to __getattr__ and __setattr__',
112 1)
113 m.Append(ID_AUTOCOMP_SINGLE, 'Include Single Underscores',
114 'Include attibutes prefixed by a single underscore', 1)
115 m.Append(ID_AUTOCOMP_DOUBLE, 'Include Double Underscores',
116 'Include attibutes prefixed by a double underscore', 1)
117
118 m = self.calltipsMenu = wx.Menu()
119 m.Append(ID_CALLTIPS_SHOW, 'Show Call Tips',
120 'Show call tips with argument signature and docstring', 1)
121
122 m = self.optionsMenu = wx.Menu()
123 m.AppendMenu(ID_AUTOCOMP, '&Auto Completion', self.autocompMenu,
124 'Auto Completion Options')
125 m.AppendMenu(ID_CALLTIPS, '&Call Tips', self.calltipsMenu,
126 'Call Tip Options')
127 m.Append(ID_WRAP, '&Wrap Lines',
128 'Wrap lines at right edge', 1)
129
130 m = self.helpMenu = wx.Menu()
131 m.AppendSeparator()
132 m.Append(ID_ABOUT, '&About...', 'About this program')
133
134 b = self.menuBar = wx.MenuBar()
135 b.Append(self.fileMenu, '&File')
136 b.Append(self.editMenu, '&Edit')
137 b.Append(self.optionsMenu, '&Options')
138 b.Append(self.helpMenu, '&Help')
139 self.SetMenuBar(b)
140
141 wx.EVT_MENU(self, ID_NEW, self.OnFileNew)
142 wx.EVT_MENU(self, ID_OPEN, self.OnFileOpen)
143 wx.EVT_MENU(self, ID_REVERT, self.OnFileRevert)
144 wx.EVT_MENU(self, ID_CLOSE, self.OnFileClose)
145 wx.EVT_MENU(self, ID_SAVE, self.OnFileSave)
146 wx.EVT_MENU(self, ID_SAVEAS, self.OnFileSaveAs)
147 wx.EVT_MENU(self, ID_NAMESPACE, self.OnFileUpdateNamespace)
148 wx.EVT_MENU(self, ID_PRINT, self.OnFilePrint)
149 wx.EVT_MENU(self, ID_EXIT, self.OnExit)
150 wx.EVT_MENU(self, ID_UNDO, self.OnUndo)
151 wx.EVT_MENU(self, ID_REDO, self.OnRedo)
152 wx.EVT_MENU(self, ID_CUT, self.OnCut)
153 wx.EVT_MENU(self, ID_COPY, self.OnCopy)
154 wx.EVT_MENU(self, ID_COPY_PLUS, self.OnCopyPlus)
155 wx.EVT_MENU(self, ID_PASTE, self.OnPaste)
156 wx.EVT_MENU(self, ID_PASTE_PLUS, self.OnPastePlus)
157 wx.EVT_MENU(self, ID_CLEAR, self.OnClear)
158 wx.EVT_MENU(self, ID_SELECTALL, self.OnSelectAll)
159 wx.EVT_MENU(self, ID_ABOUT, self.OnAbout)
160 wx.EVT_MENU(self, ID_AUTOCOMP_SHOW, self.OnAutoCompleteShow)
161 wx.EVT_MENU(self, ID_AUTOCOMP_MAGIC, self.OnAutoCompleteMagic)
162 wx.EVT_MENU(self, ID_AUTOCOMP_SINGLE, self.OnAutoCompleteSingle)
163 wx.EVT_MENU(self, ID_AUTOCOMP_DOUBLE, self.OnAutoCompleteDouble)
164 wx.EVT_MENU(self, ID_CALLTIPS_SHOW, self.OnCallTipsShow)
165 wx.EVT_MENU(self, ID_WRAP, self.OnWrap)
166
167 wx.EVT_UPDATE_UI(self, ID_NEW, self.OnUpdateMenu)
168 wx.EVT_UPDATE_UI(self, ID_OPEN, self.OnUpdateMenu)
169 wx.EVT_UPDATE_UI(self, ID_REVERT, self.OnUpdateMenu)
170 wx.EVT_UPDATE_UI(self, ID_CLOSE, self.OnUpdateMenu)
171 wx.EVT_UPDATE_UI(self, ID_SAVE, self.OnUpdateMenu)
172 wx.EVT_UPDATE_UI(self, ID_SAVEAS, self.OnUpdateMenu)
173 wx.EVT_UPDATE_UI(self, ID_NAMESPACE, self.OnUpdateMenu)
174 wx.EVT_UPDATE_UI(self, ID_PRINT, self.OnUpdateMenu)
175 wx.EVT_UPDATE_UI(self, ID_UNDO, self.OnUpdateMenu)
176 wx.EVT_UPDATE_UI(self, ID_REDO, self.OnUpdateMenu)
177 wx.EVT_UPDATE_UI(self, ID_CUT, self.OnUpdateMenu)
178 wx.EVT_UPDATE_UI(self, ID_COPY, self.OnUpdateMenu)
179 wx.EVT_UPDATE_UI(self, ID_COPY_PLUS, self.OnUpdateMenu)
180 wx.EVT_UPDATE_UI(self, ID_PASTE, self.OnUpdateMenu)
181 wx.EVT_UPDATE_UI(self, ID_PASTE_PLUS, self.OnUpdateMenu)
182 wx.EVT_UPDATE_UI(self, ID_CLEAR, self.OnUpdateMenu)
183 wx.EVT_UPDATE_UI(self, ID_SELECTALL, self.OnUpdateMenu)
184 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_SHOW, self.OnUpdateMenu)
185 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_MAGIC, self.OnUpdateMenu)
186 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_SINGLE, self.OnUpdateMenu)
187 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_DOUBLE, self.OnUpdateMenu)
188 wx.EVT_UPDATE_UI(self, ID_CALLTIPS_SHOW, self.OnUpdateMenu)
189 wx.EVT_UPDATE_UI(self, ID_WRAP, self.OnUpdateMenu)
190
191 def OnFileNew(self, event):
192 self.bufferNew()
193
194 def OnFileOpen(self, event):
195 self.bufferOpen()
196
197 def OnFileRevert(self, event):
198 self.bufferRevert()
199
200 def OnFileClose(self, event):
201 self.bufferClose()
202
203 def OnFileSave(self, event):
204 self.bufferSave()
205
206 def OnFileSaveAs(self, event):
207 self.bufferSaveAs()
208
209 def OnFileUpdateNamespace(self, event):
210 self.updateNamespace()
211
212 def OnFilePrint(self, event):
213 self.bufferPrint()
214
215 def OnExit(self, event):
216 self.Close(False)
217
218 def OnUndo(self, event):
219 win = wx.Window_FindFocus()
220 win.Undo()
221
222 def OnRedo(self, event):
223 win = wx.Window_FindFocus()
224 win.Redo()
225
226 def OnCut(self, event):
227 win = wx.Window_FindFocus()
228 win.Cut()
229
230 def OnCopy(self, event):
231 win = wx.Window_FindFocus()
232 win.Copy()
233
234 def OnCopyPlus(self, event):
235 win = wx.Window_FindFocus()
236 win.CopyWithPrompts()
237
238 def OnPaste(self, event):
239 win = wx.Window_FindFocus()
240 win.Paste()
241
242 def OnPastePlus(self, event):
243 win = wx.Window_FindFocus()
244 win.PasteAndRun()
245
246 def OnClear(self, event):
247 win = wx.Window_FindFocus()
248 win.Clear()
249
250 def OnSelectAll(self, event):
251 win = wx.Window_FindFocus()
252 win.SelectAll()
253
254 def OnAbout(self, event):
255 """Display an About window."""
256 title = 'About'
257 text = 'Your message here.'
258 dialog = wx.MessageDialog(self, text, title,
259 wx.OK | wx.ICON_INFORMATION)
260 dialog.ShowModal()
261 dialog.Destroy()
262
263 def OnAutoCompleteShow(self, event):
264 win = wx.Window_FindFocus()
265 win.autoComplete = event.IsChecked()
266
267 def OnAutoCompleteMagic(self, event):
268 win = wx.Window_FindFocus()
269 win.autoCompleteIncludeMagic = event.IsChecked()
270
271 def OnAutoCompleteSingle(self, event):
272 win = wx.Window_FindFocus()
273 win.autoCompleteIncludeSingle = event.IsChecked()
274
275 def OnAutoCompleteDouble(self, event):
276 win = wx.Window_FindFocus()
277 win.autoCompleteIncludeDouble = event.IsChecked()
278
279 def OnCallTipsShow(self, event):
280 win = wx.Window_FindFocus()
281 win.autoCallTip = event.IsChecked()
282
283 def OnWrap(self, event):
284 win = wx.Window_FindFocus()
285 win.SetWrapMode(event.IsChecked())
286
287 def OnUpdateMenu(self, event):
288 """Update menu items based on current status and context."""
289 win = wx.Window_FindFocus()
290 id = event.GetId()
291 event.Enable(True)
292 try:
293 if id == ID_NEW:
294 event.Enable(hasattr(self, 'bufferNew'))
295 elif id == ID_OPEN:
296 event.Enable(hasattr(self, 'bufferOpen'))
297 elif id == ID_REVERT:
298 event.Enable(hasattr(self, 'bufferRevert')
299 and self.hasBuffer())
300 elif id == ID_CLOSE:
301 event.Enable(hasattr(self, 'bufferClose')
302 and self.hasBuffer())
303 elif id == ID_SAVE:
304 event.Enable(hasattr(self, 'bufferSave')
305 and self.bufferHasChanged())
306 elif id == ID_SAVEAS:
307 event.Enable(hasattr(self, 'bufferSaveAs')
308 and self.hasBuffer())
309 elif id == ID_NAMESPACE:
310 event.Enable(hasattr(self, 'updateNamespace')
311 and self.hasBuffer())
312 elif id == ID_PRINT:
313 event.Enable(hasattr(self, 'bufferPrint')
314 and self.hasBuffer())
315 elif id == ID_UNDO:
316 event.Enable(win.CanUndo())
317 elif id == ID_REDO:
318 event.Enable(win.CanRedo())
319 elif id == ID_CUT:
320 event.Enable(win.CanCut())
321 elif id == ID_COPY:
322 event.Enable(win.CanCopy())
323 elif id == ID_COPY_PLUS:
324 event.Enable(win.CanCopy() and hasattr(win, 'CopyWithPrompts'))
325 elif id == ID_PASTE:
326 event.Enable(win.CanPaste())
327 elif id == ID_PASTE_PLUS:
328 event.Enable(win.CanPaste() and hasattr(win, 'PasteAndRun'))
329 elif id == ID_CLEAR:
330 event.Enable(win.CanCut())
331 elif id == ID_SELECTALL:
332 event.Enable(hasattr(win, 'SelectAll'))
333 elif id == ID_AUTOCOMP_SHOW:
334 event.Check(win.autoComplete)
335 elif id == ID_AUTOCOMP_MAGIC:
336 event.Check(win.autoCompleteIncludeMagic)
337 elif id == ID_AUTOCOMP_SINGLE:
338 event.Check(win.autoCompleteIncludeSingle)
339 elif id == ID_AUTOCOMP_DOUBLE:
340 event.Check(win.autoCompleteIncludeDouble)
341 elif id == ID_CALLTIPS_SHOW:
342 event.Check(win.autoCallTip)
343 elif id == ID_WRAP:
344 event.Check(win.GetWrapMode())
345 else:
346 event.Enable(False)
347 except AttributeError:
348 # This menu option is not supported in the current context.
349 event.Enable(False)