Ejemplo n.º 1
0
    def valueChange(self, event):
        if self._grid is None:
            return

        if event.getProperty().getValue() == ColorRangePropertyId.ALL:
            self._grid.setColorGrid(self.createAllColors(14, 10))

        elif event.getProperty().getValue() == ColorRangePropertyId.RED:
            self._grid.setColorGrid(self.createColor(Color(255, 0, 0), 14, 10))

        elif event.getProperty().getValue() == ColorRangePropertyId.GREEN:
            self._grid.setColorGrid(self.createColor(Color(0, 255, 0), 14, 10))

        elif event.getProperty().getValue() == ColorRangePropertyId.BLUE:
            self._grid.setColorGrid(self.createColor(Color(0, 0, 255), 14, 10))
Ejemplo n.º 2
0
    def createColor(self, color, rows, columns):
        """Creates the color.

        @param color:
                   the color
        @param rows:
                   the rows
        @param columns:
                   the columns

        @return: the color[][]
        """
        colors = [([None] * columns) for _ in range(rows)]
        hsv = color.getHSV()

        hue = hsv[0]
        saturation = 1.0
        value = 1.0

        for row in range(rows):
            for col in range(columns):

                index = (row * columns) + col
                saturation = 1.0
                value = 1.0

                if index <= (rows * columns) / 2:
                    saturation = index / (rows * columns) / 2.0
                else:
                    index -= (rows * columns) / 2
                    value = 1.0 - (index / (rows * columns) / 2.0)

                colors[row][col] = Color(*hsv_to_rgb(hue, saturation, value))

        return colors
Ejemplo n.º 3
0
    def valueChange(self, event):
        value = event.getProperty().getValue()

        if not self._field.isValid():
            self._field.setValue(self._oldValue)
            return
        else:
            self._oldValue = value

        if value is not None and len(value) == 7:
            red = int(value[1:3], 16)
            green = int(value[3:5], 16)
            blue = int(value[5:7], 16)
            self._color = Color(red, green, blue)

            evt = ColorChangeEvent(self._field.getData(), self._color)
            self.fireEvent(evt)
Ejemplo n.º 4
0
    def createAllColors(self, rows, columns):
        """Creates the all colors.

        @param rows:
                   the rows
        @param columns:
                   the columns

        @return: the color[][]
        """
        colors = [([None] * columns) for _ in range(rows)]

        for row in range(rows):
            for col in range(columns):

                # Create the color grid by varying the saturation and value
                if row < rows - 1:
                    # Calculate new hue value
                    # The last row should have the black&white gradient
                    hue = col / columns
                    saturation = 1.0
                    value = 1.0

                    # For the upper half use value=1 and variable saturation
                    if row < rows / 2:
                        saturation = (row + 1.0) / rows / 2.0
                    else:
                        value = 1.0 - ((row - (rows / 2.0)) / rows / 2.0)

                    colors[row][col] = \
                            Color(*hsv_to_rgb(hue, saturation, value))
                else:
                    hue = 0.0
                    saturation = 0.0
                    value = 1.0 - (col / columns)

                    colors[row][col] = \
                            Color(*hsv_to_rgb(hue, saturation, value))

        return colors
    def valueChange(self, event):
        value = event.getProperty().getValue()

        if not self._field.isValid():
            self._field.setValue(self._oldValue)
            return
        else:
            self._oldValue = value

        if value is not None and len(value) == 7:
            red = int(value[1:3], 16)
            green = int(value[3:5], 16)
            blue = int(value[5:7], 16)
            self._color = Color(red, green, blue)

            evt = ColorChangeEvent(self._field.getData(), self._color)
            self.fireEvent(evt)
Ejemplo n.º 6
0
    def __init__(self, caption='Colors', initialColor=None):
        """Instantiates a new color picker.

        @param caption:
                   the caption
        @param initialColor:
                   the initial color
        """
        self.buttonStyle = str(ButtonStyle.BUTTON_NORMAL)

        self.popupStyle = PopupStyle.POPUP_NORMAL

        self.buttonCaption = ''

        # The window.
        self._window = None

        # The window.
        self._parent_window = None

        # The popup status.
        self._popupStatus = False

        self._positionX = 0
        self._positionY = 0

        self.rgbVisible = True
        self.hsvVisible = True
        self.swatchesVisible = True
        self.historyVisible = True
        self.textfieldVisible = True

        if initialColor is None:
            initialColor = Color(0, 0, 0)

        # The color.
        self.color = initialColor
        self.caption = caption

        super(ColorPicker, self).__init__()
class ColorPickerPreview(CssLayout, IColorSelector, IValueChangeListener):
    """The Class ColorPickerPreview.

    @author: John Ahlroos / ITMill Oy 2010
    @author: Richard Lincoln
    """

    _STYLE_DARK_COLOR = 'v-textfield-dark'
    _STYLE_LIGHT_COLOR = 'v-textfield-light'

    def __init__(self, color):
        """Instantiates a new color picker preview."""
        super(ColorPickerPreview, self).__init__()

        self.setStyleName('v-colorpicker-preview')
        self.setImmediate(True)

        self._color = color

        self._field = TextField()
        self._field.setReadOnly(True)
        self._field.setImmediate(True)
        self._field.setSizeFull()
        self._field.setStyleName('v-colorpicker-preview-textfield')
        self._field.setData(self)
        self._field.addListener(self, IValueChangeListener)
        self._field.addValidator(RegexpValidator('#[0-9a-fA-F]{6}', True, ''))
        self._oldValue = None
        self.addComponent(self._field)

        self.setColor(color)


    def setColor(self, color):
        self._color = color

        red = '%.2x' % color.getRed()
#        red = '0' + red if len(red) < 2 else red

        green = '%.2x' % color.getGreen()
#        green = '0' + green if len(green) < 2 else green

        blue = '%.2x' % color.getBlue()
#        blue = '0' + blue if len(blue) < 2 else blue

        # Unregister listener
        self._field.removeListener(self, IValueChangeListener)
        self._field.setReadOnly(False)

        self._field.setValue('#' + red + green + blue)

        if self._field.isValid():
            self._oldValue = '#' + red + green + blue
        else:
            self._field.setValue(self._oldValue)

        # Re-register listener
        self._field.setReadOnly(True)
        self._field.addListener(self, IValueChangeListener)

        # Set the text color
        self._field.removeStyleName(self._STYLE_DARK_COLOR)
        self._field.removeStyleName(self._STYLE_LIGHT_COLOR)
        if (self._color.getRed() + self._color.getGreen()
                + self._color.getBlue() < 3 * 128):
            self._field.addStyleName(self._STYLE_DARK_COLOR)
        else:
            self._field.addStyleName(self._STYLE_LIGHT_COLOR)

        self.requestRepaint()


    def getColor(self):
        return self._color


    def addListener(self, listener, iface=None):
        """Adds a color change listener

        @param listener:
                   The color change listener
        """
        if (isinstance(listener, IColorChangeListener) and
                (iface is None or issubclass(iface, IColorChangeListener))):
            self.registerListener(ColorChangeEvent, listener,
                    _COLOR_CHANGE_METHOD)

        super(ColorPickerPreview, self).addListener(listener, iface)


    def addCallback(self, callback, eventType=None, *args):
        if eventType is None:
            eventType = callback._eventType  # set by decorator

        if issubclass(eventType, ColorChangeEvent):
            self.registerCallback(ColorChangeEvent, callback, None, *args)
        else:
            super(ColorPickerPreview, self).addCallback(callback, eventType,
                    *args)


    def removeListener(self, listener, iface=None):
        """Removes a color change listener

        @param listener:
                   The listener
        """
        if (isinstance(listener, IColorChangeListener) and
                (iface is None or issubclass(iface, IColorChangeListener))):
            self.withdrawListener(ColorChangeEvent, listener)

        super(ColorPickerPreview, self).removeListener(listener, iface)


    def removeCallback(self, callback, eventType=None):
        if eventType is None:
            eventType = callback._eventType

        if issubclass(eventType, ColorChangeEvent):
            self.withdrawCallback(ColorChangeEvent, callback)

        else:
            super(ColorPickerPreview, self).removeCallback(callback, eventType)


    def valueChange(self, event):
        value = event.getProperty().getValue()

        if not self._field.isValid():
            self._field.setValue(self._oldValue)
            return
        else:
            self._oldValue = value

        if value is not None and len(value) == 7:
            red = int(value[1:3], 16)
            green = int(value[3:5], 16)
            blue = int(value[5:7], 16)
            self._color = Color(red, green, blue)

            evt = ColorChangeEvent(self._field.getData(), self._color)
            self.fireEvent(evt)


    def getCss(self, c):
        """Called when the component is refreshing"""
        red = '%.2x' % self._color.getRed()
#        red = '0' + red if len(red) < 2 else red

        green = '%.2x' % self._color.getGreen()
#        green = '0' + green if len(green) < 2 else green

        blue = '%.2x' % self._color.getBlue()
#        blue = '0' + blue if len(blue) < 2 else blue

        css = 'background: #' + red + green + blue
        return css
Ejemplo n.º 8
0
class ColorPickerPreview(CssLayout, IColorSelector, IValueChangeListener):
    """The Class ColorPickerPreview.

    @author: John Ahlroos / ITMill Oy 2010
    @author: Richard Lincoln
    """

    _STYLE_DARK_COLOR = 'v-textfield-dark'
    _STYLE_LIGHT_COLOR = 'v-textfield-light'

    def __init__(self, color):
        """Instantiates a new color picker preview."""
        super(ColorPickerPreview, self).__init__()

        self.setStyleName('v-colorpicker-preview')
        self.setImmediate(True)

        self._color = color

        self._field = TextField()
        self._field.setReadOnly(True)
        self._field.setImmediate(True)
        self._field.setSizeFull()
        self._field.setStyleName('v-colorpicker-preview-textfield')
        self._field.setData(self)
        self._field.addListener(self, IValueChangeListener)
        self._field.addValidator(RegexpValidator('#[0-9a-fA-F]{6}', True, ''))
        self._oldValue = None
        self.addComponent(self._field)

        self.setColor(color)

    def setColor(self, color):
        self._color = color

        red = '%.2x' % color.getRed()
        #        red = '0' + red if len(red) < 2 else red

        green = '%.2x' % color.getGreen()
        #        green = '0' + green if len(green) < 2 else green

        blue = '%.2x' % color.getBlue()
        #        blue = '0' + blue if len(blue) < 2 else blue

        # Unregister listener
        self._field.removeListener(self, IValueChangeListener)
        self._field.setReadOnly(False)

        self._field.setValue('#' + red + green + blue)

        if self._field.isValid():
            self._oldValue = '#' + red + green + blue
        else:
            self._field.setValue(self._oldValue)

        # Re-register listener
        self._field.setReadOnly(True)
        self._field.addListener(self, IValueChangeListener)

        # Set the text color
        self._field.removeStyleName(self._STYLE_DARK_COLOR)
        self._field.removeStyleName(self._STYLE_LIGHT_COLOR)
        if (self._color.getRed() + self._color.getGreen() +
                self._color.getBlue() < 3 * 128):
            self._field.addStyleName(self._STYLE_DARK_COLOR)
        else:
            self._field.addStyleName(self._STYLE_LIGHT_COLOR)

        self.requestRepaint()

    def getColor(self):
        return self._color

    def addListener(self, listener, iface=None):
        """Adds a color change listener

        @param listener:
                   The color change listener
        """
        if (isinstance(listener, IColorChangeListener) and
            (iface is None or issubclass(iface, IColorChangeListener))):
            self.registerListener(ColorChangeEvent, listener,
                                  _COLOR_CHANGE_METHOD)

        super(ColorPickerPreview, self).addListener(listener, iface)

    def addCallback(self, callback, eventType=None, *args):
        if eventType is None:
            eventType = callback._eventType  # set by decorator

        if issubclass(eventType, ColorChangeEvent):
            self.registerCallback(ColorChangeEvent, callback, None, *args)
        else:
            super(ColorPickerPreview,
                  self).addCallback(callback, eventType, *args)

    def removeListener(self, listener, iface=None):
        """Removes a color change listener

        @param listener:
                   The listener
        """
        if (isinstance(listener, IColorChangeListener) and
            (iface is None or issubclass(iface, IColorChangeListener))):
            self.withdrawListener(ColorChangeEvent, listener)

        super(ColorPickerPreview, self).removeListener(listener, iface)

    def removeCallback(self, callback, eventType=None):
        if eventType is None:
            eventType = callback._eventType

        if issubclass(eventType, ColorChangeEvent):
            self.withdrawCallback(ColorChangeEvent, callback)

        else:
            super(ColorPickerPreview, self).removeCallback(callback, eventType)

    def valueChange(self, event):
        value = event.getProperty().getValue()

        if not self._field.isValid():
            self._field.setValue(self._oldValue)
            return
        else:
            self._oldValue = value

        if value is not None and len(value) == 7:
            red = int(value[1:3], 16)
            green = int(value[3:5], 16)
            blue = int(value[5:7], 16)
            self._color = Color(red, green, blue)

            evt = ColorChangeEvent(self._field.getData(), self._color)
            self.fireEvent(evt)

    def getCss(self, c):
        """Called when the component is refreshing"""
        red = '%.2x' % self._color.getRed()
        #        red = '0' + red if len(red) < 2 else red

        green = '%.2x' % self._color.getGreen()
        #        green = '0' + green if len(green) < 2 else green

        blue = '%.2x' % self._color.getBlue()
        #        blue = '0' + blue if len(blue) < 2 else blue

        css = 'background: #' + red + green + blue
        return css