Re: Which widget id triggered the event?

On Fri, 2007-04-13 at 05:59 -0700, MICHAEL MCGINN wrote:
An example
I have a common function that could be triggered by either a button
click, menuitem, popup menuitem, etc...

it's not a very maintainable setup; it will break badly as soon as you
find the need to perform specific code depending on the widget - like
you are now.

Depending on what widget was used I want call the same function,
detemine which widget, then process accordingly. Based on which widget
I would perform all or a subset of the function.
I've looked into the Gtk2::main and Gtk2::Widget methods and they
provide the event widget (GtkMenuItem) and complete path
(GtkWindow.GtkMenu.GtkMenuItem) but I would need the id of the menu
item (ex: "menu name1" or "menu name 2")  in order to process

you can set an arbitrary name on a widget, using
Gtk2::Widget::set_name() and Gtk2::Widget::get_name() to retrieve the
name set.

The way I do it now is to have the signal handler from the widget call
the function and pass it what it needs.

which is a perfectly fine solution:

  $bar_widget->signal_connect('foo' => \&foo_cb, 'is-bar');
  $baz_widget->signal_connect('foo' => \&foo_cb, 'is-baz');

my advise is to use separate callbacks and call a function with the
common code inside them.


Emmanuele Bassi,  E: ebassi gmail com

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