self.crustFrame = CrustFrame(locals=locals)
self.crustFrame.Show(true)
# Set focus to the shell editor.
- self.crustFrame.crust.shell.SetFocus()
+ #self.crustFrame.crust.shell.SetFocus()
self.SetTopWindow(self.crustFrame)
# Add the application object to the sys module's namespace.
# This allows a shell user to do:
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
size=wxDefaultSize, style=wxSP_3D, name='Crust Window', \
- ingredients=None, rootLabel=None, intro='', locals=None, \
+ rootObject=None, rootLabel=None, rootIsNamespace=1, \
+ intro='', locals=None, \
InterpClass=None, *args, **kwds):
"""Create a PyCrust Crust instance."""
wxSplitterWindow.__init__(self, parent, id, pos, size, style, name)
locals=locals, InterpClass=InterpClass, \
*args, **kwds)
self.filling = Filling(parent=self, \
- ingredients=self.shell.interp.locals, \
- rootLabel=rootLabel)
+ rootObject=self.shell.interp.locals, \
+ rootLabel=rootLabel, rootIsNamespace=1)
"""Add 'filling' to the interpreter's locals."""
self.shell.interp.locals['filling'] = self.filling
self.SplitHorizontally(self.shell, self.filling, 300)
- # Set focus to the shell editor. Doesn't always work as intended.
- self.shell.SetFocus()
+ self.SetMinimumPaneSize(1)
-class CrustFrame(wxFrame):
+# Temporary hack to share menus between PyCrust and PyShell.
+from shell import ShellMenu
+
+class CrustFrame(wxFrame, ShellMenu):
"""Frame containing all the PyCrust components."""
name = 'PyCrust Frame'
revision = __version__
def __init__(self, parent=None, id=-1, title='PyCrust', \
- ingredients=None, rootLabel=None, locals=None, \
- InterpClass=None, *args, **kwds):
+ rootObject=None, rootLabel=None, rootIsNamespace=1, \
+ locals=None, InterpClass=None, *args, **kwds):
"""Create a PyCrust CrustFrame instance."""
wxFrame.__init__(self, parent, id, title)
intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % VERSION
icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
self.SetIcon(icon)
self.crust = Crust(parent=self, intro=intro, \
- ingredients=ingredients, \
- rootLabel=rootLabel, locals=locals, \
+ rootObject=rootObject, \
+ rootLabel=rootLabel, \
+ rootIsNamespace=rootIsNamespace, \
+ locals=locals, \
InterpClass=InterpClass, *args, **kwds)
# Override the filling so that status messages go to the status bar.
self.crust.filling.fillingTree.setStatusText = self.SetStatusText
# Override the shell so that status messages go to the status bar.
self.crust.shell.setStatusText = self.SetStatusText
- # Set focus to the shell editor. Doesn't always work as intended.
+ # Fix a problem with the sash shrinking to nothing.
+ self.crust.filling.SetSashPosition(200)
+ # Set focus to the shell editor.
self.crust.shell.SetFocus()
+ # Temporary hack to share menus between PyCrust and PyShell.
+ self.shell = self.crust.shell
+ self.createMenus()
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
size=wxDefaultSize, style=wxTR_HAS_BUTTONS, \
- ingredients=None, rootLabel=None):
+ rootObject=None, rootLabel=None, rootIsNamespace=0):
"""Create a PyCrust FillingTree instance."""
wxTreeCtrl.__init__(self, parent, id, pos, size)
- if not ingredients:
+ self.rootIsNamespace = rootIsNamespace
+ if not rootObject:
import __main__
- ingredients = __main__
+ rootObject = __main__
+ self.rootIsNamespace = 1
if not rootLabel: rootLabel = 'Ingredients'
- rootdata = wxTreeItemData(ingredients)
- self.root = self.AddRoot(rootLabel, -1, -1, rootdata)
+ rootData = wxTreeItemData(rootObject)
+ self.root = self.AddRoot(rootLabel, -1, -1, rootData)
self.SetItemHasChildren(self.root, self.hasChildren(self.root))
EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
for item in list:
itemtext = str(item)
# Show string dictionary items with single quotes, except for
- # the first level of items, which represent the local namespace.
+ # the first level of items, if they represent a namespace.
if type(object) is types.DictType \
and type(item) is types.StringType \
- and selection != self.root:
+ and (selection != self.root \
+ or (selection == self.root and not self.rootIsNamespace)):
itemtext = repr(item)
child = self.AppendItem(selection, itemtext, -1, -1, \
wxTreeItemData(children[item]))
parentobject = self.GetPyData(parent)
name = self.GetItemText(item)
# Apply dictionary syntax to dictionary items, except the root
- # and first level children.
- if item != self.root and parent != self.root \
- and type(parentobject) is types.DictType:
+ # and first level children of a namepace.
+ if type(parentobject) is types.DictType \
+ and ((item != self.root and parent != self.root) \
+ or (parent == self.root and not self.rootIsNamespace)):
name = '[' + name + ']'
# Apply dot syntax to multipart names.
if partial:
name += partial
else:
name += '.' + partial
- # Repeat for everything but the root item and first level children.
- if item != self.root and parent != self.root:
+ # Repeat for everything but the root item
+ # and first level children of a namespace.
+ if (item != self.root and parent != self.root) \
+ or (parent == self.root and not self.rootIsNamespace):
name = self.getFullName(parent, partial=name)
return name
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
size=wxDefaultSize, style=wxSP_3D, name='Filling Window', \
- ingredients=None, rootLabel=None):
+ rootObject=None, rootLabel=None, rootIsNamespace=0):
"""Create a PyCrust Filling instance."""
wxSplitterWindow.__init__(self, parent, id, pos, size, style, name)
- self.fillingTree = FillingTree(parent=self, ingredients=ingredients, \
- rootLabel=rootLabel)
+ self.fillingTree = FillingTree(parent=self, rootObject=rootObject, \
+ rootLabel=rootLabel, \
+ rootIsNamespace=rootIsNamespace)
self.fillingText = FillingText(parent=self)
self.SplitVertically(self.fillingTree, self.fillingText, 200)
+ self.SetMinimumPaneSize(1)
# Override the filling so that descriptions go to fillingText.
self.fillingTree.setText = self.fillingText.SetText
# Select the root item.
def __init__(self, parent=None, id=-1, title='PyFilling', \
pos=wxDefaultPosition, size=wxDefaultSize, \
- style=wxDEFAULT_FRAME_STYLE, ingredients=None, \
- rootLabel=None):
+ style=wxDEFAULT_FRAME_STYLE, rootObject=None, \
+ rootLabel=None, rootIsNamespace=0):
"""Create a PyCrust FillingFrame instance."""
wxFrame.__init__(self, parent, id, title, pos, size, style)
intro = 'Welcome To PyFilling - The Tastiest Namespace Inspector'
if wxPlatform == '__WXMSW__':
icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
self.SetIcon(icon)
- self.filling = Filling(parent=self, ingredients=ingredients, \
- rootLabel=rootLabel)
+ self.filling = Filling(parent=self, rootObject=rootObject, \
+ rootLabel=rootLabel, \
+ rootIsNamespace=rootIsNamespace)
# Override the filling so that status messages go to the status bar.
self.filling.fillingTree.setStatusText = self.SetStatusText
self.stdin = stdin
self.stdout = stdout
self.stderr = stderr
- if rawin is not None:
+ if rawin:
import __builtin__
__builtin__.raw_input = rawin
del __builtin__
- copyright = 'Type "copyright", "credits" or "license" for more information.'
+ copyright = \
+ 'Type "copyright", "credits" or "license" for more information.'
self.introText = 'Python %s on %s%s%s' % \
(sys.version, sys.platform, os.linesep, copyright)
try:
except AttributeError:
sys.ps2 = '... '
self.more = 0
- self.commandBuffer = [] # List of lists to support recursive push().
- self.commandHistory = []
+ # List of lists to support recursive push().
+ self.commandBuffer = []
self.startupScript = os.environ.get('PYTHONSTARTUP')
def push(self, command):
"""Send command to the interpreter to be executed.
- Because this may be called recursively, we append a new list
- onto the commandBuffer list and then append commands into that.
- If the passed in command is part of a multi-line command we keep
- appending the pieces to the last list in commandBuffer until we
- have a complete command, then, finally, we delete that last list.
- """
+ Because this may be called recursively, we append a new list
+ onto the commandBuffer list and then append commands into
+ that. If the passed in command is part of a multi-line command
+ we keep appending the pieces to the last list in commandBuffer
+ until we have a complete command, then, finally, we delete
+ that last list."""
if not self.more: self.commandBuffer.append([])
self.commandBuffer[-1].append(command)
source = '\n'.join(self.commandBuffer[-1])
sys.stdout = self.stdout
sys.stderr = self.stderr
more = InteractiveInterpreter.runsource(self, source)
- sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr
+ # If sys.std* is still what we set it to, then restore it.
+ # But, if the executed source changed sys.std*, assume it
+ # was meant to be changed and leave it. Power to the people.
+ if sys.stdin == self.stdin:
+ sys.stdin = stdin
+ if sys.stdout == self.stdout:
+ sys.stdout = stdout
+ if sys.stderr == self.stderr:
+ sys.stderr = stderr
return more
def getAutoCompleteList(self, command='', *args, **kwds):
import keyword
import os
import sys
+from pseudo import PseudoFileIn
+from pseudo import PseudoFileOut
+from pseudo import PseudoFileErr
from version import VERSION
locals=None, InterpClass=None, *args, **kwds):
"""Create a PyCrust Shell instance."""
wxStyledTextCtrl.__init__(self, parent, id, pos, size, style)
+ # Grab these so they can be restored by self.redirect* methods.
+ self.stdin = sys.stdin
+ self.stdout = sys.stdout
+ self.stderr = sys.stderr
+ # Add the current working directory "." to the search path.
+ sys.path.insert(0, os.curdir)
# Import a default interpreter class if one isn't provided.
if InterpClass == None:
from interpreter import Interpreter
# Add the dictionary that was passed in.
if locals:
shellLocals.update(locals)
- from pseudo import PseudoFileIn, PseudoFileOut, PseudoFileErr
self.interp = Interpreter(locals=shellLocals, \
rawin=self.readRaw, \
stdin=PseudoFileIn(self.readIn), \
# environment. They can override anything they want.
try: self.execStartupScript(self.interp.startupScript)
except: pass
-
+
def destroy(self):
del self.interp
endline = self.GetCurrentLine()
# If they hit RETURN on the last line, execute the command.
if theline == endline:
- # Store the last-recalled command; see the main comment for
- # self.lastCommandRecalled.
- if command != '':
- self.lastCommandRecalled = self.historyPos
- # Reset the history position.
- self.historyPos = -1
- # Insert this command into the history, unless it's a blank line
- # or the same as the last command.
- if command != '' \
- and (len(self.history) == 0 or command != self.history[0]):
- self.history.insert(0, command)
self.push(command)
# Otherwise, replace the last line with the new line.
else:
The command may not necessarily be valid Python syntax."""
if not text:
text = self.GetCurLine()[0]
-## This is a hack due to a bug in the wxPython 2.3.2 beta. The following
-## two lines of code should go away once the bug has been fixed and the
-## line above should be restored.
-## self.write(' ')
-## text = self.GetCurLine()[0][:-1]
# XXX Need to extract real prompts here. Need to keep track of the
# prompt every time a command is issued.
ps1 = str(sys.ps1)
def push(self, command):
"""Send command to the interpreter for execution."""
+ self.addHistory(command)
self.write(os.linesep)
self.more = self.interp.push(command)
self.prompt()
# hitting enter. After they hit enter it becomes permanent.
self.EmptyUndoBuffer()
+ def addHistory(self, command):
+ """Add command to the command history."""
+ # Store the last-recalled command; see the main comment for
+ # self.lastCommandRecalled.
+ if command != '':
+ self.lastCommandRecalled = self.historyPos
+ # Reset the history position.
+ self.historyPos = -1
+ # Insert this command into the history, unless it's a blank
+ # line or the same as the last command.
+ if command != '' \
+ and (len(self.history) == 0 or command != self.history[0]):
+ self.history.insert(0, command)
+
def write(self, text):
"""Display text in the shell.
"""Replacement for stderr."""
self.write(text)
+ def redirectStdin(self, redirect=1):
+ """If redirect is true then sys.stdin will come from the shell."""
+ if redirect:
+ sys.stdin = PseudoFileIn(self.readIn)
+ else:
+ sys.stdin = self.stdin
+
+ def redirectStdout(self, redirect=1):
+ """If redirect is true then sys.stdout will go to the shell."""
+ if redirect:
+ sys.stdout = PseudoFileOut(self.writeOut)
+ else:
+ sys.stdout = self.stdout
+
+ def redirectStderr(self, redirect=1):
+ """If redirect is true then sys.stderr will go to the shell."""
+ if redirect:
+ sys.stderr = PseudoFileErr(self.writeErr)
+ else:
+ sys.stderr = self.stderr
+
def CanCut(self):
"""Return true if text is selected and can be cut."""
return self.GetSelectionStart() != self.GetSelectionEnd()
ID_CALLTIPS_SHOW = NewId()
-class ShellFrame(wxFrame):
- """Frame containing the PyCrust shell component."""
+class ShellMenu:
+ """Mixin class to add standard menu items."""
- name = 'PyCrust Shell Frame'
- revision = __version__
-
- def __init__(self, parent=None, id=-1, title='PyShell', \
- pos=wxDefaultPosition, size=wxDefaultSize, \
- style=wxDEFAULT_FRAME_STYLE, locals=None, \
- InterpClass=None, *args, **kwds):
- """Create a PyCrust ShellFrame instance."""
- wxFrame.__init__(self, parent, id, title, pos, size, style)
- intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % VERSION
- self.CreateStatusBar()
- self.SetStatusText(intro)
- if wxPlatform == '__WXMSW__':
- icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
- self.SetIcon(icon)
- self.createMenus()
- self.shell = Shell(parent=self, id=-1, introText=intro, \
- locals=locals, InterpClass=InterpClass, \
- *args, **kwds)
- # Override the shell so that status messages go to the status bar.
- self.shell.setStatusText = self.SetStatusText
-
def createMenus(self):
m = self.fileMenu = wxMenu()
m.AppendSeparator()
m.Append(wxID_UNDO, '&Undo \tCtrl+Z', 'Undo the last action')
m.Append(wxID_REDO, '&Redo \tCtrl+Y', 'Redo the last undone action')
m.AppendSeparator()
- m.Append(wxID_CUT, 'Cu&t \tCtrl+X', 'Cut the selection')
- m.Append(wxID_COPY, '&Copy \tCtrl+C', 'Copy the selection')
- m.Append(wxID_PASTE, '&Paste \tCtrl+V', 'Paste')
+ m.Append(wxID_CUT, 'Cu&t', 'Cut the selection')
+ m.Append(wxID_COPY, '&Copy', 'Copy the selection')
+ m.Append(wxID_PASTE, '&Paste', 'Paste')
m.AppendSeparator()
- m.Append(wxID_CLEAR, 'Cle&ar \tDel', 'Delete the selection')
- m.Append(wxID_SELECTALL, 'Select A&ll \tCtrl+A', 'Select all text')
+ m.Append(wxID_CLEAR, 'Cle&ar', 'Delete the selection')
+ m.Append(wxID_SELECTALL, 'Select A&ll', 'Select all text')
m = self.autocompMenu = wxMenu()
m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion', \
event.Check(self.shell.autoCallTip)
+class ShellFrame(wxFrame, ShellMenu):
+ """Frame containing the PyCrust shell component."""
+
+ name = 'PyCrust Shell Frame'
+ revision = __version__
+
+ def __init__(self, parent=None, id=-1, title='PyShell', \
+ pos=wxDefaultPosition, size=wxDefaultSize, \
+ style=wxDEFAULT_FRAME_STYLE, locals=None, \
+ InterpClass=None, *args, **kwds):
+ """Create a PyCrust ShellFrame instance."""
+ wxFrame.__init__(self, parent, id, title, pos, size, style)
+ intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % VERSION
+ self.CreateStatusBar()
+ self.SetStatusText(intro)
+ if wxPlatform == '__WXMSW__':
+ icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
+ self.SetIcon(icon)
+ self.shell = Shell(parent=self, id=-1, introText=intro, \
+ locals=locals, InterpClass=InterpClass, \
+ *args, **kwds)
+ # Override the shell so that status messages go to the status bar.
+ self.shell.setStatusText = self.SetStatusText
+ self.createMenus()
+
+
#
# Author: Lorne White, Lorne.White@telusplanet.net
#
-# Created: Feb 25, 2001
+# Created: Sept 4, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
# button colour will change to new colour
# GetColour method to get the selected colour
+# Updates:
+# call back to function if changes made
+
class ColourSelect(wxButton):
- def __init__(self, parent, position = wxPoint(20, 20), bcolour = [0, 0, 0], size = wxSize(20, 20)):
+ def __init__(self, parent, position = wxPoint(20, 20), bcolour = [0, 0, 0], size = wxSize(20, 20), callback = None):
self.win = parent
+ self.callback = callback
mID = NewId()
self.b = b = wxButton(parent, mID, "", position, size)
EVT_BUTTON(parent, mID, self.OnClick)
- self.set_colour_val = set_colour = wxColor(bcolour[0], bcolour[1], bcolour[2])
- b.SetBackgroundColour(set_colour)
- b.SetForegroundColour(wxWHITE)
- self.set_colour = bcolour
+ self.SetColourValue(bcolour)
def SetColour(self, bcolour):
self.b.SetBackgroundColour(bcolour)
+ def SetColourValue(self, bcolour):
+ self.set_colour_val = wxColor(bcolour[0], bcolour[1], bcolour[2])
+ self.set_colour = bcolour
+
+ self.b.SetBackgroundColour(self.set_colour_val)
+ self.b.SetForegroundColour(wxWHITE)
+
+ def SetValue(self, bcolour):
+ self.SetColourValue(bcolour)
+
def GetColour(self):
return self.set_colour
+ def OnChange(self):
+ if self.callback != None:
+ self.callback()
+
def OnClick(self, event):
data = wxColourData()
data.SetChooseFull(true)
self.set_colour = set = data.GetColour().Get()
self.set_colour_val = bcolour = wxColour(set[0],set[1],set[2])
self.b.SetBackgroundColour(bcolour)
+ self.OnChange()
dlg.Destroy()
# Author: Lorne White (email: lorne.white@telusplanet.net)
#
# Created:
-# Version 0.7
-# Date: August 18, 2001
+# Version 0.72
+# Date: Sept 8, 2001
# Licence: wxWindows license
#----------------------------------------------------------------------------
self.row_line_colour = {}
self.parentFrame = parentFrame
+ self.SetPreviewSize()
self.printData = wxPrintData()
self.scale = 1.0
self.SetMargins()
self.SetPortrait()
+ def SetPreviewSize(self, position = wxPoint(0, 0), size="Full"):
+ if size == "Full":
+ screenWidth = int(wx.wxSystemSettings_GetSystemMetric(wx.wxSYS_SCREEN_X))
+ screenHeight = int(wx.wxSystemSettings_GetSystemMetric(wx.wxSYS_SCREEN_Y))
+ self.preview_frame_size = wxSize(screenWidth, screenHeight)
+ self.preview_frame_pos = position
+ else:
+ self.preview_frame_size = size
+ self.preview_frame_pos = position
+
def SetPaperId(self, paper):
self.printData.SetPaperId(paper)
frame.Initialize()
if self.parentFrame:
- frame.SetPosition(self.parentFrame.GetPosition())
- frame.SetSize(self.parentFrame.GetSize())
+ frame.SetPosition(self.preview_frame_pos)
+ frame.SetSize(self.preview_frame_size)
frame.Show(true)
"bmp" :wxBITMAP_TYPE_BMP,
"png" :wxBITMAP_TYPE_PNG,
"jpeg":wxBITMAP_TYPE_JPEG,
+ "jpg" :wxBITMAP_TYPE_JPEG,
"gif" :wxBITMAP_TYPE_GIF,
"xbm" :wxBITMAP_TYPE_XBM,
}