This is an abbreviated version of what I am trying to do and it should run as-is in the Nasal console. Fair warning: the dialog won't close.
- Code: Select all
var MyDialog = {
new: func {
var m = {
parents: [MyDialog]
};
return m;
},
show: func {
var window = canvas.Window.new([300, 300], "MyDialog")
.set("title", "My Dialog");
var myCanvas = window.createCanvas()
.set("background", canvas.style.getColor("bg_color"));
var root = myCanvas.createGroup();
window.del = func {
me.cleanup(); # <--- ERROR ON THIS LINE: No such member: cleanup
call(canvas.Window.del, [], me);
}
},
cleanup: func {
print("Cleanup");
},
};
MyDialog.new().show();
When I hit the close button I get an error "No such member: cleanup" in the window.del function.
This is stretching my limited understanding of Nasal and closures but presumably this is because "me" is the window rather than my class? Is there a neat solution? Substituting code for the method call won't help, because I want to access members of my class using "me".
As an aside, this use of window.del with the call to the superclass method feels wrong to me. Shouldn't there be a window-close event akin to the button clicked and toggled events? In GTK you'd connect a callback function to the delete_event on the window, in Java Swing you'd add a window listener, etc.