def console_widget(manager): try: # Ipython v0.13 widget = RichIPythonWidget(gui_completion='droplist') except TraitError: # IPython v0.12 widget = RichIPythonWidget(gui_completion=True) widget.kernel_manager = manager return widget
def console_widget(manager): try: # Ipython v0.13 widget = RichIPythonWidget(gui_completion='droplist') except TraitError: # IPython v0.12 widget = RichIPythonWidget(gui_completion=True) widget.kernel_manager = manager return widget
def main(): # Print the ID of the main process print_process_id() app = guisupport.get_app_qt4() # Create an in-process kernel # >>> print_process_id() # will print the same process ID as the main process kernel_manager = QtInProcessKernelManager() kernel_manager.start_kernel() kernel = kernel_manager.kernel kernel.gui = 'qt4' kernel.shell.push({'foo': 43, 'print_process_id': print_process_id}) kernel_client = kernel_manager.client() kernel_client.start_channels() def stop(): kernel_client.stop_channels() kernel_manager.shutdown_kernel() app.exit() control = RichIPythonWidget() control.kernel_manager = kernel_manager control.kernel_client = kernel_client control.exit_requested.connect(stop) control.show() guisupport.start_event_loop_qt4(app)
def get_widget(self, droplist_completion=True): completion = 'droplist' if droplist_completion else 'plain' widget = RichIPythonWidget(gui_completion=completion) widget.kernel_manager = self.kernel_manager widget.kernel_client = self.kernel_client return widget
def __init__(self, app, imports=None, *args, **kwargs): QWidget.__init__(self, *args, **kwargs) self.app = app qtapp = self.app.getApp() kernel = InProcessKernel(gui='qt5') self.kernel = kernel self.shell = kernel.shell # Populate the kernel's namespace. kernel.shell.push({'api': self.app.api, 'self': self.app, 'shell': kernel.shell}) for plugin in self.app.pm.plugins: self.shell.push({plugin.name: plugin}) self.push = kernel.shell.push self.ex = kernel.shell.ex # Create a kernel manager for the frontend and register it with the kernel. km = QtInProcessKernelManager(kernel=kernel) km.start_channels() kernel.frontends.append(km) # Create the Qt console frontend. control = RichIPythonWidget() control.exit_requested.connect(qtapp.quit) control.kernel_manager = km control.show() self.widget = control self.imports = [ 'from PyQt4.QtCore import *', 'from PyQt4.QtGui import *', 'import json', 'import os, sys' ] if imports is not None and type(imports) is list: self.imports.extend(imports) for import_line in self.imports: kernel.shell.ex(import_line) self.setLayout(QVBoxLayout()) self.layout().addWidget(control) # self.addTab(control, 'Main') control.clear() self.app.api.echo = self.echo self.app.api.echoServerOutput = self.echoServerOutput self.app.api.setIPInput = self.set_input self.app.api.pushToIP = self.shell.push self.app.api.setIPCursor = self.setCursorPos
def main(): app = qapplication() mainwin = MainWindow() shell = RichIPythonWidget(local_kernel=False) shell.kernel_manager = init_kernel_manager() mainwin.insertPythonShell(shell) mainwin.show() app.exec_()
def terminal_widget(parent=None, **kwargs): kernel_app = default_kernel_app() manager = default_manager(kernel_app) widget = RichIPythonWidget(parent=parent, gui_completion='droplist') widget.kernel_manager = manager #update namespace kernel_app.shell.user_ns.update(kwargs) kernel_app.shell.user_ns['console'] = widget kernel_app.shell.run_cell( 'print("\\nAvailable variables are everything from pylab, “{}”, and this console as “console”")' .format('”, “'.join(kwargs.keys()))) kernel_app.start() return widget
def get_widget(self, droplist_completion=True): if IPython.__version__ < '0.13': completion = droplist_completion else: completion = 'droplist' if droplist_completion else 'plain' widget = RichIPythonWidget(gui_completion=completion) cf = find_connection_file(self.kernel_app.connection_file) km = QtKernelManager(connection_file=cf, config=widget.config) km.load_connection_file() km.start_channels() widget.kernel_manager = km atexit.register(km.cleanup_connection_file) sys.stdout = self._stdout sys.stderr = self._stderr sys.displayhook = self._dishook return widget
def _glue_terminal_1(**kwargs): """ Used for IPython v0.13, v0.12 """ kernel_app = default_kernel_app() manager = default_manager(kernel_app) try: # IPython v0.13 widget = RichIPythonWidget(gui_completion='droplist') except TraitError: # IPython v0.12 widget = RichIPythonWidget(gui_completion=True) widget.kernel_manager = manager # update namespace kernel_app.shell.user_ns.update(kwargs) # for debugging kernel_app.shell.user_ns['_kernel'] = kernel_app kernel_app.shell.user_ns['_manager'] = manager kernel_app.shell.user_ns['_widget'] = glue_terminal return widget
def make_terminal_widget(parent=None, **base_ns): try: gui_completion = _GUI_COMPLETION_CONVERT[kate.configuration[_GUI_COMPLETION_TYPE_CFG]] except KeyError: gui_completion = 'droplist' if gui_completion: widget = RichIPythonWidget(parent=parent, gui_completion=gui_completion) else: widget = RichIPythonWidget(parent=parent) widget.banner += i18n('\nAvailable variables are everything from pylab, “%1”, and this console as “console”', '”, “'.join(base_ns.keys())) client, manager, shell = init_ipython() # https://github.com/ipython/ipython/blob/master/examples/inprocess/embedded_qtconsole.py if ipython_1: widget.kernel_client = client widget.exit_requested.connect(widget.kernel_client.stop_channels) widget.exit_requested.connect(manager.shutdown_kernel) else: widget.exit_requested.connect(manager.cleanup_connection_file) widget.kernel_manager = manager base_ns['console'] = widget shell.user_ns.update(base_ns) try: projectPlugin = get_project_plugin() except AttributeError: projectPlugin = None if projectPlugin: def project_changed(*args, **kwargs): reset_shell(shell, base_ns) projectPlugin.projectFileNameChanged.connect(project_changed) project_changed() sys.stdout.flush() return widget
def main(): app = guisupport.get_app_qt4() # Create a kernel. # # Setting the GUI is not necessary for the normal operation of the kernel, # but it is used for IPython GUI's integration, particularly in pylab. By # default, the inline backend is used, which is safe under all toolkits. # # WARNING: Under no circumstances should another GUI toolkit, like wx, be # used when running a Qt application. This will lead to unexpected behavior, # including segfaults. kernel = InProcessKernel(gui='qt4') # Populate the kernel's namespace. kernel.shell.push({'x': 0, 'y': 1, 'z': 2}) # Create a kernel manager for the frontend and register it with the kernel. km = QtInProcessKernelManager(kernel=kernel) km.start_channels() kernel.frontends.append(km) # Create the Qt console frontend. control = RichIPythonWidget() control.exit_requested.connect(app.quit) control.kernel_manager = km control.show() # Execute some code directly. Note where the output appears. kernel.shell.run_cell('print "x=%r, y=%r, z=%r" % (x,y,z)') # Execute some code through the frontend (once the event loop is # running). Again, note where the output appears. do_later(control.execute, '%who') guisupport.start_event_loop_qt4(app)