Return a list of (row, col) tuples that need to be highlighted.
516309
def _get_positions_to_highlight(self, document):
        
        # Try for the character under the cursor.
        if document.current_char and document.current_char in self.chars:
            pos = document.find_matching_bracket_position(
                    start_pos=document.cursor_position - self.max_cursor_distance,
                    end_pos=document.cursor_position + self.max_cursor_distance)

        # Try for the character before the cursor.
        elif (document.char_before_cursor and document.char_before_cursor in
              self._closing_braces and document.char_before_cursor in self.chars):
            document = Document(document.text, document.cursor_position - 1)

            pos = document.find_matching_bracket_position(
                    start_pos=document.cursor_position - self.max_cursor_distance,
                    end_pos=document.cursor_position + self.max_cursor_distance)
        else:
            pos = None

        # 
        if pos:
            pos += document.cursor_position  # pos is relative.
            row, col = document.translate_index_to_position(pos)
            return [(row, col), (document.cursor_position_row, document.cursor_position_col)]
        else:
            return []
50014
def case_highlight(seq, subseq):
    
    return re.subs(subseq.lower(), subseq.upper(), seq.lower())
939430
def highlight_focussed_row type, r=nil, c=nil, acolor=nil
      return unless @should_show_focus
      case type
      when :FOCUSSED
        ix = @current_index
        return if is_row_selected ix
        r = _convert_index_to_printable_row() unless r
        return unless r # row is not longer visible 2013-04-10 - 16:37 
        attrib = @focussed_attrib || 'bold'

      when :UNFOCUSSED
        return if @oldrow.nil? || @oldrow == @current_index
        ix = @oldrow
        return if is_row_selected ix
        r = _convert_index_to_printable_row(@oldrow) unless r
        return unless r # row is not longer visible
        attrib = @attr
      end
      unless c
        _r, c = rowcol
      end
      # this optimization now overrides any coloring that listbox may have done per row XXX
      acolor ||= get_color $datacolor
      att = get_attrib(attrib) #if @focussed_attrib
      @graphic.mvchgat(y=r, x=c, @width-@internal_width, att , acolor , nil)
    end
161975
def _get_all_styles(self):
        
        _styles = {}
        def _get_style(bold=False, bg_col=None, border=None):
            if (bold, bg_col, border) not in _styles:
                _styles[(bold, bg_col, border)] = CellStyle(bold=bold,
                                                            bg_color=bg_col,
                                                            border=border)
            return _styles[(bold, bg_col, border)]

        ws_styles = {}
        for table, (row, col) in self.__tables.values():
            for r in range(row, row + table.header_height):
                for c in range(col, col + table.width):
                    if isinstance(table.header_style, dict):
                        col_name = table.dataframe.columns[c - col]
                        style = table.header_style.get(col_name, _get_style(bold=True))
                    else:
                        style = table.header_style or _get_style(bold=True)
                    ws_styles[(r, c)] = style

            for c in range(col, col + table.row_labels_width):
                for r in range(row + table.header_height, row + table.height):
                    if isinstance(table.index_style, dict):
                        row_name = table.dataframe.index[r - row]
                        style = table.index_style.get(row_name, _get_style(bold=True))
                    else:
                        style = table.index_style or _get_style(bold=True)
                    ws_styles[(r, c)] = style

            if table.style.stripe_colors or table.style.border:
                num_bg_cols = len(table.style.stripe_colors) if \
                    table.style.stripe_colors else 1
                bg_cols = table.style.stripe_colors if \
                    table.style.stripe_colors else None

                for i, row_offset in enumerate(range(table.header_height,
                                                     table.height)):
                    for c in range(col, col + table.width):
                        bg_col = bg_cols[i % num_bg_cols] if bg_cols else None
                        style = _get_style(bold=None, bg_col=bg_col, border=table.style.border)
                        if (row + row_offset, c) in ws_styles:
                            style = style + ws_styles[(row + row_offset, c)]
                        ws_styles[(row + row_offset, c)] = style

            for col_name, col_style in table.column_styles.items():
                try:
                    col_offset = table.get_column_offset(col_name)
                except KeyError:
                    continue
                for i, r in enumerate(range(row + table.header_height, row + table.height)):
                    style = col_style
                    if (r, col + col_offset) in ws_styles:
                        style = ws_styles[(r, col + col_offset)] + style
                    ws_styles[(r, col + col_offset)] = style

            for row_name, row_style in table.row_styles.items():
                try:
                    row_offset = table.get_row_offset(row_name)
                except KeyError:
                    continue
                for i, c in enumerate(range(col + table.row_labels_width, col + table.width)):
                    style = row_style
                    if (row + row_offset, c) in ws_styles:
                        style = ws_styles[(row + row_offset, c)] + style
                    ws_styles[(row + row_offset, c)] = style

            for (row_name, col_name), cell_style in table.cell_styles.items():
                try:
                    col_offset = table.get_column_offset(col_name)
                    row_offset = table.get_row_offset(row_name)
                except KeyError:
                    continue
                style = cell_style
                if (row + row_offset, col + col_offset) in ws_styles:
                    style = ws_styles[(row + row_offset, col + col_offset)] + style
                ws_styles[(row + row_offset, col + col_offset)] = style

        for (row, col), value in self.__values.items():
            if isinstance(value, Value):
                style = value.style
                if style:
                    if (row, col) in ws_styles:
                        style = style + ws_styles[(row, col)]
                    ws_styles[(row, col)] = style

        return ws_styles
1268825
def _filter_rows(self, rows):
        """"""
        filtered_rows = []
        for row in rows:
            filtered_row = []
            for idx, name in enumerate(self.columns.keys()):
                if name in self.visible_columns:
                    filtered_row.append(row[idx])
            filtered_rows.append(filtered_row)
        return filtered_rows
500534
def apply_styles(self, cmdmap):
        
        is_list_like = lambda arg: isinstance(arg, (list, tuple))
        is_first_param_list = lambda c: c in ('COLBACKGROUNDS', 'ROWBACKGROUNDS')
        for cmd, args in cmdmap.iteritems():
            if not is_list_like(args):
                args = [args]
            elif is_first_param_list(cmd) and is_list_like(args) and not is_list_like(args[0]):
                args = [args]
            self.apply_style(cmd, *args)
        return self
1016067
def auto_style(self):
        
        if self._row_size is None:
            return
        elif self._row_size == 3:
            self.set_cols_align(['l', 'l', 'l'])
            self.set_cols_valign(['t', 't', 't'])
            self.set_cols_width([12, 54, 12])
        elif self._row_size == 4:
            self.set_cols_align(['l', 'l', 'l', 'l'])
            self.set_cols_valign(['t', 't', 't', 't'])
            self.set_cols_width([10, 40, 10, 10])
926697
def highlightAllMatches(self):
        
        # Remove any previous highlighting.
        self.qteWidget.SCISetStylingEx(0, 0, self.styleOrig)
        SCI = self.qteWidget

        # Compile a list of spans that contain the specified string.
        self.compileMatchList()

        # Return if the substring does not exist in the text.
        if len(self.matchList) == 0:
            return

        # ------------------------------------------------------------
        # Make a copy of the style bits of the document, overwrite
        # those parts containing a substring, and then write them
        # back all at once. This is much faster than calling the
        # styling methods repeatedly.
        # ------------------------------------------------------------

        # Make a copy of the document style bits and determine the
        # cursor position in the document.
        style = bytearray(self.styleOrig)
        pos = SCI.getCursorPosition()
        cur = SCI.positionFromLineIndex(*pos)

        # Style all matches.
        self.selMatchIdx = 0
        for start, stop in self.matchList:
            if start < cur:
                self.selMatchIdx += 1
            style[start:stop] = bytes(b'\x1e') * (stop - start)

        if self.selMatchIdx >= len(self.matchList):
            self.selMatchIdx = 0

        # Style the first match after the current cursor position
        # differently to indicate that it is the currently
        # selected one.
        start, stop = self.matchList[self.selMatchIdx]
        style[start:stop] = bytes(b'\x1f') * (stop - start)

        # Place the cursor at the start of the currently selected match.
        line, col = SCI.lineIndexFromPosition(start)
        SCI.setCursorPosition(line, col)

        # Apply the modified style array to the document.
        self.qteWidget.SCISetStylingEx(0, 0, style)
1005763
def items(cls):
        
        return [
            cls.TRUE_COLOR,
            cls.FALSE_COLOR,
            cls.NDVI,
            cls.EVI
        ]
726618
def apply_style(self, cmd, *args):
        
        for c0, c1 in self.col_coord_tuples:
            for r0, r1 in self.row_coord_tuples:
                c = [cmd, (c0, r0), (c1, r1)] + list(args)
                self.style_cmds.append(c)
        return self
659552
def _build_color_table():
        
        FG = FOREGROUND_COLOR
        BG = BACKROUND_COLOR

        return [
            (0x00, 0x00, 0x00, FG.BLACK, BG.BLACK),
            (0x00, 0x00, 0xaa, FG.BLUE, BG.BLUE),
            (0x00, 0xaa, 0x00, FG.GREEN, BG.GREEN),
            (0x00, 0xaa, 0xaa, FG.CYAN, BG.CYAN),
            (0xaa, 0x00, 0x00, FG.RED, BG.RED),
            (0xaa, 0x00, 0xaa, FG.MAGENTA, BG.MAGENTA),
            (0xaa, 0xaa, 0x00, FG.YELLOW, BG.YELLOW),
            (0x88, 0x88, 0x88, FG.GRAY, BG.GRAY),

            (0x44, 0x44, 0xff, FG.BLUE | FG.INTENSITY, BG.BLUE | BG.INTENSITY),
            (0x44, 0xff, 0x44, FG.GREEN | FG.INTENSITY, BG.GREEN | BG.INTENSITY),
            (0x44, 0xff, 0xff, FG.CYAN | FG.INTENSITY, BG.CYAN | BG.INTENSITY),
            (0xff, 0x44, 0x44, FG.RED | FG.INTENSITY, BG.RED | BG.INTENSITY),
            (0xff, 0x44, 0xff, FG.MAGENTA | FG.INTENSITY, BG.MAGENTA | BG.INTENSITY),
            (0xff, 0xff, 0x44, FG.YELLOW | FG.INTENSITY, BG.YELLOW | BG.INTENSITY),

            (0x44, 0x44, 0x44, FG.BLACK | FG.INTENSITY, BG.BLACK | BG.INTENSITY),
            (0xff, 0xff, 0xff, FG.GRAY | FG.INTENSITY, BG.GRAY | BG.INTENSITY),
        ]
519525
def colors_to_needle_positions(rows):
    
    needles = []
    for row in rows:
        colors = set(row)
        if len(colors) == 1:
            needles.append([NeedlePositions(row, tuple(colors), False)])
        elif len(colors) == 2:
            color1, color2 = colors
            if color1 != row[0]:
                color1, color2 = color2, color1
            needles_ = _row_color(row, color1)
            needles.append([NeedlePositions(needles_, (color1, color2), True)])
        else:
            colors = []
            for color in row:
                if color not in colors:
                    colors.append(color)
            needles_ = []
            for color in colors:
                needles_.append(NeedlePositions(_row_color(row, color),
                                                (color,), False))
            needles.append(needles_)
    return needles
315701
def rgb(self, color_tuple):
        """"""
        # Check bounds
        self.color = tuple(map(self._apply_float_bounds, color_tuple[:3]))

        # Include alpha if necessary
        if len(color_tuple) > 3:
            self.alpha = self._apply_float_bounds(color_tuple[3])
1341818
def _highlight_cursorlines(self, cli, new_screen, cpos, x, y, width, height):
        
        cursor_line_token = (':', ) + self.cursorline_token
        cursor_column_token = (':', ) + self.cursorcolumn_token

        data_buffer = new_screen.data_buffer

        # Highlight cursor line.
        if self.cursorline(cli):
            row = data_buffer[cpos.y]
            for x in range(x, x + width):
                original_char = row[x]
                row[x] = _CHAR_CACHE[
                    original_char.char, original_char.token + cursor_line_token]

        # Highlight cursor column.
        if self.cursorcolumn(cli):
            for y2 in range(y, y + height):
                row = data_buffer[y2]
                original_char = row[cpos.x]
                row[cpos.x] = _CHAR_CACHE[
                   original_char.char, original_char.token + cursor_column_token]

        # Highlight color columns
        for cc in self.get_colorcolumns(cli):
            assert isinstance(cc, ColorColumn)
            color_column_token = (':', ) + cc.token
            column = cc.position

            for y2 in range(y, y + height):
                row = data_buffer[y2]
                original_char = row[column]
                row[column] = _CHAR_CACHE[
                   original_char.char, original_char.token + color_column_token]
86133
def selections(self):
        """
        for sel in self._selections:
            if sel.annotation.axes is None:
                raise RuntimeError("Annotation unexpectedly removed; "
                                   "use 'cursor.remove_selection' instead")
        return tuple(self._selections)
1055218
def get_highlights(self):
        '''
        '''
        # NOTE: all Instapaper API methods use POST except this one!
        path = '/'.join([self.RESOURCE, str(self.object_id), 'highlights'])
        response = self.client.request(path, method='GET', api_version='1.1')
        items = response['data']
        highlights = []
        for item in items:
            if item.get('type') == 'error':
                raise Exception(item.get('message'))
            elif item.get('type') == 'highlight':
                highlights.append(Highlight(self, **item))
        return highlights
967260
def highlight(self, search):
        
        return search.highlight(*(f if '^' not in f else f.split('^', 1)[0]
                                  for f in self.fields))