Delay after display of Window Module

Hi All,
On Base Window I created Button, in this button Activate callback
function, I written code like this:

{
ApCreateModule (ABM_NewWindow, NULL, NULL)
sleep(2);
}
By this iam able crate NewWindow, but this NewWindow apperaing after
2 seconds dalay.

But I want display first NewWindow and then 2 seconds delay. For
this what should i do, and what are the flags i need to select?

Thanks,
Suresh Kumar. Kavula

“Suresh Kumar” <skavula@nordson.com> wrote in message
news:cea5lj$1k4$1@inn.qnx.com

Hi All,
On Base Window I created Button, in this button Activate callback
function, I written code like this:

{
ApCreateModule (ABM_NewWindow, NULL, NULL)
sleep(2);
}
By this iam able crate NewWindow, but this NewWindow apperaing
after
2 seconds dalay.

But I want display first NewWindow and then 2 seconds delay. For
this what should i do, and what are the flags i need to select?

Thanks,
Suresh Kumar. Kavula
The reason that New Window appears after a 2 second delay is that you are

sleeping in the callback function. Though you call ApCreateModule in your
callback function, New Window is actually realized by photon from the
PtMainLoop function after the callback function returns a value of
Pt_CONTINUE. (If you return Pt_HALT, New Window will be created but not
realized. If you return Pt_END, New Window will be destroyed.)
One way to have New Window displayed 2 seconds after the user pushes the
Button, is to do something like;

  1. create a PtTimer widget.
  2. In the button callback;
    2a) save the pointer returned by ApCreateModule in a global variable
    2b) arm the PtTimer widget to fire after 2 seconds
    2c) return Pt_HALT from the button callback
  3. In the PtTimer’s Pt_CB_TIMER_ACTIVATE callback funtion, use
    PtRealizeWidget to realize New Window.

“Suresh Kumar” <skavula@nordson.com> wrote in message
news:cea5lj$1k4$1@inn.qnx.com

On Base Window I created Button, in this button Activate callback
function, I written code like this:

ApCreateModule (ABM_NewWindow, NULL, NULL)
sleep(2);
By this iam able crate NewWindow, but this NewWindow apperaing
after
2 seconds dalay.

Does the window have a frame? I would expect the frame to show up before
the sleep(), but the window’s contents after.

What is happenning is that ApCreateModule() creates and realizes the widgets
and then returns. The widgets haven’t drawn anything at this point –
they’re just marked as “damaged”, which will cause them to draw as soon as
the global “hold count” goes to zero (take a look at PtHold() in the docs).
The Photon library increments the hold count before invoking any callback
and decrements it after the callback returns – this way, all the widgets
that a callback modifies or creates draw just once, right after the callback
returns, even if the callback modifies a widget several times. (Think about
a callback that changes a widget’s background colour, then size, then font,
then text colour, and finally the text. If each of those changes caused the
widget to draw its new state to the screen right away, it would look pretty
bad.)

If you need to force a damaged widget to draw regardless of the hold count,
call PtFlush(). But it’s somewhat heavy-handed – it causes all the
damaged widgets in your application to draw.

(In case you wondered: the reason the window frame doesn’t pay attention to
your hold count is because it’s the window manager, not your application,
that draws it.)

But I want display first NewWindow and then 2 seconds delay. For
this what should i do, and what are the flags i need to select?

Calling PtFlush() before the sleep() should make the window draw right away;
but in general, using sleep() in a single-threaded Photon application is not
a good idea. During those two seconds, the application will do literally
nothing – it won’t react to user input, it won’t redraw itself if you drag
a window in front of it or switch consoles, and so on. It’s better to set
up a timer widget and do whatever you wanted to do after the delay in the
timer’s callback. If you don’t want the person to click on any buttons
during the two seconds, block the window (using the Pt_BLOCKED flag) – this
way it will ignore any user input but will redraw when necessary.

“John McClurkin” <jwm@lsr.nei.nih.gov> wrote in message
news:cealhu$ehk$1@inn.qnx.com

“Suresh Kumar” <> skavula@nordson.com> > wrote in message
news:cea5lj$1k4$> 1@inn.qnx.com> …
Hi All,
On Base Window I created Button, in this button Activate callback
function, I written code like this:
ApCreateModule (ABM_NewWindow, NULL, NULL)
sleep(2);
By this iam able crate NewWindow, but this NewWindow apperaing
after
2 seconds dalay.

But I want display first NewWindow and then 2 seconds delay.
For
this what should i do, and what are the flags i need to select?

The reason that New Window appears after a 2 second delay is that you are
sleeping in the callback function. Though you call ApCreateModule in your
callback function, New Window is actually realized by photon from the
PtMainLoop function after the callback function returns a value of
Pt_CONTINUE. (If you return Pt_HALT, New Window will be created but not
realized. If you return Pt_END, New Window will be destroyed.)

Um, not quite.

ApCreateModule() does realize the window. This asks the window manager to
open a window and create a region for it, and it also marks the window and
all the widgets in it as damaged. The window is realized at this point, it
just hasn’t drawn its contents yet. That’s an important difference.
“Realized” doesn’t necessarily mean that the widget is visible on the
screen. It just means that it will be, as soon as the Photon library takes
care of updating any damaged widgets.

Returning Pt_HALT indeed causes the widget to be left unrealized, and Pt_END
to be destroyed, but you have to return them from a PhAB module’s
pre-realize setup function. The callback in question is not a setup
function – it’s a button’s activate callback. I don’t think we have been
told whether the new window has a setup function or not; if it does, it’s
called before ApCreateWidget() returns.

One way to have New Window displayed 2 seconds after the user pushes
the
Button, is to do something like;

  1. create a PtTimer widget.
  2. In the button callback;
    2a) save the pointer returned by ApCreateModule in a global
    variable
    2b) arm the PtTimer widget to fire after 2 seconds
    2c) return Pt_HALT from the button callback
  3. In the PtTimer’s Pt_CB_TIMER_ACTIVATE callback funtion, use
    PtRealizeWidget to realize New Window.

No, this won’t work: it’s the module’s setup function that needs to return
Pt_HALT to prevent the window from getting realized. But unless you
actually need the unrealized widgets to exist during the two-second delay,
it might be much simpler to call ApCreateModule() from the PtTimer’s
callback rather than from the button’s.

Hi Lerch,
Thanks for your Inputs, its working fine, how i want.
Thanks onece again,
Suresh Kumar. Kavula

“Wojtek Lerch” <Wojtek_L@yahoo.ca> wrote in message
news:ceb1lp$nnr$1@inn.qnx.com

“Suresh Kumar” <> skavula@nordson.com> > wrote in message
news:cea5lj$1k4$> 1@inn.qnx.com> …
On Base Window I created Button, in this button Activate callback
function, I written code like this:

ApCreateModule (ABM_NewWindow, NULL, NULL)
sleep(2);
By this iam able crate NewWindow, but this NewWindow apperaing
after
2 seconds dalay.

Does the window have a frame? I would expect the frame to show up before
the sleep(), but the window’s contents after.

What is happenning is that ApCreateModule() creates and realizes the
widgets
and then returns. The widgets haven’t drawn anything at this point –
they’re just marked as “damaged”, which will cause them to draw as soon as
the global “hold count” goes to zero (take a look at PtHold() in the
docs).
The Photon library increments the hold count before invoking any callback
and decrements it after the callback returns – this way, all the widgets
that a callback modifies or creates draw just once, right after the
callback
returns, even if the callback modifies a widget several times. (Think
about
a callback that changes a widget’s background colour, then size, then
font,
then text colour, and finally the text. If each of those changes caused
the
widget to draw its new state to the screen right away, it would look
pretty
bad.)

If you need to force a damaged widget to draw regardless of the hold
count,
call PtFlush(). But it’s somewhat heavy-handed – it causes all the
damaged widgets in your application to draw.

(In case you wondered: the reason the window frame doesn’t pay attention
to
your hold count is because it’s the window manager, not your application,
that draws it.)

But I want display first NewWindow and then 2 seconds delay.
For
this what should i do, and what are the flags i need to select?

Calling PtFlush() before the sleep() should make the window draw right
away;
but in general, using sleep() in a single-threaded Photon application is
not
a good idea. During those two seconds, the application will do literally
nothing – it won’t react to user input, it won’t redraw itself if you
drag
a window in front of it or switch consoles, and so on. It’s better to set
up a timer widget and do whatever you wanted to do after the delay in the
timer’s callback. If you don’t want the person to click on any buttons
during the two seconds, block the window (using the Pt_BLOCKED flag) –
this
way it will ignore any user input but will redraw when necessary.