gestion d'un <enter> sur un gtk.Entry()
Bonjour,
Je cherche a prendre en compte un <enter> dans un champ de saisie a partir du code suivant qui ouvre une fenetre de dialogue simple avec un champ de saisie, un bouton OK et un bouton Cancel. J'ai des difficultes pour articuler la callback appelee par 'activate' par rapport a la fonction Run:
Code:
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
| class WinDialogPassword__:
"""
Describe the Window which asks a password to continue
"""
def __init__(self, title, parentWin):
"""
Constructor of the class
@param title: the title of the Window
@type title: str
@param parentWin: Window which open this window
@type parentWin: widget
"""
self.win = gtk.Dialog(title, parentWin,
gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
self.win.add_buttons(gtk.STOCK_OK, gtk.RESPONSE_OK,
gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL)
self.entry = gtk.Entry()
self.entry.connect("activate", self.WinDialogPasswordActivate, None)
self.entry.set_visibility(False)
self.win.vbox.pack_start(self.entry)
self.win.show_all()
def WinDialogPasswordRun(self,password):
"""
Intercept user's action in the window
@param password: password to check
@type password: str
@return: True if the password is correct
@rtype: boolean
"""
ret = False
while True:
# Wait an action
response = self.win.run()
if (response == gtk.RESPONSE_OK):
if(self.entry.get_text() == password):
ret = True
break
else:
self.entry.set_text('')
self.entry.grab_focus()
if (response == gtk.RESPONSE_CANCEL):
ret = False
break
self.win.destroy()
return ret
def WinDialogPasswordActivate(self, entry, data=None):
"""
Intercept user's action in the entry field
@param entry: the entry that received the signal
@type entry: gtk.Widget
@param data: optional
@type:
"""
???????????????????
Dans le main :
winPassword = WinDialogPassword__("Password", self.main.MainGet_Win())
ret = winPassword.WinDialogPasswordRun("password") |
L'instruction "response = self.win.run()" va mettre l'application en attente de la saisie, puis aller en séquence. Le <enter> va déclencher la callback "WinDialogPasswordActivate" et je ne sais pas ou revenir ni comment.
Merci de votre aide