May-19-2023, 06:25 PM
(This post was last modified: May-19-2023, 06:25 PM by deanhystad.)
This is a new question. You should start a new thread.
What are you trying to do with qtconsole? There is no qtconsole.qt. I would be very surprised if there is a QtCore defined anywhere in qtconsole. QtCore is in PyQt5 along with QtWidget and QtGUI.
I used qtconsole in an application. I created a console window that I could open up to run interactive python.
What are you trying to do with qtconsole? There is no qtconsole.qt. I would be very surprised if there is a QtCore defined anywhere in qtconsole. QtCore is in PyQt5 along with QtWidget and QtGUI.
I used qtconsole in an application. I created a console window that I could open up to run interactive python.
from qtconsole.inprocess import QtInProcessKernelManager from qtconsole.rich_jupyter_widget import RichJupyterWidget from qtpy import QtWidgets import asyncio class Console(QtWidgets.QWidget): def __init__(self): super().__init__() # start an ipython kernel in this process and let it run with the Qt event loop self.kernel_manager = QtInProcessKernelManager() self.kernel_manager.start_kernel() self.kernel = self.kernel_manager.kernel self.kernel.shell.register_magic_function(self._back, "line", "BACK") self.kernel.shell.register_magic_function(self._where, "line", "WHERE") self.kernel.gui = "qt4" # use qt4, but works with PySide6 # there are issues if you enter quit() or exit() in the console # override these functions # self.kernel.shell.push({"quit": self._console_quit, "exit": self._console_quit}) self.contexts = [] self.kernel_client = self.kernel_manager.client() self.kernel_client.start_channels() self.control = RichJupyterWidget() self.control.kernel_manager = self.kernel_manager self.control.kernel_client = self.kernel_client box = QtWidgets.QVBoxLayout(self) box.addWidget(self.control) self.setWindowTitle("Console") def _with(self, object): """Set object as namespace""" # TBD Make this a magic function. Need to figure out how # to evaluate "line" argument passed as argument when called. self.contexts.insert(0, object) return self._update_context() def _back(self, _): """Restore previous namespace""" if len(self.contexts) > 1: self.contexts.pop(0) return self._update_context() return None def _where(self, _): """Display context history from current to starting""" return self.contexts def _update_context(self): """Update shell to use current context""" if len(self.contexts) == 0: return None obj = self.contexts[0] if isinstance(obj, dict): context = obj.copy() else: context = obj.__dict__.copy() # TBD make WITH a magic function context.update({"self": obj, "WITH": self._with}) self.kernel.shell.reset() self.kernel.shell.push(context) return obj def setcontext(self, context): """Set base context""" self.contexts = [context] self._update_context() def showEvent(self, event): """Execute when window is shown""" self._update_context() event.accept() def shutdown(self): """Shutdown the console and stop kernels.""" self.kernel_client.stop_channels() self.kernel_manager.shutdown_kernel() if __name__ == "__main__": import sys app = QtWidgets.QApplication(sys.argv) console = Console() console.setWindowTitle("In process IPython Kernel with qconsole") console.show() sys.exit(app.exec_())