Hi Chen,

Now that you have dug into the problem, let me post the entire code I did
in glade [this code is part of a callback file, containing a function
which will be invoked when a button is clicked.


*****************************START OF CODE CHUNK****************************

#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

//C Related includes
#include<unistd.h>
#include<stdlib.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"

typedef struct
{
        GtkWidget *pbar;
        gdouble fraction;

}ProgressData;

gdouble fraction=0.0;

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{
        GtkWidget *wdgt_start_count;
        GtkWidget *wdgt_end_count;
        GtkWidget *wdgt_progress_bar;

        ProgressData *pdata;



        gchar *txt_start_count;
        gchar *txt_end_count;

        gint start_count = 0;
        gint end_count = 0;

        gint range;//end_count - start_count;
        gdouble fraction = 0.0;


        gint i;//Loop variable
        gint j = 0;//Loop variable

        pdata = (ProgressData *)g_malloc0(sizeof(ProgressData));

        txt_start_count = (gchar *) g_malloc0(50*sizeof(gchar));
        txt_end_count = (gchar *) g_malloc0(50*sizeof(gchar));

        /*Get start and end values from the text boxes.*/
        wdgt_start_count = lookup_widget(GTK_WIDGET(button), "entry1");
        wdgt_end_count = lookup_widget(GTK_WIDGET(button), "entry2");
        wdgt_progress_bar = lookup_widget(GTK_WIDGET(button),"progressbar1");

        txt_start_count = (gchar 
*)gtk_entry_get_text(GTK_ENTRY(wdgt_start_count));
        txt_end_count = (gchar *)gtk_entry_get_text(GTK_ENTRY(wdgt_end_count));

        start_count = atoi(txt_start_count);
        end_count = atoi(txt_end_count);


    //Set progress bar to the one that is currently used. Only fraction
varies.
    pdata->pbar = wdgt_progress_bar;

        pdata->fraction = 0.0;

        j = 0;

        range = end_count - start_count;
        /*I tried a timeout function which will get the value of fraction and
update regularly. It didnt work too.*/
       //g_timeout_add (100, progress_timeout, pdata);

        for(i=start_count;i<end_count;i++)
        {
                //g_print("i = (%d)\n",i);
                while(j<100000)//To kill time, keep counting until a lakh
                        j++;
                j = 0;//Make j 0 for the next loop.
                //sleep(2);
                pdata->fraction = (gdouble)i/(gdouble)(range);

                fflush(NULL);
                //gtk_progress_bar_pulse (GTK_PROGRESS_BAR (pdata->pbar));
                //gtk_progress_bar_set_pulse_step(GTK_PROGRESS_BAR
(pdata->pbar),pdata->fraction );
                gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (pdata->pbar),
pdata->fraction);
        }//End for i = start_count to end_count
        //Call function periodically
        /* Add a timer callback to update the value of the progress bar */

*************************END OF CODE CHUNK*********************************

This is the portion of the code that I am talking about. Note that I am
calculating the fraction and then updating the progress bar then and
there, but nothing happens. I have also typecasted i to gdouble for
getting fraction calculated accurately.


Please help.

On Mon, January 7, 2008 1:01 pm, Bin Chen wrote:
>

> 在 2008-01-07一的 13:04 [EMAIL PROTECTED]
>>
>> Hey Bin Chen[or how do I call you :-)],
>>
>>
>> First of all, thank you very much for your instant reply.
>>
>>
>> Let me give a simple pseudo-code explaining my problem. Please see what
>> I
>> can do with this.
>>
>> Program Goal: Do work w1 "iterations" number of times, and keep showing
>>  progress of this whole work regularly.
>>
>> Pseudo code:
>>
>>
>> for(i=0;i<iterations;i++) {
>> do w1; fraction = (i+1)/iterations; Update progress bar using this
>> fraction. }
>>
> There are somthing wrong with your programe. I use
> gtk_progress_bar_set_fraction() can properly update the bar. Be noticed
> that the number is in float number, if you ignore this there will only be
> two numbers in integer, 0 and 1.
>
> *************************************************************************
> ************
> DISCLAIMER
> This e-mail and any files transmitted with it are for the sole use of the
> intended recipient(s) and may contain confidential and privileged
> information. Any use,distribution,copying or disclosure by any other
> person is strictly prohibited. If you have received this transmission in
> error please notify SETS immediately either by replying to this e-mail or
> by telephone +91-44-28205655 and then delete this e-mail. The sender does
> not accept any responsibility for any damage which you sustain as a
> result of software viruses or malicious programs. You should therefore
> scan attachments (if any) prior to opening them.
> *************************************************************************
> ***********
>
>
>
>
>
>
>


Vijayasarathy
Senior Research Associate
SETS

***************************************************************************
DISCLAIMER
This e-mail and any files transmitted with it are for the sole use of
the intended recipient(s) and may contain confidential and privileged
information. Any use, distribution, copying or disclosure by any other
person is strictly prohibited. If you have received this transmission
in error please notify SETS immediately either by replying to this e-mail
or
by telephone on +91-44-28205655 and then delete this e-mail.
The sender does not accept any responsibility for any damage which
you sustain as a result of software viruses or malicious programs.
You should therefore scan attachments (if any) prior to opening them.
**************************************************************************


*************************************************************************************
DISCLAIMER 
This e-mail and any files transmitted with it are for the sole use of the 
intended recipient(s) and may contain confidential and privileged information. 
Any use,distribution,copying or disclosure by any other person is strictly 
prohibited. If you have received this transmission in error please notify SETS 
immediately either by replying to this e-mail or by telephone +91-44-28205655 
and then delete this e-mail. The sender does not accept any responsibility for 
any damage which you sustain as a result of software viruses or malicious 
programs. You should therefore scan attachments (if any) prior to opening them. 
************************************************************************************





_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to