Updates to contributed library stuff, a new version of PyCrust
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11602 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Binary file not shown.
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 4.6 KiB |
@@ -18,7 +18,7 @@ class App(wxApp):
|
|||||||
self.crustFrame = CrustFrame(locals=locals)
|
self.crustFrame = CrustFrame(locals=locals)
|
||||||
self.crustFrame.Show(true)
|
self.crustFrame.Show(true)
|
||||||
# Set focus to the shell editor.
|
# Set focus to the shell editor.
|
||||||
self.crustFrame.crust.shell.SetFocus()
|
#self.crustFrame.crust.shell.SetFocus()
|
||||||
self.SetTopWindow(self.crustFrame)
|
self.SetTopWindow(self.crustFrame)
|
||||||
# Add the application object to the sys module's namespace.
|
# Add the application object to the sys module's namespace.
|
||||||
# This allows a shell user to do:
|
# This allows a shell user to do:
|
||||||
|
@@ -19,7 +19,8 @@ class Crust(wxSplitterWindow):
|
|||||||
|
|
||||||
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
|
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
|
||||||
size=wxDefaultSize, style=wxSP_3D, name='Crust Window', \
|
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):
|
InterpClass=None, *args, **kwds):
|
||||||
"""Create a PyCrust Crust instance."""
|
"""Create a PyCrust Crust instance."""
|
||||||
wxSplitterWindow.__init__(self, parent, id, pos, size, style, name)
|
wxSplitterWindow.__init__(self, parent, id, pos, size, style, name)
|
||||||
@@ -27,24 +28,26 @@ class Crust(wxSplitterWindow):
|
|||||||
locals=locals, InterpClass=InterpClass, \
|
locals=locals, InterpClass=InterpClass, \
|
||||||
*args, **kwds)
|
*args, **kwds)
|
||||||
self.filling = Filling(parent=self, \
|
self.filling = Filling(parent=self, \
|
||||||
ingredients=self.shell.interp.locals, \
|
rootObject=self.shell.interp.locals, \
|
||||||
rootLabel=rootLabel)
|
rootLabel=rootLabel, rootIsNamespace=1)
|
||||||
"""Add 'filling' to the interpreter's locals."""
|
"""Add 'filling' to the interpreter's locals."""
|
||||||
self.shell.interp.locals['filling'] = self.filling
|
self.shell.interp.locals['filling'] = self.filling
|
||||||
self.SplitHorizontally(self.shell, self.filling, 300)
|
self.SplitHorizontally(self.shell, self.filling, 300)
|
||||||
# Set focus to the shell editor. Doesn't always work as intended.
|
self.SetMinimumPaneSize(1)
|
||||||
self.shell.SetFocus()
|
|
||||||
|
|
||||||
|
|
||||||
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."""
|
"""Frame containing all the PyCrust components."""
|
||||||
|
|
||||||
name = 'PyCrust Frame'
|
name = 'PyCrust Frame'
|
||||||
revision = __version__
|
revision = __version__
|
||||||
|
|
||||||
def __init__(self, parent=None, id=-1, title='PyCrust', \
|
def __init__(self, parent=None, id=-1, title='PyCrust', \
|
||||||
ingredients=None, rootLabel=None, locals=None, \
|
rootObject=None, rootLabel=None, rootIsNamespace=1, \
|
||||||
InterpClass=None, *args, **kwds):
|
locals=None, InterpClass=None, *args, **kwds):
|
||||||
"""Create a PyCrust CrustFrame instance."""
|
"""Create a PyCrust CrustFrame instance."""
|
||||||
wxFrame.__init__(self, parent, id, title)
|
wxFrame.__init__(self, parent, id, title)
|
||||||
intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % VERSION
|
intro = 'Welcome To PyCrust %s - The Flakiest Python Shell' % VERSION
|
||||||
@@ -54,14 +57,21 @@ class CrustFrame(wxFrame):
|
|||||||
icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
|
icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
|
||||||
self.SetIcon(icon)
|
self.SetIcon(icon)
|
||||||
self.crust = Crust(parent=self, intro=intro, \
|
self.crust = Crust(parent=self, intro=intro, \
|
||||||
ingredients=ingredients, \
|
rootObject=rootObject, \
|
||||||
rootLabel=rootLabel, locals=locals, \
|
rootLabel=rootLabel, \
|
||||||
|
rootIsNamespace=rootIsNamespace, \
|
||||||
|
locals=locals, \
|
||||||
InterpClass=InterpClass, *args, **kwds)
|
InterpClass=InterpClass, *args, **kwds)
|
||||||
# Override the filling so that status messages go to the status bar.
|
# Override the filling so that status messages go to the status bar.
|
||||||
self.crust.filling.fillingTree.setStatusText = self.SetStatusText
|
self.crust.filling.fillingTree.setStatusText = self.SetStatusText
|
||||||
# Override the shell so that status messages go to the status bar.
|
# Override the shell so that status messages go to the status bar.
|
||||||
self.crust.shell.setStatusText = self.SetStatusText
|
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()
|
self.crust.shell.SetFocus()
|
||||||
|
# Temporary hack to share menus between PyCrust and PyShell.
|
||||||
|
self.shell = self.crust.shell
|
||||||
|
self.createMenus()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -24,15 +24,17 @@ class FillingTree(wxTreeCtrl):
|
|||||||
|
|
||||||
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
|
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
|
||||||
size=wxDefaultSize, style=wxTR_HAS_BUTTONS, \
|
size=wxDefaultSize, style=wxTR_HAS_BUTTONS, \
|
||||||
ingredients=None, rootLabel=None):
|
rootObject=None, rootLabel=None, rootIsNamespace=0):
|
||||||
"""Create a PyCrust FillingTree instance."""
|
"""Create a PyCrust FillingTree instance."""
|
||||||
wxTreeCtrl.__init__(self, parent, id, pos, size)
|
wxTreeCtrl.__init__(self, parent, id, pos, size)
|
||||||
if not ingredients:
|
self.rootIsNamespace = rootIsNamespace
|
||||||
|
if not rootObject:
|
||||||
import __main__
|
import __main__
|
||||||
ingredients = __main__
|
rootObject = __main__
|
||||||
|
self.rootIsNamespace = 1
|
||||||
if not rootLabel: rootLabel = 'Ingredients'
|
if not rootLabel: rootLabel = 'Ingredients'
|
||||||
rootdata = wxTreeItemData(ingredients)
|
rootData = wxTreeItemData(rootObject)
|
||||||
self.root = self.AddRoot(rootLabel, -1, -1, rootdata)
|
self.root = self.AddRoot(rootLabel, -1, -1, rootData)
|
||||||
self.SetItemHasChildren(self.root, self.hasChildren(self.root))
|
self.SetItemHasChildren(self.root, self.hasChildren(self.root))
|
||||||
EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
|
EVT_TREE_ITEM_EXPANDING(self, self.GetId(), self.OnItemExpanding)
|
||||||
EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
|
EVT_TREE_ITEM_COLLAPSED(self, self.GetId(), self.OnItemCollapsed)
|
||||||
@@ -75,10 +77,11 @@ class FillingTree(wxTreeCtrl):
|
|||||||
for item in list:
|
for item in list:
|
||||||
itemtext = str(item)
|
itemtext = str(item)
|
||||||
# Show string dictionary items with single quotes, except for
|
# 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 \
|
if type(object) is types.DictType \
|
||||||
and type(item) is types.StringType \
|
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)
|
itemtext = repr(item)
|
||||||
child = self.AppendItem(selection, itemtext, -1, -1, \
|
child = self.AppendItem(selection, itemtext, -1, -1, \
|
||||||
wxTreeItemData(children[item]))
|
wxTreeItemData(children[item]))
|
||||||
@@ -128,9 +131,10 @@ class FillingTree(wxTreeCtrl):
|
|||||||
parentobject = self.GetPyData(parent)
|
parentobject = self.GetPyData(parent)
|
||||||
name = self.GetItemText(item)
|
name = self.GetItemText(item)
|
||||||
# Apply dictionary syntax to dictionary items, except the root
|
# Apply dictionary syntax to dictionary items, except the root
|
||||||
# and first level children.
|
# and first level children of a namepace.
|
||||||
if item != self.root and parent != self.root \
|
if type(parentobject) is types.DictType \
|
||||||
and type(parentobject) is types.DictType:
|
and ((item != self.root and parent != self.root) \
|
||||||
|
or (parent == self.root and not self.rootIsNamespace)):
|
||||||
name = '[' + name + ']'
|
name = '[' + name + ']'
|
||||||
# Apply dot syntax to multipart names.
|
# Apply dot syntax to multipart names.
|
||||||
if partial:
|
if partial:
|
||||||
@@ -138,8 +142,10 @@ class FillingTree(wxTreeCtrl):
|
|||||||
name += partial
|
name += partial
|
||||||
else:
|
else:
|
||||||
name += '.' + partial
|
name += '.' + partial
|
||||||
# Repeat for everything but the root item and first level children.
|
# Repeat for everything but the root item
|
||||||
if item != self.root and parent != self.root:
|
# 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)
|
name = self.getFullName(parent, partial=name)
|
||||||
return name
|
return name
|
||||||
|
|
||||||
@@ -243,13 +249,15 @@ class Filling(wxSplitterWindow):
|
|||||||
|
|
||||||
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
|
def __init__(self, parent, id=-1, pos=wxDefaultPosition, \
|
||||||
size=wxDefaultSize, style=wxSP_3D, name='Filling Window', \
|
size=wxDefaultSize, style=wxSP_3D, name='Filling Window', \
|
||||||
ingredients=None, rootLabel=None):
|
rootObject=None, rootLabel=None, rootIsNamespace=0):
|
||||||
"""Create a PyCrust Filling instance."""
|
"""Create a PyCrust Filling instance."""
|
||||||
wxSplitterWindow.__init__(self, parent, id, pos, size, style, name)
|
wxSplitterWindow.__init__(self, parent, id, pos, size, style, name)
|
||||||
self.fillingTree = FillingTree(parent=self, ingredients=ingredients, \
|
self.fillingTree = FillingTree(parent=self, rootObject=rootObject, \
|
||||||
rootLabel=rootLabel)
|
rootLabel=rootLabel, \
|
||||||
|
rootIsNamespace=rootIsNamespace)
|
||||||
self.fillingText = FillingText(parent=self)
|
self.fillingText = FillingText(parent=self)
|
||||||
self.SplitVertically(self.fillingTree, self.fillingText, 200)
|
self.SplitVertically(self.fillingTree, self.fillingText, 200)
|
||||||
|
self.SetMinimumPaneSize(1)
|
||||||
# Override the filling so that descriptions go to fillingText.
|
# Override the filling so that descriptions go to fillingText.
|
||||||
self.fillingTree.setText = self.fillingText.SetText
|
self.fillingTree.setText = self.fillingText.SetText
|
||||||
# Select the root item.
|
# Select the root item.
|
||||||
@@ -264,8 +272,8 @@ class FillingFrame(wxFrame):
|
|||||||
|
|
||||||
def __init__(self, parent=None, id=-1, title='PyFilling', \
|
def __init__(self, parent=None, id=-1, title='PyFilling', \
|
||||||
pos=wxDefaultPosition, size=wxDefaultSize, \
|
pos=wxDefaultPosition, size=wxDefaultSize, \
|
||||||
style=wxDEFAULT_FRAME_STYLE, ingredients=None, \
|
style=wxDEFAULT_FRAME_STYLE, rootObject=None, \
|
||||||
rootLabel=None):
|
rootLabel=None, rootIsNamespace=0):
|
||||||
"""Create a PyCrust FillingFrame instance."""
|
"""Create a PyCrust FillingFrame instance."""
|
||||||
wxFrame.__init__(self, parent, id, title, pos, size, style)
|
wxFrame.__init__(self, parent, id, title, pos, size, style)
|
||||||
intro = 'Welcome To PyFilling - The Tastiest Namespace Inspector'
|
intro = 'Welcome To PyFilling - The Tastiest Namespace Inspector'
|
||||||
@@ -274,8 +282,9 @@ class FillingFrame(wxFrame):
|
|||||||
if wxPlatform == '__WXMSW__':
|
if wxPlatform == '__WXMSW__':
|
||||||
icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
|
icon = wxIcon('PyCrust.ico', wxBITMAP_TYPE_ICO)
|
||||||
self.SetIcon(icon)
|
self.SetIcon(icon)
|
||||||
self.filling = Filling(parent=self, ingredients=ingredients, \
|
self.filling = Filling(parent=self, rootObject=rootObject, \
|
||||||
rootLabel=rootLabel)
|
rootLabel=rootLabel, \
|
||||||
|
rootIsNamespace=rootIsNamespace)
|
||||||
# Override the filling so that status messages go to the status bar.
|
# Override the filling so that status messages go to the status bar.
|
||||||
self.filling.fillingTree.setStatusText = self.SetStatusText
|
self.filling.fillingTree.setStatusText = self.SetStatusText
|
||||||
|
|
||||||
|
@@ -23,11 +23,12 @@ class Interpreter(InteractiveInterpreter):
|
|||||||
self.stdin = stdin
|
self.stdin = stdin
|
||||||
self.stdout = stdout
|
self.stdout = stdout
|
||||||
self.stderr = stderr
|
self.stderr = stderr
|
||||||
if rawin is not None:
|
if rawin:
|
||||||
import __builtin__
|
import __builtin__
|
||||||
__builtin__.raw_input = rawin
|
__builtin__.raw_input = rawin
|
||||||
del __builtin__
|
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' % \
|
self.introText = 'Python %s on %s%s%s' % \
|
||||||
(sys.version, sys.platform, os.linesep, copyright)
|
(sys.version, sys.platform, os.linesep, copyright)
|
||||||
try:
|
try:
|
||||||
@@ -39,19 +40,19 @@ class Interpreter(InteractiveInterpreter):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
sys.ps2 = '... '
|
sys.ps2 = '... '
|
||||||
self.more = 0
|
self.more = 0
|
||||||
self.commandBuffer = [] # List of lists to support recursive push().
|
# List of lists to support recursive push().
|
||||||
self.commandHistory = []
|
self.commandBuffer = []
|
||||||
self.startupScript = os.environ.get('PYTHONSTARTUP')
|
self.startupScript = os.environ.get('PYTHONSTARTUP')
|
||||||
|
|
||||||
def push(self, command):
|
def push(self, command):
|
||||||
"""Send command to the interpreter to be executed.
|
"""Send command to the interpreter to be executed.
|
||||||
|
|
||||||
Because this may be called recursively, we append a new list
|
Because this may be called recursively, we append a new list
|
||||||
onto the commandBuffer list and then append commands into that.
|
onto the commandBuffer list and then append commands into
|
||||||
If the passed in command is part of a multi-line command we keep
|
that. If the passed in command is part of a multi-line command
|
||||||
appending the pieces to the last list in commandBuffer until we
|
we keep appending the pieces to the last list in commandBuffer
|
||||||
have a complete command, then, finally, we delete that last list.
|
until we have a complete command, then, finally, we delete
|
||||||
"""
|
that last list."""
|
||||||
if not self.more: self.commandBuffer.append([])
|
if not self.more: self.commandBuffer.append([])
|
||||||
self.commandBuffer[-1].append(command)
|
self.commandBuffer[-1].append(command)
|
||||||
source = '\n'.join(self.commandBuffer[-1])
|
source = '\n'.join(self.commandBuffer[-1])
|
||||||
@@ -66,7 +67,15 @@ class Interpreter(InteractiveInterpreter):
|
|||||||
sys.stdout = self.stdout
|
sys.stdout = self.stdout
|
||||||
sys.stderr = self.stderr
|
sys.stderr = self.stderr
|
||||||
more = InteractiveInterpreter.runsource(self, source)
|
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
|
return more
|
||||||
|
|
||||||
def getAutoCompleteList(self, command='', *args, **kwds):
|
def getAutoCompleteList(self, command='', *args, **kwds):
|
||||||
|
@@ -13,6 +13,9 @@ from wxPython.stc import *
|
|||||||
import keyword
|
import keyword
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from pseudo import PseudoFileIn
|
||||||
|
from pseudo import PseudoFileOut
|
||||||
|
from pseudo import PseudoFileErr
|
||||||
from version import VERSION
|
from version import VERSION
|
||||||
|
|
||||||
|
|
||||||
@@ -48,6 +51,12 @@ class Shell(wxStyledTextCtrl):
|
|||||||
locals=None, InterpClass=None, *args, **kwds):
|
locals=None, InterpClass=None, *args, **kwds):
|
||||||
"""Create a PyCrust Shell instance."""
|
"""Create a PyCrust Shell instance."""
|
||||||
wxStyledTextCtrl.__init__(self, parent, id, pos, size, style)
|
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.
|
# Import a default interpreter class if one isn't provided.
|
||||||
if InterpClass == None:
|
if InterpClass == None:
|
||||||
from interpreter import Interpreter
|
from interpreter import Interpreter
|
||||||
@@ -61,7 +70,6 @@ class Shell(wxStyledTextCtrl):
|
|||||||
# Add the dictionary that was passed in.
|
# Add the dictionary that was passed in.
|
||||||
if locals:
|
if locals:
|
||||||
shellLocals.update(locals)
|
shellLocals.update(locals)
|
||||||
from pseudo import PseudoFileIn, PseudoFileOut, PseudoFileErr
|
|
||||||
self.interp = Interpreter(locals=shellLocals, \
|
self.interp = Interpreter(locals=shellLocals, \
|
||||||
rawin=self.readRaw, \
|
rawin=self.readRaw, \
|
||||||
stdin=PseudoFileIn(self.readIn), \
|
stdin=PseudoFileIn(self.readIn), \
|
||||||
@@ -108,7 +116,7 @@ class Shell(wxStyledTextCtrl):
|
|||||||
# environment. They can override anything they want.
|
# environment. They can override anything they want.
|
||||||
try: self.execStartupScript(self.interp.startupScript)
|
try: self.execStartupScript(self.interp.startupScript)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
del self.interp
|
del self.interp
|
||||||
|
|
||||||
@@ -384,17 +392,6 @@ class Shell(wxStyledTextCtrl):
|
|||||||
endline = self.GetCurrentLine()
|
endline = self.GetCurrentLine()
|
||||||
# If they hit RETURN on the last line, execute the command.
|
# If they hit RETURN on the last line, execute the command.
|
||||||
if theline == endline:
|
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)
|
self.push(command)
|
||||||
# Otherwise, replace the last line with the new line.
|
# Otherwise, replace the last line with the new line.
|
||||||
else:
|
else:
|
||||||
@@ -416,11 +413,6 @@ class Shell(wxStyledTextCtrl):
|
|||||||
The command may not necessarily be valid Python syntax."""
|
The command may not necessarily be valid Python syntax."""
|
||||||
if not text:
|
if not text:
|
||||||
text = self.GetCurLine()[0]
|
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
|
# XXX Need to extract real prompts here. Need to keep track of the
|
||||||
# prompt every time a command is issued.
|
# prompt every time a command is issued.
|
||||||
ps1 = str(sys.ps1)
|
ps1 = str(sys.ps1)
|
||||||
@@ -439,6 +431,7 @@ class Shell(wxStyledTextCtrl):
|
|||||||
|
|
||||||
def push(self, command):
|
def push(self, command):
|
||||||
"""Send command to the interpreter for execution."""
|
"""Send command to the interpreter for execution."""
|
||||||
|
self.addHistory(command)
|
||||||
self.write(os.linesep)
|
self.write(os.linesep)
|
||||||
self.more = self.interp.push(command)
|
self.more = self.interp.push(command)
|
||||||
self.prompt()
|
self.prompt()
|
||||||
@@ -447,6 +440,20 @@ class Shell(wxStyledTextCtrl):
|
|||||||
# hitting enter. After they hit enter it becomes permanent.
|
# hitting enter. After they hit enter it becomes permanent.
|
||||||
self.EmptyUndoBuffer()
|
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):
|
def write(self, text):
|
||||||
"""Display text in the shell.
|
"""Display text in the shell.
|
||||||
|
|
||||||
@@ -571,6 +578,27 @@ class Shell(wxStyledTextCtrl):
|
|||||||
"""Replacement for stderr."""
|
"""Replacement for stderr."""
|
||||||
self.write(text)
|
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):
|
def CanCut(self):
|
||||||
"""Return true if text is selected and can be cut."""
|
"""Return true if text is selected and can be cut."""
|
||||||
return self.GetSelectionStart() != self.GetSelectionEnd()
|
return self.GetSelectionStart() != self.GetSelectionEnd()
|
||||||
@@ -590,31 +618,9 @@ ID_CALLTIPS = NewId()
|
|||||||
ID_CALLTIPS_SHOW = NewId()
|
ID_CALLTIPS_SHOW = NewId()
|
||||||
|
|
||||||
|
|
||||||
class ShellFrame(wxFrame):
|
class ShellMenu:
|
||||||
"""Frame containing the PyCrust shell component."""
|
"""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):
|
def createMenus(self):
|
||||||
m = self.fileMenu = wxMenu()
|
m = self.fileMenu = wxMenu()
|
||||||
m.AppendSeparator()
|
m.AppendSeparator()
|
||||||
@@ -624,12 +630,12 @@ class ShellFrame(wxFrame):
|
|||||||
m.Append(wxID_UNDO, '&Undo \tCtrl+Z', 'Undo the last action')
|
m.Append(wxID_UNDO, '&Undo \tCtrl+Z', 'Undo the last action')
|
||||||
m.Append(wxID_REDO, '&Redo \tCtrl+Y', 'Redo the last undone action')
|
m.Append(wxID_REDO, '&Redo \tCtrl+Y', 'Redo the last undone action')
|
||||||
m.AppendSeparator()
|
m.AppendSeparator()
|
||||||
m.Append(wxID_CUT, 'Cu&t \tCtrl+X', 'Cut the selection')
|
m.Append(wxID_CUT, 'Cu&t', 'Cut the selection')
|
||||||
m.Append(wxID_COPY, '&Copy \tCtrl+C', 'Copy the selection')
|
m.Append(wxID_COPY, '&Copy', 'Copy the selection')
|
||||||
m.Append(wxID_PASTE, '&Paste \tCtrl+V', 'Paste')
|
m.Append(wxID_PASTE, '&Paste', 'Paste')
|
||||||
m.AppendSeparator()
|
m.AppendSeparator()
|
||||||
m.Append(wxID_CLEAR, 'Cle&ar \tDel', 'Delete the selection')
|
m.Append(wxID_CLEAR, 'Cle&ar', 'Delete the selection')
|
||||||
m.Append(wxID_SELECTALL, 'Select A&ll \tCtrl+A', 'Select all text')
|
m.Append(wxID_SELECTALL, 'Select A&ll', 'Select all text')
|
||||||
|
|
||||||
m = self.autocompMenu = wxMenu()
|
m = self.autocompMenu = wxMenu()
|
||||||
m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion', \
|
m.Append(ID_AUTOCOMP_SHOW, 'Show Auto Completion', \
|
||||||
@@ -781,3 +787,29 @@ class ShellFrame(wxFrame):
|
|||||||
event.Check(self.shell.autoCallTip)
|
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()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -5,7 +5,7 @@
|
|||||||
#
|
#
|
||||||
# Author: Lorne White, Lorne.White@telusplanet.net
|
# Author: Lorne White, Lorne.White@telusplanet.net
|
||||||
#
|
#
|
||||||
# Created: Feb 25, 2001
|
# Created: Sept 4, 2001
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -16,25 +16,40 @@ from wxPython.wx import *
|
|||||||
# button colour will change to new colour
|
# button colour will change to new colour
|
||||||
# GetColour method to get the selected colour
|
# GetColour method to get the selected colour
|
||||||
|
|
||||||
|
# Updates:
|
||||||
|
# call back to function if changes made
|
||||||
|
|
||||||
class ColourSelect(wxButton):
|
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.win = parent
|
||||||
|
self.callback = callback
|
||||||
|
|
||||||
mID = NewId()
|
mID = NewId()
|
||||||
self.b = b = wxButton(parent, mID, "", position, size)
|
self.b = b = wxButton(parent, mID, "", position, size)
|
||||||
EVT_BUTTON(parent, mID, self.OnClick)
|
EVT_BUTTON(parent, mID, self.OnClick)
|
||||||
|
|
||||||
self.set_colour_val = set_colour = wxColor(bcolour[0], bcolour[1], bcolour[2])
|
self.SetColourValue(bcolour)
|
||||||
b.SetBackgroundColour(set_colour)
|
|
||||||
b.SetForegroundColour(wxWHITE)
|
|
||||||
self.set_colour = bcolour
|
|
||||||
|
|
||||||
def SetColour(self, bcolour):
|
def SetColour(self, bcolour):
|
||||||
self.b.SetBackgroundColour(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):
|
def GetColour(self):
|
||||||
return self.set_colour
|
return self.set_colour
|
||||||
|
|
||||||
|
def OnChange(self):
|
||||||
|
if self.callback != None:
|
||||||
|
self.callback()
|
||||||
|
|
||||||
def OnClick(self, event):
|
def OnClick(self, event):
|
||||||
data = wxColourData()
|
data = wxColourData()
|
||||||
data.SetChooseFull(true)
|
data.SetChooseFull(true)
|
||||||
@@ -45,6 +60,7 @@ class ColourSelect(wxButton):
|
|||||||
self.set_colour = set = data.GetColour().Get()
|
self.set_colour = set = data.GetColour().Get()
|
||||||
self.set_colour_val = bcolour = wxColour(set[0],set[1],set[2])
|
self.set_colour_val = bcolour = wxColour(set[0],set[1],set[2])
|
||||||
self.b.SetBackgroundColour(bcolour)
|
self.b.SetBackgroundColour(bcolour)
|
||||||
|
self.OnChange()
|
||||||
dlg.Destroy()
|
dlg.Destroy()
|
||||||
|
|
||||||
|
|
||||||
|
@@ -5,8 +5,8 @@
|
|||||||
# Author: Lorne White (email: lorne.white@telusplanet.net)
|
# Author: Lorne White (email: lorne.white@telusplanet.net)
|
||||||
#
|
#
|
||||||
# Created:
|
# Created:
|
||||||
# Version 0.7
|
# Version 0.72
|
||||||
# Date: August 18, 2001
|
# Date: Sept 8, 2001
|
||||||
# Licence: wxWindows license
|
# Licence: wxWindows license
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
@@ -594,6 +594,7 @@ class PrintTable:
|
|||||||
self.row_line_colour = {}
|
self.row_line_colour = {}
|
||||||
|
|
||||||
self.parentFrame = parentFrame
|
self.parentFrame = parentFrame
|
||||||
|
self.SetPreviewSize()
|
||||||
|
|
||||||
self.printData = wxPrintData()
|
self.printData = wxPrintData()
|
||||||
self.scale = 1.0
|
self.scale = 1.0
|
||||||
@@ -609,6 +610,16 @@ class PrintTable:
|
|||||||
self.SetMargins()
|
self.SetMargins()
|
||||||
self.SetPortrait()
|
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):
|
def SetPaperId(self, paper):
|
||||||
self.printData.SetPaperId(paper)
|
self.printData.SetPaperId(paper)
|
||||||
|
|
||||||
@@ -843,8 +854,8 @@ class PrintTable:
|
|||||||
|
|
||||||
frame.Initialize()
|
frame.Initialize()
|
||||||
if self.parentFrame:
|
if self.parentFrame:
|
||||||
frame.SetPosition(self.parentFrame.GetPosition())
|
frame.SetPosition(self.preview_frame_pos)
|
||||||
frame.SetSize(self.parentFrame.GetSize())
|
frame.SetSize(self.preview_frame_size)
|
||||||
frame.Show(true)
|
frame.Show(true)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@ def bitmapFromFile(filename):
|
|||||||
"bmp" :wxBITMAP_TYPE_BMP,
|
"bmp" :wxBITMAP_TYPE_BMP,
|
||||||
"png" :wxBITMAP_TYPE_PNG,
|
"png" :wxBITMAP_TYPE_PNG,
|
||||||
"jpeg":wxBITMAP_TYPE_JPEG,
|
"jpeg":wxBITMAP_TYPE_JPEG,
|
||||||
|
"jpg" :wxBITMAP_TYPE_JPEG,
|
||||||
"gif" :wxBITMAP_TYPE_GIF,
|
"gif" :wxBITMAP_TYPE_GIF,
|
||||||
"xbm" :wxBITMAP_TYPE_XBM,
|
"xbm" :wxBITMAP_TYPE_XBM,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user