[go: up one dir, main page]

Menu

[r1]: / bin / AutoCompletition.py  Maximize  Restore  History

Download this file

44 lines (31 with data), 1.4 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import wx, keyword, difflib
class AutoComplet:
def __init__(self):
self.replace_dic = {"\n":" ",".":" ",",":" ",")":" ","(":" ","]":" ","[":" "\
,"{": " ", "}":" ","\"":" ", "'":" ",";":" "}
def Replace_All(self,text, dic):
for i, j in dic.iteritems():
text = text.replace(i, j)
return text
def CreateCompList(self,text):
text = self.Replace_All(text, self.replace_dic)
split_text = text.split(" ")
return list(set(split_text))
def OnKeyPressed(self,event, text_id):
CurrentWidget = wx.FindWindowById(text_id)
CurrentWidget.AutoCompSetIgnoreCase(False)
if CurrentWidget.CallTipActive():
CurrentWidget.CallTipCancel()
key = event.GetKeyCode()
if key == 32 and event.ControlDown():
pos = CurrentWidget.GetCurrentPos()
content = CurrentWidget.GetText()
word = CurrentWidget.GetTextRange(CurrentWidget.WordStartPosition(pos, True),pos)
lst = difflib.get_close_matches(word, self.CreateCompList(content), 5)
try:
del lst[0]
except: pass
st = " ".join(lst).strip(word)
if st != "":
CurrentWidget.AutoCompShow(0, st)
event.Skip()