Can anyone explain what an "iter" is?
I see it used in the docs for TextView, TreView, etc,
indifferent contexts, as if it is some basic entity.
Can someone define what an iter is, and why is it
so intertwined in the workings of Gtk2?
Are there any real-world analogies?
I'll pass on my limited understand of what's going on :)
An iter is an 'iteration' - a single instance in a collection of
'things'. It's a pointer to a particular instance, that you can use to
refer to that instance immediately after getting hold of it ( apparently
it's invalid after anything has happened to the object you're dealing
with, so you can't hold onto them for any length of time ).
For example, a model for a combo might have 10 'rows' of data. To get a
pointer to the 1st row, you'd do:
my $iter = $model->get_iter_first
To get the next iter, you'd:
$iter = $model->iter_next($iter)
Or if someone has selected an item in with the combo box, and you want
to find out what they've selected, you want the 'active' iter ( ie a
pointer to the row containing the selected data ). So you'd do:
my $iter = $model->get_active_iter
Once you've got the iter ( a pointer to the right 'row' ), you can
my $first_item = $model->get( $iter, 0);
my $second_item = $model->get( $iter, 1);
When you come across other objects that use iters, it means that they're
basically storing & retrieving data in the same way. For example you
mentioned the TextView - to access characters in a TextView you do
my $textbuffer = $textview->get_buffer;
my ( $start_iter, $end_iter ) = $textbuffer->get_bounds;
That gives you pointers to the 1st and last characters. You can then go:
$value = $textbuffer->get_text( $start_iter, $end_iter, 1 );
to get the actual text.
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
gtk-perl-list mailing list