PhAB - forcing a widget to redraw itself

I’m trying to get a progress bar to increment itself by one x iterations
when a seperate button is pressed. Each increment is seperated by a
short delay so I can see the progress.

But unfortunately, the progress bar will only update itself after the
button press has completed its x number of iterations.

Eventually, I want my button press to start a thread that will increment
the progress bar in the background, one increment at a time. But when I
went down this path, my application kept dying.

However, in the meantime, I’d settle for just being able to see the for
loop increment the progress bar visually one step at a time. I’ve tried
using PtDamageWidget(), thinking that the damage event would force an
immediate redraw, but with no success. I would like to be able to force
a widget redraw on demand.

Any ideas?

thx

Eric


I’d change the world if I could remember my password

Ok, I just ran across some documentation in Lengthy Operations saying that
during a callback widgets aren’t redrawn… Bummer.

But life goes on…

So I am now trying one of the suggestions in Lengthy Operations which is to
create a timer on the fly. When the timer expires it should call a callback
to run my function. However its not working.

Here’s a code snippet…

PtWidget_t *timer;
int timer_cb ( PtWidget_t *, void *, PtCallbackInfo_t *);

timer = PtCreateWidget(PtTimer, Pt_DFLT_PARENT, 0, NULL);
PtAddCallback(timer, Pt_CB_TIMER_ACTIVATE, timer_cb, NULL);
PtSetResource(timer,Pt_ARG_TIMER_INITIAL,time,0 );
return( Pt_CONTINUE );

}

int timer_cb( PtWidget_t *widget, void *apinfo, PtCallbackInfo_t *cbinfo )
{
while (1)
{
incBar(1);
delay(50);
}
}

I know that incBar is working because I have another button which calls that
function directly and it works.

I guess my question is, If I set the initial time of my timer, does that
start the timer? Or do I have to start it?

thx

Eric

Eric Winger wrote:

I’m trying to get a progress bar to increment itself by one x iterations
when a seperate button is pressed. Each increment is seperated by a
short delay so I can see the progress.

But unfortunately, the progress bar will only update itself after the
button press has completed its x number of iterations.

Eventually, I want my button press to start a thread that will increment
the progress bar in the background, one increment at a time. But when I
went down this path, my application kept dying.

However, in the meantime, I’d settle for just being able to see the for
loop increment the progress bar visually one step at a time. I’ve tried
using PtDamageWidget(), thinking that the damage event would force an
immediate redraw, but with no success. I would like to be able to force
a widget redraw on demand.

Any ideas?

thx

Eric


I’d change the world if I could remember my password


I’d change the world if I could remember my password

A couple of comments:

  • To get your first solution to work, use PtFlush() after each change of the
    progress. This way, you don’t need to go back into the mainloop (leave the
    callback) to see the update. Problem here is that your application is
    blocked while the progress bar is moving.
  • Your second solution (using the timer) is much better - however you need
    to realize the timer widget and set the initial delay to 1 to get the timer
    going. Plus, there is a misunderstanding: In you snippet, the timer fires
    only once and does the complete operation. Instead, the timer should fire
    multiple times (set the repeat time) and each time the timer fires you
    increase the progress bar only one step (one time incBar(), no delay())
  • Your thread solution probably did not work because you did not use
    PtEnter() and PtLeave()
    Markus



    “Eric Winger” <ewinger@keyww.com> wrote in message
    news:3AEA0ABC.9D0DC516@keyww.com

Ok, I just ran across some documentation in Lengthy Operations saying that
during a callback widgets aren’t redrawn… Bummer.

But life goes on…

So I am now trying one of the suggestions in Lengthy Operations which is
to
create a timer on the fly. When the timer expires it should call a
callback
to run my function. However its not working.

Here’s a code snippet…

PtWidget_t *timer;
int timer_cb ( PtWidget_t *, void *, PtCallbackInfo_t *);

timer = PtCreateWidget(PtTimer, Pt_DFLT_PARENT, 0, NULL);
PtAddCallback(timer, Pt_CB_TIMER_ACTIVATE, timer_cb, NULL);
PtSetResource(timer,Pt_ARG_TIMER_INITIAL,time,0 );
return( Pt_CONTINUE );

}

int timer_cb( PtWidget_t *widget, void *apinfo, PtCallbackInfo_t *cbinfo )
{
while (1)
{
incBar(1);
delay(50);
}
}

I know that incBar is working because I have another button which calls
that
function directly and it works.

I guess my question is, If I set the initial time of my timer, does that
start the timer? Or do I have to start it?

thx

Eric

Eric Winger wrote:

I’m trying to get a progress bar to increment itself by one x iterations
when a seperate button is pressed. Each increment is seperated by a
short delay so I can see the progress.

But unfortunately, the progress bar will only update itself after the
button press has completed its x number of iterations.

Eventually, I want my button press to start a thread that will increment
the progress bar in the background, one increment at a time. But when I
went down this path, my application kept dying.

However, in the meantime, I’d settle for just being able to see the for
loop increment the progress bar visually one step at a time. I’ve tried
using PtDamageWidget(), thinking that the damage event would force an
immediate redraw, but with no success. I would like to be able to force
a widget redraw on demand.

Any ideas?

thx

Eric


I’d change the world if I could remember my password


I’d change the world if I could remember my password

Thx… Using the PtFlush in a non-threaded example worked.

And using the PtEnter & PtLeave got rid of my disappearing window bug in the
threaded version.

Haven’t had a chance to play with the Timer suggestions yet.

Eric

Markus Loffler wrote:

A couple of comments:

  • To get your first solution to work, use PtFlush() after each change of the
    progress. This way, you don’t need to go back into the mainloop (leave the
    callback) to see the update. Problem here is that your application is
    blocked while the progress bar is moving.

    \
  • Your second solution (using the timer) is much better - however you need
    to realize the timer widget and set the initial delay to 1 to get the timer
    going. Plus, there is a misunderstanding: In you snippet, the timer fires
    only once and does the complete operation. Instead, the timer should fire
    multiple times (set the repeat time) and each time the timer fires you
    increase the progress bar only one step (one time incBar(), no delay())
  • Your thread solution probably did not work because you did not use
    PtEnter() and PtLeave()
    Markus

“Eric Winger” <> ewinger@keyww.com> > wrote in message
news:> 3AEA0ABC.9D0DC516@keyww.com> …
Ok, I just ran across some documentation in Lengthy Operations saying that
during a callback widgets aren’t redrawn… Bummer.

But life goes on…

So I am now trying one of the suggestions in Lengthy Operations which is
to
create a timer on the fly. When the timer expires it should call a
callback
to run my function. However its not working.

Here’s a code snippet…

PtWidget_t *timer;
int timer_cb ( PtWidget_t *, void *, PtCallbackInfo_t *);

timer = PtCreateWidget(PtTimer, Pt_DFLT_PARENT, 0, NULL);
PtAddCallback(timer, Pt_CB_TIMER_ACTIVATE, timer_cb, NULL);
PtSetResource(timer,Pt_ARG_TIMER_INITIAL,time,0 );
return( Pt_CONTINUE );

}

int timer_cb( PtWidget_t *widget, void *apinfo, PtCallbackInfo_t *cbinfo )
{
while (1)
{
incBar(1);
delay(50);
}
}

I know that incBar is working because I have another button which calls
that
function directly and it works.

I guess my question is, If I set the initial time of my timer, does that
start the timer? Or do I have to start it?

thx

Eric

Eric Winger wrote:

I’m trying to get a progress bar to increment itself by one x iterations
when a seperate button is pressed. Each increment is seperated by a
short delay so I can see the progress.

But unfortunately, the progress bar will only update itself after the
button press has completed its x number of iterations.

Eventually, I want my button press to start a thread that will increment
the progress bar in the background, one increment at a time. But when I
went down this path, my application kept dying.

However, in the meantime, I’d settle for just being able to see the for
loop increment the progress bar visually one step at a time. I’ve tried
using PtDamageWidget(), thinking that the damage event would force an
immediate redraw, but with no success. I would like to be able to force
a widget redraw on demand.

Any ideas?

thx

Eric


I’d change the world if I could remember my password


I’d change the world if I could remember my password


I’d change the world if I could remember my password