Re: ComboBox bg color



On Fri, 10 Oct 2008 20:07:01 +0000
rahed <raherh gmail com> wrote:

Hi,

I'd like to change a background color of a ComboBox widget. Generally I
do it with modify_bg for EventBox as a parent but with the ComboBox being
a compound widget I am not successful.
I build it with Gtk2::GladeXML.

Is it possible?

As far as I know, it's possible, but tricky and not reliable, because
many users use pixmap based themes( in ~/.gtkrc-2.0) and you need to override the
pixmap for any color change to take effect.

Here are a couple of tricks you might try. This dosn't work perfectly, but you
may get better results playing around with settings.

Usually, the general wisdom is not to mess with a user's themes, but to do it right,
you would make your own custom theme for your app, put it into the app's resource
dir (like ~./app_config_dir) and at the start of your script, disregard the default user
theme, and load your theme just for that app.

# must be before Gtk2 init                                                                
BEGIN { $ENV{GTK2_RC_FILES} = 'gtkrc_myapp' }    #file in same dir as script

Here is how you try to manually adjust....very tricky. Notice how I try
to wipe out any pixmap theme, often dosn't work right.

#! /usr/bin/perl
use warnings;
use strict;
use Gtk2 '-init';
use Glib qw/TRUE FALSE/; 

Gtk2::Rc->parse_string(<<__);

style "default"
{

bg_pixmap[NORMAL] = "<none>"
bg_pixmap[INSENSITIVE] = "<none>"
bg_pixmap[ACTIVE] = "<none>"
bg_pixmap[PRELIGHT] = "<none>"

bg[NORMAL] = { 1.0, 1.0, 1.0 }

}class "GtkWidget" style "default"


style "my_combo" {
font_name ="sans 24"
text[NORMAL] = "#FF0000"
base[NORMAL] = "#000000"   
}

widget "*Combo*" style "my_combo"
__
 
#standard window creation, placement, and signal connecting
my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { Gtk2->main_quit; });
$window->set_border_width(5);
$window->set_position('center_always');

#this vbox will return the bulk of the gui
my $vbox = &ret_vbox();

#add and show the vbox
$window->add($vbox);
$window->show();

#our main event-loop
Gtk2->main();


sub ret_vbox {

my $vbox = Gtk2::VBox->new(FALSE,5);

        my $cb = Gtk2::ComboBox->new_text;
        
        $cb->append_text("Select a band:");
        $cb->append_text("Beatles");
        $cb->append_text("Ten Years After");
        $cb->append_text("Bad Finger");
        $cb->append_text("Gravy Train");
        $cb->append_text("Family");
        $cb->append_text("Spirit");
        $cb->signal_connect('changed' => \&cb_changed);
        $cb->set_active(0);
        
$vbox->pack_start($cb,TRUE,TRUE,0);

my $greyl = Gtk2::Gdk::Color->new (0x9999,0x9999,0x9999);                                 
$cb->modify_bg('normal', $greyl);  

$vbox->show_all();
return $vbox;
}

sub cb_changed {
        my ($cb) = @_;
        if($cb->get_active){
        print "Right on Man, ".$cb->get_active_text." is a cool band\n"; 
        }
}
__END__


zentara

-- 
I'm not really a human, but I play one on earth.
http://zentara.net/Remember_How_Lucky_You_Are.html 



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