trouble with key bindings

Lacking any clear examples of how to set up bindings for new widgets (Havoc:
thanks for the explanation for the lack of preexisting examples, btw), I'm
striking out on my own, trying to feel my way in the dark without banging my
shin on the coffee table.

I have an extremely simple example (in Python).  I made a trivial subclass
of GtkDrawingArea:

    class Sketch(gtk.GtkDrawingArea):

for which I defined a new signal:

    gobject.signal_new("move-obj", Sketch, gobject.SIGNAL_RUN_FIRST,
                       gobject.TYPE_NONE, (gobject.TYPE_INT, gobject.TYPE_INT))

I want to be able to bind <ctl>- and <shift>-prefixed arrow keys to the
"move-obj" signal, so I defined the following

    binding "movers" {
      bind "<control>Up" { "move-obj" ( 0, -1 ) }
      bind "<shift>Up" { "move-obj" ( 0, -10 ) }
      bind "<control>Down" { "move-obj" ( 0, 1 ) }
      bind "<shift>Down" { "move-obj" ( 0, 10 ) }
      bind "<control>Left" { "move-obj" ( -1, 0 ) }
      bind "<shift>Left" { "move-obj" ( -10, 0 ) }
      bind "<control>Right" { "move-obj" ( 1, 0 ) }
      bind "<shift>Right" { "move-obj" ( 10, 0 ) }

    class "Sketch" binding "movers"

and pass it to gtk.rc_parse_string at the start of the script.

Furthermore, I attempt to make sure that my Sketch instances see keypresses:

    drw = Sketch()

and finally, establish a callback for the "move-obj" signal:

    drw.connect("move-obj", cb)

When I put this all together in the obvious fashion, my callback function is
never called.  I'm at a loss to figure out what's missing.  I suspect my key
binding stuff is incorrect somehow or I've failed to correctly set up the
Sketch object to see key presses.

Skip Montanaro (skip pobox com)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]