예제 #1
0
 def __init__(self, doc):
     QSyntaxHighlighter.__init__(self, doc)
     self.colors = {}
     self.colors['doctype'] = QColor(192, 192, 192)
     self.colors['entity'] = QColor(128, 128, 128)
     self.colors['tag'] = QColor(136, 18, 128)
     self.colors['comment'] = QColor(35, 110, 37)
     self.colors['attrname'] = QColor(153, 69, 0)
     self.colors['attrval'] = QColor(36, 36, 170)
예제 #2
0
 def __init__(self, doc):
     QSyntaxHighlighter.__init__(self, doc)
     self.colors = {}
     self.colors['doctype']        = QColor(192, 192, 192)
     self.colors['entity']         = QColor(128, 128, 128)
     self.colors['tag']            = QColor(136,  18, 128)
     self.colors['comment']        = QColor(35, 110,  37)
     self.colors['attrname']       = QColor(153,  69,   0)
     self.colors['attrval']        = QColor(36,  36, 170)
예제 #3
0
    def __init__( self, parent, sections=[], keywords=[], entries=[], entry_keywords=[] ):
        QSyntaxHighlighter.__init__( self, parent )
        self.parent = parent

        self.highlightingRules = []

        if entries:
            # *known* entries
            reentries = r'('+(r'|'.join(entries))+r')'
            self.highlightingRules.append( HighlightingRule( r"\b"+reentries+r"\b", Qt.darkGreen ) )

        # true/false -- just to be nice.
        self.highlightingRules.append( HighlightingRule( r"\b(true|false)\b", Qt.darkGreen ) )

        # *all* keywords -- change known later.
        self.errorRule = HighlightingRule( r"^[^:=\s][^:=]*[:=]", Qt.red )
        self.highlightingRules.append( self.errorRule )

        # *all* entry keywords -- change known later.
        reentrykeywords = r'('+(r'|'.join([ e % r'[a-zA-Z0-9_]+' for e in entry_keywords ]))+r')'
        self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+reentrykeywords+r"(_filelist)?\s*[:=]", Qt.darkMagenta ) )

        if entries: # separate from known entries so entry named keyword won't be masked.
            # *known* entry keywords
            reentrykeywords = r'('+(r'|'.join([ e % reentries for e in entry_keywords ]))+r')'
            self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+reentrykeywords+r"(_filelist)?\s*[:=]", Qt.blue ) )

        # *known* keywords
        rekeywords = r'('+(r'|'.join(keywords))+r')'
        self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+rekeywords+r"(_filelist)?\s*[:=]", Qt.blue ) )

        # *all* sections -- change known later.
        self.highlightingRules.append( HighlightingRule( r"^\[[^\]]+\].*?$", Qt.red, QFont.Bold, blocknum=1 ) )

        if sections:
            # *known* sections
            resections = r'('+(r'|'.join(sections))+r')'
            resections = resections.replace('.','\.') #escape dots.
            self.highlightingRules.append( HighlightingRule( r"^\["+resections+r"\]\s*$", Qt.darkBlue, QFont.Bold, blocknum=2 ) )

        # test story sections
        self.teststoryRule = HighlightingRule( r"^\[teststory:([0-9]+|defaults)\]", Qt.darkCyan, blocknum=3 )
        self.highlightingRules.append( self.teststoryRule )

        # storyUrl sections
        self.storyUrlRule = HighlightingRule( r"^\[https?://.*\]", Qt.darkMagenta, blocknum=4 )
        self.highlightingRules.append( self.storyUrlRule )

        # NOT comments -- but can be custom columns, so don't flag.
        #self.highlightingRules.append( HighlightingRule( r"(?<!^)#[^\n]*" , Qt.red ) )

        # comments -- comments must start from column 0.
        self.commentRule = HighlightingRule( r"^#[^\n]*" , Qt.darkYellow )
        self.highlightingRules.append( self.commentRule )
예제 #4
0
    def __init__( self, parent, sections=[], keywords=[], entries=[], entry_keywords=[] ):
        QSyntaxHighlighter.__init__( self, parent )
        self.parent = parent
        
        self.highlightingRules = []

        if entries:
            # *known* entries
            reentries = r'('+(r'|'.join(entries))+r')'
            self.highlightingRules.append( HighlightingRule( r"\b"+reentries+r"\b", Qt.darkGreen ) )

        # true/false -- just to be nice.
        self.highlightingRules.append( HighlightingRule( r"\b(true|false)\b", Qt.darkGreen ) )
        
        # *all* keywords -- change known later.
        self.errorRule = HighlightingRule( r"^[^:=\s][^:=]*[:=]", Qt.red )
        self.highlightingRules.append( self.errorRule )

        # *all* entry keywords -- change known later.
        reentrykeywords = r'('+(r'|'.join([ e % r'[a-zA-Z0-9_]+' for e in entry_keywords ]))+r')'
        self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+reentrykeywords+r"(_filelist)?\s*[:=]", Qt.darkMagenta ) )

        if entries: # separate from known entries so entry named keyword won't be masked.
            # *known* entry keywords
            reentrykeywords = r'('+(r'|'.join([ e % reentries for e in entry_keywords ]))+r')'
            self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+reentrykeywords+r"(_filelist)?\s*[:=]", Qt.blue ) )

        # *known* keywords
        rekeywords = r'('+(r'|'.join(keywords))+r')'
        self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+rekeywords+r"(_filelist)?\s*[:=]", Qt.blue ) )

        # *all* sections -- change known later.
        self.highlightingRules.append( HighlightingRule( r"^\[[^\]]+\].*?$", Qt.red, QFont.Bold, blocknum=1 ) )

        if sections:
            # *known* sections
            resections = r'('+(r'|'.join(sections))+r')'
            resections = resections.replace('.','\.') #escape dots.
            self.highlightingRules.append( HighlightingRule( r"^\["+resections+r"\]\s*$", Qt.darkBlue, QFont.Bold, blocknum=2 ) )

        # test story sections
        self.teststoryRule = HighlightingRule( r"^\[teststory:([0-9]+|defaults)\]", Qt.darkCyan, blocknum=3 )
        self.highlightingRules.append( self.teststoryRule )

        # storyUrl sections
        self.storyUrlRule = HighlightingRule( r"^\[https?://.*\]", Qt.darkMagenta, blocknum=4 )
        self.highlightingRules.append( self.storyUrlRule )

        # NOT comments -- but can be custom columns, so don't flag.
        #self.highlightingRules.append( HighlightingRule( r"(?<!^)#[^\n]*" , Qt.red ) )
        
        # comments -- comments must start from column 0.
        self.commentRule = HighlightingRule( r"^#[^\n]*" , Qt.darkYellow )
        self.highlightingRules.append( self.commentRule )
예제 #5
0
 def __init__(self, doc):
     QSyntaxHighlighter.__init__(self, doc)
     self.colors = {}
     self.colors['doctype'] = QColor(192, 192, 192)
     self.colors['entity'] = QColor(128, 128, 128)
     self.colors['comment'] = QColor(35, 110, 37)
     if is_dark_theme():
         from calibre.gui2.palette import dark_link_color
         self.colors['tag'] = QColor(186, 78, 188)
         self.colors['attrname'] = QColor(193, 119, 60)
         self.colors['attrval'] = dark_link_color
     else:
         self.colors['tag'] = QColor(136, 18, 128)
         self.colors['attrname'] = QColor(153, 69, 0)
         self.colors['attrval'] = QColor(36, 36, 170)
예제 #6
0
    def __init__(self, parent, theme):
        QSyntaxHighlighter.__init__(self, parent)
        self.parent = parent

        self.highlightingRules = []

        # keyword
        self.highlightingRules.append(
            HighlightingRule(r"^[^:=\s][^:=]*[:=]", Qt.blue, Qt.SolidPattern))

        # section
        self.highlightingRules.append(
            HighlightingRule(r"^\[[^\]]+\]", Qt.darkBlue, Qt.SolidPattern))

        # comment
        self.highlightingRules.append(
            HighlightingRule(r"#[^\n]*", Qt.darkYellow, Qt.SolidPattern))
예제 #7
0
    def __init__( self, parent, theme ):
        QSyntaxHighlighter.__init__( self, parent )
        self.parent = parent
        
        self.highlightingRules = []

        # keyword
        self.highlightingRules.append( HighlightingRule( r"^[^:=\s][^:=]*[:=]",
                                                         Qt.blue,
                                                         Qt.SolidPattern ) )

        # section
        self.highlightingRules.append( HighlightingRule( r"^\[[^\]]+\]",
                                                         Qt.darkBlue,
                                                         Qt.SolidPattern ) )

        # comment
        self.highlightingRules.append( HighlightingRule( r"#[^\n]*" ,
                                                         Qt.darkYellow,
                                                         Qt.SolidPattern ) )
예제 #8
0
파일: syntax_sql.py 프로젝트: ligm74/LiGM
    def __init__(self, document):
        QSyntaxHighlighter.__init__(self, document)

        # Multi-line strings (expression, flag, style)
        self.rem_start = QRegExp("/\\*")
        self.rem_end = QRegExp("\\*/")

        rules = []

        # Keyword, operator, and brace rules
        rules += [(QRegExp(r'\b%s\b' % w,
                           Qt.CaseInsensitive), 0, STYLES['keyword'])
                  for w in SQLHighlighter.keywords]

        rules += [(QRegExp(r'\b%s\b' % w,
                           Qt.CaseInsensitive), 0, STYLES['types'])
                  for w in SQLHighlighter.types]

        # All other rules
        rules += [
            (r'\bself\b', 0, STYLES['self']),

            # Numeric literals
            (r'\b[+-]?[0-9]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?0[xX][0-9A-Fa-f]+[lL]?\b', 0, STYLES['numbers']),
            (r'\b[+-]?[0-9]+(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?\b', 0,
             STYLES['numbers']),

            # Double-quoted string, possibly containing escape sequences
            (r'"[^"\\]*(\\.[^"\\]*)*"', 0, STYLES['string']),
            # Single-quoted string, possibly containing escape sequences
            (r"'[^'\\]*(\\.[^'\\]*)*'", 0, STYLES['string']),

            # From '#' until a newline
            (r'--[^\n]*', 0, STYLES['comment']),
        ]

        # Build a QRegExp for each pattern
        self.rules = [(QRegExp(pat), index, fmt)
                      for (pat, index, fmt) in rules]
예제 #9
0
    def __init__( self, parent, sections=[], keywords=[], entries=[], entry_keywords=[] ):
        QSyntaxHighlighter.__init__( self, parent )
        self.parent = parent

        self.highlightingRules = []

        colors = {
            'knownentries':Qt.darkGreen,
            'errors':Qt.red,
            'allkeywords':Qt.darkMagenta,
            'knownkeywords':Qt.blue,
            'knownsections':Qt.darkBlue,
            'teststories':Qt.darkCyan,
            'storyUrls':Qt.darkMagenta,
            'comments':Qt.darkYellow
            }
        try:
            if( hasattr(QApplication.instance(),'is_dark_theme')
                and QApplication.instance().is_dark_theme ):
                colors = {
                    'knownentries':Qt.green,
                    'errors':Qt.red,
                    'allkeywords':Qt.magenta,
                    'knownkeywords':QColor(Qt.blue).lighter(150),
                    'knownsections':Qt.darkCyan,
                    'teststories':Qt.cyan,
                    'storyUrls':Qt.magenta,
                    'comments':Qt.yellow
                    }
        except Exception as e:
            logger.error("Failed to set dark theme highlight colors: %s"%e)

        if entries:
            # *known* entries
            reentries = r'('+(r'|'.join(entries))+r')'
            self.highlightingRules.append( HighlightingRule( r"\b"+reentries+r"\b", colors['knownentries'] ) )

        # true/false -- just to be nice.
        self.highlightingRules.append( HighlightingRule( r"\b(true|false)\b", colors['knownentries'] ) )

        # *all* keywords -- change known later.
        self.errorRule = HighlightingRule( r"^[^:=\s][^:=]*[:=]", colors['errors'] )
        self.highlightingRules.append( self.errorRule )

        # *all* entry keywords -- change known later.
        reentrykeywords = r'('+(r'|'.join([ e % r'[a-zA-Z0-9_]+' for e in entry_keywords ]))+r')'
        self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+reentrykeywords+r"(_filelist)?\s*[:=]", colors['allkeywords'] ) )

        if entries: # separate from known entries so entry named keyword won't be masked.
            # *known* entry keywords
            reentrykeywords = r'('+(r'|'.join([ e % reentries for e in entry_keywords ]))+r')'
            self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+reentrykeywords+r"(_filelist)?\s*[:=]", colors['knownkeywords'] ) )

        # *known* keywords
        rekeywords = r'('+(r'|'.join(keywords))+r')'
        self.highlightingRules.append( HighlightingRule( r"^(add_to_)?"+rekeywords+r"(_filelist)?\s*[:=]", colors['knownkeywords'] ) )

        # *all* sections -- change known later.
        self.highlightingRules.append( HighlightingRule( r"^\[[^\]]+\].*?$", colors['errors'], QFont.Bold, blocknum=1 ) )

        if sections:
            # *known* sections
            resections = r'('+(r'|'.join(sections))+r')'
            resections = resections.replace('.','\.') #escape dots.
            self.highlightingRules.append( HighlightingRule( r"^\["+resections+r"\]\s*$", colors['knownsections'], QFont.Bold, blocknum=2 ) )

        # test story sections
        self.teststoryRule = HighlightingRule( r"^\[teststory:([0-9]+|defaults)\]", colors['teststories'], blocknum=3 )
        self.highlightingRules.append( self.teststoryRule )

        # storyUrl sections
        self.storyUrlRule = HighlightingRule( r"^\[https?://.*\]", colors['storyUrls'], blocknum=4 )
        self.highlightingRules.append( self.storyUrlRule )

        # NOT comments -- but can be custom columns, so don't flag.
        #self.highlightingRules.append( HighlightingRule( r"(?<!^)#[^\n]*" , colors['errors'] ) )

        # comments -- comments must start from column 0.
        self.commentRule = HighlightingRule( r"^#[^\n]*" , colors['comments'] )
        self.highlightingRules.append( self.commentRule )
예제 #10
0
 def rehighlight(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     QSyntaxHighlighter.rehighlight(self)
     QApplication.restoreOverrideCursor()
예제 #11
0
 def rehighlight(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     QSyntaxHighlighter.rehighlight(self)
     QApplication.restoreOverrideCursor()
예제 #12
0
 def __init__(self, document, dictionary):
     QSyntaxHighlighter.__init__(self, document)
     self._dictionary = dictionary
예제 #13
0
    def __init__(self, *args):
        QSyntaxHighlighter.__init__(self, *args)

        self.dict = None
    def __init__(self, parent):
        QSyntaxHighlighter.__init__(self, parent)
        self.parent = parent
        self.multilineCodeState = False
        self.multilineCodeStart = False
        self.parent.setTabStopWidth(self.parent.fontMetrics().width(' ') * 8)

        self.defaultTheme = {
            "background-color": "#ffffff",
            "color": "#000000",
            "bold": {
                "color": "#859900",
                "font-weight": "bold",
                "font-style": "normal"
            },
            "emphasis": {
                "color": "#b58900",
                "font-weight": "bold",
                "font-style": "italic"
            },
            "link": {
                "color": "#cb4b16",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "image": {
                "color": "#cb4b16",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "header": {
                "color": "#2aa198",
                "font-weight": "bold",
                "font-style": "normal"
            },
            "unorderedlist": {
                "color": "#dc322f",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "orderedlist": {
                "color": "#dc322f",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "blockquote": {
                "color": "#dc322f",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "codespan": {
                "color": "#dc322f",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "codeblock": {
                "color": "#ff9900",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "line": {
                "color": "#2aa198",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "html": {
                "color": "#c000c0",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "latex": {
                "color": "#00900d",
                "font-weight": "normal",
                "font-style": "normal"
            },
            "multilinecode": {
                "color": "#5d5d5d",
                "font-weight": "normal",
                "font-style": "normal"
            }
        }
        self.setTheme(self.defaultTheme)
예제 #15
0
    def __init__(self, *args):
        QSyntaxHighlighter.__init__(self, *args)

        self.dict = None