Exemplo n.º 1
0
    def new_qt_console(self, evt=None):
        """start a new qtconsole connected to our kernel"""
        try:
            if hasattr(self.ipkernel, 'profile'):
                return connect_qtconsole(self.ipkernel.connection_file,
                                         profile=self.ipkernel.profile)
            else:
                return connect_qtconsole(self.ipkernel.connection_file)

        except Exception as e:
            if self.logger:
                self.logger.error("Couldn't start QT Console: %s" % (str(e)))
Exemplo n.º 2
0
Arquivo: ipg.py Projeto: Cadair/ginga
    def new_qt_console(self, evt=None):
        """start a new qtconsole connected to our kernel"""
        try:
            if hasattr(self.ipkernel, 'profile'):
                return connect_qtconsole(self.ipkernel.connection_file,
                                         profile=self.ipkernel.profile)
            else:
                return connect_qtconsole(self.ipkernel.connection_file)

        except Exception as e:
            if self.logger:
                self.logger.error("Couldn't start QT Console: %s" % (
                    str(e)))
Exemplo n.º 3
0
def launch(app, MW=None):

    if MW is None:
        from manuskript.functions import mainWindow
        MW = mainWindow()

    MW.show()

    # Support for IPython Jupyter QT Console as a debugging aid.
    # Last argument must be --console to enable it
    # Code reference :
    # https://github.com/ipython/ipykernel/blob/master/examples/embedding/ipkernel_qtapp.py
    # https://github.com/ipython/ipykernel/blob/master/examples/embedding/internal_ipkernel.py
    if len(sys.argv) > 1 and sys.argv[-1] == "--console":
        try:
            from IPython.lib.kernel import connect_qtconsole
            from ipykernel.kernelapp import IPKernelApp
            # Only to ensure matplotlib QT mainloop integration is available
            import matplotlib

            # Create IPython kernel within our application
            kernel = IPKernelApp.instance()

            # Initialize it and use matplotlib for main event loop integration with QT
            kernel.initialize(['python', '--matplotlib=qt'])

            # Create the console in a new process and connect
            console = connect_qtconsole(kernel.abs_connection_file,
                                        profile=kernel.profile)

            # Export MW and app variable to the console's namespace
            kernel.shell.user_ns['MW'] = MW
            kernel.shell.user_ns['app'] = app
            kernel.shell.user_ns['kernel'] = kernel
            kernel.shell.user_ns['console'] = console

            # When we close manuskript, make sure we close the console process and stop the
            # IPython kernel's mainloop, otherwise the app will never finish.
            def console_cleanup():
                app.quit()
                console.kill()
                kernel.io_loop.stop()

            app.lastWindowClosed.connect(console_cleanup)

            # Very important, IPython-specific step: this gets GUI event loop
            # integration going, and it replaces calling app.exec_()
            kernel.start()
        except Exception as e:
            print(
                "Console mode requested but error initializing IPython : %s" %
                str(e))
            print(
                "To make use of the Interactive IPython QT Console, make sure you install : "
            )
            print("$ pip3 install ipython qtconsole matplotlib")
            qApp.exec_()
    else:
        qApp.exec_()
    qApp.deleteLater()
Exemplo n.º 4
0
 def new_qt_console(self):
     """ Start a new qtconsole connected to our kernel. """
     console = connect_qtconsole(
         self.ipkernel.connection_file, profile=self.ipkernel.profile,
         argv=['--no-confirm-exit'],
     )
     self.consoles.append(console)
     return console
Exemplo n.º 5
0
 def magic_qtconsole(self, arg_s):
     """Open a qtconsole connected to this kernel.
     
     Useful for connecting a qtconsole to running notebooks, for better
     debugging.
     """
     try:
         p = connect_qtconsole(argv=arg_split(arg_s, os.name=='posix'))
     except Exception as e:
         error("Could not start qtconsole: %r" % e)
         return
Exemplo n.º 6
0
 def magic_qtconsole(self, arg_s):
     """Open a qtconsole connected to this kernel.
     
     Useful for connecting a qtconsole to running notebooks, for better
     debugging.
     """
     try:
         p = connect_qtconsole(argv=arg_split(arg_s, os.name=='posix'))
     except Exception as e:
         error("Could not start qtconsole: %r" % e)
         return
Exemplo n.º 7
0
 def new_qt_console(self, event=None):
     """start a new qtconsole connected to our kernel"""
     ipk = g.app.ipk
     console = None
     if ipk:
         if not ipk.namespace.get('_leo'):
             ipk.namespace['_leo'] = LeoNameSpace()
         console = connect_qtconsole(self.ipkernel.connection_file,
                                     profile=self.ipkernel.profile)
         if console:
             self.consoles.append(console)
     return console
Exemplo n.º 8
0
def launch(app, MW = None):
    if MW is None:
        from manuskript.functions import mainWindow
        MW = mainWindow()

    MW.show()

    # Support for IPython Jupyter QT Console as a debugging aid.
    # Last argument must be --console to enable it
    # Code reference : 
    # https://github.com/ipython/ipykernel/blob/master/examples/embedding/ipkernel_qtapp.py
    # https://github.com/ipython/ipykernel/blob/master/examples/embedding/internal_ipkernel.py
    if len(sys.argv) > 1 and sys.argv[-1] == "--console":
        try:
            from IPython.lib.kernel import connect_qtconsole
            from ipykernel.kernelapp import IPKernelApp
            # Only to ensure matplotlib QT mainloop integration is available
            import matplotlib

            # Create IPython kernel within our application
            kernel = IPKernelApp.instance()
            
            # Initialize it and use matplotlib for main event loop integration with QT
            kernel.initialize(['python', '--matplotlib=qt'])

            # Create the console in a new process and connect
            console = connect_qtconsole(kernel.abs_connection_file, profile=kernel.profile)

            # Export MW and app variable to the console's namespace
            kernel.shell.user_ns['MW'] = MW
            kernel.shell.user_ns['app'] = app
            kernel.shell.user_ns['kernel'] = kernel
            kernel.shell.user_ns['console'] = console

            # When we close manuskript, make sure we close the console process and stop the
            # IPython kernel's mainloop, otherwise the app will never finish.
            def console_cleanup():
                app.quit()
                console.kill()
                kernel.io_loop.stop()
            app.lastWindowClosed.connect(console_cleanup)

            # Very important, IPython-specific step: this gets GUI event loop
            # integration going, and it replaces calling app.exec_()
            kernel.start()
        except Exception as e:
            print("Console mode requested but error initializing IPython : %s" % str(e))
            print("To make use of the Interactive IPython QT Console, make sure you install : ")
            print("$ pip3 install ipython qtconsole matplotlib")
            qApp.exec_()
    else:
        qApp.exec_()
    qApp.deleteLater()
Exemplo n.º 9
0
 def new_qt_console(self,event=None):
     """start a new qtconsole connected to our kernel"""
     ipk = g.app.ipk
     console = None
     if ipk:
         if not ipk.namespace.get('_leo'):
             ipk.namespace['_leo'] = LeoNameSpace()
         console = connect_qtconsole(
             self.ipkernel.connection_file,
             profile=self.ipkernel.profile)
         if console:
             self.consoles.append(console)
     return console
Exemplo n.º 10
0
 def new_qt_console(self, evt=None):
     """start a new qtconsole connected to our kernel"""
     
     import sys
     # We have to step in and cannibalise connect_qtconsole if we're on windows because
     # it launches sys.executable assuming it'll be python, when in fact it's MantidPlot
     if sys.platform == 'win32':
         argv = []
         cf = get_connection_file()
         cmd = ';'.join([
             "from IPython.frontend.qt.console import qtconsoleapp",
             "qtconsoleapp.main()"
         ])
         from subprocess import Popen, PIPE
         return Popen([get_executable(), '-c', cmd, '--existing', cf] + argv, stdout=PIPE, stderr=PIPE)
     
     return connect_qtconsole()
Exemplo n.º 11
0
 def qtconsole(self, arg_s):
     """Open a qtconsole connected to this kernel.
     
     Useful for connecting a qtconsole to running notebooks, for better
     debugging.
     """
     
     # %qtconsole should imply bind_kernel for engines:
     try:
         from IPython.parallel import bind_kernel
     except ImportError:
         # technically possible, because parallel has higher pyzmq min-version
         pass
     else:
         bind_kernel()
     
     try:
         p = connect_qtconsole(argv=arg_split(arg_s, os.name=='posix'))
     except Exception as e:
         error("Could not start qtconsole: %r" % e)
         return
Exemplo n.º 12
0
    def qtconsole(self, arg_s):
        """Open a qtconsole connected to this kernel.
        
        Useful for connecting a qtconsole to running notebooks, for better
        debugging.
        """

        # %qtconsole should imply bind_kernel for engines:
        try:
            from IPython.parallel import bind_kernel
        except ImportError:
            # technically possible, because parallel has higher pyzmq min-version
            pass
        else:
            bind_kernel()

        try:
            p = connect_qtconsole(argv=arg_split(arg_s, os.name == 'posix'))
        except Exception as e:
            error("Could not start qtconsole: %r" % e)
            return
Exemplo n.º 13
0
 def new_qt_console(self):
     """start a new qtconsole connected to our kernel"""
     return connect_qtconsole(self.ipkernel.connection_file,
                              profile=self.ipkernel.profile)
Exemplo n.º 14
0
 def new_qt_console(self, evt=None):
     """start a new qtconsole connected to our kernel"""
     return connect_qtconsole(self.ipkernel.connection_file, 
                              profile=self.ipkernel.profile)
Exemplo n.º 15
0
 def new_qt_console(self, evt=None):
     """start a new qtconsole connected to our kernel"""
     return connect_qtconsole(self.yapkernel.abs_connection_file, profile=self.yapkernel.profile)
Exemplo n.º 16
0
 def new_qt_console(self, evt=None):
     """start a new qtconsole connected to our kernel"""
     print(self.ipkernel.connection_file, self.ipkernel.profile)
     return connect_qtconsole(self.ipkernel.connection_file,
                              profile=self.ipkernel.profile)