本文整理汇总了Python中PyQt4.QtCore.QRegExp.indexIn方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.indexIn方法的具体用法?Python QRegExp.indexIn怎么用?Python QRegExp.indexIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QRegExp
的用法示例。
在下文中一共展示了QRegExp.indexIn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: highlightBlock
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def highlightBlock(self, text):
"""Apply syntax highlighting to the given block of text."""
for expression, nth, format in self.rules:
index = expression.indexIn(text, 0)
while index >= 0:
# We actually want the index of the nth match
index = expression.pos(nth)
length = expression.cap(nth).length()
self.setFormat(index, length, format)
index = expression.indexIn(text, index + length)
self.setCurrentBlockState(0)
if not self.multi_start:
# Do multi-line strings
in_multiline = self.match_multiline(text, *self.tri_single)
if not in_multiline:
in_multiline = self.match_multiline(text, *self.tri_double)
else:
# Do multi-line comment
self.comment_multiline(text, self.multi_end[0], *self.multi_start)
#Spaces
expression = QRegExp('\s+')
index = expression.indexIn(text, 0)
while index >= 0:
index = expression.pos(0)
length = expression.cap(0).length()
self.setFormat(index, length, STYLES['spaces'])
index = expression.indexIn(text, index + length)
示例2: run
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def run(self):
self.msleep(300)
block = self._highlighter.document().begin()
while block.blockNumber() != -1:
text = block.text()
formats = []
for expression, nth, char_format in self._highlighter.rules:
index = expression.indexIn(text, 0)
while index >= 0:
# We actually want the index of the nth match
index = expression.pos(nth)
length = expression.cap(nth).length()
formats.append((index, length, char_format))
index = expression.indexIn(text, index + length)
# Spaces
expression = QRegExp("\s+")
index = expression.indexIn(text, 0)
while index >= 0:
index = expression.pos(0)
length = expression.cap(0).length()
formats.append((index, length, STYLES["spaces"]))
index = expression.indexIn(text, index + length)
self.styles[block.blockNumber()] = formats
block = block.next()
示例3: run
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def run(self):
"""Execute this rules in another thread to avoid blocking the ui."""
styles = {}
self.msleep(300)
block = self._highlighter.document().begin()
while block.blockNumber() != -1:
text = block.text()
formats = []
for expression, nth, char_format in self._highlighter.rules:
index = expression.indexIn(text, 0)
while index >= 0:
# We actually want the index of the nth match
index = expression.pos(nth)
length = len(expression.cap(nth))
formats.append((index, length, char_format))
index = expression.indexIn(text, index + length)
# Spaces
expression = QRegExp("\s+")
index = expression.indexIn(text, 0)
while index >= 0:
index = expression.pos(0)
length = len(expression.cap(0))
formats.append((index, length, STYLES["spaces"]))
index = expression.indexIn(text, index + length)
styles[block.blockNumber()] = formats
block = block.next()
self.emit(SIGNAL("highlightingDetected(PyQt_PyObject)"), styles)
示例4: parse
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def parse(self, text):
"""
Parse some text, assuming it is in the form of:
word 1414 {grammar} word 1414 {grammar} etc.
and returns a list of tupples '(word, strong, grammar)'.
"""
result = []
r = QRegExp(r'([αβχδεφγηιϕκλμνοπθρστυςωξψζ]*)' +
'\s*' +
'([\d ]+)' +
'\s*' +
'\{(.*)\}\s*')
r.setMinimal(True)
pos = r.indexIn(text)
while pos >= 0:
# Some verbs have two strong numbers, we keep only the first,
# the second one being grammar
strong = r.cap(2).strip()
if " " in strong:
strong = strong.split(" ")[0]
result.append((r.cap(1).strip(),
strong,
r.cap(3).strip()))
pos = r.indexIn(text, pos + len(r.cap(0)))
return result
示例5: run
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def run(self):
styles = {}
self.msleep(300)
block = self._highlighter.document().begin()
while block.blockNumber() != -1:
text = block.text()
formats = []
for expression, nth, char_format in self._highlighter.rules:
index = expression.indexIn(text, 0)
while index >= 0:
# We actually want the index of the nth match
index = expression.pos(nth)
length = expression.cap(nth).length()
formats.append((index, length, char_format))
index = expression.indexIn(text, index + length)
#Spaces
expression = QRegExp('\s+')
index = expression.indexIn(text, 0)
while index >= 0:
index = expression.pos(0)
length = expression.cap(0).length()
formats.append((index, length, STYLES['spaces']))
index = expression.indexIn(text, index + length)
styles[block.blockNumber()] = formats
block = block.next()
self.emit(SIGNAL("highlightingDetected(PyQt_PyObject)"), styles)
示例6: handle_stdout
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def handle_stdout(self):
"""
Private slot to handle the readyReadStdout
signal of the pylint process.
"""
result_list = []
#regex = QRegExp('(\w)\S*:\S*(\d*):.*: (.*)')
regex = QRegExp('(\w)\s*:\s*(\d*):(.*)')
regex_score = \
QRegExp('.*at.(\d.\d*)/10.*')
while self.pylint_pross and self.pylint_pross.canReadLine():
result = unicode(self.pylint_pross.readLine())
if result != None:
pos = 0
while True:
pos = regex.indexIn(result, pos)
if pos < 0:
if regex_score.indexIn(result, 0) >= 0:
self.win.setWindowTitle( \
"PyLint Results :" \
+ str(regex_score.cap(1)) \
+ ':'
+ os.path.basename(str(self.parent.editor.filename)))
break
result_list.append((regex.cap(1), regex.cap(2), regex.cap(3)))
#print 'Append : ',(regex.cap(1), regex.cap(2), regex.cap(3))
pos = pos + regex.matchedLength()
if len(result_list)>0:
self.win.append_results(result_list)
示例7: highlightBlock
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def highlightBlock(self, text):
for pattern, format in self.rules:
exp = QRegExp(pattern)
index = exp.indexIn(text)
while index >= 0:
length = exp.matchedLength()
if exp.numCaptures() > 0:
self.setFormat(exp.pos(1), len(str(exp.cap(1))), format)
else:
self.setFormat(exp.pos(0), len(str(exp.cap(0))), format)
index = exp.indexIn(text, index + length)
# Multi line strings
start = self.multilineStart
end = self.multilineEnd
self.setCurrentBlockState(0)
startIndex, skip = 0, 0
if self.previousBlockState() != 1:
startIndex, skip = start.indexIn(text), 3
while startIndex >= 0:
endIndex = end.indexIn(text, startIndex + skip)
if endIndex == -1:
self.setCurrentBlockState(1)
commentLen = len(text) - startIndex
else:
commentLen = endIndex - startIndex + 3
self.setFormat(startIndex, commentLen, self.stringFormat)
startIndex, skip = (start.indexIn(text,
startIndex + commentLen + 3),
3)
示例8: RegexHighlighter
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
class RegexHighlighter(QSyntaxHighlighter):
def __init__(self, widget):
QSyntaxHighlighter.__init__(self, widget)
self.regex = None
# create format type
self.odd_format = QTextCharFormat()
self.odd_format.setFontWeight(QFont.Bold)
self.odd_format.setForeground(Qt.darkBlue)
self.even_format = QTextCharFormat()
self.even_format.setFontWeight(QFont.Bold)
self.even_format.setForeground(Qt.darkMagenta)
def set_regex(self, exp):
self.regex = QRegExp(exp)
def highlightBlock(self, text):
if not self.regex:
return
matches = 0
pos = self.regex.indexIn(text, 0)
while (pos >= 0):
length = self.regex.matchedLength()
matches += 1
if matches % 2 == 0:
self.setFormat(pos, length, self.even_format)
else:
self.setFormat(pos, length, self.odd_format)
# handle wildcard (*)
if length == 0:
pos += 1
pos = self.regex.indexIn(text, pos + length)
示例9: highlightEntity
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def highlightEntity(self,text,entity):
if entity.style == self.Default:
return
expression=QRegExp(entity.pattern)
index=expression.indexIn(text)
while index>=0:
length =expression.matchedLength()
self.setFormat(index,length,self.style(entity.style))
index=expression.indexIn(text,index+length)
示例10: highlightBlock
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def highlightBlock(self, text):
for rule in self.highlightingRules:
expression = QRegExp(rule.pattern)
index = expression.indexIn(text)
while index >= 0:
length = expression.matchedLength()
self.setFormat(index, length, rule.format)
index = expression.indexIn(text, index + length)
self.setCurrentBlockState(0)
示例11: getIndent
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def getIndent(self,text):
spaces= QRegExp("^(\\s*).*$")
#~ indentation=""
#~ if len(text) > 0 and text[-1] in [':', '{', '(', '[']:
#~ indentation=" "
if spaces.indexIn(text) == -1:
return ""
return spaces.cap(1)
示例12: getData
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def getData(self, error):
if error:
self.html = self.http.errorString()
else:
self.html = self.http.readAll()
# the following is a hack to handle redirects...
regexp = QRegExp(r'Redirect\sto\s\<a\shref=\"(.*)\">')
if regexp.indexIn(QString(self.html)) > -1:
self.setSource(QUrl(regexp.capturedTexts()[1]))
示例13: highlightRegion
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def highlightRegion(self,text,block):
if block.style == self.Default:
return
startId=0
self.setCurrentBlockState(0)
start=QRegExp(block.start)
end=QRegExp(block.end)
if self.previousBlockState() != 1:
startId= start.indexIn(text)
while startId >= 0:
endId=end.indexIn(text,startId)
if endId == -1:
self.setCurrentBlockState(1)
length=text.length()-startId
else:
length=endId - startId +end.matchedLength()
self.setFormat(startId,length,self.style(block.style))
startId=start.indexIn(text,startId+length)
示例14: find
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def find(self, name):
location = QString(robjects.r.help(unicode(name))[0])
regexp = QRegExp(r"(library.*)")
start = regexp.indexIn(location)
end = location.lastIndexOf("/")
name = location[end+1:]
location = location[start-1:]+".html"
location.replace("help", "html")
self.help_open(location, name, location)
示例15: highlightBlock
# 需要导入模块: from PyQt4.QtCore import QRegExp [as 别名]
# 或者: from PyQt4.QtCore.QRegExp import indexIn [as 别名]
def highlightBlock(self, text):
# for every pattern
for pattern, char_format in self.highlightingRules:
# Create a regular expression from the retrieved pattern
expression = QRegExp(pattern)
# Check what index that expression occurs at with the ENTIRE text
index = expression.indexIn(text)
# While the index is greater than 0
while index >= 0:
# Get the length of how long the expression is true,
# set the format from the start to the length with
# the text format
length = expression.matchedLength()
self.setFormat(index, length, char_format)
# Set index to where the expression ends in the text
index = expression.indexIn(text, index + length)
self.setCurrentBlockState(0)
start_index = 0
if self.previousBlockState() != 1:
start_index = self.value_start_expression.indexIn(text)
while start_index >= 0:
end_index = self.value_end_expression.indexIn(text, start_index)
if end_index == -1:
self.setCurrentBlockState(1)
comment_length = len(text) - start_index
else:
comment_length = \
end_index - start_index + \
self.value_end_expression.matchedLength()
self.setFormat(start_index, comment_length, self.value_format)
start_index = self.value_start_expression.indexIn(
text, start_index + comment_length)