Re: Text view vertical scroll problem
- From: Adam Preble <acp7569 ritvax isc rit edu>
- To: muppet <scott asofyet org>
- Cc: acp7569 ritvax isc rit edu, gtk-perl-list gnome org
- Subject: Re: Text view vertical scroll problem
- Date: Thu, 26 Feb 2004 01:12:48 -0600
Well thanks a bunch for pointing out the problem, the underlying problem,
and the fundamental problem of using the old version of Gtk. I thought I
was golden using Stephen Wilhelm's tutorial, but it looks like that is all
in older Gtk. By any chance, is a Perl-Gtk2 tutorial being
updated/created? My impression from the gtk2-perl sourceforge site is
"no."
muppet wrote:
On Wednesday, February 25, 2004, at 10:55 PM, Adam Preble wrote:
The code is:
use Gtk;
please do not write new programs with Gtk-Perl. both Gtk-Perl and the
1.x series of gtk+ that it binds are obsolete, and have been for some
time.
gtk2-perl, at http://gtk2-perl.sf.net , is the currently maintained
and supported perl binding for gtk+. the Gtk2::TextView /
Gtk2::TextBuffer stuff is a little more complicated but far more
powerful than Gtk::Text ever thought of being. and horizontal
scrolling works fine with it.
that said, your problem is very simple:
these two lines:
$scrolled_window = new Gtk::ScrolledWindow( $text->hadj, $text->vadj
);
...
$scrolled_window->add_with_viewport( $text );
should be
$scrolled_window = new Gtk::ScrolledWindow;
...
$scrolled_window->add( $text );
The text widget natively knows how to scroll, so all you have to do is
add it to a scrolled window and gtk+ takes care of the rest. by using
a viewport you confused gtk+; the viewports are for use with widgets
that *don't* know how to scroll themselves, like vboxen, layouts, or
drawing areas.
and, again, your whole program would be quite a bit shorter in
gtk2-perl, where the Gtk2::Dialog takes care of a lot of stuff you had
to do yourself:
#use Glib qw(TRUE FALSE); # can do this in 1.040
use Glib;
use Gtk2;
use strict;
use constant TRUE => 1;
use constant FALSE => !TRUE;
init Gtk2;
my ($window, $scrolled_window, $textview);
# Create a new dialog window for the scrolled window
$window = new Gtk2::Dialog "Scrolled Window Example", undef, [],
'gtk-close' => 'close';
$window->set_default_response ('close');
$window->signal_connect( response => sub { Gtk2->main_quit; } );
#$window->set_border_width( 0 );
$window->set_default_size( 300, 300 );
# Create the Text widget
$textview = new Gtk2::TextView;
$textview->set (editable => FALSE);
# Load this file into the text window
$/ = undef;
open FILE, $0 or die "can't open $0: $!\n";
my $text = <FILE>;
close FILE;
my $textbuffer = $textview->get_buffer;
$textbuffer->create_tag ('mono', family => 'Monospace'); # fixed-width
font
$textbuffer->insert_with_tags_by_name ($textbuffer->get_start_iter,
$text, 'mono');
# Create a new scrolled window
$scrolled_window = new Gtk2::ScrolledWindow;
$scrolled_window->set_border_width( 5 );
$scrolled_window->set_shadow_type( 'etched-in' );
$scrolled_window->set_policy( "automatic", "automatic" );
$window->vbox->pack_start( $scrolled_window, TRUE, TRUE, 0 );
$scrolled_window->show();
# Add text view to the scrolled window
$scrolled_window->add( $textview );
$textview->show();
$window->show();
main Gtk2;
--
"it's hard to be eventful when you have this much style."
- me, rationalizing yet another night of sitting at home.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]