Re: changing background colours on buttons (semi-permanently)



On Tue, 08 Aug 2006 02:14:06 +0100
Dirk Koopman <djk tobit co uk> wrote:

I have a stateful dialog box that requires the user to click their
desired button and then click another one (OK) to exit. I would like the
desired button to change its background colour (to dark green for some
obscure historical reason) to indicate that it is selected (think *huge*
radio buttons here) whilst waiting for OK or cancel to be pressed. 

Associated with this question is the fact that: whilst I seem to be able
to change the font and apply it in a style, none of the fg[xxx] or
bg[xxx] in the same style seem to do anything. There is obviously a
theme of some kind running (it is ubuntu) but it seems difficult to
override (or find out what it even is).

Dirk

I sympathize, it's a PITA to do simple color changes in Gtk2.
First, it's almost certain that Ubuntu must be using some sort of pixmap
based theme, which you need to override. I played with doing this awhile
back, and to think about it again is giving me a headache. :-)

You can find the theme directory with

print Gtk2::Rc->get_theme_dir,"\n";

This is your best bet:
If you want to do it simply, just go into the theme, (look at ~/.gtkrc-2.0 ) for
what theme it has going. Then go to that theme subdir, and find the gtkrc file.
Look for the section on button, and find the pixmap for SELECTED (maybe ACTIVE too)
and use Gimp to edit the pixmap.
Of course this will make global changes.


If you want to bang your head against the wall:
If you don't want to make global changes, and just
to include the new pixmap in only your scripts, you can try the following. 
The existing style must be explicitly cancelled out, and
it must be done by parsing an actual file, then the new style can replace it.

I had some success overriding my default window bg pixmap, but no
luck trying to override a theme style, except by removing the ~/gtkrc-2.0 file
or telling the script to parse a different one.

So this script overrides my theme, and replaces the bg pixmap with a bg.png in 
the pwd.  I could NOT get it to work for a button, but you may have more luck.

#!/usr/bin/perl
use warnings;
use strict;
use Gtk2 -init;
use Glib ':constants';

my $pwd = `pwd`;
print "$pwd\n";

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

pixmap_path  '/home/zentara/perlplay/Gtk2/styles/background-from-base64-image'

style "default"
{
bg_pixmap[NORMAL] = "./bg.png"
}

class "*" style "default"
__

my $window = Gtk2::Window->new('toplevel');
$window->signal_connect('delete_event' => sub { exit;});
$window->set_border_width(5);
$window->set_position('center_always');
$window->set_default_size(500,500);
$window->show();

print Gtk2::Rc->get_theme_dir,"\n";


Gtk2->main();
####################################################### 

__END__

Themes are great but they sure raise havoc with attempts at simple
customization.

zentara

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



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