コード例 #1
0
ファイル: qtconsoleapp.py プロジェクト: sratcliffe/ipython
    def init_kernel_manager(self):
        # Don't let Qt or ZMQ swallow KeyboardInterupts.
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        sec = self.profile_dir.security_dir
        try:
            cf = filefind(self.connection_file, ['.', sec])
        except IOError:
            # file might not exist
            if self.connection_file == os.path.basename(self.connection_file):
                # just shortname, put it in security dir
                cf = os.path.join(sec, self.connection_file)
            else:
                cf = self.connection_file

        # Create a KernelManager and start a kernel.
        self.kernel_manager = QtKernelManager(
            ip=self.ip,
            shell_port=self.shell_port,
            iopub_port=self.iopub_port,
            stdin_port=self.stdin_port,
            hb_port=self.hb_port,
            connection_file=cf,
            config=self.config,
        )
        # start the kernel
        if not self.existing:
            kwargs = dict(ipython=not self.pure)
            kwargs['extra_arguments'] = self.kernel_argv
            self.kernel_manager.start_kernel(**kwargs)
        elif self.sshserver:
            # ssh, write new connection file
            self.kernel_manager.write_connection_file()
        self.kernel_manager.start_channels()
コード例 #2
0
ファイル: draft_terminal.py プロジェクト: peper0/sdupy
def default_manager(kernel):
    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
コード例 #3
0
 def _init_kernel_manager(self):
     km = QtKernelManager(connection_file=self._connection_file,
                          config=self.config)
     km.load_connection_file()
     km.start_channels(hb=self._heartbeat)
     self.kernel_manager = km
     atexit.register(self.kernel_manager.cleanup_connection_file)
コード例 #4
0
  def __init__(self):
    QMainWindow.__init__(self)
    self.resize(1000,1000)

    self.kernel = QtKernelManager()
    self.kernel.start_kernel()
    self.kernel.start_channels()

    self.console = IPythonWidget()
    self.console.kernel_manager = self.kernel
    self.setCentralWidget(self.console)
コード例 #5
0
    def __init__(self, parent=None):

        QDialog.__init__(self, parent)

        self.main_window = parent
        self.kernel_manager = QtKernelManager()
        self.kernel_manager.start_kernel()
        self.kernel_manager.start_channels()
        self.console = IPythonWidget(local_kernel=LOCALHOST)
        self.console.kernel_manager = self.kernel_manager
        self.verticalLayout = QVBoxLayout(self)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(self.verticalLayout)
        self.verticalLayout.addWidget(self.console)
コード例 #6
0
    def init_kernel_manager(self):
        # Don't let Qt or ZMQ swallow KeyboardInterupts.
        signal.signal(signal.SIGINT, signal.SIG_DFL)

        # Create a KernelManager and start a kernel.
        self.kernel_manager = QtKernelManager(
                                shell_address=(self.ip, self.shell_port),
                                sub_address=(self.ip, self.iopub_port),
                                stdin_address=(self.ip, self.stdin_port),
                                hb_address=(self.ip, self.hb_port),
                                config=self.config
        )
        # start the kernel
        if not self.existing:
            kwargs = dict(ip=self.ip, ipython=not self.pure)
            kwargs['extra_arguments'] = self.kernel_argv
            self.kernel_manager.start_kernel(**kwargs)
        self.kernel_manager.start_channels()
コード例 #7
0
 def new_frontend_slave(self, current_widget):
     """Create and return a new frontend attached to an existing kernel.
     
     Parameters
     ----------
     current_widget : IPythonWidget
         The IPythonWidget whose kernel this frontend is to share
     """
     kernel_manager = QtKernelManager(
         connection_file=current_widget.kernel_manager.connection_file,
         config=self.config,
     )
     kernel_manager.load_connection_file()
     kernel_manager.start_channels()
     widget = self.widget_factory(config=self.config, local_kernel=False)
     widget._existing = True
     widget._may_close = False
     widget._confirm_exit = False
     widget.kernel_manager = kernel_manager
     return widget
コード例 #8
0
 def new_frontend_master(self):
     """ Create and return new frontend attached to new kernel, launched on localhost.
     """
     ip = self.ip if self.ip in LOCAL_IPS else LOCALHOST
     kernel_manager = QtKernelManager(
         ip=ip,
         connection_file=self._new_connection_file(),
         config=self.config,
     )
     # start the kernel
     kwargs = dict(ipython=not self.pure)
     kwargs['extra_arguments'] = self.kernel_argv
     kernel_manager.start_kernel(**kwargs)
     kernel_manager.start_channels()
     widget = self.widget_factory(config=self.config, local_kernel=True)
     widget.kernel_manager = kernel_manager
     widget._existing = False
     widget._may_close = True
     widget._confirm_exit = self.confirm_exit
     return widget
コード例 #9
0
ファイル: console.py プロジェクト: broxtronix/Fiat-Lux
    def __init__(self, parent=None):
        QDockWidget.__init__(self, parent)
        self.setObjectName("IPython Console")
        self.setWindowTitle(
            QCoreApplication.translate("IPython Console", "IPython Console"))
        self.setAllowedAreas(Qt.BottomDockWidgetArea)

        self.container = QWidget()
        self.layout = QVBoxLayout(self.container)

        self.kernel_manager = QtKernelManager()
        self.kernel_manager.start_kernel()
        self.kernel_manager.start_channels()

        self.console = IPythonWidget(local_kernel=LOCALHOST)
        self.console.kernel_manager = self.kernel_manager
        print dir(self.console)

        self.layout.addWidget(self.console)
        self.setWidget(self.container)
コード例 #10
0
ファイル: qtconsole.py プロジェクト: royedwards/3rdPartyAudio
    def connect_kernel(self, connection_file, heartbeat=False):
        """
        connection_file: str - is the connection file name, for example 'kernel-16098.json'
        heartbeat: bool - workaround, needed for right click/save as ... errors ... i don't know how to 
                          fix this issue. Anyone knows? Anyway it needs more testing
            example1 (standalone):

                    app = QtGui.QApplication([])
                    widget = IPythonConsoleQtWidget()
                    widget.set_default_style(colors='linux')


                    widget.connect_kernel(connection_file='some connection file name')

                    app.exec_()

            example2 (IPythonLocalKernelApp):

                    app = QtGui.QApplication([])

                    kernelapp = IPythonLocalKernelApp.instance()
                    kernelapp.initialize()

                    widget = IPythonConsoleQtWidget()

                    # Green text, black background ;)
                    widget.set_default_style(colors='linux')

                    widget.connect_kernel(connection_file='kernelapp.get_connection_file())

                    app.exec_()

        """
        km = QtKernelManager(
            connection_file=find_connection_file(connection_file),
            config=self.config)
        km.load_connection_file()
        km.start_channels(hb=heartbeat)
        self.kernel_manager = km
        atexit.register(self.kernel_manager.cleanup_connection_file)
コード例 #11
0
 def setupKernelManager(self):
     kernelManager = None
     try:
         from IPython.frontend.qt.kernelmanager import QtKernelManager
         kernelManager = QtKernelManager()
         kernelManager.start_kernel()
         kernelManager.start_channels()
         if hasattr(kernelManager, "connection_file"):
             ipconnection = kernelManager.connection_file
         else:
             shell_port = kernelManager.shell_address[1]
             iopub_port = kernelManager.sub_address[1]
             stdin_port = kernelManager.stdin_address[1]
             hb_port = kernelManager.hb_address[1]
             ipconnection = "--shell={0} --iopub={1} --stdin={2} --hb={3}".format(
                 shell_port, iopub_port, stdin_port, hb_port)
         self.supportManager.updateEnvironment(
             {"PMX_IPYTHON_CONNECTION": ipconnection})
     except ImportError as e:
         self.logger.warn("Warning: %s" % e)
         kernelManager = None
     return kernelManager
コード例 #12
0
ファイル: QIPythonWidget.py プロジェクト: satishgoda/PyInterp
 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)
コード例 #13
0
def main():
    """ Entry point for application.
    """
    # Parse command line arguments.
    parser = ArgumentParser()
    kgroup = parser.add_argument_group('kernel options')
    kgroup.add_argument('-e', '--existing', action='store_true',
                        help='connect to an existing kernel')
    kgroup.add_argument('--ip', type=str, default=LOCALHOST,
                        help=\
            "set the kernel\'s IP address [default localhost].\
            If the IP address is something other than localhost, then \
            Consoles on other machines will be able to connect\
            to the Kernel, so be careful!")
    kgroup.add_argument('--xreq', type=int, metavar='PORT', default=0,
                        help='set the XREQ channel port [default random]')
    kgroup.add_argument('--sub', type=int, metavar='PORT', default=0,
                        help='set the SUB channel port [default random]')
    kgroup.add_argument('--rep', type=int, metavar='PORT', default=0,
                        help='set the REP channel port [default random]')
    kgroup.add_argument('--hb', type=int, metavar='PORT', default=0,
                        help='set the heartbeat port [default random]')

    egroup = kgroup.add_mutually_exclusive_group()
    egroup.add_argument('--pure', action='store_true', help = \
                        'use a pure Python kernel instead of an IPython kernel')
    egroup.add_argument('--pylab', type=str, metavar='GUI', nargs='?', 
                       const='auto', help = \
        "Pre-load matplotlib and numpy for interactive use. If GUI is not \
         given, the GUI backend is matplotlib's, otherwise use one of: \
         ['tk', 'gtk', 'qt', 'wx', 'inline'].")

    wgroup = parser.add_argument_group('widget options')
    wgroup.add_argument('--paging', type=str, default='inside',
                        choices = ['inside', 'hsplit', 'vsplit', 'none'],
                        help='set the paging style [default inside]')
    wgroup.add_argument('--plain', action='store_true',
                        help='disable rich text support')
    wgroup.add_argument('--gui-completion', action='store_true',
                        help='use a GUI widget for tab completion')
    wgroup.add_argument('--style', type=str,
                        choices = list(get_all_styles()),
                        help='specify a pygments style for by name')
    wgroup.add_argument('--stylesheet', type=str,
                        help='path to a custom CSS stylesheet')
    wgroup.add_argument('--colors', type=str, help = \
        "Set the color scheme (LightBG,Linux,NoColor). This is guessed \
         based on the pygments style if not set.")

    args = parser.parse_args()

    # parse the colors arg down to current known labels
    if args.colors:
        colors=args.colors.lower()
        if colors in ('lightbg', 'light'):
            colors='lightbg'
        elif colors in ('dark', 'linux'):
            colors='linux'
        else:
            colors='nocolor'
    elif args.style:
        if args.style=='bw':
            colors='nocolor'
        elif styles.dark_style(args.style):
            colors='linux'
        else:
            colors='lightbg'
    else:
        colors=None

    # Don't let Qt or ZMQ swallow KeyboardInterupts.
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Create a KernelManager and start a kernel.
    kernel_manager = QtKernelManager(xreq_address=(args.ip, args.xreq),
                                     sub_address=(args.ip, args.sub),
                                     rep_address=(args.ip, args.rep),
                                     hb_address=(args.ip, args.hb))
    if not args.existing:
        # if not args.ip in LOCAL_IPS+ALL_ALIAS:
        #     raise ValueError("Must bind a local ip, such as: %s"%LOCAL_IPS)

        kwargs = dict(ip=args.ip)
        if args.pure:
            kwargs['ipython']=False
        else:
            kwargs['colors']=colors
            if args.pylab:
                kwargs['pylab']=args.pylab

        kernel_manager.start_kernel(**kwargs)
    kernel_manager.start_channels()

    # Create the widget.
    app = QtGui.QApplication([])
    local_kernel = (not args.existing) or args.ip in LOCAL_IPS
    if args.pure:
        kind = 'plain' if args.plain else 'rich'
        widget = FrontendWidget(kind=kind, paging=args.paging, 
                                local_kernel=local_kernel)
    elif args.plain:
        widget = IPythonWidget(paging=args.paging, local_kernel=local_kernel)
    else:
        widget = RichIPythonWidget(paging=args.paging, 
                                   local_kernel=local_kernel)
    widget.gui_completion = args.gui_completion
    widget.kernel_manager = kernel_manager

    # Configure the style.
    if not args.pure: # only IPythonWidget supports styles
        if args.style:
            widget.syntax_style = args.style
            widget.style_sheet = styles.sheet_from_template(args.style, colors)
            widget._syntax_style_changed()
            widget._style_sheet_changed()
        elif colors:
            # use a default style
            widget.set_default_style(colors=colors)
        else:
            # this is redundant for now, but allows the widget's
            # defaults to change
            widget.set_default_style()

        if args.stylesheet:
            # we got an expicit stylesheet
            if os.path.isfile(args.stylesheet):
                with open(args.stylesheet) as f:
                    sheet = f.read()
                widget.style_sheet = sheet
                widget._style_sheet_changed()
            else:
                raise IOError("Stylesheet %r not found."%args.stylesheet)

    # Create the main window.
    window = MainWindow(app, widget, args.existing, may_close=local_kernel)
    window.setWindowTitle('Python' if args.pure else 'IPython')
    window.show()

    # Start the application main loop.
    app.exec_()
コード例 #14
0
def main():
    """ Entry point for application.
    """
    # Parse command line arguments.
    parser = ArgumentParser()
    kgroup = parser.add_argument_group('kernel options')
    kgroup.add_argument('-e',
                        '--existing',
                        action='store_true',
                        help='connect to an existing kernel')
    kgroup.add_argument(
        '--ip',
        type=str,
        default=LOCALHOST,
        help='set the kernel\'s IP address [default localhost]')
    kgroup.add_argument('--xreq',
                        type=int,
                        metavar='PORT',
                        default=0,
                        help='set the XREQ channel port [default random]')
    kgroup.add_argument('--sub',
                        type=int,
                        metavar='PORT',
                        default=0,
                        help='set the SUB channel port [default random]')
    kgroup.add_argument('--rep',
                        type=int,
                        metavar='PORT',
                        default=0,
                        help='set the REP channel port [default random]')
    kgroup.add_argument('--hb',
                        type=int,
                        metavar='PORT',
                        default=0,
                        help='set the heartbeat port [default: random]')

    egroup = kgroup.add_mutually_exclusive_group()
    egroup.add_argument('--pure', action='store_true', help = \
                        'use a pure Python kernel instead of an IPython kernel')
    egroup.add_argument('--pylab', type=str, metavar='GUI', nargs='?',
                       const='auto', help = \
        "Pre-load matplotlib and numpy for interactive use. If GUI is not \
         given, the GUI backend is matplotlib's, otherwise use one of: \
         ['tk', 'gtk', 'qt', 'wx', 'inline']."                                              )

    wgroup = parser.add_argument_group('widget options')
    wgroup.add_argument('--paging',
                        type=str,
                        default='inside',
                        choices=['inside', 'hsplit', 'vsplit', 'none'],
                        help='set the paging style [default inside]')
    wgroup.add_argument('--rich',
                        action='store_true',
                        help='enable rich text support')
    wgroup.add_argument('--gui-completion',
                        action='store_true',
                        help='use a GUI widget for tab completion')

    args = parser.parse_args()

    # Don't let Qt or ZMQ swallow KeyboardInterupts.
    import signal
    signal.signal(signal.SIGINT, signal.SIG_DFL)

    # Create a KernelManager and start a kernel.
    kernel_manager = QtKernelManager(xreq_address=(args.ip, args.xreq),
                                     sub_address=(args.ip, args.sub),
                                     rep_address=(args.ip, args.rep),
                                     hb_address=(args.ip, args.hb))
    if args.ip == LOCALHOST and not args.existing:
        if args.pure:
            kernel_manager.start_kernel(ipython=False)
        elif args.pylab:
            kernel_manager.start_kernel(pylab=args.pylab)
        else:
            kernel_manager.start_kernel()
    kernel_manager.start_channels()

    # Create the widget.
    app = QtGui.QApplication([])
    if args.pure:
        kind = 'rich' if args.rich else 'plain'
        widget = FrontendWidget(kind=kind, paging=args.paging)
    elif args.rich or args.pylab:
        widget = RichIPythonWidget(paging=args.paging)
    else:
        widget = IPythonWidget(paging=args.paging)
    widget.gui_completion = args.gui_completion
    widget.kernel_manager = kernel_manager

    # Create the main window.
    window = MainWindow(app, widget, args.existing)
    window.setWindowTitle('Python' if args.pure else 'IPython')
    window.show()

    # Start the application main loop.
    app.exec_()