downloadFile & repaint issue
-
I'm using Server.downloadFile() to update .hxi's, and would like to have the Panel/Button display visual feedback but I'm having some difficulty with the download callback:
Server.downloadFile(library_updateURLs[this.data.index], {}, download_target, function() { if (this.data.finished) { Console.print("Finished"); this.data.downloading = false; //Swap SVG based on download state expButton[this.data.index].repaint(); } });
The Console Print line works, but the childpanel won't repaint. I assume it's a scope thing, but I've tried
this.repaint(); panel[i].repaint(); //The panels are in a loop already panel[this.data.index].repaint(); //Where this.data.index is a forced variable of i
And none seem to work.
-
Okay I see the issue, because the file download callback is on a different thread, the repaint outside the function calls before the download has finished.
But putting
this.repaint()
inside the download callback results in an error: function not found. -
@iamlamprey not at my computer but pretty certain Dave made a vid about this. Also think there’s a tutorial project from Christoph somewhere too that has this in.
-
The this reference in the callback is not pointing to the panel, you need to pass it in as lambda.
-
@Christoph-Hart said in downloadFile & repaint issue:
you need to pass it in as lambda.
Do you have an example of this handy? :)
-
I‘m on the go at the moment but if you search for lambda here in the forum you should find a post where I explain the feature.
-
@Christoph-Hart I've found the thread but still can't get it repainting
Server.downloadFile(library_updateURLs[this.data.index], {}, download_target, function[this]() { if (this.data.finished) { Console.print("Finished"); this.data.downloading = false; this.repaint(); } });
I assume literally passing "this" in isn't the right approach lol
-
@iamlamprey No this is a reserved keyword which you can't pass as lambda.
But if you copy it as a normal variable, it should work. Try:
// I don't know if you're in an inline function or not, so adapt the keyword // to match the scope varOrLocal thisFromFunction = this; Server.downloadFile(library_updateURLs[this.data.index], {}, download_target, function[thisFromFunction]() { if (this.data.finished) { Console.print("Finished"); this.data.downloading = false; thisFromFunction.repaint(); } });
-
@Christoph-Hart Yep that got it, cheers!