Python gi.repository.Gdk.RGBA Examples

The following are 30 code examples of gi.repository.Gdk.RGBA(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gdk , or try the search function .
Example #1
Source File: colour_palette.py    From alienfx with GNU General Public License v3.0 6 votes vote down vote up
def __init__(
            self, colours, max_colour_val, num_rows, num_cols, horizontal, 
            selected_handler):
        Gtk.Grid.__init__(self)
        row = 0
        col = 0
        (ret, width, height) = Gtk.icon_size_lookup(Gtk.IconSize.BUTTON)
        rgba = Gdk.RGBA()
        for c in colours:
            rgba.parse(c)
            colour_square = ColourPaletteSquare(
                rgba, width, height, max_colour_val)
            colour_square.connect("button-release-event", selected_handler)
            self.attach(colour_square, col, row, 1, 1)
            if horizontal:
                col += 1
                if col == num_cols:
                    col = 0
                    row += 1
            else:
                row += 1
                if row == num_rows:
                    row = 0
                    col += 1 
Example #2
Source File: gui_utilities.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def gtk_style_context_get_color(sc, color_name, default=None):
	"""
	Look up a color by it's name in the :py:class:`Gtk.StyleContext` specified
	in *sc*, and return it as an :py:class:`Gdk.RGBA` instance if the color is
	defined. If the color is not found, *default* will be returned.

	:param sc: The style context to use.
	:type sc: :py:class:`Gtk.StyleContext`
	:param str color_name: The name of the color to lookup.
	:param default: The default color to return if the specified color was not found.
	:type default: str, :py:class:`Gdk.RGBA`
	:return: The color as an RGBA instance.
	:rtype: :py:class:`Gdk.RGBA`
	"""
	found, color_rgba = sc.lookup_color(color_name)
	if found:
		return color_rgba
	if isinstance(default, str):
		color_rgba = Gdk.RGBA()
		color_rgba.parse(default)
		return color_rgba
	elif isinstance(default, Gdk.RGBA):
		return default
	return 
Example #3
Source File: tool_picker.py    From drawing with GNU General Public License v3.0 6 votes vote down vote up
def on_release_on_area(self, event, surface, event_x, event_y):
		rgba_vals = utilities_get_rgba_for_xy(surface, event_x, event_y)
		if rgba_vals is None:
			return # click outside of the surface
		r = rgba_vals[0] / 255
		g = rgba_vals[1] / 255
		b = rgba_vals[2] / 255
		a = rgba_vals[3] / 255
		color = Gdk.RGBA(red=r, green=g, blue=b, alpha=a)
		if event.button == 1:
			self.window.options_manager.set_left_color(color)
		elif event.button == 3:
			self.window.options_manager.set_right_color(color)
		self.window.back_to_previous()

	############################################################################
################################################################################ 
Example #4
Source File: infobox.py    From syncthing-gtk with GNU General Public License v2.0 6 votes vote down vote up
def recolor(self, *a):
		"""
		Called to computes actual color every time when self.color or
		self.hilight_factor changes.
		"""
		if self.dark_color is None:
			self.real_color = tuple([ min(1.0, x + HILIGHT_INTENSITY * math.sin(self.hilight_factor)) for x in self.color])
		else:
			# Darken colors when dark background is enabled
			self.real_color = tuple([ min(1.0, DARKEN_FACTOR * (x + HILIGHT_INTENSITY * math.sin(self.hilight_factor))) for x in self.color])
		gdkcol = Gdk.RGBA(*self.real_color)
		self.header.override_background_color(Gtk.StateType.NORMAL, gdkcol)
		try:
			self.header.get_children()[0].override_background_color(Gtk.StateFlags.NORMAL, gdkcol)
		except IndexError:
			# Happens when recolor is called before header widget is created
			pass

		self.queue_draw()
	
	### Translated events 
Example #5
Source File: graphview.py    From addons-source with GNU General Public License v2.0 6 votes vote down vote up
def get_tags_and_table(self, obj):
        """
        Return html tags table for obj (person or family).
        """
        tag_table = ''
        tags = []

        for tag_handle in obj.get_tag_list():
            tags.append(self.dbstate.db.get_tag_from_handle(tag_handle))

        # prepare html table of tags
        if tags:
            tag_table = ('<TABLE BORDER="0" CELLBORDER="0" '
                         'CELLPADDING="5"><TR>')
            for tag in tags:
                rgba = Gdk.RGBA()
                rgba.parse(tag.get_color())
                value = '#%02x%02x%02x' % (int(rgba.red * 255),
                                           int(rgba.green * 255),
                                           int(rgba.blue * 255))
                tag_table += '<TD BGCOLOR="%s"></TD>' % value
            tag_table += '</TR></TABLE>'

        return tags, tag_table 
Example #6
Source File: gtk.py    From pywebview with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def configure_transparency(c):
    c.set_visual(c.get_screen().get_rgba_visual())
    c.override_background_color(gtk.StateFlags.ACTIVE, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.BACKDROP, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.DIR_LTR, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.DIR_RTL, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.FOCUSED, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.INCONSISTENT, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.INSENSITIVE, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.PRELIGHT, Gdk.RGBA(0, 0, 0, 0))
    c.override_background_color(gtk.StateFlags.SELECTED, Gdk.RGBA(0, 0, 0, 0))
    transparentWindowStyleProvider = gtk.CssProvider()
    transparentWindowStyleProvider.load_from_data(b"""
        GtkWindow {
            background-color:rgba(0,0,0,0);
            background-image:none;
        }""")
    c.get_style_context().add_provider(transparentWindowStyleProvider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) 
Example #7
Source File: custom_kb_builder.py    From razerCommander with GNU General Public License v3.0 6 votes vote down vote up
def build_keyrow_box(row, colors, signal_handler, prof_index):
    box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
    for key in row.keylist:
        if not key.isGhost:
            k_col = Gdk.RGBA(
                colors[prof_index][0],
                colors[prof_index][1],
                colors[prof_index][2]
            )
        else:
            k_col = Gdk.RGBA(0, 0, 0)
        keybox = build_key_box(
            key,
            k_col,
            signal_handler
        )
        if not key.isGhost:
            prof_index += 1
        box.pack_start(keybox, True, True, 0)
    return {'row': box, 'prof_index': prof_index} 
Example #8
Source File: infobox.py    From syncthing-gtk with GNU General Public License v2.0 6 votes vote down vote up
def init_grid(self):
		# Create widgets
		self.grid = Gtk.Grid()
		self.rev = RevealerClass()
		align = Gtk.Alignment()
		self.eb = Gtk.EventBox()
		# Set values
		self.grid.set_row_spacing(1)
		self.grid.set_column_spacing(3)
		self.rev.set_reveal_child(False)
		align.set_padding(2, 2, 5, 5)
		self.eb.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*self.background))
		self.grid.override_background_color(Gtk.StateType.NORMAL, Gdk.RGBA(*self.background))
		# Connect signals
		self.eb.connect("button-release-event", self.on_grid_release)
		self.eb.connect("button-press-event", self.on_grid_click)
		self.eb.connect('enter-notify-event', self.on_enter_notify)
		self.eb.connect('leave-notify-event', self.on_leave_notify)
		# Pack together
		align.add(self.grid)
		self.eb.add(align)
		self.rev.add(self.eb)
		self.add(self.rev)
	
	### GtkWidget-related stuff 
Example #9
Source File: app.py    From syncthing-gtk with GNU General Public License v2.0 6 votes vote down vote up
def cb_realized(self, widget, *a):
		context = widget.get_style_context()
		color = context.get_background_color(Gtk.StateFlags.SELECTED)
		# Dark color: Gdk.RGBA(red=0.223529, green=0.247059, blue=0.247059, alpha=1.000000)
		# Light color: Gdk.RGBA(red=0.929412, green=0.929412, blue=0.929412, alpha=1.000000)
		light_color = False
		for c in list(color)[0:3]:
			if c > 0.75: light_color = True
		if not light_color:
			# Set dark color based on current window background
			self.dark_color = (color.red, color.green, color.blue, 1.0)
			# Recolor all boxes
			for box in self.folders.values():
				box.set_dark_color(*self.dark_color)
			for box in self.devices.values():
				box.set_dark_color(*self.dark_color) 
Example #10
Source File: results.py    From runsqlrun with MIT License 6 votes vote down vote up
def __init__(self):
        super(QueryLog, self).__init__()
        model = Gtk.ListStore(str, Gdk.RGBA)
        self.set_model(model)
        column = Gtk.TreeViewColumn(
            '', Gtk.CellRendererText(), markup=0, foreground_rgba=1)
        self.append_column(column)
        self.set_headers_visible(False)
        self.set_reorderable(False)
        self.set_enable_search(False)
        lbl = Gtk.Label()
        context = lbl.get_style_context()
        self.dimmed_fg = context.get_color(Gtk.StateFlags.INSENSITIVE)
        self.col_error = self.dimmed_fg.copy()
        self.col_error.red = max(self.col_error.red * 1.7, 1)
        self.col_error.green *= 0.7
        self.col_error.blue *= 0.7
        font_desc = Pango.FontDescription.from_string('Ubuntu Mono 12')
        self.modify_font(font_desc) 
Example #11
Source File: ChannelsPanel.py    From pychess with GNU General Public License v3.0 6 votes vote down vote up
def change_fg_colour(self, lc, cell, model, m_iter, data):
        """
        :Description: Changes the foreground colour of a cell

        :param lc: :class:`Gtk.TreeViewColumn` The column we are interested in
        :param cell: :class:`Gtk.CellRenderer` The cell we want to change
        :param model: :class:`Gtk.TreeModel`
        :param iter: :class:`Gtk.TreeIter`
        :param data: :py:class:`dict` (key=int,value=bool) value is true if channel already highlighted
        :return: None
        """

        for chan in data:
            if model[m_iter][0] == chan:
                if data[chan]:
                    cell.set_property('foreground_rgba',
                                      Gdk.RGBA(0.9, 0.2, 0.2, 1))
                else:
                    cell.set_property('foreground_rgba', Gdk.RGBA(0, 0, 0, 1)) 
Example #12
Source File: FlatCAMApp.py    From FlatCAM with MIT License 5 votes vote down vote up
def setup_component_editor(self):
        """
        Initial configuration of the component editor. Creates
        a page titled "Selection" on the notebook on the left
        side of the main window.

        :return: None
        """

        # box_selected = self.builder.get_object("vp_selected")

        # White background
        # box_selected.override_background_color(Gtk.StateType.NORMAL,
        #                                        Gdk.RGBA(1, 1, 1, 1))
        self.ui.notebook.selected_contents.override_background_color(Gtk.StateType.NORMAL,
                                                                     Gdk.RGBA(1, 1, 1, 1))

        # Remove anything else in the box
        box_children = self.ui.notebook.selected_contents.get_children()
        for child in box_children:
            self.ui.notebook.selected_contents.remove(child)

        box1 = Gtk.Box(Gtk.Orientation.VERTICAL)
        label1 = Gtk.Label("Choose an item from Project")
        box1.pack_start(label1, True, False, 1)
        self.ui.notebook.selected_contents.add(box1)
        box1.show()
        label1.show() 
Example #13
Source File: pygogauth.py    From games_nebula with GNU General Public License v3.0 5 votes vote down vote up
def create_window(self):

        app_icon = GdkPixbuf.Pixbuf.new_from_file(sys.path[0] + '/images/icon.png')

        self.login_window = Gtk.Window(
            title = "Games Nebula",
            type = Gtk.WindowType.TOPLEVEL,
            window_position = Gtk.WindowPosition.CENTER_ALWAYS,
            icon = app_icon,
            width_request = 390,
            height_request = 496,
            resizable = True
        )
        self.login_window.connect('delete-event', self.quit_app)

        self.setup_cookies()

        content_manager = self.new_content_manager()
        self.webpage = WebKit2.WebView(user_content_manager=content_manager)
        self.webpage.connect('load_changed', self.webpage_loaded)

        self.webpage_color = Gdk.RGBA(
            red = 0.149019,
            green = 0.149019,
            blue = 0.149019,
            alpha = 1.0,
        )
        self.webpage.set_background_color(self.webpage_color)

        auth_url = get_auth_url()
        self.webpage.load_uri(auth_url)

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.add(self.webpage)

        self.login_window.add(self.scrolled_window)
        self.login_window.show_all() 
Example #14
Source File: color.py    From oomox with GNU General Public License v3.0 5 votes vote down vote up
def convert_theme_color_to_gdk(theme_color):
    gdk_color = Gdk.RGBA()
    gdk_color.parse("#" + theme_color)
    return gdk_color 
Example #15
Source File: color.py    From oomox with GNU General Public License v3.0 5 votes vote down vote up
def mix_gdk_colors(gdk_color_1, gdk_color_2, ratio):
    result_gdk_color = Gdk.RGBA()
    for attr in ('red', 'green', 'blue', 'alpha'):
        setattr(
            result_gdk_color, attr, (
                getattr(gdk_color_1, attr) * ratio +
                getattr(gdk_color_2, attr) * (1 - ratio)
            )
        )
    return result_gdk_color 
Example #16
Source File: oomox_plugin.py    From oomox with GNU General Public License v3.0 5 votes vote down vote up
def get_random_gdk_color():
    return Gdk.RGBA(random.random(), random.random(), random.random(), 1) 
Example #17
Source File: scribble.py    From pympress with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, config, builder, notes_mode):
        super(Scribbler, self).__init__()

        self.load_ui('highlight')
        builder.load_widgets(self)

        self.on_draw = builder.get_callback_handler('on_draw')
        self.track_motions = builder.get_callback_handler('track_motions')
        self.track_clicks = builder.get_callback_handler('track_clicks')
        self.swap_layout = builder.get_callback_handler('swap_layout')
        self.redraw_current_slide = builder.get_callback_handler('redraw_current_slide')
        self.resize_cache = builder.get_callback_handler('cache.resize_widget')
        self.get_slide_point = builder.get_callback_handler('zoom.get_slide_point')
        self.start_zooming = builder.get_callback_handler('zoom.start_zooming')
        self.stop_zooming = builder.get_callback_handler('zoom.stop_zooming')

        self.connect_signals(self)

        self.scribble_color = Gdk.RGBA()
        self.scribble_color.parse(config.get('scribble', 'color'))
        self.scribble_width = config.getint('scribble', 'width')

        self.config = config

        # Presenter-size setup
        self.get_object("scribble_color").set_rgba(self.scribble_color)
        self.get_object("scribble_width").set_value(self.scribble_width) 
Example #18
Source File: helper.py    From clearine with MIT License 5 votes vote down vote up
def to_rgba(self, hex):
        # convert hex color to RGBA
        color = Gdk.RGBA()
        color.parse(hex)
        return color 
Example #19
Source File: labels.py    From paperwork-backend with GNU General Public License v3.0 5 votes vote down vote up
def _get_color(self):
        color = Gdk.RGBA()
        color.parse(self._color)
        return color 
Example #20
Source File: gcode_view.py    From hazzy with GNU General Public License v2.0 5 votes vote down vote up
def add_mark_category(self, category, bg_color):
        att = GtkSource.MarkAttributes()
        color = Gdk.RGBA()
        color.parse(bg_color)
        att.set_background(color)
        self.set_mark_attributes(category, att, 1) 
Example #21
Source File: mooncalendarwindow.py    From my-weather-indicator with MIT License 5 votes vote down vote up
def set_date(self):
        self.headerbar.set_subtitle(self.adate.strftime('%B - %Y'))
        fdom = first_day_of_month(self.adate)
        adate = self.adate.replace(day=1)
        for row in range(1, 7):
            wd = adate + datetime.timedelta(days=7 * (row - 1))
            self.week_days[row].set_text(str(wd.isocalendar()[1]))
        max = {'position': -1, 'value': 0}
        med = {'position': -1, 'value': 1}
        min = {'position': -1, 'value': 1}
        for contador in range(0, 42):
            if contador < fdom:
                tadate = adate - datetime.timedelta(days=(fdom - contador))
            else:
                tadate = adate + datetime.timedelta(days=(contador - fdom))
            self.days[contador].set_date(tadate)
            if tadate.month != adate.month:
                self.days[contador].override_background_color(
                    Gtk.StateFlags.NORMAL, Gdk.RGBA(.5, .5, .5, 1))
            elif tadate.date() == datetime.datetime.today().date():
                self.days[contador].override_background_color(
                    Gtk.StateFlags.NORMAL, Gdk.RGBA(1.0, 0.0, 0.0, 1))
            else:
                self.days[contador].override_background_color(
                    Gtk.StateFlags.NORMAL, Gdk.RGBA(1., 1., 1., 1))
            if tadate.month == adate.month:
                if self.days[contador].get_position() >= max['value']:
                    max['position'] = contador
                    max['value'] = self.days[contador].get_position()
                if self.days[contador].get_position() <= min['value']:
                    min['position'] = contador
                    min['value'] = self.days[contador].get_position()
                if abs(float(self.days[contador].get_position()) - .5) <=\
                        (med['value']):
                    med['position'] = contador
                    med['value'] = abs(float(
                        self.days[contador].get_position()) - 0.5)
        self.days[med['position']].override_background_color(
            Gtk.StateFlags.NORMAL, Gdk.RGBA(0.0, 0.5, 0.0, 1))
        self.days[min['position']].override_background_color(
            Gtk.StateFlags.NORMAL, Gdk.RGBA(0.5, 0.0, 0.5, 1)) 
Example #22
Source File: Config.py    From bcloud with GNU General Public License v3.0 5 votes vote down vote up
def load_color_schema():
    if not os.path.exists(COLOR_SCHEMA):
        return []
    with open(COLOR_SCHEMA) as fh:
        color_list = json.load(fh)

    schema = []
    for color in color_list:
        rgba = Gdk.RGBA()
        rgba.red = int(color[:2], base=16) / 255
        rgba.green = int(color[2:4], base=16) / 255
        rgba.blue = int(color[4:6], base=16) / 255
        rgba.alpha = int(color[6:], base=16) / 255
        schema.append(rgba)
    return schema 
Example #23
Source File: __main__.py    From razerCommander with GNU General Public License v3.0 5 votes vote down vote up
def onVirtKeyClick(self, eventbox, eventbtn):
        key = self.rkb.getKey(eventbox.keyx, eventbox.keyy)
        if not key.isGhost:
            if self.pipetteTBtn.get_active():
                color = key.color
                self.customColorPicker.set_rgba(color)
                self.pipetteTBtn.set_active(False)
            elif self.clearTBtn.get_active():
                key.color = Gdk.RGBA(0, 0, 0)
                black_rgba = Gdk.RGBA(0, 0, 0)
                eventbox.override_background_color(
                    Gtk.StateType.NORMAL,
                    black_rgba
                )
            else:
                key.color = self.customColorPicker.get_rgba()
                eventbox.override_background_color(
                    Gtk.StateType.NORMAL,
                    self.customColorPicker.get_rgba()
                ) 
Example #24
Source File: preferences.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def page_builder_images(self):
		"""Adds the widget to the grid of the 'images' page."""
		self.set_current_grid(self.page_images)

		self.add_section_title(_("New images"))
		self.add_adj(_("Default width"), 'default-width', self.adj_width)
		self.add_adj(_("Default height"), 'default-height', self.adj_height)
		bg_color_btn = Gtk.ColorButton(use_alpha=True)
		background_rgba = self._settings.get_strv('background-rgba')
		r = float(background_rgba[0])
		g = float(background_rgba[1])
		b = float(background_rgba[2])
		a = float(background_rgba[3])
		color = Gdk.RGBA(red=r, green=g, blue=b, alpha=a)
		bg_color_btn.set_rgba(color)
		bg_color_btn.connect('color-set', self.on_background_changed)
		self.add_row(_("Default background"), bg_color_btn)

		self.add_section_separator()
		self.add_section_title(_("Images saving"))
		self.add_help(_("JPEG and BMP images can't handle transparency.") + \
		        " " + _("If you save your images in these formats, what " + \
		                  "do want to use to replace transparent pixels?"))
		alpha_dict = {
			'white': _("White"),
			'black': _("Black"),
			'checkboard': _("Checkboard"),
			'nothing': _("Nothing"),
			'ask': _("Ask before saving")
		}
		self.add_radio_flowbox('replace-alpha', alpha_dict)

		self.add_section_separator()
		self.add_section_title(_("Zoom"))
		zoom_help = _("You can zoom with Ctrl+scrolling, or only scrolling.") + \
		  " " + _("Using keyboard shortcuts or touch gestures is possible too.")
		self.add_help(zoom_help)
		self.add_switch(_("Use 'Ctrl' to zoom"), 'ctrl-zoom') 
Example #25
Source File: new_image_dialog.py    From drawing with GNU General Public License v3.0 5 votes vote down vote up
def _build_ui(self):
		self.add_button(_("Cancel"), Gtk.ResponseType.CANCEL)
		# Context: Create a new image
		btn = self.add_button(_("Create"), Gtk.ResponseType.OK)
		btn.get_style_context().add_class('suggested-action')

		resource_path = '/com/github/maoschanz/drawing/ui/new-image-dialog.ui'
		builder = Gtk.Builder.new_from_resource(resource_path)
		props_content_area = builder.get_object('props_content_area')
		self.get_content_area().add(props_content_area)

		self._width_btn = builder.get_object('spin_width')
		utilities_add_unit_to_spinbtn(self._width_btn, 4, 'px')
		default_w = self._app_settings.get_int('default-width')
		self._width_btn.set_value(default_w)

		self._height_btn = builder.get_object('spin_height')
		utilities_add_unit_to_spinbtn(self._height_btn, 4, 'px')
		default_h = self._app_settings.get_int('default-height')
		self._height_btn.set_value(default_h)

		self._color_btn = builder.get_object('color_btn')
		background_rgba = self._app_settings.get_strv('background-rgba')
		r = float(background_rgba[0])
		g = float(background_rgba[1])
		b = float(background_rgba[2])
		a = float(background_rgba[3])
		color = Gdk.RGBA(red=r, green=g, blue=b, alpha=a)
		self._color_btn.set_rgba(color)

		self._default_checkbtn = builder.get_object('default_checkbtn')

	############################################################################ 
Example #26
Source File: layer_types.py    From innstereo with GNU General Public License v2.0 5 votes vote down vote up
def get_pole_rgba(self):
        """
        Returns the RGBA for pole markers of the layer.

        This method returns the Gdk.RGBA representation of the poles of this
        layer. This is the color set for poles in plane-layers and
        faultplane-layers.
        This method is called by the layer properties dialog to set the color
        of the ColorButton for poles.
        __!!__ Does not return alpha yet!
        """
        rgba = Gdk.RGBA()
        rgba.parse(self.props["pole_fill"])
        return rgba.to_color() 
Example #27
Source File: taglist.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def do_draw(self, cr):
        """
        A custom draw method for this widget.
        @param cr: A cairo context.
        @type cr: cairo.Context
        """
        if (len(self.tag_list)) == 0:
            return

        allocation = self.get_allocation()
        context = self.get_style_context()
        fg_color = context.get_color(context.get_state())

        padding = 2
        size = 10

        cr.set_line_width(1)
        self.__rects = []
        for i, tag in enumerate(self.tag_list):

            cr.rectangle(i * (padding + size),
                         padding,
                         size,
                         size)
            self.__rects.append((i * (padding + size),
                         padding,
                         size,
                         size))

            color = Gdk.RGBA()
            color.parse(tag[1])
            cr.set_source_rgba(color.red, color.green, color.blue, 1)
            cr.fill()

        self.set_size_request((size + padding) * (i + 1) + padding, -1) 
Example #28
Source File: editor.py    From gtg with GNU General Public License v3.0 5 votes vote down vote up
def date_changed(self, widget, data):
        try:
            Date.parse(widget.get_text())
            valid = True
        except ValueError:
            valid = False

        if valid:
            # If the date is valid, we write with default color in the widget
            # "none" will set the default color.
            widget.override_color(Gtk.StateType.NORMAL, None)
            widget.override_background_color(Gtk.StateType.NORMAL, None)
        else:
            # We should write in red in the entry if the date is not valid
            text_color = Gdk.RGBA()
            text_color.parse("#F00")
            widget.override_color(Gtk.StateType.NORMAL, text_color)

            bg_color = Gdk.RGBA()
            bg_color.parse("#F88")
            widget.override_background_color(Gtk.StateType.NORMAL, bg_color) 
Example #29
Source File: color_grid.py    From wpgtk with GNU General Public License v2.0 5 votes vote down vote up
def on_color_click(self, widget):
        self.done_lbl.set_text("")
        gcolor = Gdk.RGBA()
        gcolor.parse(widget.get_label())
        dialog = ColorDialog(self.parent, self.selected_file, gcolor)
        response = dialog.run()

        if response == Gtk.ResponseType.OK:
            r, g, b, _ = dialog.colorchooser.get_rgba()
            rgb = list(map(lambda x: round(x*100*2.55), [r, g, b]))
            hex_color = pywal.util.rgb_to_hex(rgb)
            widget.set_label(hex_color)

            gcolor = Gdk.color_parse(hex_color)
            if util.get_hls_val(hex_color, 'light') < 100:
                fgcolor = Gdk.color_parse('#FFFFFF')
            else:
                fgcolor = Gdk.color_parse('#000000')

            widget.set_sensitive(True)
            widget.modify_bg(Gtk.StateType.NORMAL, gcolor)
            widget.modify_fg(Gtk.StateType.NORMAL, fgcolor)

            for i, c in enumerate(self.button_list):
                if c.get_label() != self.color_list[i]:
                    self.color_list[i] = c.get_label()
            self.render_sample()
        dialog.destroy() 
Example #30
Source File: color_picker.py    From wpgtk with GNU General Public License v2.0 5 votes vote down vote up
def slider_changed(self, slider, *arg):
        newval = -slider.get_value() if arg[0] == 'sat' else slider.get_value()

        red, green, blue, _ = self.colorchooser.get_rgba()
        rgb = list(map(lambda x: round(x*100*2.55), [red, green, blue]))
        newhex = util.set_hls_val(util.rgb_to_hex(rgb), arg[0], newval)

        new_gcolor = Gdk.RGBA()
        new_gcolor.parse(newhex)
        self.colorchooser.set_rgba(new_gcolor)