ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Xubuntu 9.10, Gentoo 2.6.27 (AMD64), Darwin 9.0.0 (arm)
Posts: 1,152
Rep:
glade and scale widgets
So I'm new to this and I'm just trying to make a simple front end, but I cant seem to figure out how to get the value of my scale widgets. the only how-tos that I can find are either very simple how to make an interface with glade but not how to use them outside the limited scope of the example programs or, the gtk+-2.0 tutorial geared more to coding the whole thing yourself. but I cant find anything about using the adjustments that glade sets up. basically all I need to do is get the value of a scale widget and print it to the console that the programm is running in.
you just need to back up to the abstract GtkRange widget, calling get_value via whatever language this is done in. http://www.gtk.org/api/2.6/gtk/GtkRa...ange-get-value you can see the heirarchy of widgets in the list at the top there. so any method in an abstract widget will be still accesible in any specific based upon it.
Distribution: Xubuntu 9.10, Gentoo 2.6.27 (AMD64), Darwin 9.0.0 (arm)
Posts: 1,152
Original Poster
Rep:
thank you for your reply acid,
I should've mentioned it's gtk 2.0 with C. the link you have apears to be for gtk 2.6 but if I cut and paste it exactly it compiles fine but I'm not sure how to print this or get it into a variable so that I can use it.
Here's a C/libglade version. I didn't test it... it's just off the top of my head. It assumes the glade file is named "gui.glade" and that your scale widget has a signal handler named "on_scale_value_changed" defined in the glade file (under the signals tab of the properties window).
Code:
/* this would be in main() */
GladeXML *gxml;
gxml = glade_xml_new ("gui.glade", NULL, NULL);
/* this OR glade_xml_signal_autoconnect */
glade_xml_signal_connect (gxml,
"value-changed",
G_CALLBACK(on_scale_value_changed));
/* this is the callback for the "value-changed" signal */
void
on_scale_value_changed (GtkWidget *widget, gpointer user_data)
{
gdouble val;
val = gtk_range_get_value (GTK_RANGE(widget));
/* print to screen */
g_print("Range value: %e" val);
}
Okay, there should be a comma in that g_print call up there. Also, just to be sure I compiled a quick test, here's the whole thing. Compiles on my system using:
Distribution: Xubuntu 9.10, Gentoo 2.6.27 (AMD64), Darwin 9.0.0 (arm)
Posts: 1,152
Original Poster
Rep:
Thank you all for your help. I will study your examples and I am sure I will learn some things (I have not used c since middleschool and then just simple dos stuff so I'm just about completely lost) but, for some reason I only received email notification for acid's first post; so I stayed up till 4:00am and figured it out before I saw these examples. this is what I ended up with:
Right. Lookup "casting in C" on google to get specifics.
Also, the "GTK_RANGE(range)" is a casting macro. In that case, it's casting a GtkRange into a GtkRange-- redundant. However, if range was declared as a GtkWidget, you would then need to cast it into a GtkRange pointer before passing it to any gtk_range_SOMETHING function.
Casting is pretty common with GTK+/C and will help you out quite a bit to understand it and it's pit falls.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.