]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/shellmenu.py
1e3175a1f7f9ff032511e0a262af2135c72dd658
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / shellmenu.py
1 """Shell menu mixin shared by shell and crust."""
2
3 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4 __cvsid__ = "$Id$"
5 __revision__ = "$Revision$"[11:-2]
6
7 from wxPython import wx
8 import sys
9 from version import VERSION
10
11 try:
12 True
13 except NameError:
14 True = 1==1
15 False = 1==0
16
17 ID_AUTOCOMP = wx.wxNewId()
18 ID_AUTOCOMP_SHOW = wx.wxNewId()
19 ID_AUTOCOMP_INCLUDE_MAGIC = wx.wxNewId()
20 ID_AUTOCOMP_INCLUDE_SINGLE = wx.wxNewId()
21 ID_AUTOCOMP_INCLUDE_DOUBLE = wx.wxNewId()
22 ID_CALLTIPS = wx.wxNewId()
23 ID_CALLTIPS_SHOW = wx.wxNewId()
24 ID_COPY_PLUS = wx.wxNewId()
25 ID_PASTE_PLUS = wx.wxNewId()
26 ID_WRAP = wx.wxNewId()
27
28
29 class ShellMenu:
30 """Mixin class to add standard menu items."""
31
32 def createMenus(self):
33 m = self.fileMenu = wx.wxMenu()
34 m.AppendSeparator()
35 m.Append(wx.wxID_EXIT, 'E&xit', 'Exit PyCrust')
36
37 m = self.editMenu = wx.wxMenu()
38 m.Append(wx.wxID_UNDO, '&Undo \tCtrl+Z',
39 'Undo the last action')
40 m.Append(wx.wxID_REDO, '&Redo \tCtrl+Y',
41 'Redo the last undone action')
42 m.AppendSeparator()
43 m.Append(wx.wxID_CUT, 'Cu&t \tCtrl+X',
44 'Cut the selection')
45 m.Append(wx.wxID_COPY, '&Copy \tCtrl+C',
46 'Copy the selection - removing prompts')
47 m.Append(ID_COPY_PLUS, 'Cop&y Plus \tCtrl+Shift+C',
48 'Copy the selection - retaining prompts')
49 m.Append(wx.wxID_PASTE, '&Paste \tCtrl+V', 'Paste')
50 m.Append(ID_PASTE_PLUS, 'Past&e Plus \tCtrl+Shift+V',
51 'Paste and run commands')
52 m.AppendSeparator()
53 m.Append(wx.wxID_CLEAR, 'Cle&ar',
54 'Delete the selection')
55 m.Append(wx.wxID_SELECTALL, 'Select A&ll \tCtrl+A',
56 'Select all text')
57
58 m = self.autocompMenu = wx.wxMenu()
59 m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion',
60 'Show auto completion during dot syntax', 1)
61 m.Append(ID_AUTOCOMP_INCLUDE_MAGIC, 'Include Magic Attributes',
62 'Include attributes visible to __getattr__ and __setattr__',
63 1)
64 m.Append(ID_AUTOCOMP_INCLUDE_SINGLE, 'Include Single Underscores',
65 'Include attibutes prefixed by a single underscore', 1)
66 m.Append(ID_AUTOCOMP_INCLUDE_DOUBLE, 'Include Double Underscores',
67 'Include attibutes prefixed by a double underscore', 1)
68
69 m = self.calltipsMenu = wx.wxMenu()
70 m.Append(ID_CALLTIPS_SHOW, 'Show Call Tips',
71 'Show call tips with argument specifications', 1)
72
73 m = self.optionsMenu = wx.wxMenu()
74 m.AppendMenu(ID_AUTOCOMP, '&Auto Completion', self.autocompMenu,
75 'Auto Completion Options')
76 m.AppendMenu(ID_CALLTIPS, '&Call Tips', self.calltipsMenu,
77 'Call Tip Options')
78 m.Append(ID_WRAP, '&Wrap Lines',
79 'Wrap lines at right edge', 1)
80
81 m = self.helpMenu = wx.wxMenu()
82 m.AppendSeparator()
83 m.Append(wx.wxID_ABOUT, '&About...', 'About PyCrust')
84
85 b = self.menuBar = wx.wxMenuBar()
86 b.Append(self.fileMenu, '&File')
87 b.Append(self.editMenu, '&Edit')
88 b.Append(self.optionsMenu, '&Options')
89 b.Append(self.helpMenu, '&Help')
90 self.SetMenuBar(b)
91
92 wx.EVT_MENU(self, wx.wxID_EXIT, self.OnExit)
93 wx.EVT_MENU(self, wx.wxID_UNDO, self.OnUndo)
94 wx.EVT_MENU(self, wx.wxID_REDO, self.OnRedo)
95 wx.EVT_MENU(self, wx.wxID_CUT, self.OnCut)
96 wx.EVT_MENU(self, wx.wxID_COPY, self.OnCopy)
97 wx.EVT_MENU(self, ID_COPY_PLUS, self.OnCopyPlus)
98 wx.EVT_MENU(self, wx.wxID_PASTE, self.OnPaste)
99 wx.EVT_MENU(self, ID_PASTE_PLUS, self.OnPastePlus)
100 wx.EVT_MENU(self, wx.wxID_CLEAR, self.OnClear)
101 wx.EVT_MENU(self, wx.wxID_SELECTALL, self.OnSelectAll)
102 wx.EVT_MENU(self, wx.wxID_ABOUT, self.OnAbout)
103 wx.EVT_MENU(self, ID_AUTOCOMP_SHOW,
104 self.OnAutoCompleteShow)
105 wx.EVT_MENU(self, ID_AUTOCOMP_INCLUDE_MAGIC,
106 self.OnAutoCompleteIncludeMagic)
107 wx.EVT_MENU(self, ID_AUTOCOMP_INCLUDE_SINGLE,
108 self.OnAutoCompleteIncludeSingle)
109 wx.EVT_MENU(self, ID_AUTOCOMP_INCLUDE_DOUBLE,
110 self.OnAutoCompleteIncludeDouble)
111 wx.EVT_MENU(self, ID_CALLTIPS_SHOW,
112 self.OnCallTipsShow)
113 wx.EVT_MENU(self, ID_WRAP, self.OnWrap)
114
115 wx.EVT_UPDATE_UI(self, wx.wxID_UNDO, self.OnUpdateMenu)
116 wx.EVT_UPDATE_UI(self, wx.wxID_REDO, self.OnUpdateMenu)
117 wx.EVT_UPDATE_UI(self, wx.wxID_CUT, self.OnUpdateMenu)
118 wx.EVT_UPDATE_UI(self, wx.wxID_COPY, self.OnUpdateMenu)
119 wx.EVT_UPDATE_UI(self, ID_COPY_PLUS, self.OnUpdateMenu)
120 wx.EVT_UPDATE_UI(self, wx.wxID_PASTE, self.OnUpdateMenu)
121 wx.EVT_UPDATE_UI(self, ID_PASTE_PLUS, self.OnUpdateMenu)
122 wx.EVT_UPDATE_UI(self, wx.wxID_CLEAR, self.OnUpdateMenu)
123 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_SHOW, self.OnUpdateMenu)
124 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_INCLUDE_MAGIC, self.OnUpdateMenu)
125 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_INCLUDE_SINGLE, self.OnUpdateMenu)
126 wx.EVT_UPDATE_UI(self, ID_AUTOCOMP_INCLUDE_DOUBLE, self.OnUpdateMenu)
127 wx.EVT_UPDATE_UI(self, ID_CALLTIPS_SHOW, self.OnUpdateMenu)
128 wx.EVT_UPDATE_UI(self, ID_WRAP, self.OnUpdateMenu)
129
130 def OnExit(self, event):
131 self.Close(True)
132
133 def OnUndo(self, event):
134 self.shell.Undo()
135
136 def OnRedo(self, event):
137 self.shell.Redo()
138
139 def OnCut(self, event):
140 self.shell.Cut()
141
142 def OnCopy(self, event):
143 self.shell.Copy()
144
145 def OnCopyPlus(self, event):
146 self.shell.CopyWithPrompts()
147
148 def OnPaste(self, event):
149 self.shell.Paste()
150
151 def OnPastePlus(self, event):
152 self.shell.PasteAndRun()
153
154 def OnClear(self, event):
155 self.shell.Clear()
156
157 def OnSelectAll(self, event):
158 self.shell.SelectAll()
159
160 def OnAbout(self, event):
161 """Display an About PyCrust window."""
162 title = 'About PyCrust'
163 text = 'PyCrust %s\n\n' % VERSION + \
164 'Yet another Python shell, only flakier.\n\n' + \
165 'Half-baked by Patrick K. O\'Brien,\n' + \
166 'the other half is still in the oven.\n\n' + \
167 'Shell Revision: %s\n' % self.shell.revision + \
168 'Interpreter Revision: %s\n\n' % self.shell.interp.revision + \
169 'Python Version: %s\n' % sys.version.split()[0] + \
170 'wxPython Version: %s\n' % wx.__version__ + \
171 'Platform: %s\n' % sys.platform
172 dialog = wx.wxMessageDialog(self, text, title,
173 wx.wxOK | wx.wxICON_INFORMATION)
174 dialog.ShowModal()
175 dialog.Destroy()
176
177 def OnAutoCompleteShow(self, event):
178 self.shell.autoComplete = event.IsChecked()
179
180 def OnAutoCompleteIncludeMagic(self, event):
181 self.shell.autoCompleteIncludeMagic = event.IsChecked()
182
183 def OnAutoCompleteIncludeSingle(self, event):
184 self.shell.autoCompleteIncludeSingle = event.IsChecked()
185
186 def OnAutoCompleteIncludeDouble(self, event):
187 self.shell.autoCompleteIncludeDouble = event.IsChecked()
188
189 def OnCallTipsShow(self, event):
190 self.shell.autoCallTip = event.IsChecked()
191
192 def OnWrap(self, event):
193 self.shell.SetWrapMode(event.IsChecked())
194
195 def OnUpdateMenu(self, event):
196 """Update menu items based on current status."""
197 id = event.GetId()
198 if id == wx.wxID_UNDO:
199 event.Enable(self.shell.CanUndo())
200 elif id == wx.wxID_REDO:
201 event.Enable(self.shell.CanRedo())
202 elif id == wx.wxID_CUT:
203 event.Enable(self.shell.CanCut())
204 elif id == wx.wxID_COPY:
205 event.Enable(self.shell.CanCopy())
206 elif id == ID_COPY_PLUS:
207 event.Enable(self.shell.CanCopy())
208 elif id == wx.wxID_PASTE:
209 event.Enable(self.shell.CanPaste())
210 elif id == ID_PASTE_PLUS:
211 event.Enable(self.shell.CanPaste())
212 elif id == wx.wxID_CLEAR:
213 event.Enable(self.shell.CanCut())
214 elif id == ID_AUTOCOMP_SHOW:
215 event.Check(self.shell.autoComplete)
216 elif id == ID_AUTOCOMP_INCLUDE_MAGIC:
217 event.Check(self.shell.autoCompleteIncludeMagic)
218 elif id == ID_AUTOCOMP_INCLUDE_SINGLE:
219 event.Check(self.shell.autoCompleteIncludeSingle)
220 elif id == ID_AUTOCOMP_INCLUDE_DOUBLE:
221 event.Check(self.shell.autoCompleteIncludeDouble)
222 elif id == ID_CALLTIPS_SHOW:
223 event.Check(self.shell.autoCallTip)
224 elif id == ID_WRAP:
225 event.Check(self.shell.GetWrapMode())
226