[Vala] How to implement gtk textview auto scroll?



Hi:

    I'm using Vala to write a serialport tool...

    the window class implement the observer and the serialport class as the
subject, so i need the textview could auto scroll to the end...

    right now, my solution is :

    1.when serialport data coming, insert the data at the end of the
textbuffer

        public void data_report(uint8[] data, int size)
        {
            Gtk.TextIter iter;

            textbuffer_output.get_end_iter(out iter);

            textbuffer_output.insert(ref iter, (string)data, size);
        }

    2. in the textview's size_allocate event, scroll to the end

    [GtkCallback]
        public void on_textview_output_size_allocate(Gtk.Allocation
allocation)
        {
            Gtk.TextIter iter;

            textbuffer_output.get_end_iter(out iter);

            textview_output.scroll_to_iter(iter, 0, false, 0, 0);
        }

    it works well under the windows with msys2's gtk3's bundle, but it will
crash under ubuntu 14.04 if the data report fast...

   (magicom:3547): 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
coredump


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