If you want to use a thread and to prevent blocking, the thread code maybe 
something like this:

thread_func ()
{
  while (loop_condition)
    {
      /* do data acquisition */
      if (condition_1)
        g_idle_add ();
      if (condition_2)
        g_idle_add ();
      ...
      /* small delay */
    }
}

Like g_timeout_add*(), g_idle_add*() also call a GSourceFunc function. It runs 
in main thread,
so you can set your widget in the calling function.

--- ajhwb


--- adeelmali...@yahoo.com wrote:

From: Adeel Malik <adeelmali...@yahoo.com>
To: aj...@knac.com
Cc: gtk-app-devel-list@gnome.org
Subject: Re: Problem with continuous image updation
Date: Mon, 23 Mar 2009 00:35:41 -0700 (PDT)

Hi,
    In the button calback function I need to do data acquisition and processing 
in real-time before updating the status periodically (i.e every 1ms) using 
g_timeout_add function. So thatswhy there is a while loop in the callback 
function. 
Since current approach is not working, can I use threads in this case.
Adeel

--- On Fri, 3/20/09, Ardhan Madras <aj...@knac.com> wrote:

From: Ardhan Madras <aj...@knac.com>
Subject: Re: Problem with continuous image updation
To: adeelmali...@yahoo.com
Cc: gtk-app-devel-list@gnome.org
Date: Friday, March 20, 2009, 8:55 AM

Hi,

As i said before, don't try busy loop in the main loop bacause your program
is not 
responsive (depend on your CPU), so your program will not updated!. Look at
g_timeout_add*() 
manual, it is a integer (bool) function, if you returning TRUE (not 0) the the
source is called
again as given by the interval time. So you don't need a loop here, and you
only need to call
g_timeout*() function ONCE!. To remove the source, just provide mechanism to
returning FALSE (0)
value or use g_source_remove().

--- ajhwb


--- adeelmali...@yahoo.com wrote:

From: Adeel Malik <adeelmali...@yahoo.com>
To: aj...@knac.com
Cc: gtk-app-devel-list@gnome.org
Subject: Re: Problem with continuous image updation
Date: Thu, 19 Mar 2009 06:02:14 -0700 (PDT)

Hi Ardhan,
                Thanks for the reply. I modified the code as per your
suggestion by attaching the new source in the button callback function. I
observed that the source function was executed after a specified time
interval(e.g 200ms) but the display still couldn't update.
As there is a while loop in my button callback function, could you please
suggest whether I should call the g_timeout_add function in the while loop or
outside of it.
My current code structure looks like this:
button_callback(...)
{
gprint("button pressed");
while(...)
{
tag=g_timeout_add(200,showhide,NULL)
if(tag)
{
g_source_remove(tag)
tag=g_timeout_add(200,showhide,NULL)
}
check status;
....... other processing
}//end button callback function
static showhide ()
{
if (STATUS)
hide(RED) & show(GREEN)
else
hide(GREEN) & show(RED)
}

Regards,
Adeel
--- On Wed, 3/18/09, Ardhan Madras <aj...@knac.com> wrote:
From: Ardhan Madras <aj...@knac.com>
Subject: Re: Problem with continuous image updation
To: adeelmali...@yahoo.com
Cc: gtk-app-devel-list@gnome.org
Date: Wednesday, March 18, 2009, 5:05 PM

Looks like you want to update a widget state by running a busy loop in a main
loop 
or by using small delay. If you try this, your widget is never (look)
updated.., avoid 
using sleep or busy loop in the gtk_main() main loop. you should
try attach a new source with g_timeout_add*() functions, and set a timeout when
the function
should be called. Notice that g_timeout_add*() may be delayed. 

...
static gboolean
show_hide (gpointer data)
{
  static gboolean state = TRUE;
  if (state)
    {
      gtk_widget_show (green);
      gtk_widget_hide (red);
      state = FALSE;
    }
  else
    {
      gtk_widget_show (red);
      gtk_widget_hide (green);
      state = TRUE;
    }
  return TRUE;
}
...

and in the button callback, try:

....
g_timeout_add (200, (GSourceFunc) show_hide, NULL); /* call every 200ms */
....

to remove the source, use g_source_remove().

Another way is to create thread, then call g_idle_add() to set your widgets.

--- ajhwb


--- adeelmali...@yahoo.com wrote:

From: Adeel Malik <adeelmali...@yahoo.com>
To: Jim George <jimgeo...@gmail.com>
Cc: gtk-app-devel-list@gnome.org
Subject: Re: Problem with continuous image updation
Date: Wed, 18 Mar 2009 02:31:23 -0700 (PDT)



In my application, I am implementing status indication (displaying either
'red' or 'green' ) by using Gdkpixmap to assign an image to
'red' or 'green' pixel array. I display or hide the image by
calling gtk_widget_show (..) or gtk_widget_hide(..) once the start button is
clicked in the main gtk window.
The structure of my application is as follows:
 int main()
{
1.  Assign Pixmaps
2. Set up the start button
3. Wait for the start button press
3. rest in gtk_main ()
}
button_function(...)
{
 
//while loop
while (...)
{
..
if status=0
{
gtk_widget_hide(green);
gtk_widget_show(red);
}
else
{

gtk_widget_hide(red);
gtk_widget_show(green);
....
}
It appears that gtk is not upating the image during the whole course of while
loop (which is running at just 15 cycles/s) based on 'status' variable.
However, afer the while loop is finished, I get the updated status image. Could
someone suggest what additonal gtk calls I have to make to make sure that the
status image is updated (red or green) whenever there is a change in the value
of status variable in the while loop of ' start button' function.
 
Thanks,
Adeel

--- On Tue, 3/10/09, Jim George <jimgeo...@gmail.com> wrote:

From: Jim George <jimgeo...@gmail.com>
Subject: Re: Continuous variable updation in a text box
To: aj...@knac.com
Cc: gtk-app-devel-list@gnome.org
Date: Tuesday, March 10, 2009, 8:19 PM

It wouldn't matter too much, since most screens would only have a refresh
rate of 60-120 Hz, which is also much higher than what most people can even
see.

I've handled such cases by using g_idle_add when I get an update of the
variable's status, and have the idle function update the text box. I
preserve the event source ID for the next call, and check if that source is
still available. If so, I remove the event using g_source_remove and add a new
idle event. This way, the most recent update is shown on screen the next time
my
program goes idle. The idle function then marks the source as free, by setting
it to zero.

-Jim

Ardhan Madras wrote:
> So you will need call textbox insertion (update) 1000 times per second or
the textbox get updated every 1ms, my question is: Can you see it changes
correctly with given cycle?
> 
> --- adeelmali...@yahoo.com wrote:
> 
> From: Adeel Malik <adeelmali...@yahoo.com>
> To: gtk-app-devel-list@gnome.org
> Subject: Continuous variable updation in a text box
> Date: Tue, 10 Mar 2009 02:48:15 -0700 (PDT)
> 
> I intend to monitor the variable's value (acquired via data
acquisition hardware) at a rate of around 1,000 times per second.
> I haven't used textboxes before in GTK+. Could anyone suggest how to
update the value of a variable in a textbox etc., at this rate.
>  Thanks,
> Adeel
> 
> 
>       _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
> 
> 
> 
> 
> _____________________________________________________________
> Listen to KNAC, Hit the Home page and Tune In Live! --->
http://www.knac.com
> _______________________________________________
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

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



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




_____________________________________________________________
Listen to KNAC, Hit the Home page and Tune In Live! ---> http://www.knac.com







_____________________________________________________________
Listen to KNAC, Hit the Home page and Tune In Live! ---> http://www.knac.com







_____________________________________________________________
Listen to KNAC, Hit the Home page and Tune In Live! ---> http://www.knac.com
_______________________________________________
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