Hello everyone,
I am working on an Ignition project using Perspective, and I want to create a toast notification using a popup. The popup should automatically close after a certain delay (e.g., 5 seconds) without blocking the main thread. Here's what I've tried so far:
- Opening the Popup: I'm using
system.perspective.openPopup
, and that works perfectly. - Closing the Popup After Delay
- tried using
system.util.invokeAsynchronous
to create a separate thread and usedtime.sleep
to add a delay. - After the delay, I called
system.perspective.closePopup
to close the popup.
However, this doesn't seem to work as expected, but the closePopup
function does not execute or fails silently. Here's the relevant part of my code:
import system
import time
class ToastManager:
@staticmethod
def open_toast(popup_id, view_path, params=None, duration=5):
# Open the popup
system.perspective.openPopup(popup_id, view_path, params)
# Asynchronous task to close the popup after a delay
def async_task():
time.sleep(duration) # Wait for the specified duration
system.perspective.closePopup(popup_id) # Attempt to close the popup
system.util.invokeAsynchronous(async_task)
ToastManager.open_toast("myToastPopup", "PopupViews/MyToastView", {"message": "Hello, world!"}, 5)
The popup opens successfully, but the closePopup
function does not work. If I call the async_task
function directly it closes the popup with delay. But with invokeAsynchronous
it does not close or throw any error.
Where I am getting wrong on this? Seems like the invoke invokeAsynchronous
is not working. Where is this going wrong?
Platform
Ignition Platform 8.1.30 (b2023071408)
I only want to close the popup using project library scripting.
Questions
- Is it possible to call
system.perspective.closePopup
from an asynchronous thread usinginvokeAsynchronous
? - Do I need to use a different method to close the popup from a separate thread?
- Is there a recommended way to achieve this functionality in Ignition Perspective?