def add_calculation_plan(self, text=None): if text is None or isinstance(text, bool): text, ok = QInputDialog.getText(self, "Plan title", "Set plan title") else: text, ok = QInputDialog.getText( self, "Plan title", f"Set plan title. Previous ({text}) is already in use", text=text ) text = text.strip() if ok: if text == "": QMessageBox.information( self, "Name cannot be empty", "Name cannot be empty, Please set correct name", QMessageBox.Ok ) self.add_calculation_plan() return if text in self.settings.batch_plans: res = QMessageBox.information( self, "Name already in use", "Name already in use. Would like to overwrite?", QMessageBox.Yes | QMessageBox.No, ) if res == QMessageBox.No: self.add_calculation_plan(text) return plan = copy(self.calculation_plan) plan.set_name(text) self.settings.batch_plans[text] = plan self.settings.dump() self.plan_created.emit()
def handle_capture(window, capture): email, ok = QInputDialog.getText( window, 'Email', 'Enter your employee ID or email:', flags=Qt.FramelessWindowHint | Qt.Popup) while ok and not get_email(email): email, ok = QInputDialog.getText( window, 'Email', 'Enter a valid employee ID or email:', flags=Qt.FramelessWindowHint | Qt.Popup) if ok: print('Send email to %s' % email) pb = None try: pb = QProgressDialog("Sending...", "", 0, 0, window, Qt.FramelessWindowHint | Qt.Popup) pb.setWindowModality(Qt.WindowModal) pb.setRange(0, 0) pb.setMinimumDuration(0) pb.setCancelButton(None) pb.show() nongui(send_image)(email, capture, cache_dir=IMAGE_CACHE_DIR) except Exception: import traceback traceback.print_exc() msg = QMessageBox(window) msg.setIcon(QMessageBox.Critical) msg.setText('Error sending email.') msg.setWindowFlags(Qt.FramelessWindowHint | Qt.Popup) msg.exec_() finally: if pb: pb.close()
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 ask_add_storage(self, expr: str) -> bool: try: # Put the expression into parser to see if it is legal parse_params(expr) except Exception as error: logger.warn(error) QMessageBox.warning( self, "Loading failed", "Your expression is in an incorrect format." ) return False name, ok = QInputDialog.getText( self, "Storage", "Please input name tag:" ) if not ok: return False name_list = [ self.mechanism_storage.item(i).text() for i in range(self.mechanism_storage.count()) ] i = 0 name = name or f"Prototype_{i}" while name in name_list: name = f"Prototype_{i}" i += 1 self.__add_storage(name, expr) return True
def edit_comment(self): try: table_name = self.twg_database.get_current_table_name() if table_name is None: return idn = self.twg_database.get_table_selected_id(table_name) if idn is None: return object_class = self._table_object_dict[table_name] obj = object_class( database_name=self.database_name, mongo=self.mongo, server=self.server) obj.db_read(idn) prev_comments = obj.comments title = _QCoreApplication.translate('', 'Edit Comments') label = _QCoreApplication.translate('', 'Comments:') new_comments, resp = _QInputDialog.getText( self, title, label, text=prev_comments) if not resp: return obj.comments = new_comments obj.db_update(idn) self.update_database_tables() except Exception: _traceback.print_exc(file=_sys.stdout)
def change_format(self): """ Ask user for display format for floats and use it. This function also checks whether the format is valid and emits `sig_option_changed`. """ format, valid = QInputDialog.getText(self, _('Format'), _("Float formatting"), QLineEdit.Normal, self.dataModel.get_format()) if valid: format = str(format) try: format % 1.1 except: msg = _("Format ({}) is incorrect").format(format) QMessageBox.critical(self, _("Error"), msg) return if not format.startswith('%'): msg = _("Format ({}) should start with '%'").format(format) QMessageBox.critical(self, _("Error"), msg) return self.dataModel.set_format(format) self.sig_option_changed.emit('dataframe_format', format)
def change_format(self): """ Ask user for display format for floats and use it. This function also checks whether the format is valid and emits `sig_option_changed`. """ format, valid = QInputDialog.getText(self, _('Format'), _("Float formatting"), QLineEdit.Normal, self.dataModel.get_format()) if valid: format = str(format) try: format % 1.1 except: msg = _("Format ({}) is incorrect").format(format) QMessageBox.critical(self, _("Error"), msg) return if not format.startswith('%'): msg = _("Format ({}) should start with '%'").format(format) QMessageBox.critical(self, _("Error"), msg) return self.dataModel.set_format(format) self.sig_option_changed.emit('dataframe_format', format)
def on_new_folder(self): """ 新建文件夹时出发的回调 :return: """ path = self.get_current_file_path() name, stat = QInputDialog.getText(self, self.tr('Please Input folder name'), '', QLineEdit.Normal, '') if name.find('.') != -1: QMessageBox.critical(self, self.tr('Error'), self.tr('Folder name %s is illeagal!' % name)) return if stat: if os.path.isdir(path): new_folder_path = os.path.join(path, name) else: new_folder_path = os.path.join(os.path.dirname(path), name) if os.path.exists(new_folder_path): self.set_item_focus(new_folder_path) # 设置focus liugang 200923 QMessageBox.critical( self, self.tr('Error'), self.tr('Folder %s already exists!' % name)) return else: os.mkdir(new_folder_path) self.new_folder_signal[str].emit(new_folder_path) self.set_item_focus(new_folder_path) # 设置focus liugang 200923
def showDialog(self): # 通过下面的语句来实现QInputDialog的显示 text, ok = QInputDialog.getText(self, 'Input Dialog', 'Input some thing') if ok: self.le.setText(text)
def startTemplate(self, simulation=True): if not self._gui_node: logger.warning('Cannot start template without guiNode') return # Get list of templates files = dir(tGUIs) GUIlist = [] for name in files: if '__' not in name: GUIlist.append(name) # Ask user to select template message = 'Name of the Template to be used.' d = 0 options = GUIlist tName, ok = QInputDialog.getItem(None, 'Input', message, options, d, False) if not ok: return try: tGUI = getattr(tGUIs, tName) args, kwargs = tGUI() except AttributeError: message = 'That template was not found.' tName, ok = QInputDialog.getText(None, 'Input', message, QLineEdit.Normal) args = () kwargs = dict() self._gui_node.apparatus.applyTemplate(tName, args=args, kwargs=kwargs)
def on_change_row_col(self, operation: int): """ The slot for editting row or columns Args: operation: Returns: """ import pandas as pd import numpy as np pd_data: pd.DataFrame = self.model._data current_index = self.currentIndex() row, column = current_index.row(), current_index.column() if operation == self.INSERT_ROW: prev = pd_data.iloc[:row] lat = pd_data.iloc[row:] self.model._data = pd.concat([prev, pd.DataFrame([[]]), lat]) elif operation == self.DELETE_ROW: self.model._data = pd_data.drop(index=[row], axis=1) elif operation == self.INSERT_COLUMN: col_name, _ = QInputDialog.getText(self, QCoreApplication.translate('PMTableView','Input Column Title'), QCoreApplication.translate('PMTableView','Title')) if _: pd_data.insert(column, col_name, np.nan) elif operation == self.DELETE_COLUMN: self.model._data = pd_data.drop(columns=[column], axis=0) else: raise NotImplementedError self.model.layoutChanged.emit() self.signal_need_save.emit(True)
def __copy(self) -> None: """Ask a name to copy a data.""" row = self.collections_list.currentRow() if not row > -1: return name, ok = QInputDialog.getText( self, "Profile name", "Please enter a new profile name:" ) if not ok: return if not name: QMessageBox.warning( self, "Profile name", "Can not use blank string to rename." ) return name_old = self.collections_list.item(row).text() self.collections[name] = self.collections[name_old].copy() self.collections_list.addItem(name) self.project_no_save()
def add_dataset(self, _e): while True: name, ok = QInputDialog.getText( self, 'New Dataset', 'Enter the name of the new dataset:') if ok: try: # TODO: how to set defaults? self.model.add_dataset(Dataset(name=name)) #parameter=0)) except IntegrityError: self.model.session.rollback() QMessageBox.information( self, "Cannot proceed", "This dataset name already exists, \ please select a different one (or cancel).", defaultButton=QMessageBox.Ok) else: self.tableViewDataset.model().change_layout() self.statusBar().showMessage('Added dataset.') # self.tableViewDataset.selectRow(len(self.model.dataset) - 1) break else: # cancel self.statusBar().showMessage('Cancelled.') return # exit loop if len(self.model.get_dataset()) == 1: # first entry after being empty self.tableViewDataset.selectRow(0)
def reboot_nodes(self): """Reboots the selected nodes""" if not self.sudo: text, confirmation = QInputDialog.getText( self, "Confirmation", ("Rebooting could result in downtime, failures or worse, and whoever" "\nexecutes this should be aware of the implications of this action.\n" "\nIf you want to enter sudo mode, type in 'Beaglebone' (case sensitive)" ), ) if confirmation and text == "Beaglebone": self.sudo = True else: return confirmation = QtWidgets.QMessageBox.question( self, "Confirmation", "Are you sure you want to reboot these nodes?", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, ) if confirmation == QtWidgets.QMessageBox.Yes: current_tab = self.tabWidget.currentIndex() selected_items = (getattr(self, TABLES[current_tab] + "Table").selectionModel().selectedRows()) for bbb in selected_items: bbb_ip = bbb.sibling(bbb.row(), 0 if current_tab != 4 else 1).data() bbb_hostname = (bbb.sibling( bbb.row(), 1 if current_tab != 4 else 2).data().replace(":", "--")) self.server.reboot_node(bbb_ip, bbb_hostname)
def __rename(self) -> None: """Show up a string input to change the data name.""" row = self.collections_list.currentRow() if not row > -1: return name, ok = QInputDialog.getText( self, "Profile name", "Please enter the profile name:" ) if not ok: return if not name: QMessageBox.warning( self, "Profile name", "Can not use blank string to rename." ) return item = self.collections_list.item(row) self.collections[name] = self.collections.pop(item.text()) item.setText(name) self.project_no_save()
def set_umr_namelist(self): """Set UMR excluded modules name list""" arguments, valid = QInputDialog.getText(self, _('UMR'), _("Set the list of excluded modules as " "this: <i>numpy, scipy</i>"), QLineEdit.Normal, ", ".join(self.get_option('umr/namelist'))) if valid: arguments = to_text_string(arguments) if arguments: namelist = arguments.replace(' ', '').split(',') fixed_namelist = [module_name for module_name in namelist if programs.is_module_installed(module_name)] invalid = ", ".join(set(namelist)-set(fixed_namelist)) if invalid: QMessageBox.warning(self, _('UMR'), _("The following modules are not " "installed on your machine:\n%s" ) % invalid, QMessageBox.Ok) QMessageBox.information(self, _('UMR'), _("Please note that these changes will " "be applied only to new Python/IPython " "consoles"), QMessageBox.Ok) else: fixed_namelist = [] self.set_option('umr/namelist', fixed_namelist)
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 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_action(self): if self.profile_list.currentItem() is None: return # pragma: no cover old_name = self.profile_list.currentItem().text() if old_name not in self.profile_dict: return # pragma: no cover text, ok = QInputDialog.getText(self, "Profile Name", "Input profile name here") if not ok: return # pragma: no cover if text in self.profile_dict: # pragma: no cover QMessageBox.warning( self, "Already exists", "Profile with this name already exist.", QMessageBox.Ok, QMessageBox.Ok, ) self.rename_action() return profile = self.profile_dict[old_name] del self.profile_dict[old_name] profile.name = text self.profile_dict[text] = profile self.profile_list.clear() self.profile_list.addItems(self.profile_dict.keys())
def add_device(self) -> None: uri, ok = QInputDialog.getText( self, "Connect to device", "What is the device URI?", ) if not ok: return # Napari catches the error and displays "invalid URI" for # us! This is fantastic. device = Pyro4.Proxy(uri) # We're being naughty here and using a private function. # Maybe we should make it public. widget_cls = microscope.gui._guess_device_widget(device) if widget_cls == microscope.gui.CameraWidget: widget = MicroscopeCameraWidget(self._napari_viewer, device) else: widget = widget_cls(device) widget.setParent(self) # TODO: instead of adding the widget directly, we probably # should have a base device widget with name and close button. # This gets confusing when ther's multiple light sources and # filterwheels. self.layout().addWidget(widget)
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 save_as_dialog(self, filename): text, ok_pressed = QInputDialog.getText(self, "Save as", "New name:", QLineEdit.Normal, filename) if ok_pressed and text != '': return text else: return False
def rename_profile(self): profile_name, profiles_dict = "", {} if self.profile_list.selectedItems(): profile_name = self.profile_list.selectedItems()[0].text() profiles_dict = self._settings.roi_profiles elif self.pipeline_list.selectedItems(): profile_name = self.pipeline_list.selectedItems()[0].text() profiles_dict = self._settings.roi_pipelines if profile_name == "": return text, ok = QInputDialog.getText(self, "New profile name", f"New name for {profile_name}", text=profile_name) if ok: text = text.strip() if text in profiles_dict.keys(): res = QMessageBox.warning( self, "Already exist", f"Profile with name {text} already exist. Would you like to overwrite?", QMessageBox.Yes | QMessageBox.No, QMessageBox.No, ) if res == QMessageBox.No: self.rename_profile() return profiles_dict[text] = profiles_dict.pop(profile_name) self._settings.dump() self.update_profile_list()
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 save_state_action(self, state: ProjectInfoBase, custom_name): # TODO left elipsis # state: ProjectInfoBase = self.get_state() if not isinstance(state, ProjectInfoBase): # workaround for PointsInfo load return normed_file_path = os.path.normpath(state.file_path) sub_dict = self.state_dict[normed_file_path] name = f"state {self.state_dict_count[normed_file_path]+1}" if custom_name: name, ok = QInputDialog.getText(self, "Save name", "Save name:", text=name) if not ok: return while name in sub_dict or name in ["raw image", "image with mask"]: name, ok = QInputDialog.getText(self, "Save name", "Save name (previous in use):", text=name) if not ok: return try: index = self.file_list.index(os.path.normpath(normed_file_path)) item = self.file_view.topLevelItem(index) except ValueError: metric = QFontMetrics(self.file_view.font()) width = self.file_view.width() - 45 clipped_text = metric.elidedText(normed_file_path, Qt.ElideLeft, width) item = QTreeWidgetItem(self.file_view, [clipped_text]) item.setToolTip(0, normed_file_path) self.file_list.append(normed_file_path) QTreeWidgetItem(item, ["raw image"]) sub_dict["raw image"] = state.get_raw_copy() if state.is_masked(): QTreeWidgetItem(item, ["image with mask"]) sub_dict["image with mask"] = state.get_raw_mask_copy() item.setExpanded(True) if state.is_raw(): return it = QTreeWidgetItem(item, [name]) self.file_view.setCurrentItem(it) sub_dict[name] = state self.state_dict_count[state.file_path] += 1
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 rename_dialog(self, data_type): text, ok_pressed = QInputDialog.getText(self.parent, "Rename", "New {} name:".format(data_type), QLineEdit.Normal, "") if ok_pressed and text != '': return text else: return False
def rename(self, index): newName, ok = QInputDialog.getText(self, "QInputDialog.getText()", config.thisTranslation["edit"], QLineEdit.Normal, config.highlightCollections[index]) if ok and newName: config.highlightCollections[index] = newName self.collectionButtons[index].setText(newName)
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 save_perspective(self): perspective_name = QInputDialog.getText(self, 'Save perspective', 'Enter unique name:') if perspective_name: self.dock_manager.add_perspective(perspective_name) _ = QSignalBlocker(self.perspective_combo_box) self.perspective_combo_box.clear() self.perspective_combo_box.addItems(self.dock_manager.perspective_names()) self.perspective_combo_box.setCurrentIndex(perspective_name) self.save_perspectives()
def set_umr_namelist(self): """Set UMR excluded modules name list""" arguments, valid = QInputDialog.getText( self, _('UMR'), _("Set the list of excluded modules as this: " "<i>numpy, scipy</i>"), QLineEdit.Normal, ", ".join(self.get_option('umr/namelist')), ) if valid: arguments = to_text_string(arguments) if arguments: namelist = arguments.replace(' ', '').split(',') fixed_namelist = [] non_ascii_namelist = [] for module_name in namelist: if PY2: if all(ord(c) < 128 for c in module_name): if programs.is_module_installed(module_name): fixed_namelist.append(module_name) else: QMessageBox.warning( self, _('Warning'), _("You are working with Python 2, this means " "that you can not import a module that " "contains non-ascii characters."), QMessageBox.Ok, ) non_ascii_namelist.append(module_name) elif programs.is_module_installed(module_name): fixed_namelist.append(module_name) invalid = ", ".join( set(namelist) - set(fixed_namelist) - set(non_ascii_namelist)) if invalid: QMessageBox.warning( self, _('UMR'), _("The following modules are not " "installed on your machine:\n%s") % invalid, QMessageBox.Ok, ) QMessageBox.information( self, _('UMR'), _("Please note that these changes will " "be applied only to new IPython consoles"), QMessageBox.Ok, ) else: fixed_namelist = [] self.set_option('umr/namelist', fixed_namelist)
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 _on_copy_key(self): keys = self._get_selected_keys() assert len(keys) == 1 src = keys[0] dst, ok = QInputDialog.getText(self, f"Copy {src!r} to...", "New key") if ok: # redis.copy() only >= 6.2 #self.redis.copy(src, dst) self.redis[dst] = self.redis[src].value self.source_model.refresh()
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 clickedRow(self, index): row = self.model.getRow(index.row()) (action, key) = row newKey, ok = QInputDialog.getText(self, 'Shortcut', action, QLineEdit.Normal, key) if ok: self.model.list[index.row()] = (action, newKey) for item in self.model.fullList: if item[0] == action: item[1] = newKey
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 insert_node(self): index = self.currentIndex() parentnode = index.internalPointer() or self.model().root key, b = QInputDialog.getText( self, "Insert Json node", "Insert key for new node:") if not b: return node = JsonNode(key) parentnode.add(node) row = parentnode.index(node) self.model().beginInsertRows(index, row, row) self.model().endInsertRows()
def edit_key(self): index = self.currentIndex() if index.isValid(): node = index.internalPointer() key, b = QInputDialog.getText( self, "Edit Json item", "Insert new key for item:", text=node.key ) if not b: return node.key = key try: # PyQt5 self.model().dataChanged.emit(index, index, [Qt.DisplayRole]) except TypeError: # PyQt4, PySide self.model().dataChanged.emit(index, index)
def insert_item(self): index = self.currentIndex() if index.isValid(): node = index.internalPointer() else: node = self.model().root key, b = QInputDialog.getText( self, "Insert Json item", "Insert key for new item:") if not b: return item = JsonItem(key) node.add(item) row = node.index(item) self.model().beginInsertRows(index, row, row) self.model().endInsertRows()
def set_umr_namelist(self): """Set UMR excluded modules name list""" arguments, valid = QInputDialog.getText(self, _('UMR'), _("Set the list of excluded modules as " "this: <i>numpy, scipy</i>"), QLineEdit.Normal, ", ".join(self.get_option('umr/namelist'))) if valid: arguments = to_text_string(arguments) if arguments: namelist = arguments.replace(' ', '').split(',') fixed_namelist = [] non_ascii_namelist = [] for module_name in namelist: if PY2: if all(ord(c) < 128 for c in module_name): if programs.is_module_installed(module_name): fixed_namelist.append(module_name) else: QMessageBox.warning(self, _('Warning'), _("You are working with Python 2, this means that " "you can not import a module that contains non-" "ascii characters."), QMessageBox.Ok) non_ascii_namelist.append(module_name) elif programs.is_module_installed(module_name): fixed_namelist.append(module_name) invalid = ", ".join(set(namelist)-set(fixed_namelist)- set(non_ascii_namelist)) if invalid: QMessageBox.warning(self, _('UMR'), _("The following modules are not " "installed on your machine:\n%s" ) % invalid, QMessageBox.Ok) QMessageBox.information(self, _('UMR'), _("Please note that these changes will " "be applied only to new Python/IPython " "consoles"), QMessageBox.Ok) else: fixed_namelist = [] self.set_option('umr/namelist', fixed_namelist)
def toogle_breakpoint(self, line_number=None, condition=None, edit_condition=False): """Add/remove breakpoint.""" if not self.editor.is_python_like(): return if line_number is None: block = self.editor.textCursor().block() else: block = self.editor.document().findBlockByNumber(line_number-1) data = block.userData() if not data: data = BlockUserData(self.editor) data.breakpoint = True elif not edit_condition: data.breakpoint = not data.breakpoint data.breakpoint_condition = None if condition is not None: data.breakpoint_condition = condition if edit_condition: condition = data.breakpoint_condition condition, valid = QInputDialog.getText(self.editor, _('Breakpoint'), _("Condition:"), QLineEdit.Normal, condition) if not valid: return data.breakpoint = True data.breakpoint_condition = str(condition) if condition else None if data.breakpoint: text = to_text_string(block.text()).strip() if len(text) == 0 or text.startswith(('#', '"', "'")): data.breakpoint = False block.setUserData(data) self.editor.sig_flags_changed.emit() self.editor.sig_breakpoints_changed.emit()