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"):
'''
Prerequisites:
- Requires the ppuConfirmAction popup
Usage:
# 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})
system.nav.centerWindow(window)
window.putClientProperty('functionOnYes', fnOnYes)
window.putClientProperty('functionOnNo', fnOnNo)