How to update a ScriptUIGraphics object?
Hello,
I've been able to use ScriptUIGraphics, but as far as I've seen there's no way to update / change any object, nor it seems possible to call the onDraw() handler but once if it contains either fillPath() or strokePath() - which usually does.
For instance, the following test script pops up a panel with a red square in it. Fine. When you click the "Try" button, the onDraw() is fired again and should draw a smaller square, but stops with a very informative "cannot execute" error at some point within the onDraw():
// ScriptUI graphics update issue
// resource string
var winRes = "dialog { \
text: 'ScriptUI Graphics test', \
margins: 15, \
alignChildren: 'row', \
\
canvas: Panel { \
preferredSize: [200, 200], \
properties: {borderStyle: 'black'} , \
}, \
buttonsGroup: Group{ \
cancelButton: Button { text: 'Cancel', properties:{name:'cancel'} }, \
tryButton: Button { text: 'Try', properties:{name:'try'},size: [40,24], alignment:['right', 'center'] }, \
}, \
}"
// Window
var win = new Window(winRes);
// define the graphic property
canvasGraphics = win.canvas.graphics
// do the drawing
win.canvas.onDraw = function() {
// creates a red filled square
canvasGraphics.newPath()
canvasGraphics.rectPath(10, 10, 200, 200)
canvasGraphics.fillPath(canvasGraphics.newBrush(canvasGraphics.BrushType.SOLID_COLOR, [1,0,0,1], 1)) // HERE
}
win.buttonsGroup.tryButton.onClick = function() {
win.canvas.onDraw.call()
}
win.show()
When you run it, it works as expected; if you click the Try button, an error is fired when the script gets to the line ("HERE" in the code), that is: when it comes to fill the path.
Strangely enough! Because it doesn't seem to be a problem with the onDraw second call (apparently the second square path is constructed, but can't be filled).
Am I doing something wrong here? Should I first delete the original square (how?!), or somehow initialize it again? Are ScriptUIGraphics immutable somehow?
--- Update ---
Further experiments led me to understand that onDraw() (so the whole drawing) seem to be called just once - when the Window is shown. I've tried to remove and rebuild the canvas Panel altogether, but its own new onDraw() is never called - nor an explicit call works. Apparently you can't invoke win.show() again, nor hide and show it. Ouch!
--- ---
Thanks in advance for any suggestion
Davide
