Exemplo n.º 1
0
 def findInField(self, lookFor, parameters):
     cursor = self.fldbk.dData.textCursor()
     format = QtGui.QTextCharFormat()
     format.setBackground(QtGui.QBrush(QtGui.QColor("yellow")))
     if parameters[0] == 1:
         lookFor = self.removeAccents(lookFor)
     if parameters[1] == 1:
         lookFor = self.removeDiacrits(lookFor)
     if "#" in lookFor:
         lookFor = self.setEdge(lookFor)
     if parameters[2] == 0:
         regex = QtCore.QRegularExpression(
             lookFor, QtCore.QRegularExpression.CaseInsensitiveOption)
     else:
         regex = QtCore.QRegularExpression(lookFor)
     pos = 0
     index = QtCore.QRegularExpressionMatch()
     dataset = self.fldbk.dData.toPlainText()
     index = regex.match(dataset, pos)
     while (index.hasMatch()):
         cursor.setPosition(index.capturedStart())
         cursor.movePosition(QtGui.QTextCursor.StartOfBlock)
         cursor.movePosition(QtGui.QTextCursor.EndOfBlock,
                             QtGui.QTextCursor.KeepAnchor)
         cursor.mergeCharFormat(format)
         pos = index.capturedStart() + len(index.captured())
         index = regex.match(dataset, pos)
Exemplo n.º 2
0
 def findpattern(self):
     regex_pattern = self.expression_box.text()
     regex = qtc.QRegularExpression(regex_pattern)
     i = qtc.QRegularExpressionMatchIterator(
         regex.globalMatch(self.textedit.toPlainText()))
     word = []
     self.statusBar().showMessage('Finding.....')
     while i.hasNext():
         match = qtc.QRegularExpressionMatch(i.next())
         word.append(match.captured(0))
     self.dialogbox = DialogBox(word)
     self.dialogbox.exec()
Exemplo n.º 3
0
 def searchElement(self, entry, term, target):
     '''tests the entry to see if the search term is in the target string'''
     '''parameters = [accent,diacrit,case,append,recOnly,wholeWord]'''
     if target == None or target == False:
         hit = False
         return hit
     lookFor = term[1].strip()
     if '@' in term[0]:
         if lookFor[-1] == ".":
             lookFor = lookFor.replace('.', '')
     polarity = None
     if lookFor[0] == '¬':
         lookFor = lookFor[1:]
         polarity = 'neg'
     '''perform a search that abstracts over accents'''  #parameters[0] flags accents
     if self.parameters[1] == 1:
         '''perform a search that abstracts over diacritics'''  #parameters[1] flags diacrits
         lookFor = self.removeDiacrits(lookFor)
     if self.parameters[0] == 1:
         lookFor = self.removeAccents(lookFor)
     if self.parameters[5] == 1:  #if whole word search
         lookFor = '(\s|^)' + lookFor + '(\s|$)'
     elif "#" in lookFor:
         lookFor = self.setEdge(lookFor)
     if self.parameters[2] == 0:  #parameters[2] flags caps
         p = QtCore.QRegularExpression(
             lookFor, QtCore.QRegularExpression.CaseInsensitiveOption)
     else:
         p = QtCore.QRegularExpression(
             lookFor, QtCore.QRegularExpression.CaseInsensitiveOption)
     m = QtCore.QRegularExpressionMatch()
     m = p.match(target)
     if m.hasMatch():
         if polarity == 'neg':
             hit = False
         else:
             hit = True
     else:
         hit = False
     return hit
Exemplo n.º 4
0
def searchXML(fldbk, regExp):
    resultsDict = {}
    matchObject = QtCore.QRegularExpressionMatch()
    if dataIndex.currentCard[0] == "L":
        cardType = "Lex"
        ID = 'LexID'
    elif dataIndex.currentCard[0] == "T":
        return
    elif dataIndex.currentCard[0] == "D":
        cardType = "Dset"
        ID = 'DsetID'
    elif dataIndex.currentCard[0] == "E":
        cardType = "Ex"
        ID = 'ExID'
    else:
        return
    i = 0
    for node in dataIndex.root.iter(cardType):
        for item in node.itertext():
            matchObject = regExp.match(item)
            if matchObject.hasMatch():
                i += 1
                resultsDict[i] = node.get(ID)
    if len(resultsDict) != 0:
        tCard = resultsDict[1]
        if cardType == 'Lex':
            cardLoader.loadLexCard(dataIndex.lexDict[tCard])
        elif cardType == 'Dset':
            cardLoader.loadDataCard(dataIndex.dataDict[tCard])
        elif cardType == 'Ex':
            cardLoader.loadExCard(dataIndex.exDict[tCard])
        return resultsDict
    else:
        notFoundBox = QtWidgets.QMessageBox()
        notFoundBox.setText('Text not found.')
        notFoundBox.exec_()
        return False