Updating TextView and StatusBar problem
- From: Miguel Figueiredo <olliegator hortanet com>
- To: gtk-app-devel-list gnome org
- Subject: Updating TextView and StatusBar problem
- Date: Sat, 3 Apr 2004 12:43:39 +0100
Hi listers,
I am new to GTK and GUI development, and as usual for newbies I have a
problem.
I created a window which has a textview, a button and a statusbar. When I
press the button, I want to call a func that inserts text in both the
textview and the statusbar over a certain amount of time. The problem is that
this text is only visible when the function ends. The purpose is to display
the text as soon as it is inserted in the textview and/or statusbar.
What is the correct way to do this?
Here is a simplified code do illustrate my problem:
#include <stdio.h>
#include <unistd.h>
#include <gtk/gtk.h>
/* Aux data type */
typedef struct WINDOW{
GtkWidget *window;
GtkWidget *textview;
GtkWidget *statusbar;
}windowT;
/* Prints something in status bar */
void print_statusbar (char *string, GtkStatusbar *statusbar){
gtk_statusbar_pop (statusbar, 0);
gtk_statusbar_push (statusbar, 0, string);
}
/* Prints something in textview */
void print_textview(char *string, GtkTextView *textview){
GtkTextBuffer *buffer;
buffer = gtk_text_view_get_buffer (textview);
gtk_text_buffer_insert_at_cursor(buffer, string, -1);
}
/* Callback function */
void my_func(GtkButton *button, windowT *window){
print_textview("BLA\n", GTK_TEXT_VIEW(window->textview));
print_statusbar(" Just printed BLA", GTK_STATUSBAR(window->statusbar));
/* Do something for a while */
sleep(1);
/* End */
print_textview("BLE\n", GTK_TEXT_VIEW(window->textview));
print_statusbar(" Just printed BLE", GTK_STATUSBAR(window->statusbar));
}
/* Main window */
windowT *create_window(){
windowT *window;
GtkWidget *vbox, *button;
/* Main window */
window->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (GTK_WINDOW (window->window),450, 450);
g_signal_connect (window->window, "destroy",G_CALLBACK (gtk_main_quit),NULL);
/* Vertical box */
vbox = gtk_vbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(window->window), vbox);
gtk_widget_show(vbox);
/* Text view */
window->textview = gtk_text_view_new();
gtk_box_pack_start(GTK_BOX(vbox), window->textview, TRUE, TRUE, 0);
gtk_text_view_set_editable (GTK_TEXT_VIEW (window->textview), FALSE);
gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (window->textview), FALSE);
gtk_widget_show(window->textview);
/* Button */
button = gtk_button_new_with_label("BUTTON");
gtk_widget_show(button);
gtk_box_pack_start(GTK_BOX(vbox), button, FALSE,FALSE, 0);
g_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(my_func),
window);
/* Status bar */
window->statusbar = gtk_statusbar_new();
gtk_box_pack_start(GTK_BOX(vbox), window->statusbar, FALSE, FALSE, 0);
gtk_widget_show(window->statusbar);
return(window);
}
/* No comments ;) */
int main( int argc, char *argv[] ){
windowT *window;
gtk_init (&argc, &argv);
window = create_window();
gtk_widget_show(window->window);
gtk_main ();
return(0);
}
--
Miguel Figueiredo
IT student / Marine Biologist
"If it ain't broken, don't fix it."
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]