Re: Binding Variables to Widgets
- From: muppet <scott asofyet org>
- To: Nik Ogura <nogura uma-mn com>
- Cc: gtk-perl-list gnome org
- Subject: Re: Binding Variables to Widgets
- Date: Thu, 4 Jan 2007 13:21:04 -0500
On Jan 4, 2007, at 12:12 AM, Nik Ogura wrote:
Forgive my noobishness, I'm coming from a Perl/Tk background.
In Perl/Tk you can easily bind a variable to a widget, so that any
changes to the widget text are automatically changed in the bound
Is this sort of thing possible in Gtk2-perl? Or am I stuck doing
$widget->set_text and $widget->get_text calls to do the same?
Thank you in advance.
I second Emmanuele's recommendation of Glib::Object::tie_properties
(). The thread introducing and debating the relative merits of this
mechanism can be found here:
Of course, you could just use the object property interface directly:
($foo, $bar, $baz) = $object->get (qw/foo bar baz/);
$object->set (foo => $new_foo, bar => $new_bar, baz => $new_baz);
$object->signal_connect ('notify::foo' => \&on_foo_changed);
However, in the spirit of TIMTOWDI and full disclosure, this topic
has been broached before. Bjarne Steinsbo created a class called
Gtk2::BindVariable, which is discussed in the thread "A little tie
magic", which starts here:
We did not include that in the distribution for a few reasons:
different developers had style disagreements over it, we already had
Glib::Object::tie_properties(), and about this time we realized that
including lots of pure-perl code with the xs-only bindings was
starting to cause maintenance grief.
Take-home message --- gtk2-perl provides you the full gtk2 API, with
a few spartan niceties, but doesn't intend to go beyond that. If you
want to layer your own convenience stuff atop that, please do, and
share it on CPAN.
] [Thread Prev