2 different text styles in same program
- From: zentara <zentara zentara net>
- To: gtk-perl-list gnome org
- Subject: 2 different text styles in same program
- Date: Sun, 22 Jan 2006 10:58:27 -0500
Hi, I trying some different ways to set different styles in the
same script.
The following script has 2 textboxes. One on the left is
for line numbers, and the one on the right is for the lines.
Now I can set the color for the right box with
Gtk2::Rc->parse_string
but the method I use with the left textview is
$textview_l->modify_bg('GTK_STATE_NORMAL', $black);
and dosn't work. Anyone know why?
#!/usr/bin/perl
use warnings;
use strict;
use Glib qw(FALSE TRUE);
use Gtk2 -init;
#----- 1 way works-------------------------------------------
Gtk2::Rc->parse_string(<<__);
style "bg_text_blue" {
base[NORMAL] = "#0000FF"
GtkTextView::cursor-color = "white"
}
widget "*my_name*" style "bg_text_blue"
__
##------------------------------------------------------
my $black = Gtk2::Gdk::Color->new (0,0,0);
# create a window with linked scrolled text views.
my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub {Gtk2->main_quit;return FALSE});
$window->set_size_request(500,300);
my $hbox = Gtk2::HBox->new();
$hbox->set( "border_width" => 0 );
$window->add($hbox);
my $scroll = Gtk2::ScrolledWindow->new;
my $vadj = $scroll->get_vadjustment;
my $scroll_l = Gtk2::ScrolledWindow->new(undef,$vadj);
$scroll_l->set_policy ('never', 'never');
my $textview_l = Gtk2::TextView->new;
##------- way 2 dosn't work-----------------------------------
$textview_l->modify_bg('GTK_STATE_NORMAL', $black);
##------------------------------------------------
my $buffer_l = $textview_l->get_buffer;
create_tags($buffer_l);
$scroll_l->add($textview_l);
$hbox->pack_start($scroll_l,0, 0, 1 ); # expand?, fill?, padding;
#####$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
my $textview = Gtk2::TextView->new;
$textview->set_name("my_name1");
$scroll->add($textview);
$hbox->pack_start($scroll,1, 1, 1 ); # expand?, fill?, padding;
my $buffer = $textview->get_buffer;
create_tags($buffer);
$window->show_all;
#insert some text
my @lines = `ps auxww`;
insert_w_lines(\ lines);
Gtk2->main;
##########################################################3
sub insert_w_lines{
my $aref = shift;
my @lines = @{$aref};
my $lcount = 0;
foreach my $line (@lines){
$lcount++;
my $lineI = sprintf "%03d\n", $lcount;
$buffer_l->insert_with_tags_by_name ($buffer_l->get_end_iter, $lineI, 'col');
$buffer->insert_with_tags_by_name($buffer->get_end_iter, " $line",'blue');
}
}
################################################################3
sub create_tags{
my $buffer = shift;
$buffer->create_tag('blue',
foreground => 'lightblue',
);
$buffer->create_tag('col',
foreground => 'green',
);
}
#############################################################################
__END__
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]