def rename_file(self, fname): """Rename file""" path, valid = QInputDialog.getText(self, _("Rename"), _("New name:"), QLineEdit.Normal, osp.basename(fname)) if valid: path = osp.join(osp.dirname(fname), to_text_string(path)) if path == fname: return if osp.exists(path): if ( QMessageBox.warning( self, _("Rename"), _("Do you really want to rename <b>%s</b> and " "overwrite the existing file <b>%s</b>?") % (osp.basename(fname), osp.basename(path)), QMessageBox.Yes | QMessageBox.No, ) == QMessageBox.No ): return try: misc.rename_file(fname, path) self.parent_widget.renamed.emit(fname, path) return path except EnvironmentError as error: QMessageBox.critical( self, _("Rename"), _("<b>Unable to rename file <i>%s</i></b>" "<br><br>Error message:<br>%s") % (osp.basename(fname), to_text_string(error)), )
def create_new_folder(self, current_path, title, subtitle, is_package): """Create new folder""" if current_path is None: current_path = "" if osp.isfile(current_path): current_path = osp.dirname(current_path) name, valid = QInputDialog.getText(self, title, subtitle, QLineEdit.Normal, "") if valid: dirname = osp.join(current_path, to_text_string(name)) try: os.mkdir(dirname) except EnvironmentError as error: QMessageBox.critical( self, title, _("<b>Unable " "to create folder <i>%s</i></b>" "<br><br>Error message:<br>%s") % (dirname, to_text_string(error)), ) finally: if is_package: fname = osp.join(dirname, "__init__.py") try: with open(fname, "wb") as f: f.write(to_binary_string("#")) return dirname except EnvironmentError as error: QMessageBox.critical( self, title, _("<b>Unable " "to create file <i>%s</i></b>" "<br><br>Error message:<br>%s") % (fname, to_text_string(error)), )
def rename_file(self, fname): """Rename file""" path, valid = QInputDialog.getText(self, _('Rename'), _('New name:'), QLineEdit.Normal, osp.basename(fname)) if valid: path = osp.join(osp.dirname(fname), to_text_string(path)) if path == fname: return if osp.exists(path): if QMessageBox.warning(self, _("Rename"), _("Do you really want to rename <b>%s</b> and " "overwrite the existing file <b>%s</b>?" ) % (osp.basename(fname), osp.basename(path)), QMessageBox.Yes|QMessageBox.No) == QMessageBox.No: return try: misc.rename_file(fname, path) self.parent_widget.emit( \ SIGNAL("renamed(QString,QString)"), fname, path) return path except EnvironmentError as error: QMessageBox.critical(self, _("Rename"), _("<b>Unable to rename file <i>%s</i></b>" "<br><br>Error message:<br>%s" ) % (osp.basename(fname), to_text_string(error)))
def create_new_folder(self, current_path, title, subtitle, is_package): """Create new folder""" if current_path is None: current_path = '' if osp.isfile(current_path): current_path = osp.dirname(current_path) name, valid = QInputDialog.getText(self, title, subtitle, QLineEdit.Normal, "") if valid: dirname = osp.join(current_path, to_text_string(name)) try: os.mkdir(dirname) except EnvironmentError as error: QMessageBox.critical(self, title, _("<b>Unable " "to create folder <i>%s</i></b>" "<br><br>Error message:<br>%s" ) % (dirname, to_text_string(error))) finally: if is_package: fname = osp.join(dirname, '__init__.py') try: with open(fname, 'wb') as f: f.write(to_binary_string('#')) return dirname except EnvironmentError as error: QMessageBox.critical(self, title, _("<b>Unable " "to create file <i>%s</i></b>" "<br><br>Error message:<br>%s" ) % (fname, to_text_string(error)))
def get_arguments(self): arguments, valid = QInputDialog.getText( self, _("Arguments"), _("Command line arguments:"), QLineEdit.Normal, self.arguments ) if valid: self.arguments = to_text_string(arguments) return valid
def change_exteditor(self): """Change external editor path""" path, valid = QInputDialog.getText( self, _('External editor'), _('External editor executable path:'), QLineEdit.Normal, self.get_option('external_editor/path')) if valid: self.set_option('external_editor/path', to_text_string(path))
def change_exteditor(self): """Change external editor path""" path, valid = QInputDialog.getText(self, _('External editor'), _('External editor executable path:'), QLineEdit.Normal, self.get_option('external_editor/path')) if valid: self.set_option('external_editor/path', to_text_string(path))
def get_arguments(self): arguments, valid = QInputDialog.getText(self, _('Arguments'), _('Command line arguments:'), QLineEdit.Normal, self.arguments) if valid: self.arguments = to_text_string(arguments) return valid
def get_arguments(self): arguments, valid = QInputDialog.getText(self, _('Arguments'), _('Command line arguments:'), QLineEdit.Normal, self.arguments) if valid: self.arguments = unicode(arguments) return valid
def edit_filter(self): """Edit name filters""" filters, valid = QInputDialog.getText( self, _("Edit filename filters"), _("Name filters:"), QLineEdit.Normal, ", ".join(self.name_filters) ) if valid: filters = [f.strip() for f in to_text_string(filters).split(",")] self.parent_widget.sig_option_changed.emit("name_filters", filters) self.set_name_filters(filters)
def edit_filter(self): """Edit name filters""" filters, valid = QInputDialog.getText(self, _('Edit filename filters'), _('Name filters:'), QLineEdit.Normal, ", ".join(self.name_filters)) if valid: filters = [f.strip() for f in to_text_string(filters).split(',')] self.parent_widget.sig_option_changed.emit('name_filters', filters) self.set_name_filters(filters)
def edit_filter(self): """Edit name filters""" filters, valid = QInputDialog.getText(self, _('Edit filename filters'), _('Name filters:'), QLineEdit.Normal, ", ".join(self.name_filters)) if valid: filters = [f.strip() for f in unicode(filters).split(',')] self.parent_widget.sig_option_changed.emit('name_filters', filters) self.set_name_filters(filters)
def change_format(self): """Change display format""" format, valid = QInputDialog.getText( self, _("Format"), _("Float formatting"), QLineEdit.Normal, self.dataModel.get_format() ) if valid: format = str(format) try: format % 1.1 except: QMessageBox.critical(self, _("Error"), _("Format (%s) is incorrect") % format) return self.dataModel.set_format(format)
def change_format(self): """Change display format""" format, valid = QInputDialog.getText(self, _( 'Format'), _( "Float formatting"), QLineEdit.Normal, self.model.get_format()) if valid: format = str(format) try: format % 1.1 except: QMessageBox.critical(self, _("Error"), _("Format (%s) is incorrect") % format) return self.model.set_format(format)
def create_new_folder(self, current_path, title, subtitle, is_package): """Create new folder""" if current_path is None: current_path = '' if osp.isfile(current_path): current_path = osp.dirname(current_path) name, valid = QInputDialog.getText(self, title, subtitle, QLineEdit.Normal, "") if valid: dirname = osp.join(current_path, unicode(name)) try: os.mkdir(dirname) except EnvironmentError, error: QMessageBox.critical(self, title, _("<b>Unable " "to create folder <i>%s</i></b>" "<br><br>Error message:<br>%s" ) % (dirname, unicode(error))) finally:
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)