Re: Gtk3 custom theme parsing-- solved



On Thu, 02 Aug 2012 21:20:36 +0200
Torsten Schoenfeld <kaffeetisch gmx de> wrote:

On 02.08.2012 21:02, zentara wrote:
GdkDisplay *display = gdk_display_get_default ();
GdkScreen *screen = gdk_display_get_default_screen (display);
gtk_style_context_add_provider_for_screen (screen,
                                            GTK_STYLE_PROVIDER (provider),
                                            GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);


I can't help with the actual theme semantics, but the Perl translation 
of the above is:

  my $d = Gtk3::Gdk::Display::get_default ();
  my $s = $d->get_default_screen;
  Gtk3::StyleContext::add_provider_for_screen (
    $s, $p, Gtk3::STYLE_PROVIDER_PRIORITY_USER);
_______________________________________________

Thanks Torsten, that was very helpful.

In my attempts, I tried this wrong syntax, but got segfaults.

my $display = Gtk3::Gdk::Display->get_default();
print $display,"\n";  # ok there but apparently wrong syntax
# this line causes a segfault here
my $screen = Gtk3::Gdk::Display->get_default_screen( $display );

With your help, I have a working example.

Thanks, this is a big step for my understanding of theme override.
0m,
zentara

#############################
A working example 

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

my $window = Gtk3::Window->new('toplevel');
$window->set_title('Z');
$window ->signal_connect( 'destroy' => \&delete_event );
$window->set_border_width(10);
$window->set_size_request(400,400);

# do custom css #####################################################3

my $p = Gtk3::CssProvider->new;

$p->load_from_data ([map ord, split //, "GtkButton {font: Monospace 30; background-color: rgba(0%, 76%, 0%, 
0.6);}"]);
#print $p->to_string,"\n";

$p->load_from_data ([map ord, split //, "GtkTextView { color: blue; font: Serif 38; background-color: yellow; 
-GtkWidget-cursor-color: red; }\n
GtkTextView:selected { background-color: black; color: green  } " ]);
print $p->to_string,"\n";

my $d = Gtk3::Gdk::Display::get_default ();
my $s = $d->get_default_screen;

Gtk3::StyleContext::add_provider_for_screen ( $s, $p, Gtk3::STYLE_PROVIDER_PRIORITY_USER);

#######################################################################

my $vbox = Gtk3::VBox->new( FALSE, 6 );
$window->add($vbox);
$vbox->set_border_width(2);

my $hbox= Gtk3::HBox->new( FALSE, 6 );
$vbox->pack_end($hbox,FALSE,FALSE,0);

my $ebutton = Gtk3::Button->new_from_stock('gtk-quit');
$hbox->pack_end( $ebutton, FALSE, FALSE, 0 );
$ebutton->signal_connect( clicked => \&delete_event );

# Create a textbuffer to contain that string 
my $textbuffer = Gtk3::TextBuffer->new();
$textbuffer->set_text('yadda yadda yadda', 17); # needs length

# Create a textview using that textbuffer 
my $textview = Gtk3::TextView->new_with_buffer($textbuffer);

# Add the textview to a scrolledwindow 
my $scrolledwindow = Gtk3::ScrolledWindow->new( undef, undef );
$scrolledwindow->add($textview);
$vbox->pack_start($scrolledwindow, 1, 1, 0 );

$window->show_all();

Gtk3->main;

#####################################
sub delete_event {
Gtk3->main_quit;
return FALSE;
}
#######################################
__END__



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