Multiple components using same pop up and message handler

Good morning, I hope everyone is well. I have a new question regarding pop ups and message handlers...I know I've asked more than a few recently haha. I've created a one line diagram for an electric distribution substation, and this one line has multiple relays on it. The relays all function similarly, and there are some controls aspects to the relays. The way it works is when the relay is clicked on a popup opens with live values and control points. When a state needs to be changed the operator clicks on the control point and a pop up opens and they have the option to toggle a boolean value, and this works well. The problem that I discovered is that if I have multiple relay popups open, the boolean state change propagates over every pop up that is open. So its obvious that I need to pass some sort of parameter that has the component name in it, and have it so that the message handler coming back from the popup is targeted to only that component. I'm just not sure how to do that. I've tried chat gpt and I can't seem to get it working just right.
Here is the script the component has for calling the popup:

def runAction(self, event):
	path = "confirmpopup52A"
	
	
	system.perspective.openPopup("confirmSelected", path,)

Here is the message handler on the component:

def onMessageReceived(self, payload):
	
   
	if payload['confirm']:
			self.custom.confirmedSelected = True
	else:
		self.custom.confirmedSelected = False

And here is the script on the pushbutton inside the popup:

messageType = 'toggleManual52A'

system.perspective.sendMessage(messageType,{'confirm': True}, scope = 'page')

I appreciate everyone's help and time with walking me through this.

Hi, Brian. Can you see that your code formatting and indentation (essential for scripting) is messed up? Please see Wiki - how to post code on this forum and then you can edit your post to fix each code block. Preview before posting!

Pass the tag path to the boolean as a string parameter to the popups. Perhaps with additional params for metadata, if you don't want to use properties on the tag for that.

This is not a job for messages.

3 Likes

Reading the doco for the openPopup function should help

I have now, where I am passing the state of the specific relay to the popup. I put a label field in the popup that reads that state of the switch on that particular device. When clicking through I can see that is reading either true or false and that is correctly matching what the device state is. So, small victory. Now the step is when the "close" or "open" buttons are pushed, I need to I think that tag path into the params going backwards so that it only impacts the one that called it correct?

Don't do this. Just pass the tag path and let the popup use an indirect binding. Make that indirect binding bidirectional, and your popup buttons scripts just need to write to that bound property to update the tag.

Let me repeat: Do not snapshot live values to pass as parameters to popups or nested views.

3 Likes

Is my mistake here that I am using message handlers to begin with? Should I just pass the tagpath to the popup, let it do its thing, and leave it at that?

1 Like

Yes

1 Like

Thank you guys for your help today, I was able to get it working as I was hoping. I appreciate everyone's time and energy.

1 Like