Re: Binding Variables to Widgets
- From: Emmanuele Bassi <ebassi gmail com>
- To: gtk-perl-list gnome org
- Subject: Re: Binding Variables to Widgets
- Date: Thu, 04 Jan 2007 09:12:56 +0000
On Wed, 2007-01-03 at 23:12 -0600, 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
variable.
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?
you want Glib::Object::tie_preferences:
$object->tie_properties ($all=FALSE)
* $all (boolean) if FALSE (or omitted) tie only properties for this
objectâs class, if TRUE tie the properties of this and all parent
classes.
A special method avaiable to Glib::Object derivatives, it uses
perlâs tie facilities to associate hash keys with the properties of
the object. For example:
$button->tie_properties;
# equivalent to $button->set (label => âHello Worldâ);
$button->{label} = âHello Worldâ;
print "the label is: ".$button->{label}."\n";
[...]
-- from Glib::Object perldoc page
obviously, you really want to be sure that you don't end up adding a key
named 'text' to your Gtk2::Entry object, or you'd end up with a nasty
loop.
in any case, if you want to update a variable in sync with the changes,
just attach a callback to the Gtk2::Entry 'changed' signal and update
the variable there: it's called 'event-driven programming' for a reason,
you know. ;-)
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]