]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxPython/lib/PyCrust/crust.py
caeb20f6dbf390e1c42d0f240242139602183e9a
[wxWidgets.git] / wxPython / wxPython / lib / PyCrust / crust.py
1 """PyCrust 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
7 from wxPython import wx
8 from filling import Filling
9 import os
10 from shell import Shell
11 from shellmenu import ShellMenu
12 from version import VERSION
13
14 try:
15 True
16 except NameError:
17 True = 1==1
18 False = 1==0
19
20
21 class Crust(wx.wxSplitterWindow):
22 """PyCrust Crust based on wxSplitterWindow."""
23
24 name = 'PyCrust Crust'
25 revision = __revision__
26
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,
36 *args, **kwds)
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,
43 rootLabel=rootLabel,
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')
54 from wxd import wx_
55 self.wxdocs = Filling(parent=self.notebook,
56 rootObject=wx_,
57 rootLabel='wx',
58 rootIsNamespace=False,
59 static=True)
60 self.notebook.AddPage(page=self.wxdocs, text='wxPython Docs')
61 from wxd import stc_
62 self.stcdocs = Filling(parent=self.notebook,
63 rootObject=stc_.StyledTextCtrl,
64 rootLabel='StyledTextCtrl',
65 rootIsNamespace=False,
66 static=True)
67 self.notebook.AddPage(page=self.stcdocs, text='StyledTextCtrl Docs')
68 self.SplitHorizontally(self.shell, self.notebook, 300)
69 self.SetMinimumPaneSize(1)
70
71
72 class Calltip(wx.wxTextCtrl):
73 """Text control containing the most recent shell calltip."""
74
75 def __init__(self, parent=None, id=-1):
76 import dispatcher
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')
81
82 def display(self, calltip):
83 """Receiver for Shell.calltip signal."""
84 self.SetValue(calltip)
85
86
87 class SessionListing(wx.wxTextCtrl):
88 """Text control containing all commands for session."""
89
90 def __init__(self, parent=None, id=-1):
91 import dispatcher
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')
96
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()
102 if start != end:
103 self.SetSelection(0, 0)
104 self.AppendText(command + '\n')
105
106
107 class DispatcherListing(wx.wxTextCtrl):
108 """Text control containing all dispatches for session."""
109
110 def __init__(self, parent=None, id=-1):
111 import dispatcher
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)
116
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()
122 if start != end:
123 self.SetSelection(0, 0)
124 self.AppendText(text + '\n')
125
126
127 class CrustFrame(wx.wxFrame, ShellMenu):
128 """Frame containing all the PyCrust components."""
129
130 name = 'PyCrust Frame'
131 revision = __revision__
132
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', ', '))
145 import images
146 self.SetIcon(images.getPyCrustIcon())
147 self.crust = Crust(parent=self, intro=intro,
148 rootObject=rootObject,
149 rootLabel=rootLabel,
150 rootIsNamespace=rootIsNamespace,
151 locals=locals,
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
160 self.createMenus()
161 wx.EVT_CLOSE(self, self.OnCloseWindow)
162 # Set focus to the shell editor.
163 self.crust.shell.SetFocus()
164
165 def OnCloseWindow(self, event):
166 self.crust.shell.destroy()
167 self.Destroy()
168
169