Jupyter notebook with Slicer Preview

I’ve fixed the issue (it was related to byte buffer to string conversion, probably changed because of switching to UTF-8). It should work in tomorrow’s build but until then you can copy-paste this into a cell, run it, and then you can use display2() for capturing screenshot of the view layout:

def display2():
    layoutManager = slicer.app.layoutManager()
    slicer.util.setViewControllersVisible(False)
    slicer.app.processEvents()
    slicer.util.forceRenderAllViews()
    screenshot = layoutManager.viewport().grab()
    slicer.util.setViewControllersVisible(True)
    bArray = qt.QByteArray()
    buffer = qt.QBuffer(bArray)
    buffer.open(qt.QIODevice.WriteOnly)
    screenshot.save(buffer, "PNG")
    slicer.modules.jupyterkernel.executeResultDataValue = bArray.toBase64().data().decode()
    slicer.modules.jupyterkernel.executeResultDataType = "image/png"
1 Like