Python gi.repository.Gdk.color_parse() Examples
The following are 16
code examples of gi.repository.Gdk.color_parse().
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: custom.py From Dindo-Bot with MIT License | 6 votes |
def __init__(self, text=None, color='black', enable_buttons=False): Gtk.Box.__init__(self, orientation=Gtk.Orientation.HORIZONTAL, spacing=5) self.enable_buttons = enable_buttons # label self.label = Gtk.Label(text) self.label.modify_fg(Gtk.StateType.NORMAL, Gdk.color_parse(color)) self.add(self.label) # question buttons if enable_buttons: self.button_box = ButtonBox(linked=True) self.pack_end(self.button_box, False, False, 0) # yes self.yes_button = Gtk.Button() self.yes_button.set_tooltip_text('Yes') self.yes_button.set_image(Gtk.Image(icon_name='emblem-ok-symbolic')) self.button_box.add(self.yes_button) # no self.no_button = Gtk.Button() self.no_button.set_tooltip_text('No') self.no_button.set_image(Gtk.Image(icon_name='window-close-symbolic')) self.button_box.add(self.no_button)
Example #2
Source File: gtk.py From encompass with GNU General Public License v3.0 | 5 votes |
def set_frozen(self,entry,frozen): if frozen: entry.set_editable(False) entry.set_has_frame(False) entry.modify_base(Gtk.StateType.NORMAL, Gdk.color_parse("#eeeeee")) else: entry.set_editable(True) entry.set_has_frame(True) entry.modify_base(Gtk.StateType.NORMAL, Gdk.color_parse("#ffffff"))
Example #3
Source File: simple_color_selector.py From gtg with GNU General Public License v3.0 | 5 votes |
def on_color_add(self, widget): """Callback: when adding a new color, show the color definition window, update the model, notifies the parent.""" color_dialog = Gtk.ColorSelectionDialog(_('Choose a color')) # FIXME colorsel = color_dialog.get_color_selection() if self.selected_col is not None: color = Gdk.color_parse(self.selected_col.color) colorsel.set_current_color(color) response = color_dialog.run() new_color = colorsel.get_current_color() # Check response_id and set color if required if response == Gtk.ResponseType.OK and new_color: # FIXME # strcolor = Gtk.color_selection_palette_to_string([new_color]) strcolor = new_color.to_string() # Add the color to the palette and notify if strcolor not in self.colors: self.add_custom_color(strcolor) # Select the new color and notify self.set_selected_color(strcolor) self.emit("color-changed") # Clean up color_dialog.destroy() # public IF
Example #4
Source File: tag_editor.py From gtg with GNU General Public License v3.0 | 5 votes |
def on_tc_colsel_changed(self, widget): """Callback: update the tag color depending on the current color selection""" color = self.tc_cc_colsel.get_selected_color() if self.tag is not None: if color is not None: my_color = Gdk.color_parse(color) color = Gdk.Color(my_color.red, my_color.green, my_color.blue).to_string() color_add(color) self.tag.set_attribute('color', color) else: color_remove(self.tag.get_attribute('color')) self.tag.del_attribute('color')
Example #5
Source File: colors.py From gtg with GNU General Public License v3.0 | 5 votes |
def background_color(tags, bgcolor=None): if not bgcolor: bgcolor = Gdk.color_parse("#FFFFFF") # Compute color my_color = None color_count = 0.0 red = 0 green = 0 blue = 0 for my_tag in tags: my_color_str = my_tag.get_attribute("color") if my_color_str is not None and my_color_str not in used_color: used_color.append(my_color_str) if my_color_str: my_color = Gdk.color_parse(my_color_str) color_count = color_count + 1 red = red + my_color.red green = green + my_color.green blue = blue + my_color.blue if color_count != 0: red = int(red / color_count) green = int(green / color_count) blue = int(blue / color_count) brightness = (red + green + blue) / 3.0 target_brightness = (bgcolor.red + bgcolor.green + bgcolor.blue) / 3.0 alpha = (1 - abs(brightness - target_brightness) / 65535.0) / 2.0 red = int(red * alpha + bgcolor.red * (1 - alpha)) green = int(green * alpha + bgcolor.green * (1 - alpha)) blue = int(blue * alpha + bgcolor.blue * (1 - alpha)) my_color = Gdk.Color(red, green, blue).to_string() return my_color
Example #6
Source File: urgency_color.py From gtg with GNU General Public License v3.0 | 5 votes |
def _get_gradient_color(self, color1, color2, position): """This function returns a string in the hexadecimal form of Gdk.Color which corresponds to the position (a float value from 0 to 1) in the gradient formed by color1 & color2, both of type Gdk.Color""" color1 = Gdk.color_parse(color1) color2 = Gdk.color_parse(color2) R1, G1, B1 = color1.red, color1.green, color1.blue R2, G2, B2 = color2.red, color2.green, color2.blue R = R1 + (R2 - R1) * position G = G1 + (G2 - G1) * position B = B1 + (B2 - B1) * position return Gdk.Color.to_string(Gdk.Color(int(R), int(G), int(B)))
Example #7
Source File: color_grid.py From wpgtk with GNU General Public License v2.0 | 5 votes |
def render_buttons(self): for x, button in enumerate(self.button_list): gcolor = Gdk.color_parse(self.color_list[x]) if util.get_hls_val(self.color_list[x], 'light') < 99: fgcolor = Gdk.color_parse('#FFFFFF') else: fgcolor = Gdk.color_parse('#000000') button.set_label(self.color_list[x]) button.set_sensitive(True) button.modify_bg(Gtk.StateType.NORMAL, gcolor) button.modify_fg(Gtk.StateType.NORMAL, fgcolor)
Example #8
Source File: color_grid.py From wpgtk with GNU General Public License v2.0 | 5 votes |
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 #9
Source File: option_grid.py From wpgtk with GNU General Public License v2.0 | 5 votes |
def combo_box_change(self, combo, *gparam): x = combo.get_active() if(gparam[0] == "active"): settings[gparam[0]] = str(x) color = Gdk.color_parse(self.parent.cpage.color_list[x]) self.color_button.modify_bg(Gtk.StateType.NORMAL, color) else: settings[gparam[0]] = self.backend_list[x] self.lbl_save.set_text("")
Example #10
Source File: custom.py From Dindo-Bot with MIT License | 5 votes |
def on_draw(self, widget, cr): drawing_area = widget.get_allocation() square_width, square_height = self.grid_size cr.set_line_width(1) # set color function def set_color(value, opacity=1.0): color = Gdk.color_parse(value) cr.set_source_rgba(float(color.red) / 65535, float(color.green) / 65535, float(color.blue) / 65535, opacity) # fill background with color if self.background_color: cr.rectangle(0, 0, drawing_area.width, drawing_area.height) set_color(self.background_color) cr.fill() # draw grid lines if self.show_grid: set_color(self.grid_color) # draw vertical lines for x in range(square_width, drawing_area.width, square_width + 1): # +1 for line width cr.move_to(x + 0.5, 0) # +0.5 for smooth line cr.line_to(x + 0.5, drawing_area.height) # draw horizontal lines for y in range(square_height, drawing_area.height, square_height + 1): cr.move_to(0, y + 0.5) cr.line_to(drawing_area.width, y + 0.5) cr.stroke() # draw points for point in self.points: # fit point to drawing area (should keep here, because it's useful when drawing area get resized) x, y = fit_position_to_destination(point['x'], point['y'], point['width'], point['height'], drawing_area.width, drawing_area.height) if self.add_borders: set_color('black') cr.arc(x, y, self.point_radius, 0, 2*math.pi) if self.add_borders: cr.stroke_preserve() color_key = self.get_color_key() color = self.point_colors['None'] if point[color_key] is None else point[color_key] set_color(color, self.point_opacity) cr.fill()
Example #11
Source File: custom.py From Dindo-Bot with MIT License | 5 votes |
def get_tooltip_widget(self, point): # on draw function def on_draw(widget, cr): cr.set_line_width(1) # draw point color_key = self.get_color_key() color = Gdk.color_parse(point[color_key]) cr.set_source_rgba(float(color.red) / 65535, float(color.green) / 65535, float(color.blue) / 65535, self.point_opacity) cr.arc(self.point_radius, self.point_radius, self.point_radius, 0, 2*math.pi) cr.fill() # tooltip widget if point['name'] is not None: widget = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=3) color_key = self.get_color_key() if point[color_key] is not None: drawing_area = Gtk.DrawingArea() point_diameter = self.point_radius*2 drawing_area.set_size_request(point_diameter, point_diameter) drawing_area.connect('draw', on_draw) box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) box.pack_start(drawing_area, True, False, 0) widget.add(box) widget.add(Gtk.Label(point['name'])) widget.show_all() else: widget = None return widget
Example #12
Source File: xdot.py From bokken with GNU General Public License v2.0 | 5 votes |
def lookup_color(self, c): try: color = Gdk.color_parse(c) except ValueError: pass else: s = 1.0/65535.0 r = color.red*s g = color.green*s b = color.blue*s a = 1.0 return r, g, b, a try: dummy, scheme, index = c.split('/') r, g, b = brewer_colors[scheme][int(index)] except (ValueError, KeyError): pass else: s = 1.0/255.0 r = r*s g = g*s b = b*s a = 1.0 return r, g, b, a sys.stderr.write("warning: unknown color '%s'\n" % c) return None
Example #13
Source File: widgets.py From zim-desktop-wiki with GNU General Public License v2.0 | 5 votes |
def _set_base_color(self, valid): if valid \ or (not self.get_text() and not self.show_empty_invalid): self.modify_base(Gtk.StateType.NORMAL, self._normal_color) else: self.modify_base(Gtk.StateType.NORMAL, Gdk.color_parse(self.ERROR_COLOR))
Example #14
Source File: widgets.py From zim-desktop-wiki with GNU General Public License v2.0 | 5 votes |
def set_bgcolor(self, bgcolor): '''Set background color @param bgcolor: background color as color hex code, (e.g. "#FFF") ''' assert bgcolor.startswith('#'), 'BUG: Should specify colors in hex' color = Gdk.color_parse(bgcolor) # Gdk.Color(spec) only for gtk+ >= 2.14 self.modify_bg(Gtk.StateType.NORMAL, color)
Example #15
Source File: simple_color_selector.py From gtg with GNU General Public License v3.0 | 4 votes |
def __draw(self, cr): """Draws the widget""" alloc = self.get_allocation() # FIXME - why to use a special variables? alloc_w, alloc_h = alloc.width, alloc.height # Drawing context # cr_ctxt = Gdk.cairo_create(self.window) # gdkcontext = Gdk.CairoContext(cr_ctxt) # FIXME gdkcontext = cr # Draw rectangle if self.color is not None: my_color = Gdk.color_parse(self.color) Gdk.cairo_set_source_color(gdkcontext, my_color) else: Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0)) gdkcontext.rectangle(0, 0, alloc_w, alloc_h) gdkcontext.fill() # Outer line Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.30)) gdkcontext.set_line_width(2.0) gdkcontext.rectangle(0, 0, alloc_w, alloc_h) gdkcontext.stroke() # If selected draw a symbol if(self.selected): size = alloc_h * 0.50 - 3 pos_x = math.floor((alloc_w - size) / 2) pos_y = math.floor((alloc_h - size) / 2) Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(255, 255, 255, 0.80)) gdkcontext.arc( alloc_w / 2, alloc_h / 2, size / 2 + 3, 0, 2 * math.pi) gdkcontext.fill() gdkcontext.set_line_width(1.0) Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.20)) gdkcontext.arc( alloc_w / 2, alloc_h / 2, size / 2 + 3, 0, 2 * math.pi) gdkcontext.stroke() Gdk.cairo_set_source_rgba(gdkcontext, Gdk.RGBA(0, 0, 0, 0.50)) gdkcontext.set_line_width(3.0) gdkcontext.move_to(pos_x, pos_y + size / 2) gdkcontext.line_to(pos_x + size / 2, pos_y + size) gdkcontext.line_to(pos_x + size, pos_y) gdkcontext.stroke() # callbacks #####
Example #16
Source File: AppGrid.py From kano-apps with GNU General Public License v2.0 | 4 votes |
def refresh(self, new_app_data): old_app_data = self._app self._app = new_app_data if old_app_data["icon"] != new_app_data["icon"]: self._icon.set_from_pixbuf(get_app_icon(new_app_data['icon']).get_pixbuf()) if "colour" in new_app_data and old_app_data["colour"] != new_app_data["colour"]: self.modify_bg(Gtk.StateType.NORMAL, Gdk.color_parse(new_app_data["colour"])) self._set_title(new_app_data) self._set_tagline(new_app_data) # Refresh update button if "_update" in old_app_data and "_update" not in new_app_data: # remove button self._update_btn.destroy() self._update_btn = None if "_update" not in old_app_data and "_update" in new_app_data: # add button self._setup_update_button() # Refresh description button if "description" in old_app_data and "description" not in new_app_data: # remove button self._more_btn.destroy() self._more_btn = None if "description" not in old_app_data and "description" in new_app_data: # add button self._setup_desc_button() # Refresh remove button if "removable" in old_app_data and "removable" not in new_app_data: # remove button self._remove_btn.destroy() self._remove_btn = None if "removable" not in old_app_data and "removable" in new_app_data: # add button self._setup_remove_button() # Refresh desktop button if (("_install" in old_app_data and "_install" in new_app_data and old_app_data["_install"] == new_app_data["_install"]) or "_install" not in old_app_data and "_install" not in new_app_data) and \ (("desktop" in old_app_data and "desktop" in new_app_data and old_app_data["desktop"] == new_app_data["desktop"]) or "desktop" not in old_app_data and "desktop" not in new_app_data): if self._desktop_btn: self._desktop_btn.refresh() else: self._setup_desktop_button() else: if self._desktop_btn: self._desktop_btn.destroy() self._setup_desktop_button() self.show_all()