widget visibility
- From: haratron <haratron gmail com>
- To: gtk-perl-list gnome org
- Subject: widget visibility
- Date: Wed, 24 Nov 2010 13:35:47 +0200
I'm having a problem with the visibility of some widgets packed into an hbox.
They don't show up, despite having their visible property set to 1.
Complete code (small.pl and small.glade) follows.
small.pl:
#!/usr/bin/env perl
use Gtk2 -init;
use Glib qw/TRUE FALSE/;
use Gtk2::SimpleList;
$builder = Gtk2::Builder->new();
$builder->add_from_file('small.glade');
$builder->connect_signals();
$window= $builder->get_object('window1');
$window->set_border_width(0);
$window->set_position('center_always');
$window->signal_connect( "destroy" => sub {
Gtk2->main_quit;
});
$cbox= $builder->get_object('combobox1');
my $model1 = new Gtk2::ListStore('Glib::String');
$cbox->clear();
my $renderer1 = new Gtk2::CellRendererText;
$cbox->pack_start($renderer1, FALSE);
$cbox->set_attributes($renderer1, text => 0);
$cbox->set_model($model1);
my @listing_cbox = qw/one two three four five six/;
# This is supposed to append the @listing to the
# combobox
foreach $text (@listing_cbox) {
$cbox->append_text ($text)
}
$cbox->set_active(1);
$label2= $builder->get_object('label2');
$entry1= $builder->get_object('entry1');
#problem start
if ( ($cbox->get_active_text) eq "four" ){
$label2->visible(1);
$entry1->visible(1);
}
elsif ( ($cbox->get_active_text) ne "four" ){
$label2->visible(0);
$entry1->visible(0);
}
$cbox->signal_connect('changed' => sub {
my ($entry) = @_;
if ( ($cbox->get_active_text) eq "four" ){
$label2->visible(1);
$entry1->visible(1);
}
elsif ( ($cbox->get_active_text) ne "four" ){
$label2->visible(0);
$entry1->visible(0);
}
});
#problem end
$window->show();
$builder =undef;
Gtk2->main();
exit;
=============================================
small.glade:
<?xml version="1.0"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="label" translatable="yes">selection: </property>
</object>
<packing>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkComboBox" id="combobox1">
<property name="visible">True</property>
</object>
<packing>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="label2">
<property name="visible">True</property>
<property name="label" translatable="yes">custom: </property>
</object>
<packing>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="entry1">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
</object>
<packing>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</interface>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]