Re: Help required with TextView widget




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...


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.

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".

- 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.

- If you really don't like wrapping, you can use the scroll policy "automatic", which will show the scrollbar only when needed.


The code here will let you play around with all of the various combinations of scroll policies and wrap modes. I suggest "word" and "automatic-automatic".


#!/usr/bin/perl -w

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


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 $textview = Gtk2::TextView->new;
$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 (0);

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 (0);

$window->show_all;
Gtk2->main;

__END__


--
Doing a good job around here is like wetting your pants in a dark suit; you get a warm feeling, but no one notices.
  -- unknown





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