Beispiel #1
0
    def apply_filter(self, *args):
        text = self.filterEdit.text()
        if text:
            if self.filter_columns.currentText() == "name":
                m = QRegularExpression(text)
                if m.isValid():
                    if self.name_regex_option.currentText(
                    ) == "case-insensitive":
                        m.setPatternOptions(
                            QRegularExpression.CaseInsensitiveOption)

                    m.optimize()
                    filter = lambda row_num: m.match(
                        self.table.item(row_num, 0).text()).hasMatch()
                else:
                    return

            elif self.filter_columns.currentText() == "denticity":
                if text.isdigit():
                    filter = lambda row_num: int(
                        self.table.item(row_num, 1).text()) == int(text)
                else:
                    filter = lambda row: True

            elif self.filter_columns.currentText() == "coordinating elements":
                method = self.coordinating_elements_method.currentText()

                def filter(row_num):
                    row_key_atoms = [
                        item.strip() for item in self.table.item(
                            row_num, 2).text().split(',')
                    ]
                    search_atoms = []
                    for item in text.split():
                        for ele in item.split(','):
                            if ele.strip() != "":
                                search_atoms.append(ele)

                    if method == "exactly":
                        if all([row_key_atoms.count(element) == search_atoms.count(element) for element in set(search_atoms)]) and \
                            all([row_key_atoms.count(element) == search_atoms.count(element) for element in set(row_key_atoms)]):
                            return True
                        else:
                            return False

                    elif method == "at least":
                        if all([
                                row_key_atoms.count(element) >=
                                search_atoms.count(element)
                                for element in set(search_atoms)
                        ]):
                            return True
                        else:
                            return False

        else:
            filter = lambda row: True

        for i in range(0, self.table.rowCount()):
            self.table.setRowHidden(i, not filter(i))
Beispiel #2
0
    def onSearchBarTextChanged(self, text):
        moodleTreeView = self.findChild(QTreeView, "moodleTree")
        searchBar = self.findChild(QLineEdit, "searchBar")

        if not text:
            self.filterModel.setFilterRegularExpression(".*")
            moodleTreeView.collapseAll()
            searchBar.setStyleSheet("")
        else:
            regexp = QRegularExpression(text)
            if regexp.isValid():
                self.filterModel.setFilterRegularExpression(regexp)
                moodleTreeView.expandAll()
                searchBar.setStyleSheet("")
            else:
                log.debug("invalid search regular expression, not searching")
                searchBar.setStyleSheet("QLineEdit { color: red; }")
Beispiel #3
0
    def highlightBlock(self, text):
        for expr in self.exprs:
            fmt = expr[1]
            rExpr = QRegularExpression(expr[0])

            if not rExpr.isValid():
                continue

            matches = rExpr.globalMatch(text)

            if not matches.isValid():
                continue

            while matches.hasNext():
                match = matches.next()
                instr = match.captured('instr')
                if instr:
                    self.setFormat(
                        match.capturedStart(), match.capturedLength(), fmt)
Beispiel #4
0
def rxValidate(regexp, options):
    """
    Function to validate the given regular expression.
    
    @param regexp regular expression to validate (string)
    @param options list of options (list of string)
    @return tuple of flag indicating validity (boolean), error
        string (string) and error offset (integer)
    """
    try:
        from PyQt5.QtCore import QRegularExpression
        rxOptions = QRegularExpression.NoPatternOption
        if "CaseInsensitiveOption" in options:
            rxOptions |= QRegularExpression.CaseInsensitiveOption
        if "MultilineOption" in options:
            rxOptions |= QRegularExpression.MultilineOption
        if "DotMatchesEverythingOption" in options:
            rxOptions |= QRegularExpression.DotMatchesEverythingOption
        if "ExtendedPatternSyntaxOption" in options:
            rxOptions |= QRegularExpression.ExtendedPatternSyntaxOption
        if "InvertedGreedinessOption" in options:
            rxOptions |= QRegularExpression.InvertedGreedinessOption
        if "UseUnicodePropertiesOption" in options:
            rxOptions |= QRegularExpression.UseUnicodePropertiesOption
        if "DontCaptureOption" in options:
            rxOptions |= QRegularExpression.DontCaptureOption

        error = ""
        errorOffset = -1
        re = QRegularExpression(regexp, rxOptions)
        valid = re.isValid()
        if not valid:
            error = re.errorString()
            errorOffset = re.patternErrorOffset()
    except ImportError:
        valid = False
        error = "ImportError"
        errorOffset = 0

    return valid, error, errorOffset
def rxValidate(regexp, options):
    """
    Function to validate the given regular expression.
    
    @param regexp regular expression to validate (string)
    @param options list of options (list of string)
    @return tuple of flag indicating validity (boolean), error
        string (string) and error offset (integer)
    """
    try:
        from PyQt5.QtCore import QRegularExpression
        rxOptions = QRegularExpression.NoPatternOption
        if "CaseInsensitiveOption" in options:
            rxOptions |= QRegularExpression.CaseInsensitiveOption
        if "MultilineOption" in options:
            rxOptions |= QRegularExpression.MultilineOption
        if "DotMatchesEverythingOption" in options:
            rxOptions |= QRegularExpression.DotMatchesEverythingOption
        if "ExtendedPatternSyntaxOption" in options:
            rxOptions |= QRegularExpression.ExtendedPatternSyntaxOption
        if "InvertedGreedinessOption" in options:
            rxOptions |= QRegularExpression.InvertedGreedinessOption
        if "UseUnicodePropertiesOption" in options:
            rxOptions |= QRegularExpression.UseUnicodePropertiesOption
        if "DontCaptureOption" in options:
            rxOptions |= QRegularExpression.DontCaptureOption
        
        error = ""
        errorOffset = -1
        re = QRegularExpression(regexp, rxOptions)
        valid = re.isValid()
        if not valid:
            error = re.errorString()
            errorOffset = re.patternErrorOffset()
    except ImportError:
        valid = False
        error = "ImportError"
        errorOffset = 0
    
    return valid, error, errorOffset
Beispiel #6
0
    def apply_filter(self, *args):
        text = self.filterEdit.text()
        if text:
            if self.filter_columns.currentText() == "name":
                m = QRegularExpression(text)
                if m.isValid():
                    if self.name_regex_option.currentText(
                    ) == "case-insensitive":
                        m.setPatternOptions(
                            QRegularExpression.CaseInsensitiveOption)

                    m.optimize()
                    filter = lambda row_num: m.match(
                        self.table.item(row_num, 0).text()).hasMatch()
                else:
                    return

        else:
            filter = lambda row: True

        for i in range(0, self.table.rowCount()):
            self.table.setRowHidden(i, not filter(i))
Beispiel #7
0
    def apply_filter(self, text=None):
        if text is None:
            text = self.filter.text()

        if text:
            text = text.replace("(", "\(")
            text = text.replace(")", "\)")
            m = QRegularExpression(text)
            m.setPatternOptions(QRegularExpression.CaseInsensitiveOption)
            if m.isValid():
                m.optimize()
                filter = lambda row_num: m.match(
                    self.table.item(row_num, 0).text()
                    if self.table.item(row_num, 0) is not None else self.table.
                    cellWidget(row_num, 0).text().replace("<sub>", "").replace(
                        "</sub>", "")).hasMatch()
            else:
                return

        else:
            filter = lambda row: True

        for i in range(0, self.table.rowCount()):
            self.table.setRowHidden(i, not filter(i))