Subclassing TextBuffer

Hi all, this is my first message to the group although as I was starting out this project I have found the archives to be quite helpful.

Right now I am attempting to subclass from Gtk2::TextBuffer so that I can intercept delete and insertion signals in order to perform different actions under different conditions. Right now I have the following:

#!/usr/bin/perl -w

use strict;

package EditorBuffer;

use Gtk2;

use Glib::Object::Subclass
    signals => {
        insert_text => sub {
            my ($self, $iter, $string) = @_;
            if ($string) {
                print "Inserting Text!\n";
                print "$iter\n";
                $self -> signal_chain_from_overridden($self -> get_end_iter(),
                                                      $string, length($string));
                $self -> signal_chain_from_overridden($iter, $string,
        delete_range => sub {
            my ($self, $start_iter, $end_iter) = @_;
            print "Deleting Text!\n";
            self -> signal_chain_from_overridden($start_iter, $end_iter);

If I call this in my main code and build essentially a blank TextView it works fine, whenever I insert text it prints the "Insert Text" test from the if($string) block and prints the string. However if I try and delete text in the TextView I get an error, unable to load signal_chain_from_overridden from package 'self'.

The other error is that I have a method in my main program that, if the script is run with a text file as a command line argument it will load that text file in the TextView with some tags (colouring that works a lot like Syntax highlighting). Like so:

$buffer -> insert_with_tags_by_name($buffer -> get_end_iter,

When I try and do that I get the following warnings:

Gtk-WARNING **: Invalid text buffer iterator: either the iterator is uninitialized, or the characters/pixbufs/widgets in the buffer have been modified since the iterator was created.
You must use marks, character numbers, or line numbers to preserve a position across buffer modifications.
You can apply tags and insert marks without invalidating your iterators,
but any mutation that affects 'indexable' buffer contents (contents that can be referred to by character offset)
will invalidate all outstanding iterators at line 295.
Gtk-CRITICAL **: gtk_text_buffer_apply_tag: assertion `gtk_text_iter_get_buffer (end) == buffer' failed at line 295.
Inserting Text!

After it has gone through this for everything it needs to enter (each string in an array) it loads the contents but without the colour tags.

Prior to attempting to subclass TextBuffer I did have a functional program that displayed the given text with the colour tags, etc. None of that code has changed only that I use EditorBuffer instead of TextBuffer and create the Textview like so:

my $al_buffer = EditorBuffer -> new();
my $alignment = Gtk2::TextView -> new_with_buffer($al_buffer);

Anyone have any ideas what I am missing here?

Thank you,


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