2 """PyCrust is a python shell application.
5 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
7 __date__
= "July 1, 2001"
8 __version__
= "$Revision$"[11:-2]
10 from wxPython
.wx
import *
12 from version
import VERSION
13 from shell
import Shell
16 ID_AUTOCOMP_SHOW
= NewId()
17 ID_AUTOCOMP_INCLUDE_MAGIC
= NewId()
18 ID_AUTOCOMP_INCLUDE_SINGLE
= NewId()
19 ID_AUTOCOMP_INCLUDE_DOUBLE
= NewId()
21 ID_CALLTIPS_SHOW
= NewId()
25 """Main window for the PyCrust application."""
26 def __init__(self
, parent
, id, title
):
27 """Create the main frame object for the application."""
28 wxFrame
.__init
__(self
, parent
, id, title
)
29 intro
= 'Welcome To PyCrust %s - The Flakiest Python Shell' % VERSION
30 self
.CreateStatusBar()
31 self
.SetStatusText(intro
)
32 self
.icon
= wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO
)
33 self
.SetIcon(self
.icon
)
35 # Create the shell, which will create a default interpreter.
36 locals = {'__app__': 'PyCrust Application'}
37 self
.shell
= Shell(parent
=self
, id=-1, introText
=intro
, locals=locals)
38 # Override the shell so that status messages go to the status bar.
39 self
.shell
.setStatusText
= self
.SetStatusText
41 def createMenus(self
):
42 m
= self
.fileMenu
= wxMenu()
44 m
.Append(wxID_EXIT
, 'E&xit', 'Exit PyCrust')
46 m
= self
.editMenu
= wxMenu()
47 m
.Append(wxID_UNDO
, '&Undo \tCtrl+Z', 'Undo the last action')
48 m
.Append(wxID_REDO
, '&Redo \tCtrl+Y', 'Redo the last undone action')
50 m
.Append(wxID_CUT
, 'Cu&t \tCtrl+X', 'Cut the selection')
51 m
.Append(wxID_COPY
, '&Copy \tCtrl+C', 'Copy the selection')
52 m
.Append(wxID_PASTE
, '&Paste \tCtrl+V', 'Paste')
54 m
.Append(wxID_CLEAR
, 'Cle&ar \tDel', 'Delete the selection')
55 m
.Append(wxID_SELECTALL
, 'Select A&ll \tCtrl+A', 'Select all text')
57 m
= self
.autocompMenu
= wxMenu()
58 m
.Append(ID_AUTOCOMP_SHOW
, 'Show Auto Completion', \
59 'Show auto completion during dot syntax', checkable
=1)
60 m
.Append(ID_AUTOCOMP_INCLUDE_MAGIC
, 'Include Magic Attributes', \
61 'Include attributes visible to __getattr__ and __setattr__', checkable
=1)
62 m
.Append(ID_AUTOCOMP_INCLUDE_SINGLE
, 'Include Single Underscores', \
63 'Include attibutes prefixed by a single underscore', checkable
=1)
64 m
.Append(ID_AUTOCOMP_INCLUDE_DOUBLE
, 'Include Double Underscores', \
65 'Include attibutes prefixed by a double underscore', checkable
=1)
67 m
= self
.calltipsMenu
= wxMenu()
68 m
.Append(ID_CALLTIPS_SHOW
, 'Show Call Tips', \
69 'Show call tips with argument specifications', checkable
=1)
71 m
= self
.optionsMenu
= wxMenu()
72 m
.AppendMenu(ID_AUTOCOMP
, '&Auto Completion', self
.autocompMenu
, \
73 'Auto Completion Options')
74 m
.AppendMenu(ID_CALLTIPS
, '&Call Tips', self
.calltipsMenu
, \
77 m
= self
.helpMenu
= wxMenu()
79 m
.Append(wxID_ABOUT
, '&About...', 'About PyCrust')
81 b
= self
.menuBar
= wxMenuBar()
82 b
.Append(self
.fileMenu
, '&File')
83 b
.Append(self
.editMenu
, '&Edit')
84 b
.Append(self
.optionsMenu
, '&Options')
85 b
.Append(self
.helpMenu
, '&Help')
88 EVT_MENU(self
, wxID_EXIT
, self
.OnExit
)
89 EVT_MENU(self
, wxID_UNDO
, self
.OnUndo
)
90 EVT_MENU(self
, wxID_REDO
, self
.OnRedo
)
91 EVT_MENU(self
, wxID_CUT
, self
.OnCut
)
92 EVT_MENU(self
, wxID_COPY
, self
.OnCopy
)
93 EVT_MENU(self
, wxID_PASTE
, self
.OnPaste
)
94 EVT_MENU(self
, wxID_CLEAR
, self
.OnClear
)
95 EVT_MENU(self
, wxID_SELECTALL
, self
.OnSelectAll
)
96 EVT_MENU(self
, wxID_ABOUT
, self
.OnAbout
)
97 EVT_MENU(self
, ID_AUTOCOMP_SHOW
, self
.OnAutoCompleteShow
)
98 EVT_MENU(self
, ID_AUTOCOMP_INCLUDE_MAGIC
, self
.OnAutoCompleteIncludeMagic
)
99 EVT_MENU(self
, ID_AUTOCOMP_INCLUDE_SINGLE
, self
.OnAutoCompleteIncludeSingle
)
100 EVT_MENU(self
, ID_AUTOCOMP_INCLUDE_DOUBLE
, self
.OnAutoCompleteIncludeDouble
)
101 EVT_MENU(self
, ID_CALLTIPS_SHOW
, self
.OnCallTipsShow
)
103 EVT_UPDATE_UI(self
, wxID_UNDO
, self
.OnUpdateMenu
)
104 EVT_UPDATE_UI(self
, wxID_REDO
, self
.OnUpdateMenu
)
105 EVT_UPDATE_UI(self
, wxID_CUT
, self
.OnUpdateMenu
)
106 EVT_UPDATE_UI(self
, wxID_COPY
, self
.OnUpdateMenu
)
107 EVT_UPDATE_UI(self
, wxID_PASTE
, self
.OnUpdateMenu
)
108 EVT_UPDATE_UI(self
, wxID_CLEAR
, self
.OnUpdateMenu
)
109 EVT_UPDATE_UI(self
, ID_AUTOCOMP_SHOW
, self
.OnUpdateMenu
)
110 EVT_UPDATE_UI(self
, ID_AUTOCOMP_INCLUDE_MAGIC
, self
.OnUpdateMenu
)
111 EVT_UPDATE_UI(self
, ID_AUTOCOMP_INCLUDE_SINGLE
, self
.OnUpdateMenu
)
112 EVT_UPDATE_UI(self
, ID_AUTOCOMP_INCLUDE_DOUBLE
, self
.OnUpdateMenu
)
113 EVT_UPDATE_UI(self
, ID_CALLTIPS_SHOW
, self
.OnUpdateMenu
)
115 def OnExit(self
, event
):
118 def OnUndo(self
, event
):
121 def OnRedo(self
, event
):
124 def OnCut(self
, event
):
127 def OnCopy(self
, event
):
130 def OnPaste(self
, event
):
133 def OnClear(self
, event
):
136 def OnSelectAll(self
, event
):
137 self
.shell
.SelectAll()
139 def OnAbout(self
, event
):
140 """Display an About PyCrust window."""
141 title
= 'About PyCrust'
142 text
= 'PyCrust %s\n\n' % VERSION
+ \
143 'Yet another Python shell, only flakier.\n\n' + \
144 'Half-baked by Patrick K. O\'Brien,\n' + \
145 'the other half is still in the oven.\n\n' + \
146 'Shell Revision: %s\n' % self
.shell
.revision
+ \
147 'Interpreter Revision: %s\n' % self
.shell
.interp
.revision
148 dialog
= wxMessageDialog(self
, text
, title
, wxOK | wxICON_INFORMATION
)
152 def OnAutoCompleteShow(self
, event
):
153 self
.shell
.autoComplete
= event
.IsChecked()
155 def OnAutoCompleteIncludeMagic(self
, event
):
156 self
.shell
.autoCompleteIncludeMagic
= event
.IsChecked()
158 def OnAutoCompleteIncludeSingle(self
, event
):
159 self
.shell
.autoCompleteIncludeSingle
= event
.IsChecked()
161 def OnAutoCompleteIncludeDouble(self
, event
):
162 self
.shell
.autoCompleteIncludeDouble
= event
.IsChecked()
164 def OnCallTipsShow(self
, event
):
165 self
.shell
.autoCallTip
= event
.IsChecked()
167 def OnUpdateMenu(self
, event
):
168 """Update menu items based on current status."""
171 event
.Enable(self
.shell
.CanUndo())
172 elif id == wxID_REDO
:
173 event
.Enable(self
.shell
.CanRedo())
175 event
.Enable(self
.shell
.CanCut())
176 elif id == wxID_COPY
:
177 event
.Enable(self
.shell
.CanCopy())
178 elif id == wxID_PASTE
:
179 event
.Enable(self
.shell
.CanPaste())
180 elif id == wxID_CLEAR
:
181 event
.Enable(self
.shell
.CanCut())
182 elif id == ID_AUTOCOMP_SHOW
:
183 event
.Check(self
.shell
.autoComplete
)
184 elif id == ID_AUTOCOMP_INCLUDE_MAGIC
:
185 event
.Check(self
.shell
.autoCompleteIncludeMagic
)
186 elif id == ID_AUTOCOMP_INCLUDE_SINGLE
:
187 event
.Check(self
.shell
.autoCompleteIncludeSingle
)
188 elif id == ID_AUTOCOMP_INCLUDE_DOUBLE
:
189 event
.Check(self
.shell
.autoCompleteIncludeDouble
)
190 elif id == ID_CALLTIPS_SHOW
:
191 event
.Check(self
.shell
.autoCallTip
)
199 self
.frame
= Frame(parent
, id, title
)
200 self
.frame
.Show(true
)
201 self
.SetTopWindow(self
.frame
)
208 # Add the application object to the sys module's namespace.
209 # This allows a shell user to do:
211 # >>> sys.application.whatever
212 sys
.application
= application
213 application
.MainLoop()
215 if __name__
== '__main__':