Exemplo n.º 1
0
 def create_new_client(self, give_focus=True):
     """Create a new client"""
     client = IPythonClient(self,
                            history_filename='history.py',
                            menu_actions=self.menu_actions)
     self.add_tab(client, name=client.get_name())
     self.main.extconsole.start_ipykernel(client, give_focus=give_focus)
Exemplo n.º 2
0
    def _create_client_for_kernel(self, cf, hostname, kf, pw):
        # Verifying if the connection file exists - in the case of an empty
        # file name, the last used connection file is returned.
        try:
            cf = find_connection_file(cf, profile='default')
        except (IOError, UnboundLocalError):
            QMessageBox.critical(self, _('IPython'),
                                 _("Unable to connect to IPython <b>%s") % cf)
            return

        # Base client name:
        # remove path and extension, and use the last part when split by '-'
        base_client_name = osp.splitext(cf.split('/')[-1])[0].split('-')[-1]

        # Generating the client name by appending /A, /B... until it is unique
        count = 0
        while True:
            client_name = base_client_name + '/' + chr(65 + count)
            for cl in self.get_clients():
                if cl.name == client_name:
                    break
            else:
                break
            count += 1

        # Getting kernel_widget_id from the currently open kernels.
        kernel_widget_id = None
        for sw in self.extconsole.shellwidgets:
            if sw.connection_file == cf.split('/')[-1]:
                kernel_widget_id = id(sw)

        # Verifying if frontend and kernel have compatible versions
        if not self.kernel_and_frontend_match(cf):
            QMessageBox.critical(
                self, _("Mismatch between kernel and frontend"),
                _("Your IPython frontend and kernel versions "
                  "are <b>incompatible!!</b>"
                  "<br><br>"
                  "We're sorry but we can't create an IPython "
                  "console for you."), QMessageBox.Ok)
            return

        # Creating the client
        client = IPythonClient(self,
                               history_filename='history.py',
                               connection_file=cf,
                               kernel_widget_id=kernel_widget_id,
                               menu_actions=self.menu_actions,
                               hostname=hostname,
                               sshkey=kf,
                               password=pw)

        # Adding the tab
        self.add_tab(client, name=client.get_name())

        # Connecting kernel and client
        self.register_client(client, client_name)