# Path: pwm/ffi/xcb.py
# class XcbError(Exception):
# class Cookie:
# class Xcb:
#     def __init__(self, error):
#     def __str__(self):
#     def __init__(self, name, value):
#     def __getattr__(self, name):
#     def reply(self):
#     def check(self):
#     def __init__(self):
#     def __getattr__(self, name):
#         def request(func, *args, **kwargs):
#     def connect(self, display=None):
#     def mask(self, masks):


from pwm.ffi.xcb import xcb
# Copyright (c) 2013 Michael Bitzi
# Licensed under the MIT license http://opensource.org/licenses/MIT



def get_pixel(color):
    if color.startswith("#"):
        if len(color) != 7:
            raise ValueError("Invalid color: %s" % color)

        def x8to16(i):
            return int(0xffff * (i & 0xff) / 0xff)

        r = x8to16(int(color[1] + color[2], 16))
        g = x8to16(int(color[3] + color[4], 16))
        b = x8to16(int(color[5] + color[6], 16))

        return xcb.core.alloc_color(xcb.screen.default_colormap,
                                    r, g, b).reply().pixel
    else:

# Path: pwm/ffi/xcb.py
# class XcbError(Exception):
# class Cookie:
# class Xcb:
#     def __init__(self, error):
#     def __str__(self):
#     def __init__(self, name, value):
#     def __getattr__(self, name):
#     def reply(self):
#     def check(self):
#     def __init__(self):
#     def __getattr__(self, name):
#         def request(func, *args, **kwargs):
#     def connect(self, display=None):
#     def mask(self, masks):


# Path: pwm/color.py
from pwm.ffi.xcb import xcb

# Copyright (c) 2013 Michael Bitzi
# Licensed under the MIT license http://opensource.org/licenses/MIT



def get_pixel(color):
    if color.startswith("#"):
        if len(color) != 7:
            raise ValueError("Invalid color: %s" % color)

        def x8to16(i):
            return int(0xffff * (i & 0xff) / 0xff)

        r = x8to16(int(color[1] + color[2], 16))
        g = x8to16(int(color[3] + color[4], 16))
        b = x8to16(int(color[5] + color[6], 16))

        return xcb.core.alloc_color(xcb.screen.default_colormap,
                                    r, g, b).reply().pixel
    else:

        return xcb.core.alloc_named_color(xcb.screen.default_colormap,