Re: Problem with continuous image updation



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 <ajhwb knac com> wrote:
From: Ardhan Madras <ajhwb knac com>
Subject: Re: Problem with continuous image updation
To: adeelmalik78 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


--- adeelmalik78 yahoo com wrote:

From: Adeel Malik <adeelmalik78 yahoo com>
To: Jim George <jimgeorge 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 <jimgeorge gmail com> wrote:

From: Jim George <jimgeorge gmail com>
Subject: Re: Continuous variable updation in a text box
To: ajhwb 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?

--- adeelmalik78 yahoo com wrote:

From: Adeel Malik <adeelmalik78 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






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