Luke, Thanks for the response. I am trying to help someone out on the Pygtk list. I forgot to enclose his reasons for wanting to assign the key press. They are below: It looks like he likes his keys set out in a certain way. I am happy with mine the way they are! I used "z" in isolation just to get the logic right. I know I can assign a function to Z and make the Treeview move down one row and select the row below but I don't want to have to do this for all the different buttons. I am trying to do it without having to assign and call a whole load of different functions.
> I just start to use pygtk ... so it is just my first > question :-) > > I would like to create a small file manager based on 'lfm' (curses > based file manager). I used glade for the gui and I am able to display > the existing files and directories using two treeview widgets. > Now, at the beginning I am kind of stuck with the key bindings. In 'lfm' > it was pretty easy to define special key bindings: > > > keytable = { > # movement > ord('p'): 'cursor_up', > ord('k'): 'cursor_up', > ord('K'): 'cursor_up2', > ord('P'): 'cursor_up', > curses.KEY_UP: 'cursor_up', > ord('n'): 'cursor_down', > ord('j'): 'cursor_down', > ord('J'): 'cursor_down2', > ord('N'): 'cursor_down', > curses.KEY_DOWN: 'cursor_down', > curses.KEY_PPAGE: 'page_previous', > curses.KEY_BACKSPACE: 'page_previous', > 0x08: 'page_previous', # BackSpace > 0x10: 'page_previous', # Ctrl-P > curses.KEY_NPAGE: 'page_next', > ord(' '): 'page_next', > 0x0E: 'page_next', # Ctrl-N > curses.KEY_HOME: 'home', > 0x16A: 'home', > ord('H'): 'home', > 0x001: 'home', > curses.KEY_END: 'end', > ord('G'): 'end', > 0x181: 'end', > 0x005: 'end', > ord('h'): 'cursor_left', > ord('l'): 'cursor_right', > curses.KEY_LEFT: 'cursor_left', > curses.KEY_RIGHT: 'cursor_right', > ord('g'): 'goto_dir', > 0x13: 'goto_file', # Ctrl-S > 0x14: 'tree', # Ctrl-T > ord('0'): 'bookmark_0', > ord('1'): 'bookmark_1', > ... > > > with such a keytable I am able to bind different 'def's to every > existing key. As you can see, I like it a lot to use 'vim-like' keys > for moving around; 'j' and 'k' to move a row up and down. In glade I > found those 'accelerators', but it is just for certain functions. > Does anyone have an idea about using such a keybinding in > pygtk? Would be nice! > I have attempted to answer his question but I am not sure I am on the right track. Is there a better way to do it? Regards, John. -----Original Message----- From: Luke Paireepinart [mailto:[EMAIL PROTECTED] Sent: 27 November 2006 01:30 To: [EMAIL PROTECTED] Cc: tutor@python.org Subject: Re: [Tutor] adjust key bindings John CORRY wrote: > Hi All, > > I have been trying to bind the "z" key to the "Down" key using Python > 2.4, Glade 2 and Pygtk. I have posted this problem on the Pygtk list > but have had no response. I was hoping somebody on the tutor list could > help. I think that I am close. I can capture the "z" key press and > assign a "Down" key press but I can't get the "Down" key press to > register on the Treeview in the GUI. > > Any thoughts greatly appreciated. > > Thanks, > > John. I highly doubt that what you want to do when someone hits a 'z' is to generate a 'down' keypress. What if the user assigned the down key to z? then you'd have a z -> down -> z -> down -> .... infinite loop. What I expect you want is that each key, z and down, perform the same action. In other words, they both call the same function. So basically what you'd want is something like this (non-pyGTK specific code) def aFunc(): print "Hello, World!" bindKey = {'down':aFunc} keypress = raw_input("What keypress do you want to perform?") bindKey[keypress]()#this will call the 'aFunc' function if they type 'down', otherwise, it'll probably crash. bindKey['z'] = aFunc bindKey['z']()# now performs the same function as bindkey['down']()#this does. If you really do want to generate 'down' keypresses when someone hits 'z', please explain why, and I will try to the best of my abilities to help you in that regard! Good Luck! -Luke > > _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor