Perspective: How to send function definitions to a docked View to use on button calls?

How can I send function definitions to a docked view, which buttons in the docked view would then call? I have tried using sendMessage to send the functions within the payload and then write these to functions defined on the root container, but I get this error:
AttributeError: 'com.inductiveautomation.perspective.gateway.script' object has no attribute 'onCancel'
I assume I can’t just overwrite a function definition by setting it to another function definition…

In Vision, I do this for my custom ‘confirm action’ popup window in order to allow the designer to customise what happens when the confirm or cancel buttons are pressed. I use the Window method putClientProperty to add a function to the Window. How would I do this in Perspective?

def confirmAction(event, message, fnOnYes, fnOnNo=None, yesLabel='Yes', noLabel='No', heading="Confirm Action"):
        - Requires the ppuConfirmAction popup
	# Example code to place on a button
tagPrefix = 'tagPath'

def fnOnYes():
	system.tag.write(tagPrefix + '/YesPB', 1)
def fnOnNo():
	#actions on no, otherwise can remove this function

title = 'Confirm Reset Flow Totaliser'
message = 'This will reset the runtime hours. Are you sure?'
shared.util.gui.confirmAction(event, message, fnOnYes, fnOnNo)
	window = system.nav.openWindow('Popups/ppuConfirmAction', {'_message':message, '_yesLabel':yesLabel, '_noLabel':noLabel, '_heading':heading})
	window.putClientProperty('functionOnYes', fnOnYes)
	window.putClientProperty('functionOnNo', fnOnNo)

I’m not sure you can. .putClientProperty() is a feature of Vision simply because Vision is built on top of Swing. Perspective isn’t built on top of a technology that offers arbitrary customizations like that. You might be able to assign to a custom view property of type Object…

A quick review of the SDK API doesn’t show any obvious way to do what you are trying.

I did try this, but it just comes back as a unicode string, something like <function onConfirm 0x40>

Would this be something that a custom module could provide a function for?

Probably not. It would have to be a change to the implementation of ViewModel or a related class, which only IA could do. (Unless something I’ve not seen in the API would apply.)

We’ve found that doing it the other way round has worked well for us. This is with embedded views instead of docked ones, but I think the same principle should hold.

We have a function menu view which takes an array of “buttons” as an input parameter. The parent view which needs a function menu embeds it and defines the buttons it needs.

Each button is opened up in its own embedded view within the function menu view, which contains a single button and has input parameters for key and label. When a user presses the button (or presses the defined hotkey) the script just calls

system.perspective.sendMessage("pressedFunctionMenuButton", payload=self.view.params.key, scope = "page")

Back on the parent view which contains the function menu, we define a message handler which receives the message and then executes the appropriate function.