]> git.saurik.com Git - wxWidgets.git/blame_incremental - wxPython/wx/py/crust.py
API and etc. updates
[wxWidgets.git] / wxPython / wx / py / crust.py
... / ...
CommitLineData
1"""Crust combines the shell and filling into one control."""
2
3__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
4__cvsid__ = "$Id$"
5__revision__ = "$Revision$"[11:-2]
6
7import wx
8
9import os
10import pprint
11import sys
12
13import dispatcher
14import editwindow
15from filling import Filling
16import frame
17from shell import Shell
18from version import VERSION
19
20try:
21 True
22except NameError:
23 True = 1==1
24 False = 1==0
25
26
27class Crust(wx.SplitterWindow):
28 """Crust based on SplitterWindow."""
29
30 name = 'Crust'
31 revision = __revision__
32
33 def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
34 size=wx.DefaultSize, style=wx.SP_3D,
35 name='Crust Window', rootObject=None, rootLabel=None,
36 rootIsNamespace=True, intro='', locals=None,
37 InterpClass=None, *args, **kwds):
38 """Create Crust instance."""
39 wx.SplitterWindow.__init__(self, parent, id, pos, size, style, name)
40 self.shell = Shell(parent=self, introText=intro,
41 locals=locals, InterpClass=InterpClass,
42 *args, **kwds)
43 self.editor = self.shell
44 if rootObject is None:
45 rootObject = self.shell.interp.locals
46 self.notebook = wx.Notebook(parent=self, id=-1)
47 self.shell.interp.locals['notebook'] = self.notebook
48 self.filling = Filling(parent=self.notebook,
49 rootObject=rootObject,
50 rootLabel=rootLabel,
51 rootIsNamespace=rootIsNamespace)
52 # Add 'filling' to the interpreter's locals.
53 self.shell.interp.locals['filling'] = self.filling
54 self.notebook.AddPage(page=self.filling, text='Namespace', select=True)
55 self.display = Display(parent=self.notebook)
56 self.notebook.AddPage(page=self.display, text='Display')
57 # Add 'pp' (pretty print) to the interpreter's locals.
58 self.shell.interp.locals['pp'] = self.display.setItem
59 self.calltip = Calltip(parent=self.notebook)
60 self.notebook.AddPage(page=self.calltip, text='Calltip')
61 self.sessionlisting = SessionListing(parent=self.notebook)
62 self.notebook.AddPage(page=self.sessionlisting, text='Session')
63 self.dispatcherlisting = DispatcherListing(parent=self.notebook)
64 self.notebook.AddPage(page=self.dispatcherlisting, text='Dispatcher')
65 from wxd import wx_
66 self.wxdocs = Filling(parent=self.notebook,
67 rootObject=wx_,
68 rootLabel='wx',
69 rootIsNamespace=False,
70 static=True)
71 self.notebook.AddPage(page=self.wxdocs, text='wxPython Docs')
72 from wxd import stc_
73 self.stcdocs = Filling(parent=self.notebook,
74 rootObject=stc_.StyledTextCtrl,
75 rootLabel='StyledTextCtrl',
76 rootIsNamespace=False,
77 static=True)
78 self.notebook.AddPage(page=self.stcdocs, text='StyledTextCtrl Docs')
79 self.SplitHorizontally(self.shell, self.notebook, 300)
80 self.SetMinimumPaneSize(1)
81
82
83class Display(editwindow.EditWindow):
84 """STC used to display an object using Pretty Print."""
85
86 def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
87 size=wx.DefaultSize,
88 style=wx.CLIP_CHILDREN | wx.SUNKEN_BORDER,
89 static=False):
90 """Create Display instance."""
91 editwindow.EditWindow.__init__(self, parent, id, pos, size, style)
92 # Configure various defaults and user preferences.
93 self.SetReadOnly(True)
94 self.SetWrapMode(False)
95 if not static:
96 dispatcher.connect(receiver=self.push, signal='Interpreter.push')
97
98 def push(self, command, more):
99 """Receiver for Interpreter.push signal."""
100 self.Refresh()
101
102 def Refresh(self):
103 if not hasattr(self, "item"):
104 return
105 self.SetReadOnly(False)
106 text = pprint.pformat(self.item)
107 self.SetText(text)
108 self.SetReadOnly(True)
109
110 def setItem(self, item):
111 """Set item to pretty print in the notebook Display tab."""
112 self.item = item
113 self.Refresh()
114
115
116class Calltip(wx.TextCtrl):
117 """Text control containing the most recent shell calltip."""
118
119 def __init__(self, parent=None, id=-1):
120 style = wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2
121 wx.TextCtrl.__init__(self, parent=parent, id=id, style=style)
122 self.SetBackgroundColour(wx.Colour(255, 255, 232))
123 dispatcher.connect(receiver=self.display, signal='Shell.calltip')
124
125 def display(self, calltip):
126 """Receiver for Shell.calltip signal."""
127 self.SetValue(calltip)
128
129
130class SessionListing(wx.TextCtrl):
131 """Text control containing all commands for session."""
132
133 def __init__(self, parent=None, id=-1):
134 style = wx.TE_MULTILINE | wx.TE_READONLY | \
135 wx.TE_RICH2 | wx.TE_DONTWRAP
136 wx.TextCtrl.__init__(self, parent=parent, id=id, style=style)
137 dispatcher.connect(receiver=self.push, signal='Interpreter.push')
138
139 def push(self, command, more):
140 """Receiver for Interpreter.push signal."""
141 if command and not more:
142 self.SetInsertionPointEnd()
143 start, end = self.GetSelection()
144 if start != end:
145 self.SetSelection(0, 0)
146 self.AppendText(command + '\n')
147
148
149class DispatcherListing(wx.TextCtrl):
150 """Text control containing all dispatches for session."""
151
152 def __init__(self, parent=None, id=-1):
153 style = wx.TE_MULTILINE | wx.TE_READONLY | \
154 wx.TE_RICH2 | wx.TE_DONTWRAP
155 wx.TextCtrl.__init__(self, parent=parent, id=id, style=style)
156 dispatcher.connect(receiver=self.spy)
157
158 def spy(self, signal, sender):
159 """Receiver for Any signal from Any sender."""
160 text = '%r from %s' % (signal, sender)
161 self.SetInsertionPointEnd()
162 start, end = self.GetSelection()
163 if start != end:
164 self.SetSelection(0, 0)
165 self.AppendText(text + '\n')
166
167
168class CrustFrame(frame.Frame):
169 """Frame containing all the PyCrust components."""
170
171 name = 'CrustFrame'
172 revision = __revision__
173
174 def __init__(self, parent=None, id=-1, title='PyCrust',
175 pos=wx.DefaultPosition, size=wx.DefaultSize,
176 style=wx.DEFAULT_FRAME_STYLE,
177 rootObject=None, rootLabel=None, rootIsNamespace=True,
178 locals=None, InterpClass=None, *args, **kwds):
179 """Create CrustFrame instance."""
180 frame.Frame.__init__(self, parent, id, title, pos, size, style)
181 intro = 'PyCrust %s - The Flakiest Python Shell' % VERSION
182 intro += '\nSponsored by Orbtech - '
183 intro += 'Your source for Python programming expertise.'
184 self.SetStatusText(intro.replace('\n', ', '))
185 self.crust = Crust(parent=self, intro=intro,
186 rootObject=rootObject,
187 rootLabel=rootLabel,
188 rootIsNamespace=rootIsNamespace,
189 locals=locals,
190 InterpClass=InterpClass, *args, **kwds)
191 self.shell = self.crust.shell
192 # Override the filling so that status messages go to the status bar.
193 self.crust.filling.tree.setStatusText = self.SetStatusText
194 # Override the shell so that status messages go to the status bar.
195 self.shell.setStatusText = self.SetStatusText
196 # Fix a problem with the sash shrinking to nothing.
197 self.crust.filling.SetSashPosition(200)
198 # Set focus to the shell editor.
199 self.shell.SetFocus()
200
201 def OnClose(self, event):
202 """Event handler for closing."""
203 self.crust.shell.destroy()
204 self.Destroy()
205
206 def OnAbout(self, event):
207 """Display an About window."""
208 title = 'About PyCrust'
209 text = 'PyCrust %s\n\n' % VERSION + \
210 'Yet another Python shell, only flakier.\n\n' + \
211 'Half-baked by Patrick K. O\'Brien,\n' + \
212 'the other half is still in the oven.\n\n' + \
213 'Shell Revision: %s\n' % self.shell.revision + \
214 'Interpreter Revision: %s\n\n' % self.shell.interp.revision + \
215 'Python Version: %s\n' % sys.version.split()[0] + \
216 'wxPython Version: %s\n' % wx.VERSION_STRING + \
217 'Platform: %s\n' % sys.platform
218 dialog = wx.MessageDialog(self, text, title,
219 wx.OK | wx.ICON_INFORMATION)
220 dialog.ShowModal()
221 dialog.Destroy()