In Gtk2, I could apply a style to various widgets using RC strings. Under Gtk3, it's necessary to use CSS styles.
I can't find any working examples of the new Perl code, besides one from 2012 which no longer works. (The site won't let me post the link.)
I am able to apply a CSS style to a whole window, using the script below. But applying the style to a single widget (in this case, a Gtk3::TextView) does not work, and I can't see why it's wrong.
#!/usr/bin/perl
use strict;
use diagnostics;
use warnings;
#use Glib qw(TRUE FALSE);
use Gtk3 '-init';
# Set up CSS style
my $provider = Gtk3::CssProvider->new();
# Why are these lines necessary? What function do they serve?
my $display = Gtk3::Gdk::Display::get_default;
my $screen = Gtk3::Gdk::Display::get_default_screen($display);
Gtk3::StyleContext::add_provider_for_screen($screen, $provider, 600);
# This applies the style to the whole window
#my $theming = "* {\nbackground-color: #000000;\ncolor: #FF0000;\n}";
#$provider->load_from_data($theming, -1, undef);
# But this doesn't apply the style (just) to the textview
my $theming = "GtkTextView {\nbackground-color: #000000;\ncolor: #FF00
+00;\n}";
$provider->load_from_data($theming, -1, undef);
# Open a Gtk3 window containing a Gtk3::TextView
my $window = Gtk3::Window->new('toplevel');
$window->set_title('Hello world');
$window->set_position('center');
$window->set_default_size(600, 400);
$window->signal_connect('delete-event' => sub {
Gtk3->main_quit();
exit;
});
my $scrollWin = Gtk3::ScrolledWindow->new(undef, undef);
$window->add($scrollWin);
my $textView = Gtk3::TextView->new;
$scrollWin->add_with_viewport($textView);
$textView->get_buffer()->set_text("Hello, world!");
$window->show_all();
# Start Gtk3's main loop
Gtk3->main();