GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single button or array ?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
sherbo



Joined: 07 Jul 2007
Posts: 2

PostPosted: Sat Jul 07, 2007 3:16 pm    Post subject: Single button or array ? Reply with quote

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
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 505
Location: Portland, OR USA

PostPosted: Sat Jul 07, 2007 6:29 pm    Post subject: Reply with quote

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.
Back to top
sherbo



Joined: 07 Jul 2007
Posts: 2

PostPosted: Sat Jul 07, 2007 11:01 pm    Post subject: Reply with quote

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: (Plaintext)
1
2
3
4
5
6
7
8
9
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: (Plaintext)
1
2
3
4
5
6
7
8
9

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]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP