New PyCrust files

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12125 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2001-10-21 03:43:12 +00:00
parent 33b12a3ab3
commit 235573500c
2 changed files with 98 additions and 55 deletions

View File

@@ -36,7 +36,7 @@ def getAttributeNames(object, includeMagic=1, includeSingle=1, includeDouble=1):
for item in getAllAttributeNames(object):
dict[item] = None
attributes += dict.keys()
attributes.sort()
attributes.sort(lambda x, y: cmp(x.lower(), y.lower()))
if not includeSingle:
attributes = filter(lambda item: item[0]!='_' or item[1]=='_', attributes)
if not includeDouble:

View File

@@ -286,7 +286,6 @@ class Shell(wxStyledTextCtrl):
key = event.KeyCode()
currpos = self.GetCurrentPos()
if currpos < self.prompt1Pos[1]:
wxBell()
return
stoppos = self.promptPos[1]
if key == ord('.'):
@@ -305,6 +304,9 @@ class Shell(wxStyledTextCtrl):
command = self.GetTextRange(stoppos, currpos) + '('
self.write('(')
if self.autoCallTip: self.autoCallTipShow(command)
# Hack to keep characters from entering when Alt or Control are down.
elif event.ControlDown() or event.AltDown():
pass
else:
# Allow the normal event handling to take place.
event.Skip()
@@ -367,11 +369,9 @@ class Shell(wxStyledTextCtrl):
"""Retrieve the previous/next command from the history buffer."""
startpos = self.GetCurrentPos()
if startpos < self.prompt1Pos[1]:
wxBell()
return
newindex = self.historyIndex + step
if not (-1 <= newindex < len(self.history)):
wxBell()
return
self.historyIndex = newindex
if newindex == -1:
@@ -388,7 +388,6 @@ class Shell(wxStyledTextCtrl):
"""Search up the history buffer for the text in front of the cursor."""
startpos = self.GetCurrentPos()
if startpos < self.prompt1Pos[1]:
wxBell()
return
# The text up to the cursor is what we search for.
numCharsAfterCursor = self.GetTextLength() - startpos
@@ -437,16 +436,19 @@ class Shell(wxStyledTextCtrl):
if self.getCommand():
command = self.GetTextRange(self.prompt1Pos[1], endpos)
else:
command = self.GetTextRange(self.prompt1Pos[1], \
self.promptPos[1])
# This is a hack, now that we allow editing of previous
# lines, which throws off our promptPos values.
newend = endpos - len(self.getCommand(rstrip=0))
command = self.GetTextRange(self.prompt1Pos[1], newend)
command = command.replace(os.linesep + sys.ps2, '\n')
self.push(command)
# Otherwise, replace the last command with the new command.
# Or replace the current command with the other command.
elif thepos < self.prompt1Pos[0]:
theline = self.GetCurrentLine()
command = self.getCommand()
command = self.getCommand(rstrip=0)
# If the new line contains a command (even an invalid one).
if command:
command = self.getMultilineCommand()
self.SetCurrentPos(endpos)
startpos = self.prompt1Pos[1]
self.SetSelection(startpos, endpos)
@@ -457,6 +459,48 @@ class Shell(wxStyledTextCtrl):
else:
self.SetCurrentPos(thepos)
self.SetAnchor(thepos)
# Or add a new line to the current single or multi-line command.
elif thepos > self.prompt1Pos[1]:
self.write(os.linesep)
self.more = 1
self.prompt()
def getMultilineCommand(self, rstrip=1):
"""Extract a multi-line command from the editor.
The command may not necessarily be valid Python syntax."""
# XXX Need to extract real prompts here. Need to keep track of the
# prompt every time a command is issued.
ps1 = str(sys.ps1)
ps1size = len(ps1)
ps2 = str(sys.ps2)
ps2size = len(ps2)
# This is a total hack job, but it works.
text = self.GetCurLine()[0]
line = self.GetCurrentLine()
while text[:ps2size] == ps2 and line > 0:
line -= 1
self.GotoLine(line)
text = self.GetCurLine()[0]
if text[:ps1size] == ps1:
line = self.GetCurrentLine()
self.GotoLine(line)
startpos = self.GetCurrentPos() + ps1size
line += 1
self.GotoLine(line)
while self.GetCurLine()[0][:ps2size] == ps2:
line += 1
self.GotoLine(line)
stoppos = self.GetCurrentPos()
command = self.GetTextRange(startpos, stoppos)
command = command.replace(os.linesep + sys.ps2, '\n')
command = command.rstrip()
command = command.replace('\n', os.linesep + sys.ps2)
else:
command = ''
if rstrip:
command = command.rstrip()
return command
def getCommand(self, text=None, rstrip=1):
"""Extract a command from text which may include a shell prompt.
@@ -470,8 +514,6 @@ class Shell(wxStyledTextCtrl):
ps1size = len(ps1)
ps2 = str(sys.ps2)
ps2size = len(ps2)
if rstrip:
text = text.rstrip()
# Strip the prompt off the front of text leaving just the command.
if text[:ps1size] == ps1:
command = text[ps1size:]
@@ -479,6 +521,8 @@ class Shell(wxStyledTextCtrl):
command = text[ps2size:]
else:
command = ''
if rstrip:
command = command.rstrip()
return command
def push(self, command):
@@ -488,10 +532,6 @@ class Shell(wxStyledTextCtrl):
if not self.more:
self.addHistory(command.rstrip())
self.prompt()
# Keep the undo feature from undoing previous responses. The only
# thing that can be undone is stuff typed after the prompt, before
# hitting enter. After they hit enter it becomes permanent.
self.EmptyUndoBuffer()
def addHistory(self, command):
"""Add command to the command history."""
@@ -532,7 +572,10 @@ class Shell(wxStyledTextCtrl):
if not self.more: self.prompt1Pos[0] = self.GetCurrentPos()
self.write(prompt)
self.promptPos[1] = self.GetCurrentPos()
if not self.more: self.prompt1Pos[1] = self.GetCurrentPos()
if not self.more:
self.prompt1Pos[1] = self.GetCurrentPos()
# Keep the undo feature from undoing previous responses.
self.EmptyUndoBuffer()
# XXX Add some autoindent magic here if more.
if self.more:
self.write(' '*4) # Temporary hack indentation.