本文整理汇总了Python中IPython.qt.inprocess.QtInProcessKernelManager类的典型用法代码示例。如果您正苦于以下问题:Python QtInProcessKernelManager类的具体用法?Python QtInProcessKernelManager怎么用?Python QtInProcessKernelManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QtInProcessKernelManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args, **kw):
super(MantidIPythonWidget, self).__init__(*args, **kw)
# Create an in-process kernel
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel = kernel_manager.kernel
kernel.gui = 'qt4'
# Figure out the full path to the mantidplotrc.py file and then %run it
from os import path
mantidplotpath = path.split(path.dirname(__file__))[0] # It's the directory above this one
mantidplotrc = path.join(mantidplotpath, 'mantidplotrc.py')
shell = kernel.shell
shell.run_line_magic('run',mantidplotrc)
# These 3 lines replace the run_code method of IPython's InteractiveShell class (of which the
# shell variable is a derived instance) with our method defined above. The original method
# is renamed so that we can call it from within the our_run_code method.
f = shell.run_code
shell.run_code = types.MethodType(our_run_code, shell)
shell.ipython_run_code = f
kernel_client = kernel_manager.client()
kernel_client.start_channels()
self.kernel_manager = kernel_manager
self.kernel_client = kernel_client
示例2: main
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)
示例3: show_ipython_console
def show_ipython_console():
# from https://github.com/ipython/ipython/blob/1.x/examples/inprocess/embedded_qtconsole.py
# this might be able to be a dockable panel at some point in the future.
# it should also only allow one window open at a time - I think it steals stdout at start
# and opening a new window stops output working on the old one!
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_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)
示例4: __init__
def __init__(self):
QMainWindow.__init__(self)
self.hsplit = QSplitter()
self.setCentralWidget(self.hsplit)
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
self.kernel = kernel_manager.kernel
self.kernel.gui = 'qt'
self.control = RichIPythonWidget(gui_completion="droplist")
self.kernel.shell.push({'snipdom': self})
kernel_client = kernel_manager.client()
kernel_client.start_channels()
self.control.kernel_manager = kernel_manager
self.control.kernel_client = kernel_client
self.vsplit = QSplitter()
self.vsplit.setOrientation(Qt.Vertical)
self.vsplit.addWidget(self.control)
self.hsplit.addWidget(self.vsplit)
self.sendButton = QPushButton("send")
#self.sendButton.clicked.connect(self.sendcode)
self.vsplit.addWidget(self.sendButton)
self.bridge = Js2Py()
self.bridge.sent.connect(self.codeFromJs)
示例5: initialize
def initialize(self):
# Init your plugin
self.misc_s = self.locator.get_service('misc')
explorer_container = self.locator.get_service('explorer')
tree = explorer_container.get_tree_projects()
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel = kernel_manager.kernel
kernel.gui = 'qt4'
kernel_client = kernel_manager.client()
kernel_client.start_channels()
def stop():
kernel_client.stop_channels()
kernel_manager.shutdown_kernel()
self.ipython_console = RichIPythonWidget()
self.ipython_console.kernel_manager = kernel_manager
self.ipython_console.kernel_client = kernel_client
self.ipython_console.exit_requested.connect(stop)
self.ipython_console.show()
self.misc_s.add_widget(self.ipython_console, IMAGES["console"],
"IPython console")
addp = SIGNAL("addProjectToConsole(QString)")
delp = SIGNAL("removeProjectFromConsole(QString)")
self.connect(tree, addp, self._add_project)
self.connect(tree, delp, self._del_project)
示例6: __init__
def __init__(self, main_window):
"""
desc:
Constructor.
arguments:
main_window: The main window object.
"""
super(ipython_console, self).__init__(main_window)
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
self.kernel = kernel_manager.kernel
self.kernel.gui = 'qt4'
self.kernel.shell.banner1 = ''
kernel_client = kernel_manager.client()
kernel_client.start_channels()
self.control = RichIPythonWidget()
self.control.banner = self.banner()
self.control.kernel_manager = kernel_manager
self.control.kernel_client = kernel_client
self.verticalLayout = QtGui.QVBoxLayout(self)
self.verticalLayout.setContentsMargins(0,0,0,0)
self.setLayout(self.verticalLayout)
self.verticalLayout.addWidget(self.control)
示例7: in_process_console
def in_process_console(console_class=RichIPythonWidget, **kwargs):
"""Create a console widget, connected to an in-process Kernel
This only works on IPython v 0.13 and above
Parameters
----------
console_class : The class of the console widget to create
kwargs : Extra variables to put into the namespace
"""
km = QtInProcessKernelManager()
km.start_kernel()
kernel = km.kernel
kernel.gui = 'qt4'
client = km.client()
client.start_channels()
control = console_class()
control.kernel_manager = km
control.kernel_client = client
control.shell = kernel.shell
control.shell.user_ns.update(**kwargs)
return control
示例8: __init__
def __init__(self, parent):
from logging import getLogger, CRITICAL
logger=getLogger()
silenced=None
for handler in logger.handlers:
if handler.__class__.__name__=='QtHandler':
silenced=handler
old_level=silenced.level
silenced.setLevel(CRITICAL+1)
break
RichIPythonWidget.__init__(self)
self._parent=parent
self.buffer_size=10000 # increase buffer size to show longer outputs
self.set_default_style(colors='linux')
if IPython.__version__<'1.0':
kernelapp=IPythonLocalKernelApp.instance()
kernelapp.initialize()
self.connect_kernel(connection_file=kernelapp.get_connection_file())
else:
kernel_manager=QtInProcessKernelManager(config=self.config, gui='qt4')
kernel_manager.start_kernel()
self.kernel_manager=kernel_manager
self.kernel_client=kernel_manager.client()
self.kernel_client.start_channels()
ip=get_ipython()
# console process exceptions (IPython controlled)
ip.set_custom_exc((Exception,), ip_excepthook_overwrite)
self.namespace=ip.user_ns
self.namespace['IP']=self
self.namespace['app']=QtGui.QApplication.instance()
self.namespace['gui']=parent
self.namespace['plot']=self._plot
if silenced:
silenced.setLevel(old_level)
示例9: main
def main():
"""Start kernel manager and client, create window, run app event loop"""
app = guisupport.get_app_qt4()
if INPROCESS:
from IPython.qt.inprocess import QtInProcessKernelManager
km = QtInProcessKernelManager()
else:
from IPython.qt.manager import QtKernelManager
km = QtKernelManager()
km.start_kernel()
km.kernel.gui = 'qt4'
kc = km.client()
kc.start_channels()
widget = RichIPythonWidget()
widget.kernel_manager = km
widget.kernel_client = kc
if CLEANSHUTDOWN: # slow exit on CTRL+D
def stop():
kc.stop_channels()
km.shutdown_kernel()
app.exit()
widget.exit_requested.connect(stop)
else: # fast exit on CTRL+D
widget.exit_requested.connect(app.quit)
widget.show()
guisupport.start_event_loop_qt4(app)
示例10: IPythonView
class IPythonView(QtGui.QWidget):
def __init__(self, parent=None, getfocus=None):
super(IPythonView, self).__init__(parent)
# Create an in-process kernel
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.shell = self.kernel.shell
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
self.control = RichIPythonWidget()
self.control.set_default_style(colors='linux')
self.control.kernel_manager = self.kernel_manager
self.control.kernel_client = self.kernel_client
self.control.exit_requested.connect(self.stop)
# Enable Pylab mode.
self.shell.enable_pylab()
self.shell.automagic = True
# Add some variables in the namespace.
self.push(galry=galry)
box = QtGui.QVBoxLayout()
box.addWidget(self.control)
box.setContentsMargins(0, 0, 0, 0)
box.setSpacing(0)
self.setLayout(box)
def stop(self, *args):
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
# Public methods.
# ---------------
def set_data(self, **kwargs):
self.push(**kwargs)
def push(self, **kwargs):
"""Inject variables in the interactive namespace."""
self.shell.push(kwargs)
def run_file(self, file):
"""Execute a Python file in the interactive namespace."""
self.shell.safe_execfile(file, self.shell.user_global_ns)
def run_cell(self, *args, **kwargs):
"""Execute a cell."""
self.shell.run_cell(*args, **kwargs)
示例11: EmbedIPython
class EmbedIPython(RichIPythonWidget):
def __init__(self, **kwarg):
super(RichIPythonWidget, self).__init__()
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = "qt4"
self.kernel.shell.push(kwarg)
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
示例12: _setup_kernel
def _setup_kernel(self):
""" Setup the kernel for the widget.
"""
kernel_manager = QtInProcessKernelManager()
kernel_manager.start_kernel()
kernel_client = kernel_manager.client()
kernel_client.start_channels()
ipy_widget = self.ipy_widget
ipy_widget.kernel_manager = kernel_manager
ipy_widget.kernel_client = kernel_client
示例13: __init__
def __init__(self, parent=None, getfocus=None):
super(IPythonView, self).__init__(parent)
# Create an in-process kernel
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.shell = self.kernel.shell
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
self.control = RichIPythonWidget()
self.control.set_default_style(colors='linux')
self.control.kernel_manager = self.kernel_manager
self.control.kernel_client = self.kernel_client
self.control.exit_requested.connect(self.stop)
# Enable Pylab mode.
self.shell.enable_pylab()
self.shell.automagic = True
# Add some variables in the namespace.
self.push(galry=galry)
box = QtGui.QVBoxLayout()
box.addWidget(self.control)
box.setContentsMargins(0, 0, 0, 0)
box.setSpacing(0)
self.setLayout(box)
示例14: main
def main(self):
# Print the ID of the main process
#self.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
self.kernel_manager = QtInProcessKernelManager()
self.kernel_manager.start_kernel()
self.kernel = self.kernel_manager.kernel
self.kernel.gui = 'qt4'
self.kernel.shell.push(self.common.__dict__)
self.kernel_client = self.kernel_manager.client()
self.kernel_client.start_channels()
def stop():
self.kernel_client.stop_channels()
self.kernel_manager.shutdown_kernel()
#app.exit()
self.control = RichIPythonWidget(banner = self.banner)
self.control.kernel_manager = self.kernel_manager
self.control.kernel_client = self.kernel_client
self.control.exit_requested.connect(stop)
#start widget with certain inputs:
#import pylab, which includes all numpy; import pandas as pd
#second argument is whether the execution is hidden e.g. whether a line is used
#I have turned on hide.
self.control._execute('import pylab as pl; import pandas as pd',True)
示例15: __init__
def __init__( self, parent ):
super(self.__class__, self).__init__(parent)
# Create an in-process kernel
kernel = InProcessKernel(gui='qt4')
kernel_manager = QtInProcessKernelManager(kernel=kernel)
kernel_manager.start_kernel()
kernel_client = kernel_manager.client()
kernel_client.start_channels()
self.kernel_manager = kernel_manager
self.kernel_client = kernel_client
self.kernel = kernel
self.exit_requested.connect(self._stop)
self.show()