2003-11-12 16:34:20 -05:00
|
|
|
"""Crust combines the shell and filling into one control."""
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
__author__ = "Patrick K. O'Brien <pobrien@orbtech.com>"
|
|
|
|
__cvsid__ = "$Id$"
|
|
|
|
__revision__ = "$Revision$"[11:-2]
|
2003-07-02 19:13:10 -04:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
import wx
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pprint
|
2005-12-30 18:02:03 -05:00
|
|
|
import re
|
2003-11-12 16:34:20 -05:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import dispatcher
|
|
|
|
import editwindow
|
|
|
|
from filling import Filling
|
|
|
|
import frame
|
|
|
|
from shell import Shell
|
|
|
|
from version import VERSION
|
|
|
|
|
|
|
|
|
|
|
|
class Crust(wx.SplitterWindow):
|
|
|
|
"""Crust based on SplitterWindow."""
|
|
|
|
|
|
|
|
name = 'Crust'
|
|
|
|
revision = __revision__
|
2005-12-30 18:02:03 -05:00
|
|
|
sashoffset = 300
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
|
|
|
|
size=wx.DefaultSize, style=wx.SP_3D|wx.SP_LIVE_UPDATE,
|
2003-11-12 16:34:20 -05:00
|
|
|
name='Crust Window', rootObject=None, rootLabel=None,
|
2005-12-30 18:02:03 -05:00
|
|
|
rootIsNamespace=True, intro='', locals=None,
|
|
|
|
InterpClass=None,
|
|
|
|
startupScript=None, execStartupScript=True,
|
|
|
|
*args, **kwds):
|
2003-11-12 16:34:20 -05:00
|
|
|
"""Create Crust instance."""
|
|
|
|
wx.SplitterWindow.__init__(self, parent, id, pos, size, style, name)
|
2005-12-30 18:02:03 -05:00
|
|
|
self.shell = Shell(parent=self, introText=intro,
|
|
|
|
locals=locals, InterpClass=InterpClass,
|
|
|
|
startupScript=startupScript,
|
|
|
|
execStartupScript=execStartupScript,
|
2003-11-12 16:34:20 -05:00
|
|
|
*args, **kwds)
|
|
|
|
self.editor = self.shell
|
|
|
|
if rootObject is None:
|
|
|
|
rootObject = self.shell.interp.locals
|
|
|
|
self.notebook = wx.Notebook(parent=self, id=-1)
|
|
|
|
self.shell.interp.locals['notebook'] = self.notebook
|
2005-12-30 18:02:03 -05:00
|
|
|
self.filling = Filling(parent=self.notebook,
|
|
|
|
rootObject=rootObject,
|
|
|
|
rootLabel=rootLabel,
|
2003-11-12 16:34:20 -05:00
|
|
|
rootIsNamespace=rootIsNamespace)
|
|
|
|
# Add 'filling' to the interpreter's locals.
|
|
|
|
self.shell.interp.locals['filling'] = self.filling
|
|
|
|
self.notebook.AddPage(page=self.filling, text='Namespace', select=True)
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.display = Display(parent=self.notebook)
|
|
|
|
self.notebook.AddPage(page=self.display, text='Display')
|
|
|
|
# Add 'pp' (pretty print) to the interpreter's locals.
|
|
|
|
self.shell.interp.locals['pp'] = self.display.setItem
|
2005-12-30 18:02:03 -05:00
|
|
|
self.display.nbTab = self.notebook.GetPageCount()-1
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.calltip = Calltip(parent=self.notebook)
|
|
|
|
self.notebook.AddPage(page=self.calltip, text='Calltip')
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.sessionlisting = SessionListing(parent=self.notebook)
|
2006-02-23 20:21:26 -05:00
|
|
|
self.notebook.AddPage(page=self.sessionlisting, text='History')
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.dispatcherlisting = DispatcherListing(parent=self.notebook)
|
|
|
|
self.notebook.AddPage(page=self.dispatcherlisting, text='Dispatcher')
|
2005-12-30 18:02:03 -05:00
|
|
|
|
|
|
|
self.SplitHorizontally(self.shell, self.notebook, -self.sashoffset)
|
|
|
|
self.SetMinimumPaneSize(100)
|
|
|
|
|
|
|
|
self.Bind(wx.EVT_SIZE, self.SplitterOnSize)
|
|
|
|
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnChanged)
|
|
|
|
|
|
|
|
|
|
|
|
def OnChanged(self, event):
|
|
|
|
"""update sash offset from the bottom of the window"""
|
|
|
|
self.sashoffset = self.GetSize().height - event.GetSashPosition()
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
|
|
|
|
# Make the splitter expand the top window when resized
|
|
|
|
def SplitterOnSize(self, event):
|
|
|
|
splitter = event.GetEventObject()
|
|
|
|
sz = splitter.GetSize()
|
|
|
|
splitter.SetSashPosition(sz.height - self.sashoffset, True)
|
|
|
|
event.Skip()
|
|
|
|
|
|
|
|
|
|
|
|
def LoadSettings(self, config):
|
|
|
|
self.shell.LoadSettings(config)
|
|
|
|
self.filling.LoadSettings(config)
|
|
|
|
|
|
|
|
pos = config.ReadInt('Sash/CrustPos', 400)
|
|
|
|
wx.CallAfter(self.SetSashPosition, pos)
|
|
|
|
def _updateSashPosValue():
|
|
|
|
sz = self.GetSize()
|
|
|
|
self.sashoffset = sz.height - self.GetSashPosition()
|
|
|
|
wx.CallAfter(_updateSashPosValue)
|
|
|
|
zoom = config.ReadInt('View/Zoom/Display', -99)
|
|
|
|
if zoom != -99:
|
|
|
|
self.display.SetZoom(zoom)
|
|
|
|
|
|
|
|
|
|
|
|
def SaveSettings(self, config):
|
|
|
|
self.shell.SaveSettings(config)
|
|
|
|
self.filling.SaveSettings(config)
|
|
|
|
|
|
|
|
config.WriteInt('Sash/CrustPos', self.GetSashPosition())
|
|
|
|
config.WriteInt('View/Zoom/Display', self.display.GetZoom())
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
|
|
|
class Display(editwindow.EditWindow):
|
|
|
|
"""STC used to display an object using Pretty Print."""
|
|
|
|
|
|
|
|
def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
|
|
|
|
size=wx.DefaultSize,
|
|
|
|
style=wx.CLIP_CHILDREN | wx.SUNKEN_BORDER,
|
|
|
|
static=False):
|
|
|
|
"""Create Display instance."""
|
|
|
|
editwindow.EditWindow.__init__(self, parent, id, pos, size, style)
|
|
|
|
# Configure various defaults and user preferences.
|
|
|
|
self.SetReadOnly(True)
|
|
|
|
self.SetWrapMode(False)
|
|
|
|
if not static:
|
|
|
|
dispatcher.connect(receiver=self.push, signal='Interpreter.push')
|
|
|
|
|
|
|
|
def push(self, command, more):
|
|
|
|
"""Receiver for Interpreter.push signal."""
|
|
|
|
self.Refresh()
|
|
|
|
|
|
|
|
def Refresh(self):
|
|
|
|
if not hasattr(self, "item"):
|
|
|
|
return
|
|
|
|
self.SetReadOnly(False)
|
|
|
|
text = pprint.pformat(self.item)
|
|
|
|
self.SetText(text)
|
|
|
|
self.SetReadOnly(True)
|
|
|
|
|
|
|
|
def setItem(self, item):
|
|
|
|
"""Set item to pretty print in the notebook Display tab."""
|
|
|
|
self.item = item
|
|
|
|
self.Refresh()
|
2005-12-30 18:02:03 -05:00
|
|
|
if self.GetParent().GetSelection() != self.nbTab:
|
|
|
|
focus = wx.Window.FindFocus()
|
|
|
|
self.GetParent().SetSelection(self.nbTab)
|
|
|
|
wx.CallAfter(focus.SetFocus)
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
# TODO: Switch this to a editwindow.EditWindow
|
2003-11-12 16:34:20 -05:00
|
|
|
class Calltip(wx.TextCtrl):
|
|
|
|
"""Text control containing the most recent shell calltip."""
|
|
|
|
|
|
|
|
def __init__(self, parent=None, id=-1):
|
2004-02-08 14:28:51 -05:00
|
|
|
style = (wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH2)
|
|
|
|
wx.TextCtrl.__init__(self, parent, id, style=style)
|
2005-12-30 18:02:03 -05:00
|
|
|
self.SetBackgroundColour(wx.Colour(255, 255, 208))
|
2003-11-12 16:34:20 -05:00
|
|
|
dispatcher.connect(receiver=self.display, signal='Shell.calltip')
|
|
|
|
|
2006-02-23 20:21:26 -05:00
|
|
|
df = self.GetFont()
|
|
|
|
font = wx.Font(df.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
|
|
|
|
self.SetFont(font)
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
def display(self, calltip):
|
|
|
|
"""Receiver for Shell.calltip signal."""
|
2004-02-08 16:48:07 -05:00
|
|
|
## self.SetValue(calltip) # Caused refresh problem on Windows.
|
|
|
|
self.Clear()
|
|
|
|
self.AppendText(calltip)
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
# TODO: Switch this to a editwindow.EditWindow
|
2003-11-12 16:34:20 -05:00
|
|
|
class SessionListing(wx.TextCtrl):
|
|
|
|
"""Text control containing all commands for session."""
|
|
|
|
|
|
|
|
def __init__(self, parent=None, id=-1):
|
2004-02-08 14:28:51 -05:00
|
|
|
style = (wx.TE_MULTILINE | wx.TE_READONLY |
|
|
|
|
wx.TE_RICH2 | wx.TE_DONTWRAP)
|
|
|
|
wx.TextCtrl.__init__(self, parent, id, style=style)
|
2006-02-23 20:21:26 -05:00
|
|
|
dispatcher.connect(receiver=self.addHistory, signal="Shell.addHistory")
|
|
|
|
dispatcher.connect(receiver=self.clearHistory, signal="Shell.clearHistory")
|
|
|
|
dispatcher.connect(receiver=self.loadHistory, signal="Shell.loadHistory")
|
|
|
|
|
|
|
|
df = self.GetFont()
|
|
|
|
font = wx.Font(df.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
|
|
|
|
self.SetFont(font)
|
|
|
|
|
|
|
|
def loadHistory(self, history):
|
|
|
|
# preload the existing history, if any
|
|
|
|
hist = history[:]
|
|
|
|
hist.reverse()
|
|
|
|
self.SetValue('\n'.join(hist) + '\n')
|
|
|
|
self.SetInsertionPointEnd()
|
2003-11-12 16:34:20 -05:00
|
|
|
|
2006-02-23 20:21:26 -05:00
|
|
|
def addHistory(self, command):
|
|
|
|
if command:
|
2003-11-12 16:34:20 -05:00
|
|
|
self.SetInsertionPointEnd()
|
|
|
|
self.AppendText(command + '\n')
|
|
|
|
|
2006-02-23 20:21:26 -05:00
|
|
|
def clearHistory(self):
|
|
|
|
self.SetValue("")
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
class DispatcherListing(wx.TextCtrl):
|
|
|
|
"""Text control containing all dispatches for session."""
|
|
|
|
|
|
|
|
def __init__(self, parent=None, id=-1):
|
2004-02-08 14:28:51 -05:00
|
|
|
style = (wx.TE_MULTILINE | wx.TE_READONLY |
|
|
|
|
wx.TE_RICH2 | wx.TE_DONTWRAP)
|
|
|
|
wx.TextCtrl.__init__(self, parent, id, style=style)
|
2003-11-12 16:34:20 -05:00
|
|
|
dispatcher.connect(receiver=self.spy)
|
|
|
|
|
2006-02-23 20:21:26 -05:00
|
|
|
df = self.GetFont()
|
|
|
|
font = wx.Font(df.GetPointSize(), wx.TELETYPE, wx.NORMAL, wx.NORMAL)
|
|
|
|
self.SetFont(font)
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
def spy(self, signal, sender):
|
|
|
|
"""Receiver for Any signal from Any sender."""
|
|
|
|
text = '%r from %s' % (signal, sender)
|
|
|
|
self.SetInsertionPointEnd()
|
|
|
|
start, end = self.GetSelection()
|
|
|
|
if start != end:
|
|
|
|
self.SetSelection(0, 0)
|
|
|
|
self.AppendText(text + '\n')
|
|
|
|
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
|
|
|
|
class CrustFrame(frame.Frame, frame.ShellFrameMixin):
|
2003-11-12 16:34:20 -05:00
|
|
|
"""Frame containing all the PyCrust components."""
|
|
|
|
|
|
|
|
name = 'CrustFrame'
|
|
|
|
revision = __revision__
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
def __init__(self, parent=None, id=-1, title='PyCrust',
|
|
|
|
pos=wx.DefaultPosition, size=wx.DefaultSize,
|
|
|
|
style=wx.DEFAULT_FRAME_STYLE,
|
|
|
|
rootObject=None, rootLabel=None, rootIsNamespace=True,
|
2005-12-30 18:02:03 -05:00
|
|
|
locals=None, InterpClass=None,
|
|
|
|
config=None, dataDir=None,
|
|
|
|
*args, **kwds):
|
2003-11-12 16:34:20 -05:00
|
|
|
"""Create CrustFrame instance."""
|
|
|
|
frame.Frame.__init__(self, parent, id, title, pos, size, style)
|
2005-12-30 18:02:03 -05:00
|
|
|
frame.ShellFrameMixin.__init__(self, config, dataDir)
|
|
|
|
|
|
|
|
if size == wx.DefaultSize:
|
|
|
|
self.SetSize((800, 600))
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
intro = 'PyCrust %s - The Flakiest Python Shell' % VERSION
|
|
|
|
self.SetStatusText(intro.replace('\n', ', '))
|
|
|
|
self.crust = Crust(parent=self, intro=intro,
|
|
|
|
rootObject=rootObject,
|
|
|
|
rootLabel=rootLabel,
|
|
|
|
rootIsNamespace=rootIsNamespace,
|
|
|
|
locals=locals,
|
2005-12-30 18:02:03 -05:00
|
|
|
InterpClass=InterpClass,
|
|
|
|
startupScript=self.startupScript,
|
|
|
|
execStartupScript=self.execStartupScript,
|
|
|
|
*args, **kwds)
|
2003-11-12 16:34:20 -05:00
|
|
|
self.shell = self.crust.shell
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
# Override the filling so that status messages go to the status bar.
|
|
|
|
self.crust.filling.tree.setStatusText = self.SetStatusText
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
# Override the shell so that status messages go to the status bar.
|
|
|
|
self.shell.setStatusText = self.SetStatusText
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
self.shell.SetFocus()
|
2005-12-30 18:02:03 -05:00
|
|
|
self.LoadSettings()
|
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
|
|
|
|
def OnClose(self, event):
|
|
|
|
"""Event handler for closing."""
|
2005-12-30 18:02:03 -05:00
|
|
|
self.SaveSettings()
|
2003-11-12 16:34:20 -05:00
|
|
|
self.crust.shell.destroy()
|
|
|
|
self.Destroy()
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
|
2003-11-12 16:34:20 -05:00
|
|
|
def OnAbout(self, event):
|
|
|
|
"""Display an About window."""
|
|
|
|
title = 'About PyCrust'
|
|
|
|
text = 'PyCrust %s\n\n' % VERSION + \
|
|
|
|
'Yet another Python shell, only flakier.\n\n' + \
|
|
|
|
'Half-baked by Patrick K. O\'Brien,\n' + \
|
|
|
|
'the other half is still in the oven.\n\n' + \
|
|
|
|
'Shell Revision: %s\n' % self.shell.revision + \
|
|
|
|
'Interpreter Revision: %s\n\n' % self.shell.interp.revision + \
|
2004-10-15 16:31:23 -04:00
|
|
|
'Platform: %s\n' % sys.platform + \
|
2003-11-12 16:34:20 -05:00
|
|
|
'Python Version: %s\n' % sys.version.split()[0] + \
|
|
|
|
'wxPython Version: %s\n' % wx.VERSION_STRING + \
|
2005-12-30 18:02:03 -05:00
|
|
|
('\t(%s)\n' % ", ".join(wx.PlatformInfo[1:]))
|
2003-11-12 16:34:20 -05:00
|
|
|
dialog = wx.MessageDialog(self, text, title,
|
|
|
|
wx.OK | wx.ICON_INFORMATION)
|
|
|
|
dialog.ShowModal()
|
|
|
|
dialog.Destroy()
|
2005-12-30 18:02:03 -05:00
|
|
|
|
|
|
|
|
2006-01-17 00:42:30 -05:00
|
|
|
def OnHelp(self, event):
|
|
|
|
"""Show a help dialog."""
|
|
|
|
frame.ShellFrameMixin.OnHelp(self, event)
|
|
|
|
|
2005-12-30 18:02:03 -05:00
|
|
|
|
|
|
|
def LoadSettings(self):
|
|
|
|
if self.config is not None:
|
|
|
|
frame.ShellFrameMixin.LoadSettings(self)
|
|
|
|
frame.Frame.LoadSettings(self, self.config)
|
|
|
|
self.crust.LoadSettings(self.config)
|
|
|
|
|
|
|
|
|
2006-02-03 18:07:15 -05:00
|
|
|
def SaveSettings(self, force=False):
|
2005-12-30 18:02:03 -05:00
|
|
|
if self.config is not None:
|
|
|
|
frame.ShellFrameMixin.SaveSettings(self)
|
2006-02-03 18:07:15 -05:00
|
|
|
if self.autoSaveSettings or force:
|
2005-12-30 18:02:03 -05:00
|
|
|
frame.Frame.SaveSettings(self, self.config)
|
|
|
|
self.crust.SaveSettings(self.config)
|
|
|
|
|
|
|
|
|
|
|
|
def DoSaveSettings(self):
|
|
|
|
if self.config is not None:
|
2006-02-03 18:07:15 -05:00
|
|
|
self.SaveSettings(force=True)
|
2005-12-30 18:02:03 -05:00
|
|
|
self.config.Flush()
|
|
|
|
|
|
|
|
|
|
|
|
|