Example #1
0
    def highlightBlock(self, text):
        """Called by Qt when the highlighting of the current line needs updating."""
        # find the state of the previous line
        prev = self.previousBlockState()
        state = self._fridge.thaw(prev)
        blank = not state and (not text or text.isspace())
        if not state:
            state = self.initialState()

        # collect and save the tokens
        tokens = tuple(state.tokens(text))
        cursortools.data(self.currentBlock()).tokens = tokens

        # if blank thus far, keep the highlighter coming back
        # because the parsing state is not yet known; else save the state
        self.setCurrentBlockState(prev -
                                  1 if blank else self._fridge.freeze(state))

        # apply highlighting if desired
        if self._highlighting:
            setFormat = lambda f: self.setFormat(token.pos, len(token), f)
            mapping = highlight_mapping()
            for token in tokens:
                f = mapping[token]
                if f:
                    setFormat(f)
Example #2
0
    def highlightBlock(self, text):
        """Called by Qt when the highlighting of the current line needs updating."""
        # find the state of the previous line
        prev = self.previousBlockState()
        state = self._fridge.thaw(prev)
        blank = not state and (not text or text.isspace())
        if not state:
            state = self.initialState()

        # collect and save the tokens
        tokens = tuple(state.tokens(text))
        cursortools.data(self.currentBlock()).tokens = tokens

        # if blank thus far, keep the highlighter coming back
        # because the parsing state is not yet known; else save the state
        self.setCurrentBlockState(prev - 1 if blank else self._fridge.freeze(state))

        # apply highlighting if desired
        if self._highlighting:
            setFormat = lambda f: self.setFormat(token.pos, len(token), f)
            mapping = highlight_mapping()
            for token in tokens:
                f = mapping[token]
                if f:
                    setFormat(f)
Example #3
0
 def mark(self, block, state=None):
     if state is None:
         try:
             return block.userData().folded
         except AttributeError:
             return False
     elif state:
         cursortools.data(block).folded = state
     else:
         try:
             del block.userData().folded
         except AttributeError:
             pass
Example #4
0
 def mark(self, block, state=None):
     if state is None:
         try:
             return block.userData().folded
         except AttributeError:
             return False
     elif state:
         cursortools.data(block).folded = state
     else:
         try:
             del block.userData().folded
         except AttributeError:
             pass
Example #5
0
 def slotItemExpanded(self, item):
     """Called when the user expands an item."""
     block = self.cursorForItem(item).block()
     cursortools.data(block).collapsed = False
Example #6
0
 def slotItemCollapsed(self, item):
     """Called when the user collapses an item."""
     block = self.cursorForItem(item).block()
     cursortools.data(block).collapsed = True
Example #7
0
 def slotItemExpanded(self, item):
     """Called when the user expands an item."""
     block = self.cursorForItem(item).block()
     cursortools.data(block).collapsed = False
Example #8
0
 def slotItemCollapsed(self, item):
     """Called when the user collapses an item."""
     block = self.cursorForItem(item).block()
     cursortools.data(block).collapsed = True