Re: [pygtk] Questions about accelerators.
On Fri, 29 Sep 2000, James Henstridge wrote: Can you give me a quick code example? If you just want to do something special for a particular widget, then using the key_press_event signal is the correct aproach. You look at the attributes of the event object to see which key was pressed. Return TRUE if you handled the event yourself, and FALSE otherwise. Okay, that makes a lot of sense, but I"m having problems wrapping the event trigger. (sp_sendtext is a gtktext widget) 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? Also, could you point me to the structure of an event object? ---. Web-based problem management: www.stonekeep.com Dave Belfer-Shevett . [EMAIL PROTECTED] / Don't byte off more than you can view. (Maxims for \ -- the Internet Age)| \__/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Questions about accelerators.
On Fri, 29 Sep 2000, Dave Belfer-Shevett wrote: This is -OUTSTANDING- information. I have just one teeny weeny question, which will cement me as a Newbie. :) We where all newbies once. On Fri, 29 Sep 2000, Alexandre Fayolle wrote: struct GdkEventKey { GdkEventType type; GdkWindow *window; gint8 send_event; guint32 time; guint state; guint keyval; gint length; gchar *string; }; Etc. I understand that it's an GdkEventKey struct. There's a lot of structures returned from GTK. I understand there are methods associated with Objects that come back (ala a 'set_text' associated with a GtkEntry field, etc). But how do I retrieve values from the structure? ala, 'gint' is within the structure. How do I get that value, with an explicit get_gint() method associated with the object? Ahem. In the above snippet of doc, 'gint' is a type, not a member. ;o) The python mappings are very easy to use: the keyevent parameter you get is a python object with attributes that match the names of the C structure members. If you want to react on a ^C, for example, you can do something like: import GDK def keyevent_handler(widget,keyevent): if keyevent.keyval=GDK.C and keyevent.state=GDK.CONTROL_MASK: # do something here pass Does this answer your question? -- Alexandre Fayolle http://www.logilab.com - "Mais où est donc Ornicar ?" - LOGILAB, Paris (France). ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Questions about accelerators.
On Fri, 29 Sep 2000, Alexandre Fayolle wrote: Ahem. In the above snippet of doc, 'gint' is a type, not a member. ;o) I knew that. Really. Blame it on the cold. The python mappings are very easy to use: the keyevent parameter you get is a python object with attributes that match the names of the C structure members. If you want to react on a ^C, for example, you can do something like: import GDK def keyevent_handler(widget,keyevent): if keyevent.keyval=GDK.C and keyevent.state=GDK.CONTROL_MASK: # do something here pass Does this answer your question? It did, once the fever listed and I noticed you used '=' instead of '==' :) Thanks tons! ---. Web-based problem management: www.stonekeep.com Dave Belfer-Shevett . [EMAIL PROTECTED] / 30. For every action there is an equal and opposite \ -- criticism. | \__/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
[pygtk] Questions about accelerators.
Hey folks. I sent this to glade-users, and perhaps its more appropriate for this list. Any ideas? ---. Web-based problem management: www.stonekeep.com Dave Belfer-Shevett . [EMAIL PROTECTED] /My idea of an agreeable person is a person who\ -- agrees with me. (Benjamin Disreali) | \__/ -- Forwarded message -- Date: Thu, 28 Sep 2000 16:09:38 -0400 (EDT) From: Dave Belfer-Shevett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Questions about accelerators. Hi folks. I'm writing a GTK app using libglade in Python. So far thinks are going okay, but I'm having some difficulty connecting accelerators and trapping signals from them. I've defined an accelerator within a GtkText widget (call it 'ctrl-f1'), and bound it to the key. I save it, and in the Glade file, I have: [shevett@cheetah]:~/python/spanker/proj1$ ./spanker.py Gtk-WARNING **: gtk_accel_group_add(): could not find signal "ctrl-f1"in the `GtkText' class ancestry Gtk-WARNING **: gtk_signal_connect_full(): could not find signal "enter" in the `GtkText' class ancestry Okay, fine, that means I need to use a signal that exists. (I think). But what I -rally- want to do is link 'Ctrl-f1' to the 'clicked' signal on a button elsewhere. How do I do this - specifically in python/Glade. :) Thanks! ---. Web-based problem management: www.stonekeep.com Dave Belfer-Shevett . [EMAIL PROTECTED] / 32. Never do card tricks for the group you play\ -- poker with. | \__/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk
Re: [pygtk] Questions about accelerators.
On Thu, 28 Sep 2000, Dave Belfer-Shevett wrote: Hey folks. I sent this to glade-users, and perhaps its more appropriate for this list. Any ideas? ---. Web-based problem management: www.stonekeep.com Dave Belfer-Shevett . [EMAIL PROTECTED] /My idea of an agreeable person is a person who\ -- agrees with me. (Benjamin Disreali) | \__/ -- Forwarded message -- Date: Thu, 28 Sep 2000 16:09:38 -0400 (EDT) From: Dave Belfer-Shevett [EMAIL PROTECTED] To: [EMAIL PROTECTED] Subject: Questions about accelerators. Hi folks. I'm writing a GTK app using libglade in Python. So far thinks are going okay, but I'm having some difficulty connecting accelerators and trapping signals from them. I've defined an accelerator within a GtkText widget (call it 'ctrl-f1'), and bound it to the key. I save it, and in the Glade file, I have: [shevett@cheetah]:~/python/spanker/proj1$ ./spanker.py Gtk-WARNING **: gtk_accel_group_add(): could not find signal "ctrl-f1"in the `GtkText' class ancestry Gtk-WARNING **: gtk_signal_connect_full(): could not find signal "enter" in the `GtkText' class ancestry Okay, fine, that means I need to use a signal that exists. (I think). But what I -rally- want to do is link 'Ctrl-f1' to the 'clicked' signal on a button elsewhere. How do I do this - specifically in python/Glade. :) This is not pygtk problem. You can't just invent signal names like that. Accelerators have to activate an existing signal on an object. If you just want to catch some other key presses on a particular widget, then connect to its key_press_event signal, and handle the key presses there. Thanks! James. -- Email: [EMAIL PROTECTED] WWW: http://www.daa.com.au/~james/ ___ pygtk mailing list [EMAIL PROTECTED] http://www.daa.com.au/mailman/listinfo/pygtk