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 Dec 18, 2014 11:30 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: GTK Noob question
PostPosted: Tue Nov 27, 2007 12:33 pm 
Offline
Familiar Face

Joined: Tue Nov 27, 2007 12:20 pm
Posts: 5
Hi,

I've just started learning about GTK and I've run into something which I cant seem to figure out. I have two buttons (find_node & cancel_process) in an hbox, which appear after a selection from my program menu) and I would like the cancel_process button to destroy only the hbox (not the entire program), if it is 'clicked'.

The thing is, only the process_cancel button is being removed, and I want them both (i.e. the entire hbox) to be destroyed.

My code is as follows:

GtkWidget *find_node;
GtkWidget *cancel_process;
GtkWidget *hbox;

printf("Entering certify node process\n");

hbox = gtk_hbox_new(FALSE, 0);

find_node = gtk_button_new_with_label ("Find Node");
cancel_process = gtk_button_new_with_label ("Cancel");


gtk_box_pack_start(GTK_BOX(hbox), find_node, FALSE, FALSE, 10);
gtk_box_pack_start(GTK_BOX(hbox), cancel_process, FALSE, FALSE, 0);

gtk_widget_show_all (GTK_WIDGET (hbox));

g_signal_connect(G_OBJECT(cancel_process), "clicked", G_CALLBACK(gtk_destroy_widget), hbox);


Could anyone possibly point me in the right direction?

Cheers,

Neilly


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 27, 2007 4:53 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Well, the function is gtk_widget_destroy() that you should add to your callback. However, are you going to be recreating these widgets multiple times? If so, maybe you should just connect the hbox to gtk_widget_hide_all().

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 1:08 pm 
Offline
Familiar Face

Joined: Tue Nov 27, 2007 12:20 pm
Posts: 5
openldev wrote:
Well, the function is gtk_widget_destroy() that you should add to your callback. However, are you going to be recreating these widgets multiple times? If so, maybe you should just connect the hbox to gtk_widget_hide_all().


Ah..so my problem was a typo...oops. And no, these will be a one off creation.

I have another question though...I have a list of parameters which I need to be able to individually edit their initialised values. I was hoping to do this with gtk_entry_new.

I am developing my code in the Maemo environment (for running on a Nokia N700) and I have a vbox full of gtk_entry widgets, filled in with their initialised values. Whenever I click on one of the entry boxes the little virtual keyboard of the Nokia pops up. My question is, what signal is triggered whenever I select the entry box to edit the value?

Or more to the point, at what stage could I insert the new parameter value from the entry widget to its allocated variable?

Cheers.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 2:42 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
I don't quite understand your last question, but there are two very useful signals here. "activate" is emitted when the user presses the Enter key while the entry has focus.

Also, since GtkEntry is derived from GtkWidget, focus-in-event will be emitted when the entry receives the cursor.

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 2:53 pm 
Offline
Familiar Face

Joined: Tue Nov 27, 2007 12:20 pm
Posts: 5
I think I found a way of updating the entry through the "changed' signal (because its editable)...maybe not the best way but at the moment it works, but this has led to another problem.

I have a data structure (GtkNetSettings) which holds a few parameters of type char*. I use this struct to populate a window where I can see how these parameters are set. I also use the struct in a window where I want to edit the values of the parameters (using gtk_entry, like I mentioned). However, after getting the updated value from the gtk_entry and setting the value in the struct, when I go back to view it I get the following error:

GLIB WARNING ** Pango - Invalid UTF-8 string passed to pango_layout_set_text()


My data struct is:

struct _GtkNetSettings
{

HildonWindow *Settings_window;
char *SSID;
char *subnet_addr;
char *PN_ID;
char *VPN_server;

};


and the method I use to view it is:

gtk_label_set_text(GTK_LABEL(label_SSID_value), ns->SSID);

and the method I use to set the updated value from the gtk_entry is:

ns->SSID = gtk_entry_get_text(w);


Where 'ns' is of type GtkNetSettings and 'w' is the gtk_entry widget for the SSID value.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 29, 2007 3:49 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
Note that gtk_entry_get_text returns const gchar*. This means you have to make a copy of it with g_strdup(). Also, make sure you free the string that you are storing before setting it to a new value!

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 7:52 am 
Offline
Familiar Face

Joined: Tue Nov 27, 2007 12:20 pm
Posts: 5
Thank you very much for your help. I have also asked my boss to order your book :)


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

All times are UTC


Who is online

Users browsing this forum: Google Adsense [Bot], Yahoo [Bot] and 3 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