[Glade-users] gtk/glade programming

Seb James seb@hypercubesystems.co.uk
25 Sep 2003 13:04:22 +0100


On Thu, 2003-09-25 at 10:27, Seb James wrote:
> 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?

I found out how to work this out. I created a global variable, 
GtkWidget *console_window_global, which I set to being equal to the
variable console, when the console is created. Then, I pass this
variable as the first argument to lookup_widget(). That works, as
lookup_widget can now find the text area that is a child of console.


> Thanks
> 
> Seb.
> 
> _______________________________________________
> Glade-users maillist  -  Glade-users@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/glade-users