OnStartup Timer [Perspective]

Hello There,

Would anyone be able to tell me how I could accomplish the following:

I would like a component on my page to only become visible 5 seconds after the page has been loaded.

Is there a way to do this?

Many thanks

  • There are two ways to do this, and it depends on the whether the parent container of the component is Coordinate or Flex. If in a Flex container, set Component.position.display to a value of false (boolean). If in a Coordinate Container, set Component.props.style.display to a value of ‘none’ (string).

  • In the onStartup Event of the View the component resides in:

  • Then:
  1. Right-click the component.
  2. Select “Configure Scripts”.
  3. Double Click “Add Handler…”
  4. Set the Message Type input to “FIVESECONDTIMER”.
  5. Leave the scope checkboxes alone.
  6. Supply the following code for the script:
from time import sleep
# Flex
self.props.display = True
# Coordinate
self.props.style.display = 'block'

You should be aware that this will happen in the Designer as well, so if you work on the View, the Button will appear after five seconds. If you save the View while the button is visible, then it will be immediately visible in sessions, so you should apply similar logic to make the button invisible immediately in the View’s onStartup Event.

Thank you for this info.

In the Vision world, we were always warned against using “sleep” within GUI scripts. Does Perspective handle this in a separate thread automatically?

It won’t hang the UI like in Vision but it’s still not a good idea. I would treat this suggestion as a quick hack at best.

1 Like

I have a separate thread going about setting the value of checkboxes within a FlexRepeater. I have not been able to get the bools set to the value I want on view startup unless I delay running the script. Since a sleep delay is still not a good idea, what do you suggest to trigger my script?