Skip to content

Instantly share code, notes, and snippets.

@bob-ross27
Created November 23, 2021 13:13
Show Gist options
  • Save bob-ross27/4ec7b518392493d60635108a4d006e8f to your computer and use it in GitHub Desktop.
Save bob-ross27/4ec7b518392493d60635108a4d006e8f to your computer and use it in GitHub Desktop.
Example of using QProgressDialog with the render class in Toon Boom Harmony.
/**
* Example of using a QProgressDialog with the render class in Harmony.
*/
function renderDialogExample() {
/**
* Create the progress dialog
* @param {int} frames - Number of frames to use as the maximum value
* @returns {QProgressDialog} progressUI - The created QProgressDialog
*/
function createUI(frames) {
var progressUI = new QProgressDialog(
"\nRendering...",
"Cancel",
0,
frames,
this,
Qt.FramelessWindowHint
);
progressUI.modal = true; // Ensure the user can't change focus during render
progressUI.setCancelButton(null); // Supporting cancel is beyond the scope of this example
progressUI.autoReset = false; // The dialog will stay at 100% after completion instead of resetting to 0% automatically.
progressUI.value = 0; // Set the initial progress value
progressUI.minimumDuration = 0; // Always show the dialog
return progressUI;
};
/**
* Called by the render class when a frame is completed.
* Save the frame to disk and add to the array of completed frames.
* @param {int} frame - Number of the rendered frame
* @param {Cel} celImage - Frame object for file storage operations
*/
function frameReady(frame, celImage) {
var filename = scene.currentProjectPath() + "/frames/" + frame + ".png";
celImage.imageFile(filename);
renderedFrames.push(filename);
this.ui.value += 1; // Increment the progress value.
}
/**
* Called by the render class when the entire render is completed.
* Use the rendered frames to generate an OpenH264 .mov using WebCCExporter.
*/
function renderFinished() {
this.ui.setLabelText("Generating video output...");
QCoreApplication.processEvents(); // Force the application to process UI events and update the dialog label
var moviePath = scene.currentProjectPath() + "/frames/example.mov"
WebCCExporter.exportMovieFromFiles(moviePath, renderedFrames);
this.ui.close();
}
this.ui = createUI(frame.numberOf());
this.ui.show();
var renderedFrames = [];
render.frameReady.connect(this, frameReady);
render.renderFinished.connect(this, renderFinished);
render.setRenderDisplay("Top/Display");
render.renderSceneAll();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment