Re: Gtk2::ComboBox - setting value by string?



Matthew Braid wrote:
> Hi all,
>
> Running into a minor problem with Gtk2::ComboBox. I can set the
> current selected option by using an iter (or a string representation
> of the iter like "0") but I can't just set it to a string I know is in
> the list directly.
>
> As a workaround I've had to create a little helper function like:
>
> sub find_index {
>   my ($model, $find) = @_;
>   my $i = 0;
>   while (1) {
>     my $iter = $model->get_iter_from_string($i);
>     last if not defined $iter;
>     return $i if $find eq $model->get($iter, 0);
>     ++$i;
>   }
>   return undef;
> }
>
> (where $model is the combobox's model from $cb->get_model).
>
> Is this sort of thing necessary or is there a way to set a combobox's
> value by string rather than by index?

Yes it's required:
http://bugzilla.gnome.org/show_bug.cgi?id=149248


While you're at it, write yourself another little function to call your
other little function ( above ) when the focus leaves the Combo's entry,
because Combo's don't automatically detect if someone types a string
into their entry that matches an item in their model ( ie the correct
iter is only set as 'active' if you use the *mouse* to select an item
... any keyboard input is ignored ! ):
http://bugzilla.gnome.org/show_bug.cgi?id=156017


And look out if you try to get a value out of a CellRendererCombo in a
TreeView:
http://bugzilla.gnome.org/show_bug.cgi?id=317387


IMHO there are *far* too many combo-related bugs in gtk+ :( Don't the
developers use combos?

-- 
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: dkasak nusconsulting com au
website: http://www.nusconsulting.com.au



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