def importShortcut(filename, widget, schemeWidget): """Loads shortcuts from a file""" try: d = ET.parse(filename) root = d.getroot() if root.tag != 'frescobaldi-shortcut': raise ValueError(_("No shortcuts found.")) except Exception as e: QMessageBox.critical(widget, app.caption(_("Error")), _("Can't read from source:\n\n{url}\n\n{error}").format( url=filename, error=e)) return schemeWidget.scheme.blockSignals(True) scheme = schemeWidget.addScheme(root.get('name')) schemeWidget.scheme.blockSignals(False) for col in root.findall('collection'): for name in col.findall('name'): shortcuts = [QKeySequence.fromString(shortcut.text) for shortcut in name.findall('shortcut')] item = widget.item(col.attrib['name'], name.attrib['name']) if item: item.setShortcuts(shortcuts, scheme) schemeWidget.disableDefault(False) schemeWidget.currentChanged.emit() schemeWidget.changed.emit()
def filter(self, filterString: str, item: QTreeWidgetItem) -> bool: visible = (filterString == "") columnCount = item.columnCount() for i in range(columnCount): if not visible: break text = item.text(i) if HostOsInfo.isMacHost(): # accept e.g. Cmd+E in the filter. the text shows special fancy characters for Cmd if i == columnCount - 1: key = QKeySequence.fromString(text, QKeySequence.NativeText) if not key.isEmpty(): text = key.toString(QKeySequence.PortableText) text.replace("Ctrl", "Cmd") text.replace("Meta", "Ctrl") text.replace("Alt", "Opt") if filterString.upper() in text.upper(): # case insensitive visible = True childCount = item.childCount() if childCount > 0: # force visibility if this item matches leafFilterString = "" if visible else filterString for i in range(childCount): citem = item.child(i) # QTreeWidgetItem if not filter(leafFilterString, citem): visible = True item.setHidden(not visible) return not visible
def importShortcut(filename, widget, schemeWidget): """Loads shortcuts from a file""" try: d = ET.parse(filename) root = d.getroot() if root.tag != 'frescobaldi-shortcut': raise ValueError(_("No shortcuts found.")) except Exception as e: QMessageBox.critical( widget, app.caption(_("Error")), _("Can't read from source:\n\n{url}\n\n{error}").format( url=filename, error=e)) return schemeWidget.scheme.blockSignals(True) scheme = schemeWidget.addScheme(root.get('name')) schemeWidget.scheme.blockSignals(False) for col in root.findall('collection'): for name in col.findall('name'): shortcuts = [ QKeySequence.fromString(shortcut.text) for shortcut in name.findall('shortcut') ] item = widget.item(col.attrib['name'], name.attrib['name']) if item: item.setShortcuts(shortcuts, scheme) schemeWidget.disableDefault(False) schemeWidget.currentChanged.emit() schemeWidget.changed.emit()
def shortcut(self): return QKeySequence.fromString(self.text())