[pygtk] Questions about accelerators.

Alexandre Fayolle alf@logilab.com
Fri, 29 Sep 2000 17:25:39 +0200 (CEST)


On Fri, 29 Sep 2000, Dave Belfer-Shevett wrote:

> 
> 	ta = widgets.get_widget('sp_sendtext')
> 	ta.signal_connect('key_press_event',sendkey)
> 
> Which triggers
> 
> def sendkey():
> 	print "Key pressed!  "
> 	return FALSE
> 
> But I get:
> 
> [shevett@cheetah]:~/python/spanker/proj1$ ./spanker.py 
> Traceback (innermost last):
>   File "/usr/local/lib/python1.5/site-packages/gtk.py", line 125, in
> __call__
>     ret = apply(self.func, a)
> TypeError: no arguments expected
> 
> Wha'd i do wrong?

your handler takes no argument, and gtk tries to call it with arguments,
hence the error. 
You could do  
def sendkeys(*args): 
if you don't care about which key was pressed, or 
def senkeys(widget,keyevent):
if you want to get some info. The key event has the following
fields (from the gtk documentation project):

struct GdkEventKey
  {
    GdkEventType type;
    GdkWindow *window;
    gint8 send_event;
    guint32 time;
    guint state;
    guint keyval;
    gint length;
    gchar *string;
  };

 GdkEventType type
the type of the event (GDK_KEY_PRESS or
GDK_KEY_RELEASE).

 GdkWindow *window
the window which received the event.

 gint8 send_event
TRUE if the event was sent explicitly (e.g. using XSendEvent).

 guint32 time
the time of the event in milliseconds.

 guint state
a bit-mask representing the state of the modifier keys (e.g. Control,
Shift and Alt) and the pointer buttons. See GdkModifierType.

 guint keyval
the key that was pressed or released. See the <gdk/gdkkeysym.h> header
file for a complete list of GDK key codes.

 gint length
the length of string.

 gchar *string
a null-terminated multi-byte string containing the composed characters
resulting from the key press. When text is being input, in a GtkEntry for
example, it is these characters which should be added to the input buffer.
When using Input Methods to support internationalized text input, the
composed characters appear here after the pre-editing has been completed.

 --
Alexandre Fayolle http://www.logilab.com - "Mais oł est donc Ornicar ?" - 
LOGILAB, Paris (France).