[pygtk] Re: adjust key bindings
John CORRY
john.corry at ntlworld.com
Tue Nov 21 03:25:45 WST 2006
Fabian,
(Sorry the previous e-mail I sent you, I forgot to copy it to the list.
I have now copied it to the list to see if anyone else thinks this is
the right direction to go or can modify the following code to get what
you want.)
I use the following code to trap a key in a text box. The first
function connects to the Glade, Window1 and the text box1. The second
function is triggered when any key on the keyboard is hit. Callback3000
then matches the key that is hit against my keys that I have listed. If
it matches one of these keys, it allows the key press to put the number
in the text box. If it does not match the key list, then nothing is put
in the box.
I am not sure if you can use this to do what you want. It may give you
some ideas.
Under treeview you also have a key_press_event in Glade. You can trap
this and put your code together to do different things depending on what
key is pressed. I am not sure how you would get "z" key to equal the
"up" key etc. Maybe somebody else on the list can take what I have
written here and adapt it.
def __init__(self):
self.wTree = gtk.glade.XML ("shopcard.glade", "window1")
text1 = self.wTree.get_widget("entry244")
text1.connect("key_press_event",self.callback3000)
def callback3000(self,widget,event,saves):
import re
"""prevents the possibility of inputting wrong chars"""
## fixme: missing comma, and cut&paste
key = gtk.gdk.keyval_name (event.keyval)
ONLYDIGITS="([0-9.,]|BackSpace|Left|Right|F1|period|Tab|Up|Down)"
if not re.match (ONLYDIGITS, key):
return True
#This tells the script to ignore the key press as it
does not #match one of the keys specified.
else:
# If a key that you want to trap is hit, this will activate
any # code you put below.
return False
I'll maybe have a go at it myself and see if I can get it to work.
Regards,
John.
-----Original Message-----
From: pygtk-bounces at daa.com.au [mailto:pygtk-bounces at daa.com.au] On
Behalf Of Sebastian Pölsterl
Sent: 19 November 2006 12:09
To: pygtk at daa.com.au
Subject: Re: [pygtk] Re: adjust key bindings
Fabian Braennstroem wrote:
> Hi,
>
> sorry, is that question to stupid or does nobody has a hint?
>
>
Have a look at gtk.AccelGroup and the UIManager tutorial at
http://www.pygtk.org/pygtk2tutorial/sec-UIManager.html
--
Greetings,
Sebastian Pölsterl
_______________________________________________
pygtk mailing list pygtk at daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
More information about the pygtk
mailing list