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 Oct 02, 2014 6:23 am

All times are UTC




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: refresh boxes without new gtk_box_pack_start
PostPosted: Wed Jan 02, 2013 10:27 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Hello!
Happy new year to all members and thank you for your help during the last year!

Maybe it is a silly question but I'm not sure how to do it:
I have a dialog with 4 boxes, that I added with the command
Code:
gtk_box_pack_start (GTK_BOX (rm_local.widgets.vboxXXXX), alignSpeed ,TRUE, TRUE, 5);

The contains of the 1 and the 4th box are constant.
The contains of the boxes 2 and 3 are to be refreshed every second.

But If remove first the boxes 2 and 3 with the command
Code:
gtk_container_remove (GTK_CONTAINER(gtk_widget_get_parent(rm_local.widgets.vboxXXX)),   rm_local.widgets.vboxXXX);

I would get the new boxes behind the 1 and 4.
How can I "refresh" the contain of the boxes (labels and buttons) without removing the box before?

Or should I remove every time all the boxes in the dialog and make them all new even if they didn't change?
Thanks a lot in advance

MBoerner


Top
 Profile  
 
 Post subject: Re: refresh boxes without new gtk_box_pack_start
PostPosted: Wed Jan 02, 2013 5:34 pm 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 750
Location: UK
Hello,

It is not totally clear what you want to do.

I expect that what is needed is that you just want to up date the GtkLabel and GtkButton. You do not need to delete the container to do this. All that is needed is to set the new value to the GtkLabel or GtkButton.

_________________
E.


Top
 Profile  
 
 Post subject: Re: refresh boxes without new gtk_box_pack_start
PostPosted: Thu Jan 03, 2013 7:54 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
oh ok,
My problem is that I don't really understand whats happens when I use the command "pack_start"
Here is my code:
1) I read the new values from a variable that has been set in another task
2) I put them in a labelfield
3) I align them
4) I put the widgets in the boxes.

When the values are just changed, what should I do? Just remake the points 1 to 3 and then gtk_widget_show_all?
Can you give me an example How you would do it, if you use the same commands to fill the box "rm_local.widgets.vboxSpin"?

Thanks a lot!
MBoerner

Code:
static void rm_fill_box_stop_mode_spin(int stepnr)
{
   char strlabelSpeed[50];
   char strlabelAcc[50];
   char strlabelTime[50];
   GtkWidget* alignSpeed;
   GtkWidget* alignAcc;
   GtkWidget* alignTime;

// 1)set the current value of the speed, the acceleration and the ellapsed time
   sprintf(strlabelSpeed, "%s:%5d/%5d",descr_editBuffer.step.spin.speed.description, 0 ,recipe_editBuffer.step[stepnr].spin.speed);
   sprintf(strlabelAcc, "%s:%5d",descr_editBuffer.step.spin.acceleration.description, recipe_editBuffer.step[stepnr].spin.acceleration);
   sprintf(strlabelTime, "%s:%5d/%5d",descr_editBuffer.step.spin.spintime.description, 0, recipe_editBuffer.step[stepnr].spin.spintime);
// 2)put the values in label fields
   rm_local.widgets.lblSpinSpeed = gtk_label_new(strlabelSpeed);
   rm_local.widgets.lblSpinAcc = gtk_label_new(strlabelAcc);
   rm_local.widgets.lblSpinTime = gtk_label_new(strlabelTime);
// 3)align the fields
   alignSpeed = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
   gtk_container_add(GTK_CONTAINER(alignSpeed), rm_local.widgets.lblSpinSpeed);
   alignAcc = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
   gtk_container_add(GTK_CONTAINER(alignAcc), rm_local.widgets.lblSpinAcc);
   alignTime = gtk_alignment_new(0.0, 0.5, 0.0, 0.0);
   gtk_container_add(GTK_CONTAINER(alignTime), rm_local.widgets.lblSpinTime);
// 4)put them in the different boxes
   gtk_box_pack_start (GTK_BOX (rm_local.widgets.vboxSpin), alignSpeed ,TRUE, TRUE, 5);
   gtk_box_pack_start (GTK_BOX (rm_local.widgets.vboxSpin), alignAcc ,TRUE, TRUE, 5);
   gtk_box_pack_start (GTK_BOX (rm_local.widgets.vboxSpin), alignTime ,TRUE, TRUE, 5);
   gtk_label_set_justify(GTK_LABEL(rm_local.widgets.lblSpinSpeed), GTK_JUSTIFY_LEFT);
   gtk_label_set_justify(GTK_LABEL(rm_local.widgets.lblSpinAcc), GTK_JUSTIFY_LEFT);
}
step


Top
 Profile  
 
 Post subject: I have it!
PostPosted: Thu Jan 03, 2013 8:46 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Thank you errol!
I tried just to change the text of the labels and refresh the dialogs.
It works!

Thank you!
MBoerner


Top
 Profile  
 
 Post subject: Re: refresh boxes without new gtk_box_pack_start
PostPosted: Sat Jan 05, 2013 4:13 am 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Just as a note you shouldn use sprintf, there are overflow as well as security issues with it:
http://www.gtkforums.com/viewtopic.php?f=3&t=178138&hilit=+sprintf


Top
 Profile  
 
 Post subject: Re: refresh boxes without new gtk_box_pack_start
PostPosted: Mon Jan 07, 2013 6:35 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Thank you, I read it, I will use asprintf.
MBoerner


Top
 Profile  
 
 Post subject: Re: refresh boxes without new gtk_box_pack_start
PostPosted: Mon Jan 07, 2013 7:05 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 750
Location: UK
Hello,

Please avoid the use of asprintf() in a GTK+ application. This function is an extension to GNU C, is non-standard and is only available for GNU C and FreeBSD. Your application would then be tied to only those two.

Use g_strdup_printf () instead which would be available under all versions of GTK+ in the Glib library. See the documentation at http://developer.gnome.org/glib/stable/glib-String-Utility-Functions.html#g-strdup-printf. Please also check the top of the page for extra information on formatting.

_________________
E.


Top
 Profile  
 
 Post subject: Re: refresh boxes without new gtk_box_pack_start
PostPosted: Tue Jan 08, 2013 6:11 am 
Offline
Familiar Face

Joined: Fri Oct 26, 2012 10:49 am
Posts: 37
Notified, thanks a lot!


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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