예제 #1
0
def data(block):
    """Get the block's QTextBlockUserData, creating it if necessary.""" 
    data = block.userData()
    if not data:
        data = QTextBlockUserData()
        block.setUserData(data)
    return data
예제 #2
0
    def highlightBlock_enchant(self, text):
        """Method for pyenchant spell checker"""

        if not self._sp_dict:
            return

        # Build a list of all misspelled words and highlight them
        misspellings = []
        for (word, pos) in self.tokenizer(text):
            if not self._sp_dict.check(word):
                self.setFormat(pos, len(word), self.err_format)
                misspellings.append((pos, pos + len(word)))

        # Store the list so the context menu can reuse this tokenization pass
        # (Block-relative values so editing other blocks won't invalidate them)
        data = QTextBlockUserData()
        data.misspelled = misspellings
        self.setCurrentBlockUserData(data)
예제 #3
0
 def __init__(self, data):
     QTextBlockUserData.__init__(self)
     self.data = data
예제 #4
0
 def __init__(self, data):
     QTextBlockUserData.__init__(self)
     self.data = data
예제 #5
0
 def __init__(self):
     QTextBlockUserData.__init__(self)
예제 #6
0
 def __init__(self):
     QTextBlockUserData.__init__(self)
     self._listLevel = 0
     self._leadingSpaces = 0
     self._emptyLinesBefore = 0
     self._listSymbol = ""
예제 #7
0
파일: base.py 프로젝트: ninja-ide/ninja-ide
 def __init__(self):
     QTextBlockUserData.__init__(self)
     self.attrs = {}
예제 #8
0
 def __init__(self):
     QTextBlockUserData.__init__(self)
     self.attrs = {}
예제 #9
0
 def __init__(self):
     QTextBlockUserData.__init__(self)
예제 #10
0
 def __init__(self):
     QTextBlockUserData.__init__(self)
     self._listLevel = 0
     self._leadingSpaces = 0
     self._emptyLinesBefore = 0
     self._listSymbol = ""
예제 #11
0
    def highlightBlock(self, text):
        """Analyse chaque ligne et applique les lignes"""
        """Analyse des lignes avec les règles"""
        #Style avec
        if not hasattr(self.currentUserData(), "isPHP"):
            userData = QTextBlockUserData()
            userData.isStyle = False
            userData.isPHP = False
            self.setCurrentUserData(userData)
        if not hasattr(self.nextUserData(), "isPHP"):
            userData = QTextBlockUserData()
            userData.isStyle = False
            userData.isPHP = False
            self.setNextUserData(userData)

        if self.language.lower() in ("html", "htm", "php"):
            """-------Langage HTML---------------"""

            regle = RegleHTML(self.coloration)
            """Balises"""
            for expression, tformat in regle.regles_tags:
                #Si l'expression ne doit pas avoir de parent
                index = expression.indexIn(text)
                while index >= 0:
                    length = expression.matchedLength()
                    self.setFormat(index, length, tformat)
                    """Attributs"""
                    # Recherche des attributs dans la balise
                    contenuTag = text[index:(length + index)]
                    #Debut de la partie apres le nom de la balise
                    debutAttr = contenuTag.find(" ")
                    #Recuperation de la chaine correspondant à cette partie
                    after_space = contenuTag[debutAttr::]
                    for exp_attr, format_attr in regle.regles_attributes:
                        index_attr = exp_attr.indexIn(after_space)
                        while index_attr >= 0:
                            length_attr = exp_attr.matchedLength()
                            self.setFormat(index + debutAttr + index_attr,
                                           length_attr, format_attr)
                            index_attr = exp_attr.indexIn(
                                after_space, index_attr + length_attr)
                        index_text_attr = regle.attributesText_regex.indexIn(
                            after_space)
                        """Texte attributs"""
                        while index_text_attr >= 0:
                            length_text_attr = regle.attributesText_regex.matchedLength(
                            )
                            self.setFormat(index + debutAttr + index_text_attr,
                                           length_text_attr,
                                           regle.attributesTextFormat)
                            index_text_attr = regle.attributesText_regex.indexIn(
                                after_space,
                                index_text_attr + length_text_attr)
                    index = expression.indexIn(text, index + length)
            self.setCurrentBlockState(0)
            """Utilisation de la fonction colorationCommentaires pour le style"""
            debutStyle = QRegExp("(<style [^<>]*>)|(<style>)",
                                 Qt.CaseInsensitive)
            finStyle = QRegExp("</style>", Qt.CaseInsensitive)
            startIndexStyle = debutStyle.indexIn(text)
            if hasattr(self.previousUserData(),
                       "isStyle") and self.previousUserData().isStyle:
                startIndexStyle = 0
            while startIndexStyle >= 0:
                if not self.previousUserData().isStyle:
                    startText = startIndexStyle + debutStyle.matchedLength()
                else:
                    startText = startIndexStyle
                self.currentUserData().isStyle = True
                textStyle = ""
                # On vérifie si la fin du style est sur la ligne courante
                endIndexStyle = finStyle.indexIn(text, startIndexStyle)
                if endIndexStyle == -1:
                    # Si ce n'est pas le cas
                    style_length = len(text) - startIndexStyle
                    textStyle = text[startText:]
                else:
                    # Si oui
                    self.currentUserData().isStyle = False
                    textStyle = text[startText:endIndexStyle]
                    style_length = len(textStyle)
                regleCSS = RegleCSS(self.coloration)
                for list_regles in regleCSS.lists_regles:
                    for regex, format in list_regles:
                        index = regex.indexIn(textStyle)
                        while index >= 0:
                            self.setFormat(startText + index,
                                           regex.matchedLength(), format)
                            index = regex.indexIn(
                                textStyle, index + regex.matchedLength())
                """Les autres règles"""
                for simple_regle in regleCSS.simples_regles:
                    index = simple_regle["regex"].indexIn(textStyle)
                    while index >= 0:
                        self.setFormat(startText + index,
                                       simple_regle["regex"].matchedLength(),
                                       simple_regle["format"])
                        index = simple_regle["regex"].indexIn(
                            textStyle,
                            index + simple_regle["regex"].matchedLength())
                startIndexStyle = debutStyle.indexIn(
                    text, startIndexStyle + style_length)
            self.setCurrentBlockState(0)
            """Commentaires"""
            self.colorationCommentaires(text, regle.comments_debut,
                                        regle.comments_fin,
                                        regle.commentsFormat)
            """------Coloration du PHP------------"""
            regle = ReglePHP(self.coloration)
            startPHP = regle.debutPHP.indexIn(text)
            if hasattr(self.previousUserData(),
                       "isPHP") and self.previousUserData().isPHP:
                startPHP = 0
            if startPHP >= 0:
                self.currentUserData().isPHP = True
                endPHP = regle.finPHP.indexIn(text, startPHP)
                if endPHP == -1:
                    lengthPHP = len(text) - startPHP
                else:
                    self.currentUserData().isPHP = False
                    lengthPHP = endPHP - startPHP + regle.finPHP.matchedLength(
                    )
                textPHP = text[startPHP:(endPHP +
                                         regle.finPHP.matchedLength())]
                self.setFormat(startPHP, lengthPHP, self.simpleTextFormat)
                for list_regles in regle.lists_regles:
                    for regex, format in list_regles:
                        index = regex.indexIn(textPHP)
                        while index >= 0:
                            self.setFormat(startPHP + index,
                                           regex.matchedLength(), format)
                            index = regex.indexIn(
                                textPHP, index + regex.matchedLength())
                """Les autres règles"""
                for simple_regle in regle.simples_regles:
                    index = simple_regle["regex"].indexIn(textPHP)
                    while index >= 0:
                        self.setFormat(startPHP + index,
                                       simple_regle["regex"].matchedLength(),
                                       simple_regle["format"])
                        index = simple_regle["regex"].indexIn(
                            textPHP,
                            index + simple_regle["regex"].matchedLength())
                """Commentaire sur une ligne"""
                index = regle.lineComment.indexIn(textPHP)
                if index >= 0:
                    self.setFormat(startPHP + index, len(textPHP),
                                   regle.commentsFormat)
                self.setCurrentBlockState(0)
                self.colorationCommentaires(textPHP, regle.comments_debut,
                                            regle.comments_fin,
                                            regle.commentsFormat, startPHP)

                startPHP = regle.debutPHP.indexIn(text, startPHP + lengthPHP)

        elif self.language.lower() in ("css", "scss"):
            """------Langage CSS--------------"""

            regle = RegleCSS(self.coloration)
            """Regles sur les mots clés"""
            for list_regles in regle.lists_regles:
                for regex, format in list_regles:
                    index = regex.indexIn(text)
                    while index >= 0:
                        self.setFormat(index, regex.matchedLength(), format)
                        index = regex.indexIn(text,
                                              index + regex.matchedLength())
            """Les autres règles"""
            for simple_regle in regle.simples_regles:
                index = simple_regle["regex"].indexIn(text)
                while index >= 0:
                    self.setFormat(index,
                                   simple_regle["regex"].matchedLength(),
                                   simple_regle["format"])
                    index = simple_regle["regex"].indexIn(
                        text, index + simple_regle["regex"].matchedLength())

            self.setCurrentBlockState(0)
            """Commentaires"""
            self.colorationCommentaires(text, regle.comments_debut,
                                        regle.comments_fin,
                                        regle.commentsFormat)