New PyCrust files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12168 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -53,7 +53,8 @@ class FillingTree(wxTreeCtrl):
|
|||||||
objtype = type(object)
|
objtype = type(object)
|
||||||
if objtype is types.DictType:
|
if objtype is types.DictType:
|
||||||
dict = object
|
dict = object
|
||||||
elif (objtype in (types.InstanceType, types.ModuleType)) \
|
elif (objtype in (types.ClassType, types.InstanceType, \
|
||||||
|
types.ModuleType)) \
|
||||||
or hasattr(object, '__class__'):
|
or hasattr(object, '__class__'):
|
||||||
for key in introspect.getAttributeNames(object):
|
for key in introspect.getAttributeNames(object):
|
||||||
# Believe it or not, some attributes can disappear, such as
|
# Believe it or not, some attributes can disappear, such as
|
||||||
|
@@ -125,8 +125,8 @@ class Shell(wxStyledTextCtrl):
|
|||||||
else:
|
else:
|
||||||
Interpreter = InterpClass
|
Interpreter = InterpClass
|
||||||
# Create default locals so we have something interesting.
|
# Create default locals so we have something interesting.
|
||||||
shellLocals = {'__name__': 'PyShell',
|
shellLocals = {'__name__': 'PyCrust-Shell',
|
||||||
'__doc__': 'PyShell, The PyCrust Python Shell.',
|
'__doc__': 'PyCrust-Shell, The PyCrust Python Shell.',
|
||||||
'__version__': VERSION,
|
'__version__': VERSION,
|
||||||
}
|
}
|
||||||
# Add the dictionary that was passed in.
|
# Add the dictionary that was passed in.
|
||||||
@@ -283,10 +283,10 @@ class Shell(wxStyledTextCtrl):
|
|||||||
"""Keypress event handler.
|
"""Keypress event handler.
|
||||||
|
|
||||||
Prevents modification of previously submitted commands/responses."""
|
Prevents modification of previously submitted commands/responses."""
|
||||||
|
if not self.CanEdit():
|
||||||
|
return
|
||||||
key = event.KeyCode()
|
key = event.KeyCode()
|
||||||
currpos = self.GetCurrentPos()
|
currpos = self.GetCurrentPos()
|
||||||
if currpos < self.prompt1Pos[1]:
|
|
||||||
return
|
|
||||||
stoppos = self.promptPos[1]
|
stoppos = self.promptPos[1]
|
||||||
if key == ord('.'):
|
if key == ord('.'):
|
||||||
# The dot or period key activates auto completion.
|
# The dot or period key activates auto completion.
|
||||||
@@ -318,8 +318,13 @@ class Shell(wxStyledTextCtrl):
|
|||||||
key = event.KeyCode()
|
key = event.KeyCode()
|
||||||
currpos = self.GetCurrentPos()
|
currpos = self.GetCurrentPos()
|
||||||
stoppos = self.promptPos[1]
|
stoppos = self.promptPos[1]
|
||||||
|
# Return is used to submit a command to the interpreter.
|
||||||
|
if key == WXK_RETURN:
|
||||||
|
if self.AutoCompActive(): self.AutoCompCancel()
|
||||||
|
if self.CallTipActive: self.CallTipCancel()
|
||||||
|
self.processLine()
|
||||||
# If the auto-complete window is up let it do its thing.
|
# If the auto-complete window is up let it do its thing.
|
||||||
if self.AutoCompActive():
|
elif self.AutoCompActive():
|
||||||
event.Skip()
|
event.Skip()
|
||||||
# Retrieve the previous command from the history buffer.
|
# Retrieve the previous command from the history buffer.
|
||||||
elif (event.ControlDown() and key == WXK_UP) \
|
elif (event.ControlDown() and key == WXK_UP) \
|
||||||
@@ -332,10 +337,6 @@ class Shell(wxStyledTextCtrl):
|
|||||||
# Search up the history for the text in front of the cursor.
|
# Search up the history for the text in front of the cursor.
|
||||||
elif key == WXK_F8:
|
elif key == WXK_F8:
|
||||||
self.OnHistorySearch()
|
self.OnHistorySearch()
|
||||||
# Return is used to submit a command to the interpreter.
|
|
||||||
elif key == WXK_RETURN:
|
|
||||||
if self.CallTipActive: self.CallTipCancel()
|
|
||||||
self.processLine()
|
|
||||||
# Home needs to be aware of the prompt.
|
# Home needs to be aware of the prompt.
|
||||||
elif key == WXK_HOME:
|
elif key == WXK_HOME:
|
||||||
if currpos >= stoppos:
|
if currpos >= stoppos:
|
||||||
@@ -357,7 +358,7 @@ class Shell(wxStyledTextCtrl):
|
|||||||
event.Skip()
|
event.Skip()
|
||||||
# Only allow these keys after the latest prompt.
|
# Only allow these keys after the latest prompt.
|
||||||
elif key in (WXK_TAB, WXK_DELETE):
|
elif key in (WXK_TAB, WXK_DELETE):
|
||||||
if currpos >= self.prompt1Pos[1]:
|
if self.CanEdit():
|
||||||
event.Skip()
|
event.Skip()
|
||||||
# Don't toggle between insert mode and overwrite mode.
|
# Don't toggle between insert mode and overwrite mode.
|
||||||
elif key == WXK_INSERT:
|
elif key == WXK_INSERT:
|
||||||
@@ -367,9 +368,9 @@ class Shell(wxStyledTextCtrl):
|
|||||||
|
|
||||||
def OnHistoryRetrieve(self, step):
|
def OnHistoryRetrieve(self, step):
|
||||||
"""Retrieve the previous/next command from the history buffer."""
|
"""Retrieve the previous/next command from the history buffer."""
|
||||||
startpos = self.GetCurrentPos()
|
if not self.CanEdit():
|
||||||
if startpos < self.prompt1Pos[1]:
|
|
||||||
return
|
return
|
||||||
|
startpos = self.GetCurrentPos()
|
||||||
newindex = self.historyIndex + step
|
newindex = self.historyIndex + step
|
||||||
if not (-1 <= newindex < len(self.history)):
|
if not (-1 <= newindex < len(self.history)):
|
||||||
return
|
return
|
||||||
@@ -386,9 +387,9 @@ class Shell(wxStyledTextCtrl):
|
|||||||
|
|
||||||
def OnHistorySearch(self):
|
def OnHistorySearch(self):
|
||||||
"""Search up the history buffer for the text in front of the cursor."""
|
"""Search up the history buffer for the text in front of the cursor."""
|
||||||
startpos = self.GetCurrentPos()
|
if not self.CanEdit():
|
||||||
if startpos < self.prompt1Pos[1]:
|
|
||||||
return
|
return
|
||||||
|
startpos = self.GetCurrentPos()
|
||||||
# The text up to the cursor is what we search for.
|
# The text up to the cursor is what we search for.
|
||||||
numCharsAfterCursor = self.GetTextLength() - startpos
|
numCharsAfterCursor = self.GetTextLength() - startpos
|
||||||
searchText = self.getCommand(rstrip=0)
|
searchText = self.getCommand(rstrip=0)
|
||||||
@@ -547,6 +548,12 @@ class Shell(wxStyledTextCtrl):
|
|||||||
"""Display text in the shell.
|
"""Display text in the shell.
|
||||||
|
|
||||||
Replace line endings with OS-specific endings."""
|
Replace line endings with OS-specific endings."""
|
||||||
|
text = self.fixLineEndings(text)
|
||||||
|
self.AddText(text)
|
||||||
|
self.EnsureCaretVisible()
|
||||||
|
|
||||||
|
def fixLineEndings(self, text):
|
||||||
|
"""Return text with line endings replaced by OS-specific endings."""
|
||||||
lines = text.split('\r\n')
|
lines = text.split('\r\n')
|
||||||
for l in range(len(lines)):
|
for l in range(len(lines)):
|
||||||
chunks = lines[l].split('\r')
|
chunks = lines[l].split('\r')
|
||||||
@@ -554,9 +561,7 @@ class Shell(wxStyledTextCtrl):
|
|||||||
chunks[c] = os.linesep.join(chunks[c].split('\n'))
|
chunks[c] = os.linesep.join(chunks[c].split('\n'))
|
||||||
lines[l] = os.linesep.join(chunks)
|
lines[l] = os.linesep.join(chunks)
|
||||||
text = os.linesep.join(lines)
|
text = os.linesep.join(lines)
|
||||||
self.AddText(text)
|
return text
|
||||||
self.EnsureCaretVisible()
|
|
||||||
#self.ScrollToColumn(0)
|
|
||||||
|
|
||||||
def prompt(self):
|
def prompt(self):
|
||||||
"""Display appropriate prompt for the context, either ps1 or ps2.
|
"""Display appropriate prompt for the context, either ps1 or ps2.
|
||||||
@@ -698,12 +703,62 @@ class Shell(wxStyledTextCtrl):
|
|||||||
|
|
||||||
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()
|
if self.GetSelectionStart() != self.GetSelectionEnd() \
|
||||||
|
and self.GetSelectionStart() >= self.prompt1Pos[1] \
|
||||||
|
and self.GetSelectionEnd() >= self.prompt1Pos[1]:
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
def CanCopy(self):
|
def CanCopy(self):
|
||||||
"""Return true if text is selected and can be copied."""
|
"""Return true if text is selected and can be copied."""
|
||||||
return self.GetSelectionStart() != self.GetSelectionEnd()
|
return self.GetSelectionStart() != self.GetSelectionEnd()
|
||||||
|
|
||||||
|
def CanPaste(self):
|
||||||
|
"""Return true if a paste should succeed."""
|
||||||
|
if self.CanEdit() and wxStyledTextCtrl.CanPaste(self):
|
||||||
|
return 1
|
||||||
|
else:
|
||||||
|
return 0
|
||||||
|
|
||||||
|
def CanEdit(self):
|
||||||
|
"""Return true if editing should succeed."""
|
||||||
|
return self.GetCurrentPos() >= self.prompt1Pos[1]
|
||||||
|
|
||||||
|
def Cut(self):
|
||||||
|
"""Remove selection and place it on the clipboard."""
|
||||||
|
if self.CanCut() and self.CanCopy():
|
||||||
|
if self.AutoCompActive(): self.AutoCompCancel()
|
||||||
|
if self.CallTipActive: self.CallTipCancel()
|
||||||
|
self.Copy()
|
||||||
|
self.ReplaceSelection('')
|
||||||
|
|
||||||
|
def Copy(self):
|
||||||
|
"""Copy selection and place it on the clipboard."""
|
||||||
|
if self.CanCopy():
|
||||||
|
command = self.GetSelectedText()
|
||||||
|
command = command.replace(os.linesep + sys.ps2, os.linesep)
|
||||||
|
data = wxTextDataObject(command)
|
||||||
|
if wxTheClipboard.Open():
|
||||||
|
wxTheClipboard.SetData(data)
|
||||||
|
wxTheClipboard.Close()
|
||||||
|
|
||||||
|
def Paste(self):
|
||||||
|
"""Replace selection with clipboard contents."""
|
||||||
|
if self.CanPaste():
|
||||||
|
if wxTheClipboard.Open():
|
||||||
|
if wxTheClipboard.IsSupported(wxDataFormat(wxDF_TEXT)):
|
||||||
|
data = wxTextDataObject()
|
||||||
|
if wxTheClipboard.GetData(data):
|
||||||
|
command = data.GetText()
|
||||||
|
command = self.fixLineEndings(command)
|
||||||
|
command = command.replace(os.linesep + sys.ps2, '\n')
|
||||||
|
command = command.replace(os.linesep, '\n')
|
||||||
|
command = command.replace('\n', os.linesep + sys.ps2)
|
||||||
|
self.ReplaceSelection('')
|
||||||
|
self.write(command)
|
||||||
|
wxTheClipboard.Close()
|
||||||
|
|
||||||
|
|
||||||
wxID_SELECTALL = NewId() # This *should* be defined by wxPython.
|
wxID_SELECTALL = NewId() # This *should* be defined by wxPython.
|
||||||
ID_AUTOCOMP = NewId()
|
ID_AUTOCOMP = NewId()
|
||||||
@@ -727,9 +782,9 @@ class ShellMenu:
|
|||||||
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', 'Cut the selection')
|
m.Append(wxID_CUT, 'Cu&t \tCtrl+X', 'Cut the selection')
|
||||||
m.Append(wxID_COPY, '&Copy', 'Copy the selection')
|
m.Append(wxID_COPY, '&Copy \tCtrl+C', 'Copy the selection')
|
||||||
m.Append(wxID_PASTE, '&Paste', 'Paste')
|
m.Append(wxID_PASTE, '&Paste \tCtrl+V', 'Paste')
|
||||||
m.AppendSeparator()
|
m.AppendSeparator()
|
||||||
m.Append(wxID_CLEAR, 'Cle&ar', 'Delete the selection')
|
m.Append(wxID_CLEAR, 'Cle&ar', 'Delete the selection')
|
||||||
m.Append(wxID_SELECTALL, 'Select A&ll', 'Select all text')
|
m.Append(wxID_SELECTALL, 'Select A&ll', 'Select all text')
|
||||||
|
Reference in New Issue
Block a user