]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/crust.py
caeb20f6dbf390e1c42d0f240242139602183e9a
1 """PyCrust Crust combines the shell and filling into one control."""
3 __author__
= "Patrick K. O'Brien <pobrien@orbtech.com>"
5 __revision__
= "$Revision$"[11:-2]
7 from wxPython
import wx
8 from filling
import Filling
10 from shell
import Shell
11 from shellmenu
import ShellMenu
12 from version
import VERSION
21 class Crust(wx
.wxSplitterWindow
):
22 """PyCrust Crust based on wxSplitterWindow."""
24 name
= 'PyCrust Crust'
25 revision
= __revision__
27 def __init__(self
, parent
, id=-1, pos
=wx
.wxDefaultPosition
,
28 size
=wx
.wxDefaultSize
, style
=wx
.wxSP_3D
,
29 name
='Crust Window', rootObject
=None, rootLabel
=None,
30 rootIsNamespace
=True, intro
='', locals=None,
31 InterpClass
=None, *args
, **kwds
):
32 """Create a PyCrust Crust instance."""
33 wx
.wxSplitterWindow
.__init
__(self
, parent
, id, pos
, size
, style
, name
)
34 self
.shell
= Shell(parent
=self
, introText
=intro
,
35 locals=locals, InterpClass
=InterpClass
,
37 if rootObject
is None:
38 rootObject
= self
.shell
.interp
.locals
39 self
.notebook
= wx
.wxNotebook(parent
=self
, id=-1)
40 self
.shell
.interp
.locals['notebook'] = self
.notebook
41 self
.filling
= Filling(parent
=self
.notebook
,
42 rootObject
=rootObject
,
44 rootIsNamespace
=rootIsNamespace
)
45 # Add 'filling' to the interpreter's locals.
46 self
.shell
.interp
.locals['filling'] = self
.filling
47 self
.notebook
.AddPage(page
=self
.filling
, text
='Namespace', select
=True)
48 self
.calltip
= Calltip(parent
=self
.notebook
)
49 self
.notebook
.AddPage(page
=self
.calltip
, text
='Calltip')
50 self
.sessionlisting
= SessionListing(parent
=self
.notebook
)
51 self
.notebook
.AddPage(page
=self
.sessionlisting
, text
='Session')
52 self
.dispatcherlisting
= DispatcherListing(parent
=self
.notebook
)
53 self
.notebook
.AddPage(page
=self
.dispatcherlisting
, text
='Dispatcher')
55 self
.wxdocs
= Filling(parent
=self
.notebook
,
58 rootIsNamespace
=False,
60 self
.notebook
.AddPage(page
=self
.wxdocs
, text
='wxPython Docs')
62 self
.stcdocs
= Filling(parent
=self
.notebook
,
63 rootObject
=stc_
.StyledTextCtrl
,
64 rootLabel
='StyledTextCtrl',
65 rootIsNamespace
=False,
67 self
.notebook
.AddPage(page
=self
.stcdocs
, text
='StyledTextCtrl Docs')
68 self
.SplitHorizontally(self
.shell
, self
.notebook
, 300)
69 self
.SetMinimumPaneSize(1)
72 class Calltip(wx
.wxTextCtrl
):
73 """Text control containing the most recent shell calltip."""
75 def __init__(self
, parent
=None, id=-1):
77 style
= wx
.wxTE_MULTILINE | wx
.wxTE_READONLY | wx
.wxTE_RICH2
78 wx
.wxTextCtrl
.__init
__(self
, parent
=parent
, id=id, style
=style
)
79 self
.SetBackgroundColour(wx
.wxColour(255, 255, 232))
80 dispatcher
.connect(receiver
=self
.display
, signal
='Shell.calltip')
82 def display(self
, calltip
):
83 """Receiver for Shell.calltip signal."""
84 self
.SetValue(calltip
)
87 class SessionListing(wx
.wxTextCtrl
):
88 """Text control containing all commands for session."""
90 def __init__(self
, parent
=None, id=-1):
92 style
= wx
.wxTE_MULTILINE | wx
.wxTE_READONLY | \
93 wx
.wxTE_RICH2 | wx
.wxTE_DONTWRAP
94 wx
.wxTextCtrl
.__init
__(self
, parent
=parent
, id=id, style
=style
)
95 dispatcher
.connect(receiver
=self
.push
, signal
='Interpreter.push')
97 def push(self
, command
, more
):
98 """Receiver for Interpreter.push signal."""
99 if command
and not more
:
100 self
.SetInsertionPointEnd()
101 start
, end
= self
.GetSelection()
103 self
.SetSelection(0, 0)
104 self
.AppendText(command
+ '\n')
107 class DispatcherListing(wx
.wxTextCtrl
):
108 """Text control containing all dispatches for session."""
110 def __init__(self
, parent
=None, id=-1):
112 style
= wx
.wxTE_MULTILINE | wx
.wxTE_READONLY | \
113 wx
.wxTE_RICH2 | wx
.wxTE_DONTWRAP
114 wx
.wxTextCtrl
.__init
__(self
, parent
=parent
, id=id, style
=style
)
115 dispatcher
.connect(receiver
=self
.spy
)
117 def spy(self
, signal
, sender
):
118 """Receiver for Any signal from Any sender."""
119 text
= '%r from %s' % (signal
, sender
)
120 self
.SetInsertionPointEnd()
121 start
, end
= self
.GetSelection()
123 self
.SetSelection(0, 0)
124 self
.AppendText(text
+ '\n')
127 class CrustFrame(wx
.wxFrame
, ShellMenu
):
128 """Frame containing all the PyCrust components."""
130 name
= 'PyCrust Frame'
131 revision
= __revision__
133 def __init__(self
, parent
=None, id=-1, title
='PyCrust',
134 pos
=wx
.wxDefaultPosition
, size
=wx
.wxDefaultSize
,
135 style
=wx
.wxDEFAULT_FRAME_STYLE
,
136 rootObject
=None, rootLabel
=None, rootIsNamespace
=True,
137 locals=None, InterpClass
=None, *args
, **kwds
):
138 """Create a PyCrust CrustFrame instance."""
139 wx
.wxFrame
.__init
__(self
, parent
, id, title
, pos
, size
, style
)
140 intro
= 'PyCrust %s - The Flakiest Python Shell' % VERSION
141 intro
+= '\nSponsored by Orbtech - '
142 intro
+= 'Your source for Python programming expertise.'
143 self
.CreateStatusBar()
144 self
.SetStatusText(intro
.replace('\n', ', '))
146 self
.SetIcon(images
.getPyCrustIcon())
147 self
.crust
= Crust(parent
=self
, intro
=intro
,
148 rootObject
=rootObject
,
150 rootIsNamespace
=rootIsNamespace
,
152 InterpClass
=InterpClass
, *args
, **kwds
)
153 # Override the filling so that status messages go to the status bar.
154 self
.crust
.filling
.tree
.setStatusText
= self
.SetStatusText
155 # Override the shell so that status messages go to the status bar.
156 self
.crust
.shell
.setStatusText
= self
.SetStatusText
157 # Fix a problem with the sash shrinking to nothing.
158 self
.crust
.filling
.SetSashPosition(200)
159 self
.shell
= self
.crust
.shell
161 wx
.EVT_CLOSE(self
, self
.OnCloseWindow
)
162 # Set focus to the shell editor.
163 self
.crust
.shell
.SetFocus()
165 def OnCloseWindow(self
, event
):
166 self
.crust
.shell
.destroy()