Re: 2 different text styles in same program




On Jan 22, 2006, at 10:58 AM, zentara wrote:

but the method I use with the left textview is
$textview_l->modify_bg('GTK_STATE_NORMAL', $black);

$textview_l->modify_base (normal => $black);

and dosn't work. Anyone know why?

Can't seem to locate this table in the docs, but it goes like this:

  bg is the background of normal widgets
  fg is the foreground of normal widget
  base is the background of "editor" widgets
  text is the foreground of "editor" widgets

Where "editor" widgets are things like GtkEntry or GtkTextView.


my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub {Gtk2->main_quit;return FALSE});

The destroy signal has no return value, so the return FALSE is unnecessary here. You're thinking of "delete-event".

$window->set_size_request(500,300);

You actually want set_default_size() here. Setting the size request on a toplevel is akin to setting its minimum size; setting the default size just sets the default, still allowing the user to shrink it.


my $scroll_l   = Gtk2::ScrolledWindow->new(undef,$vadj);
$scroll_l->set_policy ('never', 'never');

The scrolled windows are unnecessary here. You also wind up with the odd-looking behavior of the scrollbar that doesn't span the whole thing it scrolls. You can fix that by using scrollbars manually. It's very easy. Here's a stripped-down version of your example that does this:

#!/usr/bin/perl
use warnings;
use strict;
use Glib qw(FALSE TRUE);
use Gtk2 -init;

my $window = Gtk2::Window->new;
$window->signal_connect (destroy => sub {Gtk2->main_quit});
$window->set_default_size (500,300);

# create a bunch of widgets.

my $table = Gtk2::Table->new (2, 2);

my $frame = Gtk2::Frame->new; # no title, it's used just for the border.
$frame->set_shadow_type ('in');

my $hbox = Gtk2::HBox->new (FALSE, 0);

my $vscrollbar = Gtk2::VScrollbar->new;
my $hscrollbar = Gtk2::HScrollbar->new;

my $textview_l = Gtk2::TextView->new;
my $textview = Gtk2::TextView->new;

# The two text views go inside the HBox, which is in the frame.
# I've adjusted the packing so there is no space between them.
$hbox->pack_start ($textview_l, FALSE, FALSE, 0);
$hbox->pack_start ($textview,TRUE, TRUE, 0);
$frame->add ($hbox);

# The frame goes in the upper left, set to expand and fill the whole area. $table->attach ($frame, 0, 1, 0, 1, ['expand', 'fill'], ['expand', 'fill'], 0, 0);
# the scrollbars take the spots adjacent to the frame.
$table->attach ($vscrollbar, 1, 2, 0, 1, ['fill'], ['expand', 'fill'], 0, 0); $table->attach ($hscrollbar, 0, 1, 1, 2, ['expand', 'fill'], ['fill'], 0, 0);
# the bottom right is empty.

$window->add ($table);

# Tell the TextViews to use the scroll adjustments from the Scrollbars.
# Note that you can't pass undef through set_scroll_adjustments, so
# I'm using Glib::Object::new to create a bogus adjustment for the
# horizontal scroll of the line number view; we don't want it to scroll,
# so the numbers don't matter, and using Glib::Object::new allows me
# to omit all of the parameters to Gtk2::Adjustment::new that i don't
# care about.  ;-)
$textview_l->set_scroll_adjustments (Glib::Object::new (Gtk2::Adjustment::,),
                                     $vscrollbar->get_adjustment);
$textview->set_scroll_adjustments ($hscrollbar->get_adjustment,
                                   $vscrollbar->get_adjustment);

# Now, for this to work, we have to tell the frame to take the size given
# to it by the window --- otherwise, the frame will ask its children for
# their desired sizes.  Setting the frame's request to 0,0 bypasses all
# of that.
$frame->set_size_request (0, 0);

# Since i packed the views with no space in between, the text runs
# together.  If i'd packed with space in between, there'd be an ugly
# gutter of widget background (usually gray).  If i told the view to use
# a border padding, there'd be a white border on all sides, which looks
# quite bizarre. The proper thing is to tell it to expand one of its margins.
# This has the effect of setting a border between the boxes.
$textview_l->set_right_margin (5);

# Make both textboxes use a monospaced font.
my $fontdesc = Gtk2::Pango::FontDescription->from_string ('monospace');
$textview_l->modify_font ($fontdesc);
$textview->modify_font ($fontdesc);

$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 $buffer = $textview->get_buffer;
  my $buffer_l = $textview_l->get_buffer;

  my $lcount = 0;
  foreach my $line (@lines){
     $lcount++;
$buffer_l->insert($buffer_l->get_end_iter, sprintf("%03d\n", $lcount));
     $buffer->insert($buffer->get_end_iter, " $line");

     }

}
################################################################3


--
In some newer operating systems, time_t has been widened to 64 bits. In the negative direction, this goes back more than twenty times the age of the universe, and so suffices. In the positive direction, whether this range is sufficient to represent all possible times depends on the ultimate fate of the universe, but it can be expected to postpone overflow long enough for such implementation limits to be abolished.
  -- Wikipedia, on UNIX time.




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