Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: add color to a Gtk2::TextView

by zentara (Archbishop)
on Sep 30, 2018 at 17:16 UTC ( [id://1223333]=note: print w/replies, xml ) Need Help??


in reply to add color to a Gtk2::TextView

Hi, here are a few more techniques to add color and images. Setting the cursor color is useful depending on your base color. You will need to provide a background.png file, or comment out the lines relating to it. The Rc->parse_string is needed to override any default colors and images in the ~/.grtkrc-2.0 file.
#!/usr/bin/perl use warnings; use strict; use Glib qw/TRUE FALSE/; use Gtk2 '-init'; Gtk2::Rc->parse_string(<<__); pixmap_path '.' style "my_text" { font_name ="sans 24" text[NORMAL] = "#FFAA00" base[NORMAL] = "#000000" GtkTextView::cursor-color = "red" } style "my_cursor"{ fg[NORMAL] = "#FF0000" } widget "*Text*" style "my_text" style "my-scrolledwindow" { xthickness = 10 ythickness = 10 GtkScrolledWindow ::scrollbars-within-bevel = 1 GtkScrolledWindow ::scrollbar-spacing = 10 engine "pixmap" { image { function = SHADOW file = "./background.png" border = {10, 10, 10, 10} detail = "scrolled_window" } } } class "GtkScrolledWindow" style "my-scrolledwindow" __ my $window = Gtk2::Window->new('toplevel'); $window->set_title('Z'); $window ->signal_connect( 'destroy' => \&delete_event ); $window->set_border_width(10); $window->set_size_request(300,300); my $back_pixbuf = Gtk2::Gdk::Pixbuf->new_from_file('background.png'); my ($pixmap,$mask) = $back_pixbuf->render_pixmap_and_mask(255); my $style = $window->get_style(); $style=$style->copy(); $style->bg_pixmap("normal",$pixmap); $window->set_style($style); my $vbox = Gtk2::VBox->new( FALSE, 6 ); $window->add($vbox); $vbox->set_border_width(5); my $hbox= Gtk2::HBox->new( FALSE, 6 ); $vbox->pack_end($hbox,FALSE,FALSE,0); my $ebutton = Gtk2::Button->new_from_stock('gtk-quit'); $hbox->pack_end( $ebutton, FALSE, FALSE, 0 ); $ebutton->signal_connect( clicked => \&delete_event ); my $str; my $file = shift || $0; open( TEST, "< $file" ) or die "Cannot open test.txt\n"; while (<TEST>) { $str .= $_; } close TEST; # Create a textbuffer to contain that string my $textbuffer = Gtk2::TextBuffer->new(); $textbuffer->set_text($str); # Create a textview using that textbuffer my $textview = Gtk2::TextView->new_with_buffer($textbuffer); # Add the textview to a scrolledwindow my $scrolledwindow = Gtk2::ScrolledWindow->new( undef, undef ); $scrolledwindow->add($textview); $scrolledwindow->set_shadow_type ('etched-out'); $scrolledwindow->set_policy ('automatic', 'automatic'); $vbox->pack_start($scrolledwindow, 1, 1, 0 ); $window->show_all(); Gtk2->main; ##################################### sub delete_event { Gtk2->main_quit; return FALSE; } #######################################

I'm not really a human, but I play one on earth. ..... an animated JAPH

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1223333]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 09:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found