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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| #!/usr/bin/env python
#-*- coding: utf-8 -*-
#
#
import Tkinter
import pyHook
import pythoncom
import win32api, win32con
import threading
import time
import sys
class Clavier(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.run()
def run(self):
""" Initialisation du Hook """
self.threadidph = win32api.GetCurrentThreadId()
self.hm = pyHook.HookManager()
self.hm.KeyDown = self.on_event
self.hm.HookKeyboard()
pythoncom.PumpMessages()
def stop(self):
win32api.PostThreadMessage(self.threadidph, win32con.WM_QUIT, 0, 0)
def on_event(self, event):
f=open(r'c:\mot.txt','r')
syntaxe=f.read()
f.close()
if event.Ascii==32:
print syntaxe
f=open(r'c:\mot.txt','w')
f.write('')
f.close()
elif event.Key=="Escape":
print "Arreter le pyHook"
self.stop()
elif event.Key=="Down":
self.appel_fenetre()
elif event.Ascii!=0:
syntaxe+=chr(event.Ascii)
f=open(r'c:\mot.txt','w')
f.write(syntaxe)
f.close()
return True
def appel_fenetre(self):
self.af=Interface()
self.af.run()
self.af.affichage()
class Interface(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.run()
def run(self):
self.threadidaf = win32api.GetCurrentThreadId()
def selection(self):
self.selection_set(0,0)
def affichage(self):
self.fenetre_compl=Fenetre()
self.liste_choix=self.recherche_complements()
self.fenetre_compl.liste_proposition.delete(0,Tkinter.END)
for mot_select in self.liste_choix:
self.fenetre_compl.liste_proposition.insert(Tkinter.END,mot_select)
self.fenetre_compl.liste_proposition.bind('Down',self.selection)
self.fenetre_compl.mainloop()
# def activation_fenetre(self):
def recherche_complements(self):
""" création de la liste des mots pour le complément"""
#Liste_mots 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))
liste_complement=[]
f=open(r'c:\mot.txt','r')
saisie=f.read()
f.close()
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
class Fenetre(Tkinter.Tk):
def __init__(self):
""" Création de la fenêtre """
Tkinter.Tk.__init__(self)
self.title("Compléments")
self.cadre=Tkinter.Frame(self)
self.cadre.pack()
self.liste_proposition=Tkinter.Listbox(self.cadre,height=4)
self.liste_proposition.pack(fill=Tkinter.Y)
self.bouton_fin = Tkinter.Button(self.cadre, text = 'Quitter', command = self.quitter)
self.bouton_fin.pack()
def quitter(self):
self.sys.exit()
class Master():
def __init__(self):
pH=Clavier()
pH.run()
if __name__ == '__main__':
f=open(r'c:\mot.txt','w')
f.write('')
f.close()
Master() |