# Path: matplotlib/colors.py
# def rgb2hex(rgb):
#     'Given an rgb or rgba sequence of 0-1 floats, return the hex string'
#     return '#%02x%02x%02x' % tuple([np.round(val * 255) for val in rgb[:3]])


import sys
import datetime
from matplotlib.backends.qt4_compat import QtGui,QtCore
from matplotlib.colors import rgb2hex
        from copy import deepcopy
    __pyqtSignals__ = ("colorChanged(QColor)",)

    def __init__(self, parent=None):
        QPushButton.__init__(self, parent)
        self.setFixedSize(20, 20)
        self.setIconSize(QSize(12, 12))
        self.connect(self, SIGNAL("clicked()"), self.choose_color)
        self._color = QColor()

    def choose_color(self):
        color = QColorDialog.getColor(self._color,self.parentWidget(),'')
        if color.isValid():
            self.set_color(color)

    def get_color(self):
        return self._color

    @QtCore.Slot("QColor")
    def set_color(self, color):
        if color != self._color:
            self._color = color
            self.emit(SIGNAL("colorChanged(QColor)"), self._color)
            pixmap = QPixmap(self.iconSize())
            pixmap.fill(color)
            self.setIcon(QtGui.QIcon(pixmap))

    color = QtCore.Property("QColor", get_color, set_color)

def col2hex(color):
    """Convert matplotlib color to hex before passing to Qt"""

# Path: matplotlib/colors.py
# def rgb2hex(rgb):
#     'Given an rgb or rgba sequence of 0-1 floats, return the hex string'
#     return '#%02x%02x%02x' % tuple([np.round(val * 255) for val in rgb[:3]])


# Path: matplotlib/backends/qt4_editor/formlayout.py
import sys
import datetime
from matplotlib.backends.qt4_compat import QtGui,QtCore
from matplotlib.colors import rgb2hex
        from copy import deepcopy

    __pyqtSignals__ = ("colorChanged(QColor)",)

    def __init__(self, parent=None):
        QPushButton.__init__(self, parent)
        self.setFixedSize(20, 20)
        self.setIconSize(QSize(12, 12))
        self.connect(self, SIGNAL("clicked()"), self.choose_color)
        self._color = QColor()

    def choose_color(self):
        color = QColorDialog.getColor(self._color,self.parentWidget(),'')
        if color.isValid():
            self.set_color(color)

    def get_color(self):
        return self._color

    @QtCore.Slot("QColor")
    def set_color(self, color):
        if color != self._color:
            self._color = color
            self.emit(SIGNAL("colorChanged(QColor)"), self._color)
            pixmap = QPixmap(self.iconSize())
            pixmap.fill(color)
            self.setIcon(QtGui.QIcon(pixmap))

    color = QtCore.Property("QColor", get_color, set_color)

def col2hex(color):
    """Convert matplotlib color to hex before passing to Qt"""

    return rgb2hex(colorConverter.to_rgb(color))