]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/py/crust.py
   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') 
  66         self
.wxdocs 
= Filling(parent
=self
.notebook
,  
  69                               rootIsNamespace
=False, 
  71         self
.notebook
.AddPage(page
=self
.wxdocs
, text
='wxPython Docs') 
  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
=parent
, id=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
) 
 130 class SessionListing(wx
.TextCtrl
): 
 131     """Text control containing all commands for session.""" 
 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') 
 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() 
 145                 self
.SetSelection(0, 0) 
 146             self
.AppendText(command 
+ '\n') 
 149 class DispatcherListing(wx
.TextCtrl
): 
 150     """Text control containing all dispatches for session.""" 
 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
) 
 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() 
 164             self
.SetSelection(0, 0) 
 165         self
.AppendText(text 
+ '\n') 
 168 class CrustFrame(frame
.Frame
): 
 169     """Frame containing all the PyCrust components.""" 
 172     revision 
= __revision__
 
 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
, 
 188                            rootIsNamespace
=rootIsNamespace
, 
 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() 
 201     def OnClose(self
, event
): 
 202         """Event handler for closing.""" 
 203         self
.crust
.shell
.destroy() 
 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
)