An object that contains a reference to a rendered cel (image) in the application.
from PySide6.QtGui import QPixmap, QScreen
from PySide6.QtWidgets import QApplication, QWidget, QLabel, QSizePolicy, QVBoxLayout
import tempfile
import math
import os
from ToonBoom import harmony
class ImageShow(QWidget):
def __init__(self):
super().__init__()
self.init()
def init(self):
self.setWindowTitle( "Render-Tester" )
self.label = QLabel(self)
self.pixmap = QPixmap()
def setImage(self, path, title, frame, count):
self.setWindowTitle( title )
frmn = frame-1
squared = int(math.sqrt(count)+0.5)
offsetx = frmn%squared
offsety = int(frmn/squared)
screenSize = QScreen.availableGeometry( QApplication.primaryScreen() )
width_target = screenSize.width()/squared
height_target = screenSize.height()/squared
self.resize( width_target, height_target )
self.pixmap.load( path )
self.label.setPixmap( self.pixmap.scaled( self.width(), self.height() ) );
frmX = ( screenSize.width () - self.width () ) / 2.0
frmY = ( screenSize.height() - self.height() ) / 2.0
self.move( offsetx*width_target, offsety*height_target )
self.show()
def resizeEvent( self, event ):
self.label.setPixmap( self.pixmap.scaled( self.width(), self.height() ) )
self.label.resize( self.width(), self.height() )
sess = harmony.session()
proj = sess.project
scene = proj.scene
nodes = scene.nodes
readnode = False
displayers = []
for node in nodes:
if node.type.upper() == "READ":
readnode = node
break
if readnode:
print( "Rendering %s"%(readnode.path) )
renderhandler = proj.create_render_handler()
frame_count = 25
def renderhandler_ready_frame( node, frame, cel ):
displayer = ImageShow()
displayers.append( displayer )
print( "Frame Ready : %s at %s"%(node.path, frame) )
frame_output = os.path.join( tempfile.gettempdir(), "%s.%05d.png"%(node.name, frame) )
print( "Saving to: %s"%(frame_output) )
cel.write( frame_output )
displayer.setImage( frame_output, "%s at %s"%(node.path, frame), frame, frame_count )
renderhandler.frame_ready_callback = renderhandler_ready_frame
renderhandler.node_add( readnode )
renderhandler.render( 1, frame_count )
else:
print( "Unable to find a Read Node to render." )