'Update the selection rects.'

def update_selection_rects(self):

    def continuous_ranges(selections):
        '    Group    continuous    ranges\n                                                '
        selections = iter(selections)
        start = end = next(selections)
        try:
            while True:
                new_end = next(selections)
                if (new_end > (end + 1)):
                    (yield (start, end))
                    start = end = new_end
                else:
                    end = new_end
        except StopIteration:
            (yield (start, end))
    def group_selections(selections):
        'Group    selections    along    with    heatmaps.\n                                                '
        rows2hm = self.rows_to_heatmaps()
        selections = iter(selections)
        try:
            start = end = next(selections)
        except StopIteration:
            return
        end_heatmaps = rows2hm[end]
        try:
            while True:
                new_end = next(selections)
                new_end_heatmaps = rows2hm[new_end]
                if ((new_end > (end + 1)) or (new_end_heatmaps != end_heatmaps)):
                    (yield (start, end, end_heatmaps))
                    start = end = new_end
                    end_heatmaps = new_end_heatmaps
                else:
                    end = new_end
        except StopIteration:
            (yield (start, end, end_heatmaps))
    def selection_rect(start, end, heatmaps):
        rect = QRectF()
        for heatmap in heatmaps:
            (h_start, _) = self._heatmap_ranges[heatmap]
            rect |= heatmap.mapToScene(heatmap.row_rect((start - h_start))).boundingRect()
            rect |= heatmap.mapToScene(heatmap.row_rect((end - h_start))).boundingRect()
        return rect
    self.selection_rects = []
    for (start, end, heatmaps) in group_selections(self.selections):
        rect = selection_rect(start, end, heatmaps)
        self.selection_rects.append(rect)
