I have a Qt application with an embedded Jupyter QtConsole. This is the code that I use to create the Jupyter console:
from qtconsole.rich_jupyter_widget import RichJupyterWidget
from qtconsole.inprocess import QtInProcessKernelManager
class EmbeddedJupyterConsole(RichJupyterWidget):
def __init__(self, gui):
super(RichJupyterWidget, self).__init__(gui.ipython_container)
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
gui.ipython.kernel_manager = self.kernel_manager
gui.ipython.kernel_client = self.kernel_client
gui.ipython.exit_requested.connect(self.stop)
def executeCmd(self, cmd):
self.kernel.shell.ev(cmd)
def pushVar(self, **kwarg):
self.kernel.shell.push(kwarg)
def stop(self):
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
self.app.exit()
And this is the code that I use to generate the main Qt window:
class QtMainWindow(QMainWindow):
def __init__(self,app):
self.console = EmbeddedJupyterConsole(self)
# Initialize other widgets within the main window
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = QtMainWindow(app)
sys.exit(app.exec_())
Whenever I run this code, the Jupyter console and QtApplication work correctly. However, I also see the following error:
Traceback (most recent call last):
File "C:\...\Miniconda2\lib\site-packages\qtconsole\console_widget.py", line 464, in sizeHint
font_metrics = QtGui.QFontMetrics(self.font)
AttributeError: 'EmbeddedJupyterConsole' object has no attribute 'font'
If I add add a "fake" font property to the EmbeddedJupyterConsole, then I loose the nice format of the console and the error still appears. Does anyone know what is the issue and how to solve it?