Re: setting style xthickness/ythickness



On Thu, 08 Apr 2010 10:29:17 +1000
Kevin Ryde <user42 zip com au> wrote:

Is there a right way to set field values in a Gtk2::Style, like
xthickness.  $style->xthickness() is only an accessor, if I'm not
mistaken.

Dunno what the right thing to do in C code is.  Just plonk a value in
the struct?  (A copy of the struct if it belongs to someone else of
course.)  Could the same be done from perl?

I thought to change some style settings from program code and stick the
changed style onto selected widgets.  It's not for anything important,
and I get close enough with a Gtk2::Rc->parse_string() with new values,
but wondered if it was possible to operate programmatically on style
objects as such.

Here is an old clue from Muppet
Good Luck! :-)

#################################################
#!/usr/bin/perl

=head1
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:
=cut
#by muppet
use warnings;
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";
}

$window->show_all();
Gtk2->main;

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]