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


Python QtCore.QRegExp类代码示例

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


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

示例1: highlightBlock

 def highlightBlock(self, text):
     for rule in self.highlighting_rules:
         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)
开发者ID:AbuRah,项目名称:pycode,代码行数:9,代码来源:SyntaxClasses.py

示例2: handleHtmlPage

 def handleHtmlPage(self, htmlPage):
         tup = ()
         self._gridList = []
         wina7rx = QRegExp("\{\"pool_id\":700(\\d+).*\"pool_end\":(\\d+).*\"guaranteed_amount\":(\\d+).*\}")
         posi = wina7rx.indexIn(str(htmlPage))
         ngrille = wina7rx.cap(1)
         print "ngrille=%s" % ngrille
         #self.gridList.append(wina7rx.cap(1))
         date = wina7rx.cap(2)
         print "date=%s" % date
         jackpot = wina7rx.cap(3)
         print "jackpot=%s" % jackpot
         tup = (ngrille, date, jackpot)
         self._gridList.append(tup)
         while posi != -1 :
                 posi = wina7rx.indexIn(str(htmlPage), posi+1)
                 ngrille = wina7rx.cap(1)
                 print "ngrille=%s" % ngrille
                 date = wina7rx.cap(2)
                 print "date=%s" % date
                 jackpot = wina7rx.cap(3)
                 print "jackpot=%s" % jackpot
                 tup = (ngrille, date, jackpot)
                 self._gridList.append(tup)
         print self._gridList
开发者ID:poupou14,项目名称:CombinoGen,代码行数:25,代码来源:ReadWinamax7Handler.py

示例3: handleDistribHtmlPage

 def handleDistribHtmlPage(self, htmlPage):
         euro7startRx = QRegExp("data-grid-id=\"(\\d*)\"")
         indexGrille = ""
         posi = 0
         while posi != -1 and indexGrille != self._gridList[self._indexGrille][0]:
             print "posi = %d" % posi
             print "indexGrille = %s" % indexGrille
             print "self._indexGrille = %s" % self._gridList[self._indexGrille][0]
             posi= euro7startRx.indexIn(htmlPage, posi+1)
             indexGrille = euro7startRx.cap(1)
         euro7TeamRx = QRegExp("<label for=\"[^\"]*\">([^<]*)<\/label>")
         self._grid = Grille()
         self._grid.setReturnRate(0.75)
         self._grid.setFirstRankRate(0.55)
         self._grid.setScndRankRate(0.45)
         jackpot = int(self._gridList[self._index][2])
         self._grid.setJackpot(jackpot)
         self._grid.setNbPlayers(jackpot)
         index_l = 0
         total = 0
         #size_l = 5
         i=0
         #try:
         if True:
             posi= euro7TeamRx.indexIn(htmlPage, posi)
             print "posi = %d" % posi
             while posi != -1 and i < self._gridSize:
                 i += 1
                 team1 = euro7TeamRx.cap(1)
                 print "team1 = %s" % team1
                 posi= euro7TeamRx.indexIn(htmlPage, posi+1)
                 posi= euro7TeamRx.indexIn(htmlPage, posi+1)
                 team2 = euro7TeamRx.cap(1)
                 print "indice %i" % i
                 print "team2 = %s" % team2
                 match = Match(team1 + " vs " + team2)
                 match.setTeam1(team1)
                 match.setTeam2(team2)
                 p1 = 0.33
                 pN = 0.33
                 p2 = 0.33
                 total = p1 + pN +p2
                 r1 = p1/total*100
                 r2 = p2/total*100
                 rN = pN/total*100
                 match.setRepartition(p1/total, pN/total, p2/total)
                 self._grid.addGame(match)
                 print "game added : %d" % i
                 posi= euro7TeamRx.indexIn(htmlPage, posi+1)
         #except:
                 #msg = QMessageBox()
                 #msg.setText("Loading page error")
                 #msg.exec_()
         #self.__workbook1.save(self.__outPutFileName)
         return
开发者ID:poupou14,项目名称:CombinoGen,代码行数:55,代码来源:ReadEuro7Handler.py

示例4: __init__

 def __init__(self):
     self.regexp_str="Wait(?: at most "+Regexfloat+" secs)? for magnet (X|Y|Z) to finish ramping"
     self.label="Wait (at most X secs) for magnet (X|Y|Z) to finish ramping"
     self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
     self.regexp=QRegExp(self.regexp_str)
     self.waiting=False
     self.waiting_start=0
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:7,代码来源:Macro_editor.py

示例5: WaitForHStableCommand

class WaitForHStableCommand():
    def __init__(self):
        self.regexp_str="Wait(?: at most "+Regexfloat+" secs)? for magnet (X|Y|Z) to finish ramping"
        self.label="Wait (at most X secs) for magnet (X|Y|Z) to finish ramping"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
        self.waiting=False
        self.waiting_start=0
    
    def run(self,main):
        values=self.regexp.capturedTexts()
        #wait for field to stabilize (and lock only when accessing the instrument)
        with main.reserved_access_to_instr:
            magnet=eval("main.magnet_"+values[2])
            stat=magnet.query_status()
        if self.waiting==False:
            self.waiting=True
            self.waiting_start=time.clock()
        if not(stat=='RAMPING to programmed current/field') or (values[1]!='' and time.clock()-self.waiting_start>float(values[1])):
            #ramping is finished or time limit is reached, go to next line of macro
            self.waiting=False
            self.next_move=1
            self.wait_time=500
        else:
            #wait 5s and check again
            self.next_move=0
            self.wait_time=5000       
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:27,代码来源:Macro_editor.py

示例6: SetTempVTICommand

class SetTempVTICommand():
    def __init__(self):
        self.regexp_str="Set VTI Loop (\d+) to "+Regexfloat+" K(?: @ "+Regexfloat+" K/min)?"
        self.label="Set VTI Loop X to X K (@ X K/min)"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
        self.waiting=False
        self.waiting_start=0
        
    def run(self,main):
        values=self.regexp.capturedTexts()
        ##get the loop index and setpoint value
        loop=float(values[1])
        setpoint=float(values[2])
        #if a ramp rate was also provided, go to this setpoint at this rate
        VTI=main.instr_9
        if values[3]!='':
            rate=float(values[3])
            with main.reserved_access_to_instr:
                VTI.conf_ramp(loop,rate,'on')
                VTI.set_setpoint(loop,setpoint)
        else:        
            with main.reserved_access_to_instr:            
                VTI.switch_ramp(loop,'off')
                VTI.set_setpoint(loop,setpoint)
        #go to next line of macro after stdwtime (give some time to process other events)
        self.next_move=1
        self.wait_time=500
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:28,代码来源:Macro_editor.py

示例7: AngleCommand

class AngleCommand():
    def __init__(self):
        #Text that will appear in the list of commands on the right side of the Macro editor
        self.label="Set start|stop|step angle to FLOAT"
        #Regular expression which may or may not catch parameters
        self.regexp_str="Set (start|stop|step) angle to "+Regexfloat
        #Add this to the beginning and end of the regular expression
        #so that whitespaces before and after will not prevent the regex from matching
        self.regexp_str="^ *"+self.regexp_str+" *$"
        #instantiate regex
        self.regexp=QRegExp(self.regexp_str)
    
    def run(self,main):
        #what to do when the regex defined just above in __init__
        #has matched the current line of the Macro
        #get the captured parameters
        values=self.regexp.capturedTexts()
        #set the corresponding angle box
        if values[1] in ['stop','step','start']:
            anglebox=eval("main.ui.angle"+values[1])
            anglebox.setValue(float(values[2]))           
        #Finally go to next line of macro...
        self.next_move=1
        #...after 10 milliseconds
        self.wait_time=10 
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:25,代码来源:Macro_editor.py

示例8: WaitCommand

class WaitCommand():
    def __init__(self):
        self.regexp_str="Wait "+Regexfloat+" secs"
        self.label="Wait X secs"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
    
    def run(self,main):
        values=self.regexp.capturedTexts()
        #self.values[1]!=''
        #go to next line of macro after 'values[1]' seconds
        self.next_move=1
        self.wait_time=float(values[1])*1000      
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:13,代码来源:Macro_editor.py

示例9: highlightBlock

 def highlightBlock(self, text):
     # Derived from Qt function, used to apply color-syntaxing to text
     # :param text: text input
     
     rules = [(QColor(100, 165, 225), r"^(//|#).+$"),         #blue 100, 165, 225
              (QColor(205, 200, 120), r"^(//|#) Warning.+$"), #yellow 205, 200, 120
              (QColor(165,  75,  75), r"^(//|#).+Error.+$"),  #red 165, 75, 75
              (QColor(115, 215, 150), r"^(//|#).+Result.+$")] #green 115, 215, 150
     # loop through rules
     for color, pattern in rules:
         keyword = QTextCharFormat()
         keyword.setForeground(color)
         # get regexp pattern
         expression = QRegExp(pattern)
         index = expression.indexIn(text)
         # loop until all matches are done
         while index >= 0:
             length = expression.matchedLength()
             # format text with current formatting
             self.setFormat(index, length, keyword)
             index = expression.indexIn(text, index + length)
     self.setCurrentBlockState(0)
开发者ID:m3trik,项目名称:Python-2.7,代码行数:22,代码来源:scriptEditorOutputTextHighlighting.py

示例10: SetSaveFileCommand

class SetSaveFileCommand():
    def __init__(self):
        self.regexp_str="Set Save file to "+Regexsimplefile+""
        self.label="Set Save file to X"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
    
    def run(self,main):
        values=self.regexp.capturedTexts()
        main.ui.savefile_txt_input.setText(values[1])
        #new file name is set, go to next line of macro
        self.next_move=1
        self.wait_time=500                                     
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:13,代码来源:Macro_editor.py

示例11: highlightBlock

    def highlightBlock(self, text):
        """ Highlight a block of text """
        if self.enabled is False:
            return
        text = unicode(text)
        original_text = text
        prev_data = self.currentBlock().previous().userData()

        if prev_data is not None:
            self._lexer._saved_state_stack = prev_data.syntax_stack
        elif hasattr(self._lexer, '_saved_state_stack'):
            del self._lexer._saved_state_stack

        # Lex the text using Pygments
        index = 0
        for token, text in self._lexer.get_tokens(text):
            length = len(text)
            self.setFormat(index, length, self._get_format(token))
            index += length

        if hasattr(self._lexer, '_saved_state_stack'):
            data = PygmentsBlockUserData(
                syntax_stack=self._lexer._saved_state_stack)
            self.currentBlock().setUserData(data)
            # Clean up for the next go-round.
            del self._lexer._saved_state_stack

        #Spaces
        expression = QRegExp('\s+')
        index = expression.indexIn(original_text, 0)
        while index >= 0:
            index = expression.pos(0)
            length = len(expression.cap(0))
            self.setFormat(index, length, self._get_format(Whitespace))
            index = expression.indexIn(original_text, index + length)

        self.hilighlightingBlock.emit(original_text, self)
开发者ID:hofoen,项目名称:pcef-core,代码行数:37,代码来源:sh.py

示例12: MacroHighlighter

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,代码行数:36,代码来源:Macro_editor.py

示例13: SetVTIHeaterCommand

class SetVTIHeaterCommand():
    def __init__(self):
        self.regexp_str="Set VTI heater range to (\d)"
        self.label="Set VTI heater range to DIGIT"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
    
    def run(self,main):
        values=self.regexp.capturedTexts()
        #set the heater range
        with main.reserved_access_to_instr:
            main.instr_9.set_heater_range(int(values[1]))                     
        #go to next line of macro
        self.next_move=1
        self.wait_time=500         
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:15,代码来源:Macro_editor.py

示例14: StartMeasureCommand

class StartMeasureCommand():
    def __init__(self):
        #type name_of_program() to start it
        self.regexp_str="Start "+Regexprogramfile+"\((.*)\)"
        self.label="Start PROGRAM()"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
    
    def run(self,main):
        values=self.regexp.capturedTexts()
        main.ui.measMode.setCurrentIndex(main.ui.measMode.findText(values[1]))
        #start measurements
        main.start_measurements()
        #go to next line of macro
        self.next_move=1
        self.wait_time=500                      
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:16,代码来源:Macro_editor.py

示例15: WaitForEpoch

class WaitForEpoch():
    def __init__(self):
        self.regexp_str="Wait for Epoch \+ "+Regexfloat+" secs"
        self.label="Wait for Epoch + X secs"
        self.regexp_str="^ *"+self.regexp_str+" *$" #so that the same string with heading and trailing whitespaces also matches
        self.regexp=QRegExp(self.regexp_str)
    
    def run(self,main):
        values=self.regexp.capturedTexts()
        #test if the current time is greater than the time provided in the macro (in Epoch seconds)
        if float(values[1])>time.time():
            self.next_move=0
            self.wait_time=5000
        else:
            self.next_move=1
            self.wait_time=100
开发者ID:Max-Leroux,项目名称:PyGMI,代码行数:16,代码来源:Macro_editor.py


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