Open popup from session event

Session Events have no context of “page”.

Consider the following code:

def runAction(self, event):
	"""
	This event is fired when the 'action' of the component occurs.

	Arguments:
		self: A reference to the component that is invoking this function.
		event: An empty event object.
	"""
    system.perspective.openPopup(“0”,‘Popups/PopupLoginAck’)

Note that you are NOT supplying a pageId. This sort of usage allows the thread in use to fallback to the page which is in use, because this is from a Button, which must belong to a View, which must belong to a Page in some capacity.

Now consider the following code:

def onBarcodeDataReceived(session, data, context):
	"""
	Called when a session is running in a native application and it has received
	barcode scan data

	Arguments:
		session: The perspective project session.
		data: The data returned from the barcode scan.
		context: The user-defined context object associated with the barcode
		         scan event.
	"""
    system.perspective.openPopup(“0”,‘Popups/PopupLoginAck’)

Note that you are still not supplying a pageId arg (or kwarg), but this script is NOT part of any component/View/Page. It does have information about the session it received the invocation from, but it has no context as to what page of that session to open the Popup on.

So, given that, there are two ways to do what you want:

  1. (Recommended) in the Barcode Scanned event, use system.perspective.sendMessage("BARCODESCANNED", payload={"data": data}, scope="session"), and then configure a Message Handler listener (named “BARCODESCANNED”) which then invokes your openPopup code.
  2. Loop through the available page Ids of the session object in the Barcode Scanned Event and invoke your code for each page of the session. This is not a good solution because it would open the Popup on EVERY page, instead of the page which originally scanned the barcode. I’ll include the code for this in case you want to try it.
for user_session in system.perspective.getSessionInfo():
    if user_session.id = session.props.id:  # if potential user session is this session
        for pageId in user_session.pageIds:  # for every page of this session
            system.perspective.openPopup(“0”,‘Popups/PopupLoginAck’, pageId=pageId)
1 Like