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)
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)
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)
def create_client_for_kernel(self): """Create a client connected to an existing kernel""" example = _("(for example: kernel-3764.json, or simply 3764)") while True: cf, valid = QInputDialog.getText(self, _('IPython'), _('Provide an IPython kernel connection file:')+\ '\n'+example, QLineEdit.Normal) if valid: cf = str(cf) match = re.match('(kernel-|^)([a-fA-F0-9-]+)(.json|$)', cf) if match is not None: kernel_num = match.groups()[1] if kernel_num: cf = 'kernel-%s.json' % kernel_num break else: return # Generating the client name and setting kernel_widget_id match = re.match('^kernel-([a-fA-F0-9-]+).json', cf) count = 0 kernel_widget_id = None while True: client_name = match.groups()[0] if '-' in client_name: # Avoid long names client_name = client_name.split('-')[0] client_name = client_name + '/' + chr(65+count) for cl in self.get_clients(): if cl.name == client_name: kernel_widget_id = cl.kernel_widget_id break else: break count += 1 # Trying to get kernel_widget_id from the currently opened kernels if # the previous procedure fails. This could happen when the first # client connected to a kernel is closed but the kernel is left open # and you try to connect new clients to it if kernel_widget_id is None: for sw in self.extconsole.shellwidgets: if sw.connection_file == cf: kernel_widget_id = id(sw) # Verifying if the kernel exists try: find_connection_file(cf, profile='default') except (IOError, UnboundLocalError): QMessageBox.critical(self, _('IPython'), _("Unable to connect to IPython <b>%s") % cf) return # 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) self.add_tab(client, name=client.get_name()) self.register_client(client, client_name)