This is "the dog bug report"
.
When examining the different onNode* properties of the TreeBox object, I had to make some somersaults (spanish "voltereta"
) to make onNodeUpdated work. Check out this code:
#include <pjsr/Sizer.jsh>
#include <pjsr/FrameStyle.jsh>
#include <pjsr/NumericControl.jsh>
#include <pjsr/TextAlign.jsh>
#include <pjsr/StdButton.jsh>
#include <pjsr/StdIcon.jsh>
#include <pjsr/ColorSpace.jsh>
#include <pjsr/SampleType.jsh>
#include <pjsr/UndoFlag.jsh>
function kappa_sigma_dialog() {
this.__base__ = Dialog;
this.__base__();
this.target_List = new TreeBox (this);
this.target_List.setMinSize (400, 200);
this.target_List.headerVisible = true;
this.target_List.setHeaderText (0, "Views");
this.target_List.setHeaderAlignment (0, Align_Left);
this.target_List.onNodeClicked = function() {
var node = this.dialog.target_List.currentNode;
console.writeln (node.text (0));
}
this.target_List.onNodeUpdated = function() {
var node = this.dialog.target_List.currentNode;
console.writeln (node.text (0));
// var foo=0;
// for (bar in node) if (!foo++) { // beware of the dog!
// console.writeln (node.text (0));
// }
}
// Node creation helper
function addViewNode (parent, view) {
var node = new TreeBoxNode (parent);
node.checkable = true;
node.checked = false;
node.setText (0, view.fullId);
var image = view.image;
var metadata = format ("%5d x %5d x %d", image.width, image.height, image.numberOfChannels);
node.setText (1, metadata);
return node;
}
// Build the view tree structure
var windows = ImageWindow.windows;
for (var i = 0; i < windows.length; ++i) {
var node = addViewNode (this.target_List, windows[i].mainView);
node.expanded = false; // or true to initially expand all preview lists
var previews = windows[i].previews;
for (var j = 0; j < previews.length; ++j)
addViewNode (this.target_List, previews[j]);
}
this.target_List.sort();
}
kappa_sigma_dialog.prototype = new Dialog;
var dialog = new kappa_sigma_dialog();
dialog.execute();
There's a function onNodeClicked and another function onNodeUpdated. They are exactly the same, yet the code doesn't compile and triggers an error in line 28 (console.writeln in onNodeUpdated). Commenting that line out and uncommenting the "dog", it works as expected.
How did I reach that construct? I first tried:
for (bar in node) {
if ("checked" == bar) {
blah blah;
}
}
But then I realized that all properties of node are accessible, no matter in which iteration of the loop we're in. So I simplified the if and added a foo variable so that we only go through the real code once. Maybe a little more obscure than the original I know.
---
Another bug, that I wasn't able to reproduce until now (at last!
). I know I shouldn't be reporting two bugs in a single message, but I feel it's much easier in this case, because I'm reproducing it now with this code. We can call this the "cat" bug
.
What would you think if you pasted that code just to see that it compiles and runs, against my claims? Well, just try again! One out of two times, it compiles and runs; the other it won't. But there's more: when it runs, the event handlers don't get called. Try to click here and there and see the console stay silent. Not even the Cancel button would close the dialog (of course, since its handler doesn't get called) (there's no such button in this example).
I've found this while building KSIntegration. Sometimes everything worked fine until I clicked in the interface element I was working on, then the interface stopped responding as I've just shown. I then added debug statements (console.writeln ("still here 1")) until I reached the point where the error was, then the code didn't compile and PixInsight informed me of the exact problem. I felt like I had to hunt the wrong line, just to have PixInsight tell me "Finally, you've found it!
".
Now I've discovered that this happens without adding debug lines or anything. Just every second time.
I'm able to reproduce this by hitting F9 without explicitly saving the file. Maybe it doesn't show by saving or by using the mouse.