Re: getting system background color
- From: muppet <scott asofyet org>
- To: rahed <raherh gmail com>
- Cc: gtk-perl-list gnome org
- Subject: Re: getting system background color
- Date: Wed, 3 Jan 2007 14:29:32 -0500
On Jan 3, 2007, at 1:59 PM, rahed wrote:
I'd like to get label widget background color. It's a sort of (system)
gray color also present with some other widgets.
I'm able to set the color with modify_base for entry widgets or
modify_bg for window widgets but getting this color is a puzzle.
Just ask the style object for it, e.g.
$bg = $style->bg ('normal');
or
$bg = $label->get_style->bg ($label->state);
Or, a little more obtusely:
#!/usr/bin/perl -w
use strict;
use Gtk2 -init;
my $window = Gtk2::Window->new; # possibly unnecessary, but i'm lazy
$window->ensure_style ();
my $style = $window->get_style;
my @states = map { $_->{nick} } Glib::Type->list_values
('Gtk2::StateType');
print join ' ', sprintf ("%12s", "color"), map { sprintf "%12s", $_ }
@states;
print "\n";
foreach my $which (qw(fg bg text base dark mid light)) {
print join ' ',
sprintf ("%12s", $which),
map { sprintf "%12s", color_to_str ($style->$which ($_)) }
@states,
;
print "\n";
}
sub color_to_str {
my ($color) = @_;
return sprintf "#%02x%02x%02x",
$color->red >> 8, $color->green >> 8, $color->blue >> 8;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]