Re: Advise



On Thu, 20 Jan 2005 11:47:35 +0100, Benoît Touron
<b touron citb bull net> wrote:
> If I could update the TextBuffer each time an event occurs, and actually
> display the TextView, say every second, it would be fine for me.
> How can I update a TextBuffer without updating the TextView ?

It's automatic: just update the buffer and everything will work.

Make the textview inside a scrolled window like this:

        swin = gtk_scrolled_window_new( NULL, NULL );
        gtk_scrolled_window_set_policy( GTK_SCROLLED_WINDOW( swin ),
                GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC );
        gtk_box_pack_start( GTK_BOX( vbox ), swin, TRUE, TRUE, 0 );
        gtk_widget_show( swin );

        /* Not editable, no visible cursor, monospaced font.
         */
        trace->view = gtk_text_view_new();
        gtk_text_view_set_editable( GTK_TEXT_VIEW( trace->view ), FALSE );
        gtk_text_view_set_cursor_visible( GTK_TEXT_VIEW( trace->view ),
                FALSE );
        font_desc = pango_font_description_from_string( "Mono" );
        gtk_widget_modify_font( trace->view, font_desc );
        pango_font_description_free( font_desc );

        gtk_container_add( GTK_CONTAINER( swin ), trace->view );
        gtk_widget_show( trace->view );

Add text and make the view scroll to the end like this:

                GtkTextView *text_view = GTK_TEXT_VIEW( trace->view );
                GtkTextBuffer *text_buffer =
                        gtk_text_view_get_buffer( text_view );
                GtkTextMark *mark = gtk_text_buffer_get_insert( text_buffer );
                GtkTextIter iter;

                /* Move insert point to end of buffer, insert text, scroll to 
                 * make insert point visible.
                 */
                gtk_text_buffer_get_end_iter( text_buffer, &iter );
                gtk_text_buffer_move_mark( text_buffer, mark, &iter );
                gtk_text_buffer_insert_at_cursor( text_buffer, buf, -1 );
                gtk_text_view_scroll_to_mark( text_view, mark,
                        0.0, TRUE, 0.5, 1 );

The screen update will occur automatically when your computer has some
spare time.

Of course the buffer will get very big :-( you'll need a "clear
buffer" button, or maybe just keep the last 1000 lines or something.

John



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