当前位置: 首页>>代码示例>>Python>>正文


Python QRegExp.captureCount方法代码示例

本文整理汇总了Python中PySide.QtCore.QRegExp.captureCount方法的典型用法代码示例。如果您正苦于以下问题:Python QRegExp.captureCount方法的具体用法?Python QRegExp.captureCount怎么用?Python QRegExp.captureCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtCore.QRegExp的用法示例。


在下文中一共展示了QRegExp.captureCount方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MacroHighlighter

# 需要导入模块: from PySide.QtCore import QRegExp [as 别名]
# 或者: from PySide.QtCore.QRegExp import captureCount [as 别名]
class MacroHighlighter(QSyntaxHighlighter):
    def __init__(self,textboxdoc,valid_list_of_commands):
        QSyntaxHighlighter.__init__(self,textboxdoc)
        self.valid_syntax="|".join([command.regexp_str for command in valid_list_of_commands])
        self.my_expression = QRegExp(self.valid_syntax)
        #define a blue font format for valid commands
        self.valid = QTextCharFormat()
        self.valid.setForeground(Qt.black)
        #define a bold red font format for invalid commands
        self.invalid = QTextCharFormat()
        self.invalid.setFontWeight(QFont.Bold)
        self.invalid.setForeground(Qt.red)
        #define a blue font format for valid parameters
        self.valid_value=QTextCharFormat()        
        self.valid_value.setFontWeight(QFont.Bold)
        #self.valid_value.setForeground(QColor.fromRgb(255,85,0))
        self.valid_value.setForeground(Qt.blue)
                
    def highlightBlock(self, text):
        #this function is automatically called when some text is changed
        #in the texbox. 'text' is the line of text where the change occured    
        #check if the line of text contains a valid command
        match = self.my_expression.exactMatch(text)
        if match:
            #valid command found: highlight the command in blue
            self.setFormat(0, len(text), self.valid)
            #highlight the parameters in orange
            #loop on all the parameters that can be captured
            for i in range(self.my_expression.captureCount()):
                #if a parameter was captured, it's position in the text will be >=0 and its capture contains some value 'xxx'
                #otherwise its position is -1 and its capture contains an empty string ''
                if self.my_expression.pos(i+1)!=-1:
                    self.setFormat(self.my_expression.pos(i+1), len(self.my_expression.cap(i+1)), self.valid_value)
        else:
            #no valid command found: highlight in red
            self.setFormat(0, len(text), self.invalid)
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:38,代码来源:Macro_editor.py


注:本文中的PySide.QtCore.QRegExp.captureCount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。