Gtk2::ComboBox with a dummy entry



Hi all,

I'm trying to build a gui with a Gtk2::ComboBox that isn't used to
display what is selected.

Essentially, I want the CB to always show 'Choose an extension to
add', but have a list of valid extensions pop up when its clicked that
does _not_ include 'Choose an extension to add' (herein referred to as
'CAETA').

I've tried initializing it to have CAETA as the only value in the CB's
model and selecting index 0, then trapping various signals to populate
the model with the real values when its activated. Unfortunately I
can't seem to find a signal that reliably (and _only_) fires when the
CB's menu pops up. Oddly the button-release-event (which I could have
jerry-rigged) _never_ seems to fire.

Sample code ensues (with no regard for return values etc, so you'll
probably have to CTRL-C out of it). SOMETHING-OR-OTHER obviously
should be the 'right' signal.

(and yes I am aware this is _exactly_ what a menu button does.
Apparently a menu button doesn't 'fit in' as well as a combobox
will....)

use Gtk2 -init;
my $mw = Gtk2::Window->new('toplevel');
my $cb = Gtk2::ComboBox->new_text;
$cb->prepend_text('CLICK ME');
$cb->set_active(0);
$cb->signal_connect('SOMETHING-OR-OTHER', sub {
                     $cb->remove_text(0);
                     $cb->append_text("1");
                     $cb->append_text("2");
                     $cb->append_text("3");
                   });
$cb->signal_connect('changed',
                   sub {
                     my $sel = $cb->get_active_text;
                     $cb->remove_text(0);
                     $cb->remove_text(0);
                     $cb->remove_text(0);
                     $cb->append_text('CLICK ME');
                     $cb->set_active(0);
                     print "YOU SELECTED $sel\n";
                   });
$mw->add($cb);
$mw->show_all;
Gtk2->main;

Ta,
MB



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