]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/PyCrust.py
84edad7ca06ff1b3b9ae848600af62c6c735d570
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / PyCrust.py
1 #!/usr/bin/env python
2 """PyCrust is a python shell application.
3 """
4
5 __author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
6 __cvsid__ = "$Id$"
7 __date__ = "July 1, 2001"
8 __version__ = "$Revision$"[11:-2]
9
10 from wxPython.wx import *
11
12 from version import VERSION
13 from shell import Shell
14
15 ID_AUTOCOMP = NewId()
16 ID_AUTOCOMP_SHOW = NewId()
17 ID_AUTOCOMP_INCLUDE_MAGIC = NewId()
18 ID_AUTOCOMP_INCLUDE_SINGLE = NewId()
19 ID_AUTOCOMP_INCLUDE_DOUBLE = NewId()
20 ID_CALLTIPS = NewId()
21 ID_CALLTIPS_SHOW = NewId()
22
23
24 class Frame(wxFrame):
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)
34 self.createMenus()
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
40
41 def createMenus(self):
42 m = self.fileMenu = wxMenu()
43 m.AppendSeparator()
44 m.Append(wxID_EXIT, 'E&xit', 'Exit PyCrust')
45
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')
49 m.AppendSeparator()
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')
53 m.AppendSeparator()
54 m.Append(wxID_CLEAR, 'Cle&ar \tDel', 'Delete the selection')
55 m.Append(wxID_SELECTALL, 'Select A&ll \tCtrl+A', 'Select all text')
56
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)
66
67 m = self.calltipsMenu = wxMenu()
68 m.Append(ID_CALLTIPS_SHOW, 'Show Call Tips', \
69 'Show call tips with argument specifications', checkable=1)
70
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, \
75 'Call Tip Options')
76
77 m = self.helpMenu = wxMenu()
78 m.AppendSeparator()
79 m.Append(wxID_ABOUT, '&About...', 'About PyCrust')
80
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')
86 self.SetMenuBar(b)
87
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)
102
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)
114
115 def OnExit(self, event):
116 self.Close(true)
117
118 def OnUndo(self, event):
119 self.shell.Undo()
120
121 def OnRedo(self, event):
122 self.shell.Redo()
123
124 def OnCut(self, event):
125 self.shell.Cut()
126
127 def OnCopy(self, event):
128 self.shell.Copy()
129
130 def OnPaste(self, event):
131 self.shell.Paste()
132
133 def OnClear(self, event):
134 self.shell.Clear()
135
136 def OnSelectAll(self, event):
137 self.shell.SelectAll()
138
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)
149 dialog.ShowModal()
150 dialog.Destroy()
151
152 def OnAutoCompleteShow(self, event):
153 self.shell.autoComplete = event.IsChecked()
154
155 def OnAutoCompleteIncludeMagic(self, event):
156 self.shell.autoCompleteIncludeMagic = event.IsChecked()
157
158 def OnAutoCompleteIncludeSingle(self, event):
159 self.shell.autoCompleteIncludeSingle = event.IsChecked()
160
161 def OnAutoCompleteIncludeDouble(self, event):
162 self.shell.autoCompleteIncludeDouble = event.IsChecked()
163
164 def OnCallTipsShow(self, event):
165 self.shell.autoCallTip = event.IsChecked()
166
167 def OnUpdateMenu(self, event):
168 """Update menu items based on current status."""
169 id = event.GetId()
170 if id == wxID_UNDO:
171 event.Enable(self.shell.CanUndo())
172 elif id == wxID_REDO:
173 event.Enable(self.shell.CanRedo())
174 elif id == wxID_CUT:
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)
192
193
194 class App(wxApp):
195 def OnInit(self):
196 parent = None
197 id = -1
198 title = 'PyCrust'
199 self.frame = Frame(parent, id, title)
200 self.frame.Show(true)
201 self.SetTopWindow(self.frame)
202 return true
203
204
205 def main():
206 import sys
207 application = App(0)
208 # Add the application object to the sys module's namespace.
209 # This allows a shell user to do:
210 # >>> import sys
211 # >>> sys.application.whatever
212 sys.application = application
213 application.MainLoop()
214
215 if __name__ == '__main__':
216 main()