Re: ComboBox signals



On Thursday, November 13, 2003, at 05:09 AM, David Sword wrote:

I have a combobox in my application which is set to $editable(FALSE), as I only want users to select an item from the drop down list. The action
of selecting then uses a callback to load data from the database!

you're using the wrong widget.

you want a GtkOptionMenu.

(in Gtk2 1.011, do perldoc Gtk2::OptionMenu)


you can create the menu with ItemFactory, or by hand if you don't need accelerators. here's the type of code i use rather often:

        @options = (
                { label => 'One', func => \&do_one },
                { label => 'Two', func => \&do_two },
                { label => 'Red', func => \&do_red },
                { label => 'blue', func => \&do_blue },
        );

        $option = Gtk2::OptionMenu->new;
        $menu = Gtk2::Menu->new;
        foreach (@options) {
                my $item = Gtk2::MenuItem->new ($_->{label});
                $item->signal_connect (activate => $_->{callback});
                $menu->append ($item);
                $item->show;
        }
        $option->set_menu ($menu);
        $option->set_history ($index_of_current_selection);

there are, of course, millions of ways to do that --- use a single callback and pass an identifier to it, watch for the selected index while building the list, etc etc etc.



rationale:

GtkComboBox is broken and slated for replacement in 2.4.0, with GtkCombo, whose non-editable form looks like a GtkOptionMenu. it is rather a bit easier to use and more flexible, too.

using read-only comboboxen for multiple choice is a holdoves from Win32's broken ui. don't fall for it. the option menu is a button that pops up a menu of available choices; it doesn't look editable, so you know that you have a finite number of options from which to choose.


--
"that's it! you're a genius!" "yes. that's what i think. do you think i deserve a raise?"
        - dialogue from 'Godzilla versus Mothra', 1964




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