Gtk.ColorChooserWidget


Gtk.ColorChooserWidget — A widget for choosing colors

Object Hierarchy:

    GObject
    ╰── GInitiallyUnowned
        ╰── Gtk.Widget
            ╰── Gtk.Container
                ╰── Gtk.Box
                    ╰── Gtk.ColorChooserWidget

See also:

Gtk.ColorChooserDialog


Functions:

  • new () -> Gtk.Widget

Description:

The Gtk.ColorChooserWidget widget lets the user select a color. By default, the chooser presents a predefined palette of colors, plus a small number of settable custom colors.

It is also possible to select a different color with the single-color editor. To enter the single-color editing mode, use the context menu of any color of the palette, or use the '+' button to add a new custom color.

The chooser automatically remembers the last selection, as well as custom colors.

To change the initially selected color, use Gtk.ColorChooser::set_rgba().

To get the selected color use Gtk.ColorChooser::get_rgba().

The GtkColorChooserWidget is used in the Gtk.ColorChooserDialog to provide a dialog for selecting colors.


Function Details:

new()

new () -> Gtk.Widget

Creates a new Gtk.ColorChooserWidget.

  • Returns: a new Gtk.ColorChooserWidget

  • Since: 3.4


Example:

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import inspect

class ColorChooserWidget(Gtk.Window):
    def __init__(self):
        Gtk.Window.__init__(self)
        self.set_title('ColorChooserWidget')
        self.set_border_width(5)
        self.connect('destroy', Gtk.main_quit)

        self.colorchooserwidget = Gtk.ColorChooserWidget(show_editor=False)
        self.add(self.colorchooserwidget)
        self.color = self.colorchooserwidget.get_rgba()
        self.colorchooserwidget.connect('color-activated', self.on_color_activated)        
        #self.colorchooserwidget.connect('motion-notify-event', self.on_button_motion)

        #self.colorchooserwidget.connect('event', self.on_event)
        self.colorchooserwidget.connect('button-press-event', self.on_event)
        self.colorchooserwidget.connect('property-notify-event', self.on_event)
        self.colorchooserwidget.connect('selection-received', self.on_event)

        #r = inspect.getmembers(Gtk.ColorChooserWidget)
        #for s in r:
        #    print(s)
        #for w in self.colorchooserwidget.get_children():
        #    w.connect('button-press-event', self.on_button_press)
        #print(lst)       

    def on_event(self, widget, event):
        print(event)

    def on_button_motion(self, widget, event):
        #print(widget, event)
        color = self.colorchooserwidget.get_rgba()
        if color == self.color:
            return
        self.color = color
        red = int(color.red * 255)
        green = int(color.green * 255)
        blue = int(color.blue * 255)
        print('Hex: #%02x%02x%02x' % (red, green, blue))

    def on_color_activated(self, colorchooserwidget, color):
        red = (color.red * 255)
        green = (color.green * 255)
        blue = (color.blue * 255)

        print('Hex: #%02x%02x%02x' % (red, green, blue))

window = ColorChooserWidget()
window.show_all()

Gtk.main()

results matching ""

    No results matching ""