aslewis has asked for the wisdom of the Perl Monks concerning the following question:

The usual Perl GTK tutorial http://gtk2-perl.sourceforge.net/doc/gtk2-perl-study-guide/c1701.html provides a nice example of how to disable/grey out buttons:

# desensitize the save button if the entry is empty or blank my $text = $entry->get_text; $window->set_response_sensitive ('accept', $text !~ m/^\s*$/); $window->set_response_sensitive ('reject', TRUE);

This works on the parent Gtk2::Dialog to desensitise every button in the window, but it doesn't desensitise any Gtk2::Entry boxes in the window.

It's simple to make the entry uneditable:

my $entry = Gtk2::Entry->new(); $entry->set_editable(FALSE);

...but this leaves no visual indication that the box has been desensitised. How can I achieve the same effect, namely to grey out the entry box?

Replies are listed 'Best First'.
Re: Gtk2::Entry - how to desensitise
by zentara (Cardinal) on Jan 15, 2012 at 11:50 UTC
    This is one of those areas where Gtk2's theme engine makes things tricky. Here are a couple of self-explanatory examples.
    #!/usr/bin/perl use warnings; use strict; use Gtk2 '-init'; #the Entry settings in ~/.gtkrc-2.0 dosn't #seem to do anything except create a subtle outline #under the entry box. So you need to manually make one. Gtk2::Rc->parse_string(<<__); #include "/usr/local/share/themes/Bumblebee/gtk-2.0/gtkrc" style "normal" { font_name ="serif 30" } style "my_entry" { font_name ="sans 25" text[NORMAL] = "#FF0000" text[INSENSITIVE] = "#555555" } widget "*" style "normal" widget "*Entry*" style "my_entry" __ my $window = Gtk2::Window->new; $window->set_title("Hello world"); $window->signal_connect( destroy => sub { Gtk2->main_quit; } ); my $vbox = Gtk2::VBox->new(); $vbox->set( "border_width" => 10 ); $window->add($vbox); my $label = Gtk2::Label->new("ועפשץי"); $vbox->pack_start( $label, 0, 0, 5 ); # expand?, fill?, padding my $entry = Gtk2::Entry->new(); $vbox->pack_start( $entry, 0, 0, 5 ); my $button = Gtk2::Widget->new( "Gtk2::Button", label => "Set Insensit +ive" ); $button->signal_connect( clicked => sub { $entry->set_state('insensiti +ve') } ); my $button1 = Gtk2::Widget->new( "Gtk2::Button", label => "Quit" ); $button1->signal_connect( clicked => sub { Gtk2->main_quit; } ); $vbox->pack_start( $button, 0, 0, 5 ); $vbox->pack_start( $button1, 0, 0, 5 ); $window->show_all(); Gtk2->main;
    #!/usr/bin/perl use warnings; use strict; use Gtk2 '-init'; #the Entry settings in ~/.gtkrc-2.0 dosn't #seem to do anything except create a subtle outline #under the entry box. So you need to manually make one. Gtk2::Rc->parse_string(<<__); include "/usr/local/share/themes/Bumblebee/gtk-2.0/gtkrc" style "normal" { font_name ="serif 30" } style "my_entry" { font_name ="sans 25" text[NORMAL] = "#FF0000" } widget "*" style "normal" widget "*Entry*" style "my_entry" __ my $window = Gtk2::Window->new; $window->set_title("Hello world"); $window->signal_connect( destroy => sub { Gtk2->main_quit; } ); my $vbox = Gtk2::VBox->new(); $vbox->set( "border_width" => 10 ); $window->add($vbox); my $label = Gtk2::Label->new("ועפשץי"); $vbox->pack_start( $label, 0, 0, 5 ); # expand?, fill?, padding my $entry = Gtk2::Entry->new(); $vbox->pack_start( $entry, 0, 0, 5 ); my $button = Gtk2::Widget->new( "Gtk2::Button", label => "Quit" ); $button->signal_connect( clicked => sub { Gtk2->main_quit; } ); my $button1 = Gtk2::Widget->new( "Gtk2::Button", label => "Toggle Entr +y Color" ); $button1->signal_connect( clicked => sub { my ( $red, $green, $blue, $color); ( $red, $green, $blue) = (int rand 65535, int rand 65535,int ra +nd 65535 ); $color = Gtk2::Gdk::Color->new ( $red, $green, $blue); $entry->modify_text ( 'GTK_STATE_NORMAL', $color); $entry->set_text ("$red $green $blue" ); } ); $vbox->pack_start( $button, 0, 0, 5 ); $vbox->pack_start( $button1, 0, 0, 5 ); $window->show_all(); Gtk2->main;

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh