# Path: munin/helper.py
# def grouper(iterable, n, fillvalue=None):
#     "Collect data into fixed-length chunks or blocks"
#     # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
#     args = [iter(iterable)] * n
#     return zip_longest(*args, fillvalue=fillvalue)


from collections import deque, defaultdict
from munin.helper import grouper
from cairo import PDFSurface, Context
from gi.repository import Pango, PangoCairo
        from subprocess import call
    import sys
    scale_step = w // 100
    for i in range(0, w + scale_step, scale_step):
        x = min(max(i - 5, 0), w - 21)
        text = str(int(i / scale_step)) + '%'

        if i % (scale_step * 10) is 0:
            height, width = h / 15, 2
            draw_text_at_pos(ctx, x, h - height - 10, '<b>{}</b>'.format(text), font_size=6)
        elif i % (scale_step * 5) is 0:
            height, width = h / 20, 1.5
            draw_text_at_pos(ctx, x, h - height - 8, '<i>{}</i>'.format(text), font_size=5)
        else:
            height, width = h / 35, 0.75

        ctx.rectangle(i, h - height, width, height)
        ctx.fill()

    # Pain the little white border between moodbar and scala:
    ctx.rectangle(0, h - h / 6, w, 1)
    ctx.fill()


def read_moodbar_values(path):
    rgb_values = deque()
    with open(path, 'rb') as handle:
        vector = handle.read()

    if len(vector) is 0:
        raise OSError('broken moodbar file: ' + path)


# Path: munin/helper.py
# def grouper(iterable, n, fillvalue=None):
#     "Collect data into fixed-length chunks or blocks"
#     # grouper('ABCDEFG', 3, 'x') --> ABC DEF Gxx"
#     args = [iter(iterable)] * n
#     return zip_longest(*args, fillvalue=fillvalue)


# Path: munin/scripts/moodbar_visualizer.py
from collections import deque, defaultdict
from munin.helper import grouper
from cairo import PDFSurface, Context
from gi.repository import Pango, PangoCairo
        from subprocess import call
    import sys

    scale_step = w // 100
    for i in range(0, w + scale_step, scale_step):
        x = min(max(i - 5, 0), w - 21)
        text = str(int(i / scale_step)) + '%'

        if i % (scale_step * 10) is 0:
            height, width = h / 15, 2
            draw_text_at_pos(ctx, x, h - height - 10, '<b>{}</b>'.format(text), font_size=6)
        elif i % (scale_step * 5) is 0:
            height, width = h / 20, 1.5
            draw_text_at_pos(ctx, x, h - height - 8, '<i>{}</i>'.format(text), font_size=5)
        else:
            height, width = h / 35, 0.75

        ctx.rectangle(i, h - height, width, height)
        ctx.fill()

    # Pain the little white border between moodbar and scala:
    ctx.rectangle(0, h - h / 6, w, 1)
    ctx.fill()


def read_moodbar_values(path):
    rgb_values = deque()
    with open(path, 'rb') as handle:
        vector = handle.read()

    if len(vector) is 0:
        raise OSError('broken moodbar file: ' + path)


    for rgb in grouper(vector, n=3):