More PyCrust updates

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18277 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2002-12-16 21:21:30 +00:00
parent df011ca6e2
commit c77f57b50a
3 changed files with 19 additions and 25 deletions

View File

@@ -51,6 +51,7 @@ class Interpreter(InteractiveInterpreter):
If the passed in command is part of a multi-line command we keep 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 appending the pieces to the last list in commandBuffer until we
have a complete command. If not, we delete that last list.""" have a complete command. If not, we delete that last list."""
command = str(command) # In case the command is unicode.
if not self.more: if not self.more:
try: del self.commandBuffer[-1] try: del self.commandBuffer[-1]
except IndexError: pass except IndexError: pass
@@ -63,9 +64,7 @@ class Interpreter(InteractiveInterpreter):
def runsource(self, source): def runsource(self, source):
"""Compile and run source code in the interpreter.""" """Compile and run source code in the interpreter."""
stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr
sys.stdin = self.stdin sys.stdin, sys.stdout, sys.stderr = self.stdin, self.stdout, self.stderr
sys.stdout = self.stdout
sys.stderr = self.stderr
more = InteractiveInterpreter.runsource(self, source) more = InteractiveInterpreter.runsource(self, source)
# If sys.std* is still what we set it to, then restore it. # If sys.std* is still what we set it to, then restore it.
# But, if the executed source changed sys.std*, assume it # But, if the executed source changed sys.std*, assume it
@@ -86,7 +85,10 @@ class Interpreter(InteractiveInterpreter):
"""Return list of auto-completion options for a command. """Return list of auto-completion options for a command.
The list of options will be based on the locals namespace.""" The list of options will be based on the locals namespace."""
stdin, stdout, stderr = sys.stdin, sys.stdout, sys.stderr
sys.stdin, sys.stdout, sys.stderr = self.stdin, self.stdout, self.stderr
return introspect.getAutoCompleteList(command, self.locals, *args, **kwds) return introspect.getAutoCompleteList(command, self.locals, *args, **kwds)
sys.stdin, sys.stdout, sys.stderr = stdin, stdout, stderr
def getCallTip(self, command='', *args, **kwds): def getCallTip(self, command='', *args, **kwds):
"""Return call tip text for a command. """Return call tip text for a command.

View File

@@ -217,7 +217,7 @@ def getRoot(command, terminator=None):
else: else:
# start represents the last known good point in the line. # start represents the last known good point in the line.
start = token[2][1] start = token[2][1]
elif tokenstring in ('[({])}'): elif len(tokenstring) == 1 and tokenstring in ('[({])}'):
# Remember, we're working backwords. # Remember, we're working backwords.
# So prefix += tokenstring would be wrong. # So prefix += tokenstring would be wrong.
if prefix in emptyTypes and tokenstring in ('[({'): if prefix in emptyTypes and tokenstring in ('[({'):

View File

@@ -76,8 +76,13 @@ class ShellFrame(wx.wxFrame, ShellMenu):
wx.EVT_CLOSE(self, self.OnCloseWindow) wx.EVT_CLOSE(self, self.OnCloseWindow)
def OnCloseWindow(self, event): def OnCloseWindow(self, event):
self.shell.destroy() """Event handler for closing."""
self.Destroy() # This isn't working the way I want, but I'll leave it for now.
if self.shell.waiting:
event.Veto(True)
else:
self.shell.destroy()
self.Destroy()
class ShellFacade: class ShellFacade:
@@ -244,7 +249,7 @@ class Shell(stc.wxStyledTextCtrl):
except: pass except: pass
def destroy(self): def destroy(self):
# del self.interp del self.interp
pass pass
def config(self): def config(self):
@@ -364,7 +369,7 @@ Platform: %s""" % (VERSION, self.revision, self.interp.revision,
def OnIdle(self, event): def OnIdle(self, event):
"""Free the CPU to do other things.""" """Free the CPU to do other things."""
if self.waiting: if self.waiting:
time.sleep(0.1) time.sleep(0.05)
def OnUpdateUI(self, event): def OnUpdateUI(self, event):
"""Check for matching braces.""" """Check for matching braces."""
@@ -821,32 +826,19 @@ Platform: %s""" % (VERSION, self.revision, self.interp.revision,
self.prompt() self.prompt()
try: try:
while not reader.input: while not reader.input:
time.sleep(0.1) # Free up the CPU. wx.wxYieldIfNeeded()
wx.wxYield()
input = reader.input input = reader.input
finally: finally:
reader.input = '' reader.input = ''
reader.isreading = 0 reader.isreading = 0
input = str(input) # In case of Unicode.
return input return input
def readlines(self): def readlines(self):
"""Replacement for stdin.readlines().""" """Replacement for stdin.readlines()."""
lines = [] lines = []
input = '' while lines[-1:] != ['\n']:
reader = self.reader lines.append(self.readline())
reader.isreading = 1
try:
while lines[-1:] != ['\n']:
self.prompt()
while not reader.input:
time.sleep(0.1) # Free up the CPU.
wx.wxYield()
input = reader.input
lines.append(input)
reader.input = ''
finally:
reader.input = ''
reader.isreading = 0
return lines return lines
def raw_input(self, prompt=''): def raw_input(self, prompt=''):