Accessing a GtkTable's children.

2007-04-07 Thread Craig Pemberton

Hello everyone,

I hope this is the proper place to post this! I am developing a graphical
front-end for a
diagnostics panel for an autonomous vehicle. I am fairly new to C++ and GTK.
I've
searched all over for the solution but maybe I'm looking for the wrong
things.

I cobbled together the widgets using Glade-2. I have a GtkTable that lays
out all the needed
widgets in a grid.  Now I am working in callbacks.c and need to be able to
alter a label when
a toggle button is pressed.

I have gotten fairly far but am now stuck:

//Callback function, the stub of which was automatically generated by
Glade-2
//It is called when ever the toggle button enable is clicked.
//This event is called when you press the enable/disable toggle button for
the estop.

void on_toggletoolbutton_enable_toggled( GtkToggleToolButton
*toggletoolbutton,  gpointer user_data )
{

//Getting the parent of the toggle button, my table
GtkTable *parent = (GtkTable*) gtk_widget_get_parent( (GtkWidget*)
toggletoolbutton);
//Getting the list of children widgets from the table. I checked and it has
the correct number of children.
GList *children = g_list_first(parent-children);
//Iterate through and print the name of each child widget
while (children)
{
//Get the first widget from the list
GtkWidget *test = (GtkWidget*) (g_list_first(children)-data);
//Print the name of this widget
g_print(gtk_widget_get_name (test));
//Knock the first widget off of the list
children = g_list_next(children);
}

This code does not work. I get the following errors 16 times (the number of
children in my table):

(dash:10933): Gtk-CRITICAL **: gtk_widget_get_name: assertion `GTK_IS_WIDGET
(widget)' failed
(dash:10933): GLib-CRITICAL **: g_print: assertion `format != NULL' failed

What am I doing wrong? If anyone could help me it would be greatly
appreciated. I have been fighting with this all day.

- Craig

-- 
View this message in context: 
http://www.nabble.com/Accessing-a-GtkTable%27s-children.-tf3539983.html#a9881778
Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessing a GtkTable's children.

2007-04-07 Thread Andrew Cowie
On Fri, 2007-04-06 at 23:45 -0700, Craig Pemberton wrote: 
 GList *children = g_list_first(parent-children);

For starters, you want

gtk_container_get_children()

From there, you might also double check you're using the GList API
properly.

AfC
Sydney

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Accessing a GtkTable's children.

2007-04-07 Thread Craig Pemberton

Thank you so much Andrew!

It is now working beautifully. The final code is below for anyone who may
read this thread looking for the same fix.

void on_toggletoolbutton_enable_toggled( GtkToggleToolButton
*toggletoolbutton, gpointer user_data )
{
GtkTable *parent = (GtkTable*)
gtk_widget_get_parent((GtkWidget*)toggletoolbutton);
GList *children = gtk_container_get_children(parent);
int len = g_list_length(children);
int i;
for(i=0; i  len; i++)
{
GtkWidget *test = (GtkWidget*) g_list_nth_data(children, i);

g_printf(Widget %d is %s.\n, i, gtk_widget_get_name (test));
}
. . . 

 - Craig
-- 
View this message in context: 
http://www.nabble.com/Accessing-a-GtkTable%27s-children.-tf3539983.html#a9882649
Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessing a GtkTable's children.

2007-04-07 Thread Craig Pemberton
I just discovered lookup_widget()! This makes life much easier. The code now
looks like the following. I'm not sure if this is best, but I used it by
getting the parent and then using lookup_widget() to look through it's
children.

I'm happy with this code now. Thanks again.

//This event is called when you press the enable/disable toggle button for
the estop.
void
on_toggletoolbutton_enable_toggled(GtkToggleToolButton *toggletoolbutton,
gpointer user_data)
{
//We need the references to the widgets for the engage label and toggle
GtkTable*  parent = (GtkTable*)
gtk_widget_get_parent((GtkWidget*)toggletoolbutton);
GtkWidget* label_engage= lookup_widget(parent,
label_engage);
GtkWidget* toggletoolbutton_enable = lookup_widget(parent,
toggletoolbutton_enable);


//These are the icons that show a connection and broken connecton
GtkIconSize icon_size = gtk_tool_item_get_icon_size( (GtkToolItem*)
toggletoolbutton);
GtkWidget *connect_image =gtk_image_new_from_stock (gtk-connect,
icon_size);
GtkWidget *disconnect_image = gtk_image_new_from_stock
(gtk-disconnect, icon_size);


//If off when pressed, turn it on! The icon should indicate that it is
connected.
if (fstop_engaged == 0)
{
gtk_tool_button_set_icon_widget( (GtkToolButton*) toggletoolbutton,
connect_image);
gtk_label_set_text (label_engage, _(Enabled));
//Redisplay the widgets
gtk_widget_show ( (GtkWidget*) toggletoolbutton);
gtk_widget_show ( (GtkWidget*) connect_image);
gtk_widget_show ( (GtkWidget*) label_engage);
fstop_engaged = 1;
}

//If on when pressed, turn it off! The icon should indicate that it is
disconnected.
else
{
gtk_tool_button_set_icon_widget( (GtkToolButton*) toggletoolbutton,
disconnect_image);
gtk_label_set_text (label_engage, _(Disabled));
gtk_widget_show ( (GtkWidget*) toggletoolbutton);
gtk_widget_show ( (GtkWidget*) disconnect_image);
//Redisplay the widgets
gtk_widget_show ( (GtkWidget*) toggletoolbutton);
gtk_widget_show ( (GtkWidget*) connect_image);
gtk_widget_show ( (GtkWidget*) label_engage);
fstop_engaged = 0;
}

}

On 4/7/07, Craig Pemberton [EMAIL PROTECTED] wrote:


 Thank you so much Andrew!

 It is now working beautifully. The final code is below for anyone who may
 read this thread looking for the same fix.

 void on_toggletoolbutton_enable_toggled( GtkToggleToolButton
 *toggletoolbutton, gpointer user_data )
 {
 GtkTable *parent = (GtkTable*)
 gtk_widget_get_parent((GtkWidget*)toggletoolbutton);
 GList *children = gtk_container_get_children(parent);
 int len = g_list_length(children);
 int i;
 for(i=0; i  len; i++)
 {
 GtkWidget *test = (GtkWidget*) g_list_nth_data(children,
 i);
 g_printf(Widget %d is %s.\n, i, gtk_widget_get_name
 (test));
 }
 . . .

 - Craig
 --
 View this message in context:
 http://www.nabble.com/Accessing-a-GtkTable%27s-children.-tf3539983.html#a9882649
 Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.

 ___
 gtk-app-devel-list mailing list
 gtk-app-devel-list@gnome.org
 http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Looking for signal/callback design advice

2007-04-07 Thread Craig Pemberton

Hello Everyone,

I am looking advice on how to structure the gtk application I am working on.
I think that it lends itself very well to the signal/callback mechanism but
I am not sure and would hate to waste time.

The program is going to be a diagnostic heads up display for an autonomous
vehicle. It needs to keep an eye on various servos, battery voltages, relays
et cetera and feed that information through to a graphical display. Further
more there are toggle buttons that should send signals back to the hardware
to turn on or off various items. These items can be safely abstracted as
sockets, files, whatever they need to be abstracted as. Ideal it should be
very easy to plug them into the signal / callback mechanism for people who
shouldn't have to know anything about gtk at all. 


So basically, the front-end part is more or less done. Now I just need to
know how to make a back-end interface.

Anyone who can give advice or link to examples or tutorials would be a
godsend. Anything that will save wasting development time in the long run. 

- Craig
-- 
View this message in context: 
http://www.nabble.com/Looking-for-signal-callback-design-advice-tf3540512.html#a9883327
Sent from the Gtk+ - Apps Dev mailing list archive at Nabble.com.

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessing a GtkTable's children.

2007-04-07 Thread Michael Torrie
On Sat, 2007-04-07 at 05:15 -0500, Craig Pemberton wrote:
 I just discovered lookup_widget()! This makes life much easier. The code now
 looks like the following. I'm not sure if this is best, but I used it by
 getting the parent and then using lookup_widget() to look through it's
 children.
 
 I'm happy with this code now. Thanks again.

You mentioned C++ earlier.  If you are coding in C++ and not actually
straight C, and you want to take more advantage of object-oriented
programming with C++ classes, you might want to take a look at
http://www.gtkmm.org/

Your C GTK code usually can convert rather readily to GTKmm, although
you'd want to develop a class hierarchy.  Anyway, just a possibility.
There's nothing at all wrong with using straight C.  I kind of like it
myself.

Michael




___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: Accessing a GtkTable's children.

2007-04-07 Thread Jim George
On 4/7/07, Craig Pemberton [EMAIL PROTECTED] wrote:
 I just discovered lookup_widget()!
If you're using lookup_widget(), that means you're using Glade's code
generation, which is going away in glade 3. Use libglade instead,
especially if you're not too far into your project.

-Jim
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list