Re: Which widget id triggered the event?
- From: Emmanuele Bassi <ebassi gmail com>
- To: gtk-perl-list gnome org
- Subject: Re: Which widget id triggered the event?
- Date: Fri, 13 Apr 2007 14:18:24 +0100
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
accordingly.
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.
ciao,
Emmanuele.
--
Emmanuele Bassi, E: ebassi gmail com
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]