]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/crust.py
ef9d235804987fa088c36b7cadfae68fe051681a
1 """Crust combines the shell and filling into one control."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __revision__
= "$Revision$"[11:-2]
15 from filling
import Filling
17 from shell
import Shell
18 from version
import VERSION
27 class Crust(wx
.SplitterWindow
):
28 """Crust based on SplitterWindow."""
31 revision
= __revision__
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
,
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
,
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,
69 ## rootIsNamespace=False,
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,
78 ## self.notebook.AddPage(page=self.stcdocs, text='StyledTextCtrl Docs')
79 self
.SplitHorizontally(self
.shell
, self
.notebook
, 300)
80 self
.SetMinimumPaneSize(1)
83 class Display(editwindow
.EditWindow
):
84 """STC used to display an object using Pretty Print."""
86 def __init__(self
, parent
, id=-1, pos
=wx
.DefaultPosition
,
88 style
=wx
.CLIP_CHILDREN | wx
.SUNKEN_BORDER
,
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)
96 dispatcher
.connect(receiver
=self
.push
, signal
='Interpreter.push')
98 def push(self
, command
, more
):
99 """Receiver for Interpreter.push signal."""
103 if not hasattr(self
, "item"):
105 self
.SetReadOnly(False)
106 text
= pprint
.pformat(self
.item
)
108 self
.SetReadOnly(True)
110 def setItem(self
, item
):
111 """Set item to pretty print in the notebook Display tab."""
116 class Calltip(wx
.TextCtrl
):
117 """Text control containing the most recent shell calltip."""
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
, id, style
=style
)
122 self
.SetBackgroundColour(wx
.Colour(255, 255, 232))
123 dispatcher
.connect(receiver
=self
.display
, signal
='Shell.calltip')
125 def display(self
, calltip
):
126 """Receiver for Shell.calltip signal."""
127 ## self.SetValue(calltip) # Caused refresh problem on Windows.
129 self
.AppendText(calltip
)
132 class SessionListing(wx
.TextCtrl
):
133 """Text control containing all commands for session."""
135 def __init__(self
, parent
=None, id=-1):
136 style
= (wx
.TE_MULTILINE | wx
.TE_READONLY |
137 wx
.TE_RICH2 | wx
.TE_DONTWRAP
)
138 wx
.TextCtrl
.__init
__(self
, parent
, id, style
=style
)
139 dispatcher
.connect(receiver
=self
.push
, signal
='Interpreter.push')
141 def push(self
, command
, more
):
142 """Receiver for Interpreter.push signal."""
143 if command
and not more
:
144 self
.SetInsertionPointEnd()
145 start
, end
= self
.GetSelection()
147 self
.SetSelection(0, 0)
148 self
.AppendText(command
+ '\n')
151 class DispatcherListing(wx
.TextCtrl
):
152 """Text control containing all dispatches for session."""
154 def __init__(self
, parent
=None, id=-1):
155 style
= (wx
.TE_MULTILINE | wx
.TE_READONLY |
156 wx
.TE_RICH2 | wx
.TE_DONTWRAP
)
157 wx
.TextCtrl
.__init
__(self
, parent
, id, style
=style
)
158 dispatcher
.connect(receiver
=self
.spy
)
160 def spy(self
, signal
, sender
):
161 """Receiver for Any signal from Any sender."""
162 text
= '%r from %s' % (signal
, sender
)
163 self
.SetInsertionPointEnd()
164 start
, end
= self
.GetSelection()
166 self
.SetSelection(0, 0)
167 self
.AppendText(text
+ '\n')
170 class CrustFrame(frame
.Frame
):
171 """Frame containing all the PyCrust components."""
174 revision
= __revision__
176 def __init__(self
, parent
=None, id=-1, title
='PyCrust',
177 pos
=wx
.DefaultPosition
, size
=wx
.DefaultSize
,
178 style
=wx
.DEFAULT_FRAME_STYLE
,
179 rootObject
=None, rootLabel
=None, rootIsNamespace
=True,
180 locals=None, InterpClass
=None, *args
, **kwds
):
181 """Create CrustFrame instance."""
182 frame
.Frame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
183 intro
= 'PyCrust %s - The Flakiest Python Shell' % VERSION
184 intro
+= '\nSponsored by Orbtech - '
185 intro
+= 'Your source for Python programming expertise.'
186 self
.SetStatusText(intro
.replace('\n', ', '))
187 self
.crust
= Crust(parent
=self
, intro
=intro
,
188 rootObject
=rootObject
,
190 rootIsNamespace
=rootIsNamespace
,
192 InterpClass
=InterpClass
, *args
, **kwds
)
193 self
.shell
= self
.crust
.shell
194 # Override the filling so that status messages go to the status bar.
195 self
.crust
.filling
.tree
.setStatusText
= self
.SetStatusText
196 # Override the shell so that status messages go to the status bar.
197 self
.shell
.setStatusText
= self
.SetStatusText
198 # Fix a problem with the sash shrinking to nothing.
199 self
.crust
.filling
.SetSashPosition(200)
200 # Set focus to the shell editor.
201 self
.shell
.SetFocus()
203 def OnClose(self
, event
):
204 """Event handler for closing."""
205 self
.crust
.shell
.destroy()
208 def OnAbout(self
, event
):
209 """Display an About window."""
210 title
= 'About PyCrust'
211 text
= 'PyCrust %s\n\n' % VERSION
+ \
212 'Yet another Python shell, only flakier.\n\n' + \
213 'Half-baked by Patrick K. O\'Brien,\n' + \
214 'the other half is still in the oven.\n\n' + \
215 'Shell Revision: %s\n' % self
.shell
.revision
+ \
216 'Interpreter Revision: %s\n\n' % self
.shell
.interp
.revision
+ \
217 'Python Version: %s\n' % sys
.version
.split()[0] + \
218 'wxPython Version: %s\n' % wx
.VERSION_STRING
+ \
219 'Platform: %s\n' % sys
.platform
220 dialog
= wx
.MessageDialog(self
, text
, title
,
221 wx
.OK | wx
.ICON_INFORMATION
)