Re: GtkTextView::get_text() Missing First Character
| From: | Anant Narayanan | Date: | Sat, 11 Nov 2006 15:29:18 +0000 |
| Subject: | Re: GtkTextView::get_text() Missing First Character | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-7458@lists.php.net to get a copy of this message | ||
Hi Ron,
I'm not sure if this is a bug, or if I'm missing something fundamental about how GtkTextView::get_text() works. The following code should retrieve the entire contents of the buffer and echo it to the CLI each time a key is pressed. However, the first character never shows up.The GtkTextBuffer is in-charge of the contents of a TextView, not the textview itself. So whenever you're trying to deal with the content of a TextView remember that you do this via its buffer rather than the view itself. I think I clarified this for you earlier, but here it is again: avoid using the key-press-event signal. It's a pretty "low-level" signal if I might say so, to be used only in cases where you're building specialized applications. For simple things like your program a simple "changed" signal on the TextBuffer suffices. Here's the slightly corrected program that does what you wanted: <?php function keyPress($buffer) {
$startIter = $buffer->get_start_iter();
$endIter = $buffer->get_end_iter();
$endOffset = $endIter->get_offset();
$text = $buffer->get_text($startIter, $endIter);
echo("text: $text\n");
} // keyPress()
$clipboard = GtkClipboard::get();
$textView = new GtkTextView();
$textView->get_buffer()->connect("changed", "keyPress");
$window = new GtkWindow();
$window->add($textView);
$window->show_all();
Gtk::main();
?>
Hope this helps.
Cheers,
- Anant