Exemple #1
0
    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
Exemple #2
0
    def addOverrideAction(self, action: QAction, context: Context, scriptable: bool):
        if HostOsInfo.isMacHost():
            action.setIconVisibleInMenu(False)
            if self.isEmpty():
                self._action.initialize(action)
            if context.isEmpty():
                self._contextActionMap[None] = action
            else:
                for i in range(len(context)):
                    cId = context[i]
                    if cId in self._contextActionMap:
                        warnings.warn(self.__msgActionWarning(action, cId, self._contextActionMap.get(cId, None)))
                    self._contextActionMap[cId] = action

            self._scriptableMap[action] = scriptable
            self.setCurrentContext(self._context)