Beispiel #1
0
def default_kernel_manager(kernel_app):
    from IPython.lib.kernel import find_connection_file
    from IPython.qt.manager import QtKernelManager
    connection = find_connection_file(kernel_app.connection_file)
    kernelManager = QtKernelManager(connection_file=connection)
    kernelClient = kernelManager.client()
    kernelClient.load_connection_file()
    kernelClient.start_channels()
    #atexit.register(kernelManager.cleanup_connection_file)
    return kernelManager, kernelClient, connection
Beispiel #2
0
    def __init__(self, parent=None, **kwargs):
        super(self.__class__, self).__init__(parent)
        self.app = app = guisupport.get_app_qt4()

        self.kernel_manager = QtKernelManager()
        self.kernel_manager.start_kernel()
        self.kernel_manager.kernel.gui = 'qt4'
        self.kernel_client = self.kernel_manager.client()
        self.kernel_client.start_channels()
        self.confirm_restart = False
Beispiel #3
0
class IPythonWidget(RichIPythonWidget):
    def __init__(self, parent=None, **kwargs):
        super(self.__class__, self).__init__(parent)
        self.app = app = guisupport.get_app_qt4()

        self.kernel_manager = QtKernelManager()
        self.kernel_manager.start_kernel()
        self.kernel_manager.kernel.gui = 'qt4'
        self.kernel_client=self.kernel_manager.client()
        self.kernel_client.start_channels()
        self.confirm_restart=False
Beispiel #4
0
class IPythonConsole(idaapi.PluginForm):
    def __init__(self, connection_file, *args):
        super(IPythonConsole, self).__init__(*args)
        self.connection_file = connection_file

    def OnCreate(self, form):
        try:
            if is_using_pyqt5():
                self.parent = self.FormToPyQtWidget(form,
                                                    ctx=sys.modules[__name__])
            else:
                self.parent = self.FormToPySideWidget(
                    form, ctx=sys.modules[__name__])
            layout = self._createConsoleWidget()
            self.parent.setLayout(layout)
        except:
            import traceback
            print(traceback.format_exc())

    def _createConsoleWidget(self):
        if is_using_pyqt5():
            layout = QtWidgets.QVBoxLayout()
        else:
            layout = QtGui.QVBoxLayout()
        connection_file = find_connection_file(self.connection_file)
        self.kernel_manager = QtKernelManager(connection_file=connection_file)
        self.kernel_manager.load_connection_file()
        self.kernel_manager.client_factory = QtKernelClient
        self.kernel_client = self.kernel_manager.client()
        self.kernel_client.start_channels()

        self.ipython_widget = RichIPythonWidget(self.parent)
        self.ipython_widget.kernel_manager = self.kernel_manager
        self.ipython_widget.kernel_client = self.kernel_client
        layout.addWidget(self.ipython_widget)

        return layout

    def Show(self, name="IPython Console"):
        return idaapi.PluginForm.Show(self, name)

    def OnClose(self, form):
        try:
            pass
        except:
            import traceback
            print(traceback.format_exc())
Beispiel #5
0
    def _createConsoleWidget(self):
        if is_using_pyqt5():
            layout = QtWidgets.QVBoxLayout()
        else:
            layout = QtGui.QVBoxLayout()
        connection_file = find_connection_file(self.connection_file)
        self.kernel_manager = QtKernelManager(connection_file=connection_file)
        self.kernel_manager.load_connection_file()
        self.kernel_manager.client_factory = QtKernelClient
        self.kernel_client = self.kernel_manager.client()
        self.kernel_client.start_channels()

        self.ipython_widget = RichIPythonWidget(self.parent)
        self.ipython_widget.kernel_manager = self.kernel_manager
        self.ipython_widget.kernel_client = self.kernel_client
        layout.addWidget(self.ipython_widget)

        return layout
Beispiel #6
0
 def _init_kernel_manager(self):
     connection_file = find_connection_file(self.app.connection_file)
     manager = QtKernelManager(connection_file=connection_file)
     manager.load_connection_file()
     manager.start_channels()
     atexit.register(manager.cleanup_connection_file)
     self.kernel_manager = manager
Beispiel #7
0
 def create_kernel_manager_and_client(self,
                                      connection_file=None,
                                      hostname=None,
                                      sshkey=None,
                                      password=None):
     """Create kernel manager and client"""
     cf = find_connection_file(connection_file, profile='default')
     kernel_manager = QtKernelManager(connection_file=cf, config=None)
     if programs.is_module_installed('IPython', '>=1.0'):
         kernel_client = kernel_manager.client()
         kernel_client.load_connection_file()
         if hostname is not None:
             try:
                 newports = tunnel_to_kernel(
                     dict(ip=kernel_client.ip,
                          shell_port=kernel_client.shell_port,
                          iopub_port=kernel_client.iopub_port,
                          stdin_port=kernel_client.stdin_port,
                          hb_port=kernel_client.hb_port), hostname, sshkey,
                     password)
                 (kernel_client.shell_port, kernel_client.iopub_port,
                  kernel_client.stdin_port,
                  kernel_client.hb_port) = newports
             except Exception as e:
                 QMessageBox.critical(
                     self, _('Connection error'),
                     _('Could not open ssh tunnel\n') + str(e))
                 return None, None
         kernel_client.start_channels()
         # To rely on kernel's heartbeat to know when a kernel has died
         kernel_client.hb_channel.unpause()
         return kernel_manager, kernel_client
     else:
         kernel_manager.load_connection_file()
         if hostname is not None:
             try:
                 newports = tunnel_to_kernel(
                     dict(ip=kernel_manager.ip,
                          shell_port=kernel_manager.shell_port,
                          iopub_port=kernel_manager.iopub_port,
                          stdin_port=kernel_manager.stdin_port,
                          hb_port=kernel_manager.hb_port), hostname, sshkey,
                     password)
                 (kernel_manager.shell_port, kernel_manager.iopub_port,
                  kernel_manager.stdin_port,
                  kernel_manager.hb_port) = newports
             except Exception as e:
                 QMessageBox.critical(
                     self, _('Connection error'),
                     _('Could not open ssh tunnel\n') + str(e))
                 return None, None
         kernel_manager.start_channels()
         return kernel_manager, None
Beispiel #8
0
def default_manager(kernel):
    """ Return a configured QtKernelManager

    :param kernel: An IPKernelApp instance
    """
    connection_file = find_connection_file(kernel.connection_file)
    manager = QtKernelManager(connection_file=connection_file)
    manager.load_connection_file()
    manager.start_channels()
    atexit.register(manager.cleanup_connection_file)
    return manager
 def create_kernel_manager_and_client(self, connection_file=None):
     """Create kernel manager and client"""
     cf = find_connection_file(connection_file, profile='default')
     kernel_manager = QtKernelManager(connection_file=cf, config=None)
     if programs.is_module_installed('IPython', '>=1.0'):
         kernel_client = kernel_manager.client()
         kernel_client.load_connection_file()
         kernel_client.start_channels()
         # To rely on kernel's heartbeat to know when a kernel has died
         kernel_client.hb_channel.unpause()
     else:
         kernel_client = None
         kernel_manager.load_connection_file()
         kernel_manager.start_channels()
     return kernel_manager, kernel_client
Beispiel #10
0
 def create_kernel_manager_and_client(self, connection_file=None,
                                      hostname=None, sshkey=None,
                                      password=None):
     """Create kernel manager and client"""
     cf = find_connection_file(connection_file, profile='default')
     kernel_manager = QtKernelManager(connection_file=cf, config=None)
     if programs.is_module_installed('IPython', '>=1.0'):
         kernel_client = kernel_manager.client()
         kernel_client.load_connection_file()
         if hostname is not None:
             try:
                 newports = tunnel_to_kernel(dict(ip=kernel_client.ip,
                                       shell_port=kernel_client.shell_port,
                                       iopub_port=kernel_client.iopub_port,
                                       stdin_port=kernel_client.stdin_port,
                                       hb_port=kernel_client.hb_port),
                                       hostname, sshkey, password)
                 (kernel_client.shell_port, kernel_client.iopub_port,
                  kernel_client.stdin_port, kernel_client.hb_port) = newports
             except Exception as e:
                 QMessageBox.critical(self, _('Connection error'), 
                                  _('Could not open ssh tunnel\n') + str(e))
                 return None, None
         kernel_client.start_channels()
         # To rely on kernel's heartbeat to know when a kernel has died
         kernel_client.hb_channel.unpause()
         return kernel_manager, kernel_client
     else:
         kernel_manager.load_connection_file()
         if hostname is not None:
             try:
                 newports = tunnel_to_kernel(dict(ip=kernel_manager.ip,
                                       shell_port=kernel_manager.shell_port,
                                       iopub_port=kernel_manager.iopub_port,
                                       stdin_port=kernel_manager.stdin_port,
                                       hb_port=kernel_manager.hb_port),
                                       hostname, sshkey, password)
                 (kernel_manager.shell_port, kernel_manager.iopub_port,
                  kernel_manager.stdin_port, kernel_manager.hb_port) = newports
             except Exception as e:
                 QMessageBox.critical(self, _('Connection error'), 
                                  _('Could not open ssh tunnel\n') + str(e))
                 return None, None
         kernel_manager.start_channels()
         return kernel_manager, None
Beispiel #11
0
 def connect_kernel(self, conn, heartbeat=False):
     km = QtKernelManager(connection_file=find_connection_file(conn))
     km.load_connection_file()
     km.start_channels(hb=heartbeat)
     self.kernel_manager = km
     atexit.register(self.kernel_manager.cleanup_connection_file)
Beispiel #12
0
def kernelmanager():
    kernel_manager = QtKernelManager()
    kernel_manager.start_kernel()
    #kernel = kernel_manager.kernel
    #kernel.gui = 'qt4'
    return kernel_manager