GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Jul 23, 2014 8:08 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: How to KIll a widget?
PostPosted: Sun Oct 14, 2007 12:16 am 
Offline

Joined: Sun Apr 29, 2007 7:07 pm
Posts: 3
Hey all,

Code extract:
Code:
140 int pin_io()
  141 {
  142 GtkWidget *window;
  143 GtkWidget *mb;
  144 GtkWidget *frame;
  145 GtkWidget *vbox1;
  146 GtkWidget *hbox;
  147 GtkWidget *button;
  148
  149 //button labels
  150 const gchar *l1,*l2,*l3,*l4,*l5,*l6,*l7,*l8,*l9;
  151
  152 //button labels when in write mode
  153 if (rw==1)
  154 {
  155   l1="P2"; l2="P3"; l3="P4"; l4="P5"; l5="P6"; l6="P7"; l7="P8";
  156   l8="P9"; l9="N/A";
  157
  158 }
  159
  160 //button labels when in read mode
  161 if (rw==0)
  162 {
  163   l1="P15"; l2="P13"; l3="P12"; l4="P10"; l5="P11"; l6="P1"; l7="P14";
  164   l8="P16"; l9 = "P17";
  165 }
  166
  167 //create pin i/o window
  168 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  169
  170 g_signal_connect (G_OBJECT (window), "destroy",   G_CALLBACK (delete_event), NULL);
  171
  172 //set boarder width
  173 gtk_container_set_border_width (GTK_CONTAINER (window), 12);
  174
  175 //window title
  176 gtk_window_set_title (GTK_WINDOW (window), "Pin I/O");
  177
  178 mb = gtk_hbox_new(FALSE, 10);
  179 gtk_container_add (GTK_CONTAINER (window), mb);
  180
  181
  182 vbox1 = gtk_vbox_new(FALSE, 10);
  183 gtk_box_pack_start (GTK_BOX (mb), vbox1, FALSE, FALSE, 0);
  184
  185
  186 //box for our labels and text
  187 hbox = gtk_hbox_new(FALSE, 0);
  188 gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
  189
  190
  191 //Making the Pin I/O "Updates" label
  192   frame = gtk_frame_new ("Updates");
  193   label2 = gtk_label_new ("Displays current status pin status\n");
  194   gtk_container_add (GTK_CONTAINER (frame), label2);
  195   gtk_box_pack_start (GTK_BOX (vbox1), frame, FALSE, FALSE, 15);
  196
  197 gtk_widget_show (frame);
  198 gtk_widget_show (label2);
  199 gtk_widget_show (hbox);
  200
  201
  202 /* the box to put the switches in            */
  203 hbox = gtk_hbox_new(FALSE, 5);
  204 /* add hbox to window                                           */
  205 gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
  206
  207
  208
  209  button = gtk_toggle_button_new_with_label (l1);
  210  g_signal_connect (G_OBJECT (button), "clicked",
  211                      G_CALLBACK (pin_2), NULL);
  212  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  213
  214
  215
  216  button = gtk_toggle_button_new_with_label (l2);
  217  g_signal_connect (G_OBJECT (button), "clicked",
  218                      G_CALLBACK (pin_3), NULL);
  219  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  220
  221
  222
  223  button = gtk_toggle_button_new_with_label (l3);
  224  g_signal_connect (G_OBJECT (button), "clicked",
  225                      G_CALLBACK (pin_4), NULL);
  226  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  227
  228
  229
  230  button = gtk_toggle_button_new_with_label (l4);
  231  g_signal_connect (G_OBJECT (button), "clicked",
  232                      G_CALLBACK (pin_5), NULL);
  233  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  234
  235
  236
  237  button = gtk_toggle_button_new_with_label (l5);
  238  g_signal_connect (G_OBJECT (button), "clicked",
  239                      G_CALLBACK (pin_6), NULL);
  240  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  241
  242
  243
  244  button = gtk_toggle_button_new_with_label (l6);
  245  g_signal_connect (G_OBJECT (button), "clicked",
  246                      G_CALLBACK (pin_7), NULL);
  247  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  248
  249
  250
  251  button = gtk_toggle_button_new_with_label (l7);
  252  g_signal_connect (G_OBJECT (button), "clicked",
  253                      G_CALLBACK (pin_8), NULL);
  254  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  255
  256
  257
  258  button = gtk_toggle_button_new_with_label (l8);
  259  g_signal_connect (G_OBJECT (button), "clicked",
  260                      G_CALLBACK (pin_9), NULL);
  261  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  262
  263  button = gtk_toggle_button_new_with_label (l9);
  264  g_signal_connect (G_OBJECT (button), "clicked",
  265                      G_CALLBACK (pin_10), NULL);
  266  gtk_box_pack_start (GTK_BOX(hbox), button,FALSE, FALSE, 3);
  267
  268
  269
  [b]270  button = gtk_toggle_button_new_with_label ("Close");
  271  g_signal_connect (G_OBJECT (button), "clicked",
  272  G_CALLBACK (delete_event),  G_OBJECT (window));[/b]
  273
  274
  275
  276 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
  277 gtk_widget_show (button);
  278
  279
  280 gtk_widget_show_all(window);
  281
  282 return 0;
  283 }


Towards the end of the function there is button with the label "Close". It currently points to a function that will kill the entire gtk program. However, this function (pin_io)) makes a popup window when called. When the "close" button is called, how do I make it only destroy the pin_io window and not the main gtk program?

I take we have to use gtk_widget_destroy() is some way here?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 14, 2007 7:47 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
Is this pin I/O window something that will be opened and closed periodically throughout the application's lifetime? If so, rather than creating and destroying the window each time, you may want to simply create it once, and from then on simply hide and show the widget.

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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 14, 2007 10:07 pm 
Offline

Joined: Sun Apr 29, 2007 7:07 pm
Posts: 3
Destroying the widget would do just fine. Would it be something like this?

button = gtk_toggle_button_new_with_label ("Close");
g_signal_connect (G_OBJECT (button), "clicked",
gtk_widget_destroy, window);

edit: I compiled with the above change. But when I hit the close button, the button destroys itself and the pin i/o window is still there.


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 4 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