Re: Help required with TextView widget



Hi Muppet,
Thanks for your response. It clarified my doubts. I still have one related question with
respect to word wrapping at 80columns.
Thanks
Ashwin


On 1/30/07, muppet <scott asofyet org> wrote:

On Jan 25, 2007, at 3:49 AM, Ashwin Ramachandran wrote:

> Hi All,
> I have an application in which there are NoteBook Pages. In each of
> these pages,
> I have a few widgets[of type label and text entry] and then a
> TextView widget
> at the bottom of the page. I have set word wrapping for the
> TextView widgets.

To what did you set word wrapping?  There are four possible values...

This was set to 'word'

> I am observing a strange problem in case of a NoteBook Page with a
> scrolled
> window[VPolicy: Always, HPolicy: Never]. Whenever, I type words
> into the
> TextView widget, as the number of words/characters increase in a
> given line
> [more than the initial NoteBook Page screen size], I observe the
> following:
> a. the word wrapping does not happen
> b. As I keep typing, all the other widgets in the Page[namely the
> label
> and TextEntry widgets], also move towards the right.

It's generally most helpful if you create a *minimal* yet complete
example that exhibits the problem.  This should be something that we
can paste into a file and execute, and play around with.  Instead, we
must cobble together something with which to experiment, and what we
create may not be what you're talking about.

Sorry from next time onwards, I will try giving a simple program. In this case, I was
also using Glade, so did not have one off-hand.

 

At any rate:

- With hscroll policy of never, the textview acts as it would when
there was no scroll adjustment there.  When the wrap mode says that a
word cannot be broken, the text view will request enough horizontal
space to show the entire word.  This will typically cause the widget
to expand, which causes what i think you're describing as "move to
the right".

Thanks. This explains my problem.
 

- I put together a simple example which exhibits this behavior even
without the notebook.  It's just how the widget works.

- If you use the "word" wrap mode, it is often possible to get words
too long for a narrow widget.  Even with wide widgets, the "word"
mode will not wrap long strings, such as URLs.  However, the "char"
mode will break on any character, and the "word-char" mode will break
at a word if possible, and on a character if no word boundary can be
found.

I am now using wrapping set to word and scrollbar policy set to 'auto', 'auto' as suggested.
One more related question:
In the case of wrapping, I specifically require "word" wrapping at 80 columns. I was
asked to use GtkSourceView[in the list] for the same.  I have given an executable below
for the same[similar to the one you had given, using GtkSourceView, instead of TextView].

#!/usr/bin/perl -w

use strict;
use Gtk2 -init;
use Glib ':constants';
use Gtk2::SourceView;


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

my $vbox = Gtk2::VBox->new;
$window->add ($vbox);

my $scroller = Gtk2::ScrolledWindow->new;
#$scroller->set_policy ('never', 'always');
$vbox->add ($scroller);

my $buffer = Gtk2::SourceView::Buffer->new(undef);
my $textview = Gtk2::SourceView::View->new_with_buffer($buffer);
$textview->set_right_margin(160);
$textview->set_show_margin(160);
$scroller->add ($textview);


my $wrap_option = Gtk2::ComboBox->new_text;
$vbox->pack_start ($wrap_option, FALSE, FALSE, 0);
$wrap_option->append_text ('none');
$wrap_option->append_text ('char');
$wrap_option->append_text ('word');
$wrap_option->append_text ('word-char');
$wrap_option->signal_connect (changed => sub {
        $textview->set_wrap_mode ($wrap_option->get_active_text);
});
$wrap_option->set_active (2);

my $policy_option = Gtk2::ComboBox->new_text;
$vbox->pack_start ($policy_option, FALSE, FALSE, 0);
foreach my $hpolicy (qw(never always automatic)) {
        foreach my $vpolicy (qw(never always automatic)) {
                $policy_option->append_text ("$hpolicy-$vpolicy");
        }
}
$policy_option->signal_connect (changed => sub {
        $scroller->set_policy (split /-/, $policy_option->get_active_text);
});
$policy_option->set_active (8);

$window->show_all;
Gtk2->main;

__END__


The above code, has "word" wrapping and scrollbar policy set to 'auto, auto'.When you
expand the window fully and start typing in, the words do  not appear to wrap around at the
shown margin, but wrap around much later than 80cols. [I observed this behaviour in gedit also].
Is there some other setting that I need to do for this? 
I need to get the words wrapped around at exactly 80columns. Please let me know if  I have missed
something here.

Thanks
Ashwin



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