Ejemplo n.º 1
0
    def __init__(self, initialColor):
        """Instantiates a new color picker popup."""

        #: The tabs.
        self._tabs = TabSheet()

        #: The layout.
        self._layout = VerticalLayout()

        #: The ok button.
        self._ok = Button('OK')

        #: The cancel button.
        self._cancel = Button('Cancel')

        #: The resize button.
        self._resize = Button('...')

        #: The selected color.
        self._selectedColor = Color.WHITE

        #: The history.
        self._history = None

        #: The history container.
        self._historyContainer = None

        #: The rgb gradient.
        self._rgbGradient = None

        #: The hsv gradient.
        self._hsvGradient = None

        #: The red slider.
        self._redSlider = None

        #: The green slider.
        self._greenSlider = None

        #: The blue slider.
        self._blueSlider = None

        #: The hue slider.
        self._hueSlider = None

        #: The saturation slider.
        self._saturationSlider = None

        #: The value slider.
        self._valueSlider = None

        #: The preview on the rgb tab.
        self._rgbPreview = None

        #: The preview on the hsv tab.
        self._hsvPreview = None

        #: The preview on the swatches tab.
        self._selPreview = None

        #: The color select.
        self._colorSelect = None

        #: The selectors.
        self._selectors = set()

        super(ColorPickerPopup, self).__init__()

        self._selectedColor = initialColor

        self.setWidth('250px')
        self.setScrollable(False)
        self.setStyleName(self._STYLENAME)
        self.setResizable(False)
        self.setImmediate(True)

        # Create the history
        self._history = ColorPickerHistory()
        self._history.addListener(self, IColorChangeListener)

        # Create the preview on the rgb tab
        self._rgbPreview = ColorPickerPreview(self._selectedColor)
        self._rgbPreview.setWidth('220px')
        self._rgbPreview.setHeight('20px')
        self._rgbPreview.addListener(self, IColorChangeListener)
        self._selectors.add(self._rgbPreview)

        # Create the preview on the hsv tab
        self._hsvPreview = ColorPickerPreview(self._selectedColor)
        self._hsvPreview.setWidth('220px')
        self._hsvPreview.setHeight('20px')
        self._hsvPreview.addListener(self, IColorChangeListener)
        self._selectors.add(self._hsvPreview)

        # Create the preview on the swatches tab
        self._selPreview = ColorPickerPreview(self._selectedColor)
        self._selPreview.setWidth('220px')
        self._selPreview.setHeight('20px')
        self._selPreview.addListener(self, IColorChangeListener)
        self._selectors.add(self._selPreview)

        # Set the layout
        self._layout.setSpacing(False)
        self._layout.setSizeFull()
        self.setContent(self._layout)

        # Create the tabs
        self._rgbTab = self.createRGBTab(self._selectedColor)
        self._tabs.addTab(self._rgbTab, 'RGB', None)

        self._hsvTab = self.createHSVTab(self._selectedColor)
        self._tabs.addTab(self._hsvTab, 'HSV', None)

        self._swatchesTab = self.createSelectTab()
        self._tabs.addTab(self._swatchesTab, 'Swatches', None)

        # Add the tabs
        self._tabs.setWidth('100%')

        self._layout.addComponent(self._tabs)

        # Add the history
        self._history.setWidth('97%')
        self._history.setHeight('27px')

        # Create the default colors
        defaultColors = list()
        defaultColors.append(Color.BLACK)
        defaultColors.append(Color.WHITE)

        # Create the history
        innerContainer = VerticalLayout()
        innerContainer.setSizeFull()
        innerContainer.addComponent(self._history)
        innerContainer.setExpandRatio(self._history, 1)

        outerContainer = VerticalLayout()
        outerContainer.setWidth('99%')
        outerContainer.setHeight('27px')
        outerContainer.addComponent(innerContainer)
        self._historyContainer = outerContainer

        self._layout.addComponent(self._historyContainer)

        # Add the resize button for the history
        self._resize.addListener(self, IClickListener)
        self._resize.setData(False)
        self._resize.setWidth('100%')
        self._resize.setHeight('10px')
        self._resize.setStyleName('resize-button')
        self._layout.addComponent(self._resize)

        # Add the buttons
        self._ok.setWidth('70px')
        self._ok.addListener(self, IClickListener)

        self._cancel.setWidth('70px')
        self._cancel.addListener(self, IClickListener)

        buttons = HorizontalLayout()
        buttons.addComponent(self._ok)
        buttons.addComponent(self._cancel)
        buttons.setWidth('100%')
        buttons.setHeight('30px')
        buttons.setComponentAlignment(self._ok, Alignment.MIDDLE_CENTER)
        buttons.setComponentAlignment(self._cancel, Alignment.MIDDLE_CENTER)
        self._layout.addComponent(buttons)

        self.setHeight(self.calculateHeight())
Ejemplo n.º 2
0
    def init(self):
        # This is called whenever a colorpicker popup is closed
        main = Window()
        main.setWidth('1000px')
        self.setMainWindow(main)

        # Create an instance of the preview and add it to the window
        #        self._display = Embedded('Color preview')
        self._display = Canvas()
        self._display.setWidth('270px')
        self._display.setHeight('270px')

        # Add the foreground and background colorpickers to a layout
        self._mainLayout = mainLayout = HorizontalLayout()
        mainLayout.setMargin(True)
        mainLayout.setSpacing(True)
        main.setContent(mainLayout)

        layout = VerticalLayout()
        layout.setWidth('450px')
        layout.setSpacing(True)

        optPanel = Panel('Customize the color picker popup window',
                         GridLayout(3, 2))
        optPanel.getContent().setSizeFull()
        optPanel.getContent().setMargin(True)
        optPanel.getContent().setSpacing(True)

        self._rgbBox.addListener(RgbClickListener(self), IClickListener)
        self._rgbBox.setValue(self._rgbVisible)
        self._rgbBox.setImmediate(True)
        optPanel.getContent().addComponent(self._rgbBox)

        self._hsvBox.addListener(HsvClickListener(self), IClickListener)
        self._hsvBox.setValue(self._hsvVisible)
        self._hsvBox.setImmediate(True)
        optPanel.getContent().addComponent(self._hsvBox)

        self._swaBox.addListener(SwaClickListener(self), IClickListener)
        self._swaBox.setValue(self._swaVisible)
        self._swaBox.setImmediate(True)
        optPanel.getContent().addComponent(self._swaBox)

        self._hisBox.addListener(HisClickListener(self), IClickListener)
        self._hisBox.setValue(self._historyVisible)
        self._hisBox.setImmediate(True)
        optPanel.getContent().addComponent(self._hisBox)

        self._txtBox.addListener(TxtClickListener(self), IClickListener)
        self._txtBox.setValue(self._txtfieldVisible)
        self._txtBox.setImmediate(True)
        optPanel.getContent().addComponent(self._txtBox)

        layout.addComponent(optPanel)

        panel1 = Panel(
            'Button like colorpicker with current color and CSS code',
            HorizontalLayout())
        panel1.getContent().setSizeFull()
        panel1.getContent().setMargin(True)

        self._colorpicker1 = ColorPicker('Foreground', self._foregroundColor)
        self._colorpicker1.setWidth('100px')
        self._colorpicker1.addListener(self)
        panel1.addComponent(self._colorpicker1)
        panel1.getContent().setComponentAlignment(self._colorpicker1,
                                                  Alignment.MIDDLE_CENTER)

        self._colorpicker2 = ColorPicker('Background', self._backgroundColor)
        self._colorpicker2.addListener(self)
        self._colorpicker2.setWidth('100px')
        panel1.addComponent(self._colorpicker2)
        panel1.getContent().setComponentAlignment(self._colorpicker2,
                                                  Alignment.MIDDLE_CENTER)
        layout.addComponent(panel1)

        panel2 = Panel(
            'Button like colorpicker with current color and custom caption',
            HorizontalLayout())
        panel2.getContent().setSizeFull()
        panel2.getContent().setMargin(True)
        self._colorpicker3 = ColorPicker('Foreground', self._foregroundColor)
        self._colorpicker3.addListener(self)
        self._colorpicker3.setWidth('120px')
        self._colorpicker3.setButtonCaption('Foreground')
        panel2.addComponent(self._colorpicker3)
        panel2.getContent().setComponentAlignment(self._colorpicker3,
                                                  Alignment.MIDDLE_CENTER)

        self._colorpicker4 = ColorPicker('Background', self._backgroundColor)
        self._colorpicker4.addListener(self)
        self._colorpicker4.setWidth('120px')
        self._colorpicker4.setButtonCaption('Background')
        panel2.addComponent(self._colorpicker4)
        panel2.getContent().setComponentAlignment(self._colorpicker4,
                                                  Alignment.MIDDLE_CENTER)
        layout.addComponent(panel2)

        panel3 = Panel('Color area color picker with caption',
                       HorizontalLayout())
        panel3.getContent().setSizeFull()
        panel3.getContent().setMargin(True)

        self._colorpicker5 = ColorPicker('Foreground', self._foregroundColor)
        self._colorpicker5.setCaption('Foreground')
        self._colorpicker5.addListener(self)
        self._colorpicker5.setButtonStyle(ButtonStyle.BUTTON_AREA)
        panel3.addComponent(self._colorpicker5)
        panel3.getContent().setComponentAlignment(self._colorpicker5,
                                                  Alignment.MIDDLE_CENTER)

        self._colorpicker6 = ColorPicker('Background', self._backgroundColor)
        self._colorpicker6.setCaption('Background')
        self._colorpicker6.addListener(self)
        self._colorpicker6.setButtonStyle(ButtonStyle.BUTTON_AREA)
        panel3.addComponent(self._colorpicker6)
        panel3.getContent().setComponentAlignment(self._colorpicker6,
                                                  Alignment.MIDDLE_CENTER)
        layout.addComponent(panel3)

        mainLayout.addComponent(layout)
        mainLayout.addComponent(self._display)

        self.updateDisplay(self._foregroundColor, self._backgroundColor)
    def init(self):
        # This is called whenever a colorpicker popup is closed
        main = Window()
        main.setWidth('1000px')
        self.setMainWindow(main)

        # Create an instance of the preview and add it to the window
#        self._display = Embedded('Color preview')
        self._display = Canvas()
        self._display.setWidth('270px')
        self._display.setHeight('270px')

        # Add the foreground and background colorpickers to a layout
        self._mainLayout = mainLayout = HorizontalLayout()
        mainLayout.setMargin(True)
        mainLayout.setSpacing(True)
        main.setContent(mainLayout)

        layout = VerticalLayout()
        layout.setWidth('450px')
        layout.setSpacing(True)

        optPanel = Panel('Customize the color picker popup window',
                GridLayout(3, 2))
        optPanel.getContent().setSizeFull()
        optPanel.getContent().setMargin(True)
        optPanel.getContent().setSpacing(True)

        self._rgbBox.addListener(RgbClickListener(self), IClickListener)
        self._rgbBox.setValue(self._rgbVisible)
        self._rgbBox.setImmediate(True)
        optPanel.getContent().addComponent(self._rgbBox)

        self._hsvBox.addListener(HsvClickListener(self), IClickListener)
        self._hsvBox.setValue(self._hsvVisible)
        self._hsvBox.setImmediate(True)
        optPanel.getContent().addComponent(self._hsvBox)

        self._swaBox.addListener(SwaClickListener(self), IClickListener)
        self._swaBox.setValue(self._swaVisible)
        self._swaBox.setImmediate(True)
        optPanel.getContent().addComponent(self._swaBox)

        self._hisBox.addListener(HisClickListener(self), IClickListener)
        self._hisBox.setValue(self._historyVisible)
        self._hisBox.setImmediate(True)
        optPanel.getContent().addComponent(self._hisBox)

        self._txtBox.addListener(TxtClickListener(self), IClickListener)
        self._txtBox.setValue(self._txtfieldVisible)
        self._txtBox.setImmediate(True)
        optPanel.getContent().addComponent(self._txtBox)

        layout.addComponent(optPanel)

        panel1 = Panel(
                'Button like colorpicker with current color and CSS code',
                HorizontalLayout())
        panel1.getContent().setSizeFull()
        panel1.getContent().setMargin(True)

        self._colorpicker1 = ColorPicker('Foreground', self._foregroundColor)
        self._colorpicker1.setWidth('100px')
        self._colorpicker1.addListener(self)
        panel1.addComponent(self._colorpicker1)
        panel1.getContent().setComponentAlignment(self._colorpicker1,
                Alignment.MIDDLE_CENTER)

        self._colorpicker2 = ColorPicker('Background', self._backgroundColor)
        self._colorpicker2.addListener(self)
        self._colorpicker2.setWidth('100px')
        panel1.addComponent(self._colorpicker2)
        panel1.getContent().setComponentAlignment(self._colorpicker2,
                Alignment.MIDDLE_CENTER)
        layout.addComponent(panel1)

        panel2 = Panel(
                'Button like colorpicker with current color and custom caption',
                HorizontalLayout())
        panel2.getContent().setSizeFull()
        panel2.getContent().setMargin(True)
        self._colorpicker3 = ColorPicker('Foreground', self._foregroundColor)
        self._colorpicker3.addListener(self)
        self._colorpicker3.setWidth('120px')
        self._colorpicker3.setButtonCaption('Foreground')
        panel2.addComponent(self._colorpicker3)
        panel2.getContent().setComponentAlignment(self._colorpicker3,
                Alignment.MIDDLE_CENTER)

        self._colorpicker4 = ColorPicker('Background', self._backgroundColor)
        self._colorpicker4.addListener(self)
        self._colorpicker4.setWidth('120px')
        self._colorpicker4.setButtonCaption('Background')
        panel2.addComponent(self._colorpicker4)
        panel2.getContent().setComponentAlignment(self._colorpicker4,
                Alignment.MIDDLE_CENTER)
        layout.addComponent(panel2)

        panel3 = Panel(
                'Color area color picker with caption',
                HorizontalLayout())
        panel3.getContent().setSizeFull()
        panel3.getContent().setMargin(True)

        self._colorpicker5 = ColorPicker('Foreground', self._foregroundColor)
        self._colorpicker5.setCaption('Foreground')
        self._colorpicker5.addListener(self)
        self._colorpicker5.setButtonStyle(ButtonStyle.BUTTON_AREA)
        panel3.addComponent(self._colorpicker5)
        panel3.getContent().setComponentAlignment(self._colorpicker5,
                Alignment.MIDDLE_CENTER)

        self._colorpicker6 = ColorPicker('Background', self._backgroundColor)
        self._colorpicker6.setCaption('Background')
        self._colorpicker6.addListener(self)
        self._colorpicker6.setButtonStyle(ButtonStyle.BUTTON_AREA)
        panel3.addComponent(self._colorpicker6)
        panel3.getContent().setComponentAlignment(self._colorpicker6,
                Alignment.MIDDLE_CENTER)
        layout.addComponent(panel3)

        mainLayout.addComponent(layout)
        mainLayout.addComponent(self._display)

        self.updateDisplay(self._foregroundColor, self._backgroundColor)