On Fri, 16 Feb 2001, Markus Gritsch wrote:

> > > Markus Gritsch wrote:
> > >
> > > ok, I figured out, how to put an underscore under a letter in a label,
> > > but I still wonder, how to trigger a function with a keyboard
> > > accelerator.
> >
> > First of all, get a reference to the label in the button like so:
> >   label = button.children()[0]
> >
> > Next, call the parse_uline function of the label:
> >   keysym = label.parse_uline('The _Label I want')
> >
> > This will set the label with the correct underline, and return the keysym
> > for the accelerator with any modifiers (ctrl, or whatever) you want:
> >
> > Next, add an accelerator to some accel group
> >   accel_group.add(keysym, modifiers, 0, button, 'clicked')
> >
> > (and make sure the accel group is attached to the window you want it to
> > work from).  Now when the accelerator is pressed, the clicked signal of
> > the button will be emitted (the same as happens when the button is really
> > clicked).
> 
> Thanks for your detailed description.  Fortunately I came up with the same
> solution.
> 
> The problem which remains is, how can I bind a keyboard accelerator to
> something else than a signal of an object?  For example to some arbitrary
> function.  A suggested solution was to create an invisible button, and bind
> a keyboard accelerator to it's clicked signal which in turn calls my
> function, but I think there must be a more elegant way.

In that case, you should probably just connect to the key_press_event of
the widget in question and look for the appropriate key presses, and
return TRUE if you decide to handle the event.

James.

-- 
Email: [EMAIL PROTECTED]
WWW:   http://www.daa.com.au/~james/



_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk

Reply via email to