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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
# -*- coding: utf8 -*-
import pyHook
import Tkinter as tkinter
import pythoncom
def mots_pour_complements():
"""Liste des mots susceptibles d'être complétés - qui sera remplacée par une liste de mots dans un fichier"""
liste_mots=['convivial','Déterminer','déterminer','si et seulement si','ensemble','solution','condition','nécessaire',
'suffisante','condiment','par contre','contretemps','seulement','Seulement','Par contre','Par ailleurs',
'Résoudre','résoudre','événement','alpha','beta']
liste_mots=list(set(liste_mots))
return liste_mots
def recherche_complement(saisie,liste_mots):
"""La variable saisie correspond au début du mot à* compléter éventuellement;
liste_mots est la liste de l'ensemble de tous les mots susceptibles d'être complétés
En retour: liste_complement qui est la liste triée dans l'ordre croissant des mots trouvés
dans liste_mots qui commencent par la variable affectée à saisie"""
liste_complement=[]
for mots in liste_mots:
if mots.startswith(saisie):
liste_complement.append(mots)
numero_index=1
while numero_index<len(liste_complement):
numero_test=numero_index-1
while liste_complement[numero_test]>liste_complement[numero_index] and numero_test>=0:
numero_test=numero_test-1
if numero_test<numero_index-1:
tampon=liste_complement[numero_index]
j=numero_index
while j>numero_test+1:
liste_complement[j]=liste_complement[j-1]
j=j-1
liste_complement[numero_test+1]=tampon
numero_index=numero_index+1
return liste_complement
def interface(mot):
fen_compl=tkinter.Tk()
fen_compl.title("Principale")
cadre=tkinter.Frame(fen_compl)
cadre.pack()
ascenseur=tkinter.Scrollbar(cadre,orient=tkinter.VERTICAL)
ascenseur.pack(side=tkinter.RIGHT,fill=tkinter.Y)
liste_proposition=tkinter.Listbox(cadre,yscrollcommand=ascenseur.set)
ascenseur.config(command=liste_proposition.yview)
liste_proposition.pack(fill=tkinter.Y)
liste_mots_initiale=mots_pour_complements()
liste_gen=recherche_complement(mot,liste_mots_initiale)
liste_proposition.delete(0,tkinter.END)
for mot_select in liste_gen:
liste_proposition.insert(tkinter.END,mot_select)
liste_proposition.selection_set(0,0)
bouton=tkinter.Button(fen_compl,text='Quitter',command=fen_compl.destroy)
bouton.pack(side=tkinter.BOTTOM)
fen_compl.wm_attributes("-topmost", 1, "-alpha", 0.75)
fen_compl.overrideredirect(1)
fen_compl.mainloop()
def OnKeyboardEvent(touche):
f=open(r'c:\mot.txt','r')
syntaxe=f.read()
f.close()
f=open(r'c:\mot.txt','w')
if touche.Ascii==32:
print syntaxe
f.write('')
elif touche.Key=="Down":
selection()
elif touche.Ascii!=0:
syntaxe+=chr(touche.Ascii)
f.write(syntaxe)
interface(syntaxe)
f.close()
return True
def selection():
fen_compl.liste_proposition.focus_set()
if __name__ == '__main__':
f=open(r'c:\mot.txt','w')
f.write('')
f.close()
hm = pyHook.HookManager()
hm.KeyDown=OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages() |