gdk_input_add problem..



Hai all..

I wrote a program to update the progress bar..when ever there is some activity over a file ...

i used the "gdk_input_add" function for this..

i am not getting n e out put from this..

i have included the files below...

please help me..

JD,,

 

 

*******&&&&&&  TIMEOUT.C&&&&&&&&&&***************

/* example-start progressbar timeout.c---By JD. */

#include <gtk/gtk.h>

#include "progbar.h"

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

#include<pthread.h>

#include<stdlib.h>

#include<stdio.h>

pthread_t write1,gui;

pthread_attr_t attr;

gint fd;

void main_gtk()

{

ProgressData *pdata;

GtkWidget *align;

// GtkWidget *separator;

//GtkWidget *table;

GtkAdjustment *adj;

GtkWidget *button;

//GtkWidget *check;

GtkWidget *vbox;

/* Allocate memory for the data that is passwd to the callbacks */

pdata = g_malloc( sizeof(ProgressData) );

pdata->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

gtk_window_set_policy (GTK_WINDOW (pdata->window), FALSE, FALSE, TRUE);

gtk_signal_connect (GTK_OBJECT (pdata->window), "destroy",

GTK_SIGNAL_FUNC (destroy_progress),

pdata);

gtk_window_set_title (GTK_WINDOW (pdata->window), "GtkProgressBar");

gtk_container_set_border_width (GTK_CONTAINER (pdata->window), 0);

vbox = gtk_vbox_new (FALSE, 5);

gtk_container_set_border_width (GTK_CONTAINER (vbox), 10);

gtk_container_add (GTK_CONTAINER (pdata->window), vbox);

gtk_widget_show(vbox);

/* Create a centering alignment object */

align = gtk_alignment_new (0.5, 0.5, 0, 0);

gtk_box_pack_start (GTK_BOX (vbox), align, FALSE, FALSE, 5);

gtk_widget_show(align);

/* Create a Adjusment object to hold the range of the

* progress bar */

adj = (GtkAdjustment *) gtk_adjustment_new (0, 1, 150, 0, 0, 0);

/* Create the GtkProgressBar using the adjustment */

pdata->pbar = gtk_progress_bar_new_with_adjustment (adj);

/* Set the format of the string that can be displayed in the

* trough of the progress bar:

* %p - percentage

* %v - value

* %l - lower range value

* %u - upper range value */

gtk_progress_set_format_string (GTK_PROGRESS (pdata->pbar),

"%v from [%l-%u] (=%p%%)");

gtk_container_add (GTK_CONTAINER (align), pdata->pbar);

gtk_widget_show(pdata->pbar);

/* Add a timer callback to update the value of the progress bar */

pdata->timer = gdk_input_add (fd,GDK_INPUT_WRITE,(GdkInputFunction) progress_timeout, pdata->pbar);

// pdata->timer = gtk_timeout_add(100,progress_timeout,pdata->pbar);

/* Add a radio button to select discrete display mode */

/* Add a button to exit the program */

button = gtk_button_new_with_label ("close");

gtk_signal_connect_object (GTK_OBJECT (button), "clicked",

// (GtkSignalFunc) gtk_widget_destroy,

(GtkSignalFunc)closeall,

GTK_OBJECT (pdata->window));

gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);

/* This makes it so the button is the default. */

GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);

/* This grabs this button to be the default button. Simply hitting

* the "Enter" key will cause this button to activate. */

gtk_widget_grab_default (button);

gtk_widget_show(button);

gtk_widget_show (pdata->window);

gtk_main ();

// return(0);

}

 

void writer()

{

int fd,i,n;

char buff[]="Hello";

// fd=open("data",O_WRONLY);

for(i=1;i<5;i++)

{

sleep(1);

n=write(fd,buff,sizeof(buff));

printf("Writing!!!\n");

sleep(1);

}

}

 

void main(int argc, char *argv[])

{

int status;

pthread_attr_init(&attr);

fd=open("data",O_RDWR);

gtk_init (&argc, &argv);

pthread_create(&gui,&attr,main_gtk,NULL);

pthread_create(&write1,&attr,writer,NULL);

pthread_join(write1,&status);

printf("Writer returned\n");

pthread_join(gui,&status);

}

 

 

@@@@@@@@PROGBAR.H@@@@@@@@@@@@

typedef struct _ProgressData

{

GtkWidget *window;

GtkWidget *pbar;

int timer;

} ProgressData;

/* Update the value of the progress bar so that we get

* * some movement */

gint progress_timeout( gpointer data,gint source,GdkInputCondition cond)

{

gfloat new_val;

GtkAdjustment *adj;

/* Calculate the value of the progress bar using the

* * value range set in the adjustment object */

new_val = gtk_progress_get_value( GTK_PROGRESS(data) ) + 50;

adj = GTK_PROGRESS (data)->adjustment;

if (new_val > adj->upper)

new_val = adj->lower;

/* Set the new value */

gtk_progress_set_value (GTK_PROGRESS (data), new_val);

/* As this is a timeout function, return TRUE so that it

* * continues to get called */

return(TRUE);

}

void destroy_progress( GtkWidget *widget,

ProgressData *pdata)

{

gtk_timeout_remove (pdata->timer);

pdata->timer = 0;

pdata->window = NULL;

g_free(pdata);

// gtk_main_quit();

}

void closeall()

{

gtk_main_quit();

}

 

 

 

 

 



Do you Yahoo!?
HotJobs - Search new jobs daily now

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]