当前位置: 首页>>代码示例>>Python>>正文


Python Gdk.color_parse方法代码示例

本文整理汇总了Python中gi.repository.Gdk.color_parse方法的典型用法代码示例。如果您正苦于以下问题:Python Gdk.color_parse方法的具体用法?Python Gdk.color_parse怎么用?Python Gdk.color_parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gi.repository.Gdk的用法示例。


在下文中一共展示了Gdk.color_parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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) 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:23,代码来源:custom.py

示例2: on_color_click

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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() 
开发者ID:deviantfero,项目名称:wpgtk,代码行数:30,代码来源:color_grid.py

示例3: set_frozen

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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")) 
开发者ID:mazaclub,项目名称:encompass,代码行数:11,代码来源:gtk.py

示例4: on_color_add

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:28,代码来源:simple_color_selector.py

示例5: on_tc_colsel_changed

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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') 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:15,代码来源:tag_editor.py

示例6: background_color

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:35,代码来源:colors.py

示例7: _get_gradient_color

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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))) 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:14,代码来源:urgency_color.py

示例8: render_buttons

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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) 
开发者ID:deviantfero,项目名称:wpgtk,代码行数:13,代码来源:color_grid.py

示例9: combo_box_change

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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("") 
开发者ID:deviantfero,项目名称:wpgtk,代码行数:11,代码来源:option_grid.py

示例10: on_draw

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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() 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:40,代码来源:custom.py

示例11: get_tooltip_widget

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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 
开发者ID:AXeL-dev,项目名称:Dindo-Bot,代码行数:29,代码来源:custom.py

示例12: lookup_color

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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 
开发者ID:inguma,项目名称:bokken,代码行数:30,代码来源:xdot.py

示例13: _set_base_color

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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)) 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:8,代码来源:widgets.py

示例14: set_bgcolor

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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) 
开发者ID:zim-desktop-wiki,项目名称:zim-desktop-wiki,代码行数:10,代码来源:widgets.py

示例15: __draw

# 需要导入模块: from gi.repository import Gdk [as 别名]
# 或者: from gi.repository.Gdk import color_parse [as 别名]
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 ##### 
开发者ID:getting-things-gnome,项目名称:gtg,代码行数:51,代码来源:simple_color_selector.py


注:本文中的gi.repository.Gdk.color_parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。