def OnKeyPressed(self, event):
if self.CallTipActive():
self.CallTipCancel()
key = event.GetKeyCode()
current_pos = self.GetCurrentPos()
selected = self.GetSelection()
text_selected = selected[0] != selected[1]
# Test if caret is before Windows like new line
text = self.GetText()
if current_pos < len(text) and ord(text[current_pos]) == 13:
newline_size = 2
else:
newline_size = 1
# Disable to type any character in section header lines
if (self.GetLineState(self.LineFromPosition(current_pos)) and
not text_selected and
key not in NAVIGATION_KEYS + [
wx.WXK_RETURN,
wx.WXK_NUMPAD_ENTER]):
return
# Disable to delete line between code and header lines
elif (self.GetCurLine()[0].strip() != "" and not text_selected and
(key == wx.WXK_BACK and
self.GetLineState(self.LineFromPosition(max(0, current_pos - 1))) or
key in [wx.WXK_DELETE, wx.WXK_NUMPAD_DELETE] and
self.GetLineState(self.LineFromPosition(min(len(text), current_pos + newline_size))))):
return
elif key == 32 and event.ControlDown():
pos = self.GetCurrentPos()
# Tips
if event.ShiftDown():
pass
# Code completion
else:
self.AutoCompSetIgnoreCase(False) # so this needs to match
keywords = self.KEYWORDS + [var["Name"]
for var in self.Controler.GetVariables()]
keywords.sort()
self.AutoCompShow(0, " ".join(keywords))
else:
event.Skip()
评论列表
文章目录