GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Apr 24, 2014 5:51 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Single button or array ?
PostPosted: Sat Jul 07, 2007 3:16 pm 
Offline

Joined: Sat Jul 07, 2007 3:06 pm
Posts: 2
Hello,

I'm building a C/GTK1.2 application that will control 15 devices. The window will contain 15 "Start" buttons, and for any device that is already running - the button should display "STOP" instead, and a label would show the time elapsed. I have 3 questions:

1) Do I need to use an array of 15 button widgets ? Or is there some way to do with only 1 widget ?

2) How do I make the buttons change labels from "start" to "stop" ?

3) Do you think this GUI arrangement would look good ? I'm placing the buttons/labels in a 3x5 table. If you can think of any alternative way to do this then please tell me.

I know that my questions may sound very trivial for some of you, but this is my first experience with any graphical toolkit what-so-ever.

Awaiting your replies


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 6:29 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You can initially create the GUI with glade or by using a loop (iterating 15 times) to create each button. So you don't need to create a 15-element array. The label text is changed via the button's "clicked" signal callback using the gtk_button_set_label() function. You could use something like g_ascii_strcasecmp() to see which label you need to set or possible store the states in static local variables or a global array.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 07, 2007 11:01 pm 
Offline

Joined: Sat Jul 07, 2007 3:06 pm
Posts: 2
Micah, Thank you for your reply. I used one button as you told me, and toggling the buttons between Start/Stop is OK.

But there's a small problem. I need the callback function to know which button got clicked, in order to take other action in the program. Here is my code:

Code:
void click_callback( GtkWidget *button, gpointer data )

{

    g_print ("Hello again - %s was pressed\n", (char *) data);

   gtk_button_set_label(GTK_BUTTON(button), "STOP");

}



Code:
for(z=1; z <= 15; z++)
{
sprintf(name,"%d",z);
button = gtk_button_new_with_label("Start");
gtk_signal_connect( GTK_OBJECT(button), "clicked",GTK_SIGNAL_FUNC (click_callback), (gpointer) name );
}




Now the problem is: I always get "15" as the output of g_print. I think it's a problem with the signals overwriting each other or something... Please advise.

Best Regards
Ahmed[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group