1 """Shell menu mixin shared by shell and crust."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __revision__
= "$Revision$"[11:-2]
7 from wxPython
import wx
9 from version
import VERSION
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()
30 """Mixin class to add standard menu items."""
32 def createMenus(self
):
33 m
= self
.fileMenu
= wx
.wxMenu()
35 m
.Append(wx
.wxID_EXIT
, 'E&xit', 'Exit PyCrust')
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')
43 m
.Append(wx
.wxID_CUT
, 'Cu&t \tCtrl+X',
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')
53 m
.Append(wx
.wxID_CLEAR
, 'Cle&ar',
54 'Delete the selection')
55 m
.Append(wx
.wxID_SELECTALL
, 'Select A&ll \tCtrl+A',
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__',
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)
69 m
= self
.calltipsMenu
= wx
.wxMenu()
70 m
.Append(ID_CALLTIPS_SHOW
, 'Show Call Tips',
71 'Show call tips with argument specifications', 1)
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
,
78 m
.Append(ID_WRAP
, '&Wrap Lines',
79 'Wrap lines at right edge', 1)
81 m
= self
.helpMenu
= wx
.wxMenu()
83 m
.Append(wx
.wxID_ABOUT
, '&About...', 'About PyCrust')
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')
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
,
113 wx
.EVT_MENU(self
, ID_WRAP
, self
.OnWrap
)
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
)
130 def OnExit(self
, event
):
133 def OnUndo(self
, event
):
136 def OnRedo(self
, event
):
139 def OnCut(self
, event
):
142 def OnCopy(self
, event
):
145 def OnCopyPlus(self
, event
):
146 self
.shell
.CopyWithPrompts()
148 def OnPaste(self
, event
):
151 def OnPastePlus(self
, event
):
152 self
.shell
.PasteAndRun()
154 def OnClear(self
, event
):
157 def OnSelectAll(self
, event
):
158 self
.shell
.SelectAll()
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
)
177 def OnAutoCompleteShow(self
, event
):
178 self
.shell
.autoComplete
= event
.IsChecked()
180 def OnAutoCompleteIncludeMagic(self
, event
):
181 self
.shell
.autoCompleteIncludeMagic
= event
.IsChecked()
183 def OnAutoCompleteIncludeSingle(self
, event
):
184 self
.shell
.autoCompleteIncludeSingle
= event
.IsChecked()
186 def OnAutoCompleteIncludeDouble(self
, event
):
187 self
.shell
.autoCompleteIncludeDouble
= event
.IsChecked()
189 def OnCallTipsShow(self
, event
):
190 self
.shell
.autoCallTip
= event
.IsChecked()
192 def OnWrap(self
, event
):
193 self
.shell
.SetWrapMode(event
.IsChecked())
195 def OnUpdateMenu(self
, event
):
196 """Update menu items based on current status."""
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
)
225 event
.Check(self
.shell
.GetWrapMode())