[Glade-users] gtk/glade programming

Seb James seb@hypercubesystems.co.uk
25 Sep 2003 10:27:22 +0100


Hello all,

My application receives serial data. It has the following code in main.c
to set up the creation of a signal everytime a line is ready to be read
on the serial port:


	/* Now we need to set things up so that receiving a line
	   on the serial port will generate a signal to decode the 
	   input and display it. */
	serial_input_tag = gdk_input_add (fd, GDK_INPUT_READ, 
					  on_serial_data_receive, 
					  &target_io_states);    


And the following code to handle that signal in callbacks.c:

void
on_serial_data_receive                 (gpointer            user_data,
					gint                fd,
					GdkInputCondition   target_io_states)
{
	GtkWidget *console_textview;

	char buf[255];
	gint res;

	/* Don't know how to call lookup_widget in this case: */
	console_textview = lookup_widget (GTK_WIDGET (console_textview), "console_textview");

	res = read(fd,buf,255); 
	buf[res]=0;  /* set end of string, so we can printf */

	/* print the received data to sdout */
	printf("Buffer:%sNumber of characters:%d\n", buf, res);

	/* Plus output it to the console window: */
	gtk_text_buffer_set_text (gtk_text_view_get_buffer (GTK_TEXT_VIEW (console_textview)),
				  _("Buffer text"), -1);
	/* How to replace "Buffer text" with "%s", buf ? */

	return;
}


The comments show my problems - I need to get the text from the serial
port onto a console window that I've created in glade. The problem seems
to be with looking up the widget. The form that I need my signal handler
in doesn't have a `parent' widget for lookup_widget to search for
console_textview in.

I'm trying to do something like that which I programmed for, for
example, closing the console window when its close button is clicked:

void
on_close_console_clicked               (GtkButton       *button,
                                        gpointer         user_data)
{
	GtkWidget *console;
	console = lookup_widget (GTK_WIDGET (button), "console");
	gtk_widget_destroy (console);

	return;
}

In this code, you put in GTK_WIDGET (button) as the first argument of
lookup_widget. button is a pointer to the button you clicked, and so
lookup_widget finds console, as it is the parent of the button. However,
my serial_data_receive function has no such widget passed to it. How can
I use lookup_widget here?

Can anyone help with this?

Thanks

Seb.