本文整理汇总了Python中utils.color_hex_to_cairo函数的典型用法代码示例。如果您正苦于以下问题:Python color_hex_to_cairo函数的具体用法?Python color_hex_to_cairo怎么用?Python color_hex_to_cairo使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了color_hex_to_cairo函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: expose_spin_bg
def expose_spin_bg(self, widget, event):
'''
Internal callback for `expose-event` signal.
'''
# Init.
cr = widget.window.cairo_create()
rect = widget.allocation
x, y, w, h = rect.x, rect.y, rect.width, rect.height
# Draw frame.
with cairo_disable_antialias(cr):
cr.set_line_width(1)
if widget.state == gtk.STATE_INSENSITIVE:
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
else:
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
cr.rectangle(rect.x, rect.y, rect.width, rect.height)
cr.stroke()
if widget.state == gtk.STATE_INSENSITIVE:
cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("disable_background").get_color(), 0.9)))
else:
cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
cr.fill()
propagate_expose(widget, event)
return False
示例2: render
def render(self, cr, rect):
'''
IconView interface function.
Render item.
@param cr: Cairo context.
@param rect: Render rectangle area.
'''
# Init.
draw_x = rect.x + self.padding_x
draw_y = rect.y + self.padding_y
# Draw color.
cr.set_source_rgb(*color_hex_to_cairo(self.color))
cr.rectangle(draw_x, draw_y, self.width, self.height)
cr.fill()
if self.hover_flag:
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("color_item_hover").get_color()))
cr.rectangle(draw_x, draw_y, self.width, self.height)
cr.stroke()
elif self.highlight_flag:
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("color_item_highlight").get_color()))
cr.rectangle(draw_x, draw_y, self.width, self.height)
cr.stroke()
# Draw frame.
with cairo_disable_antialias(cr):
cr.set_line_width(1)
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("color_item_frame").get_color()))
cr.rectangle(draw_x, draw_y, self.width, self.height)
cr.stroke()
示例3: __expose
def __expose(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
x, y = rect.x, rect.y
with cairo_disable_antialias(cr):
cr.set_source_rgb(*color_hex_to_cairo("#FFFFFF"))
cr.rectangle(x - self.padding_x,
y - self.padding_y,
rect.width + self.padding_x,
rect.height + self.padding_y)
cr.fill()
cr.set_source_rgb(*color_hex_to_cairo("#FAFAFA"))
cr.set_line_width(self.line_width)
cr.rectangle(x,
y,
self.width,
self.height - self.padding_y)
cr.fill()
cr.set_source_rgb(*color_hex_to_cairo("#E2E2E2"))
cr.set_line_width(self.line_width)
cr.rectangle(x,
y,
self.width,
self.height - self.padding_y)
cr.stroke()
self.emit("resize", y + self.height)
self.expose_override(cr, rect)
return True
示例4: draw_tray_text
def draw_tray_text(cr, text, x, y,
out_text_color="#000000",
in_text_color="#FFFFFF",
line_width=3,
text_font=DEFAULT_FONT,
text_size=DEFAULT_FONT_SIZE,
):
line_width = line_width
cr_alpha = 0.5
# set out text color.
r, g, b = color_hex_to_cairo(out_text_color)
context = pangocairo.CairoContext(cr)
layout = context.create_layout()
layout.set_font_description(pango.FontDescription("%s %s" % (text_font, text_size)))
# set text.
layout.set_text(text)
#
cr.move_to(x, y)
cr.save()
cr.layout_path(layout)
cr.set_line_width(line_width)
cr.set_source_rgba(r, g, b, cr_alpha)
cr.stroke_preserve()
cr.fill()
cr.restore()
cr.save()
cr.new_path()
r, g, b = color_hex_to_cairo(in_text_color)
cr.set_source_rgb(r, g, b)
cr.set_operator(cairo.OPERATOR_OVER)
cr.move_to(x, y)
context.show_layout(layout)
示例5: scrollbar_expose_event
def scrollbar_expose_event(self, widget, event, direction="v"):
cr = widget.window.cairo_create()
rect = widget.allocation
if direction == "v":
widget.set_size_request(self.bar_width, rect.height)
else:
widget.set_size_request(rect.width, self.bar_width)
cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
cr.rectangle(*rect)
cr.fill()
if direction == "v":
real_height = self._eventBox.allocation.height
bar_height = rect.height ** 2 / real_height + 2
_adjustment = widget.get_adjustment()
offsetY = _adjustment.get_value() * rect.height / real_height
real_rect = (rect.x - 1, rect.y + offsetY,
self.bar_width + 1, bar_height)
else:
real_width = self._eventBox.allocation.width
if self._vscrollbar:
bar_width = rect.width ** 2 / real_width + rect.height + 2
else:
bar_width = rect.width ** 2 / real_width
_adjustment = widget.get_adjustment()
offsetX = _adjustment.get_value() * rect.width / real_width
real_rect = (rect.x + offsetX, rect.y - 1,
bar_width, self.bar_width + 1)
cr.set_source_rgb(*color_hex_to_cairo(THEME['hover']))
cr.rectangle(*real_rect)
cr.fill()
propagate_expose(widget, event)
return True
示例6: on_expose_combo_frame
def on_expose_combo_frame(self, widget, event):
# Init.
cr = widget.window.cairo_create()
rect = widget.allocation
# Draw frame.
with cairo_disable_antialias(cr):
cr.set_line_width(1)
if self.get_sensitive():
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("combo_entry_frame").get_color()))
else:
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("disable_frame").get_color()))
cr.rectangle(rect.x, rect.y, rect.width, rect.height)
cr.stroke()
if self.focus_flag:
color = (ui_theme.get_color("combo_entry_select_background").get_color(), 0.9)
cr.set_source_rgba(*alpha_color_hex_to_cairo(color))
cr.rectangle(rect.x, rect.y, rect.width - 1 - self.drop_button_width, rect.height - 1)
cr.fill()
cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
cr.rectangle(rect.x + rect.width - 1 - self.drop_button_width, rect.y, self.drop_button_width, rect.height - 1)
cr.fill()
else:
cr.set_source_rgba(*alpha_color_hex_to_cairo((ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1)
cr.fill()
# Propagate expose to children.
propagate_expose(widget, event)
return True
示例7: render
def render(self, cr, rect):
# Init.
x, y, w, h = rect.x, rect.y, rect.width, rect.height
# Draw background frame.
with cairo_state(cr):
cr.rectangle(x, y + 1, w, h - 2)
cr.rectangle(x + 1, y, w - 2, h)
cr.clip()
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_background_frame").get_color()))
cr.rectangle(x, y, w, h)
cr.set_line_width(1)
cr.stroke()
# Draw background.
with cairo_state(cr):
cr.rectangle(x + 1, y + 1, w - 2, h - 2)
cr.clip()
draw_vlinear(cr, x + 1, y + 1, w - 2, h - 2,
ui_theme.get_shadow_color("progressbar_background").get_color_info(),
)
if self.progress > 0:
# Draw foreground frame.
with cairo_state(cr):
cr.rectangle(x, y + 1, w, h - 2)
cr.rectangle(x + 1, y, w - 2, h)
cr.clip()
cr.set_antialias(cairo.ANTIALIAS_NONE)
cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("progressbar_foreground_frame").get_color()))
cr.rectangle(x + 1, y + 1, int(w * self.progress / 100) - 1, h - 1)
cr.set_line_width(1)
cr.stroke()
# Draw foreground.
with cairo_state(cr):
cr.rectangle(x + 1, y + 1, w - 2, h - 2)
cr.clip()
draw_vlinear(cr, x + 1, y + 1, int(w * self.progress / 100) - 2, h - 2,
ui_theme.get_shadow_color("progressbar_foreground").get_color_info(),
)
# Draw light.
with cairo_disable_antialias(cr):
cr.set_source_rgba(1, 1, 1, 0.5)
cr.rectangle(x + 1, y + 1, w - 2, 1)
cr.fill()
示例8: render_text
def render_text(cr, markup, x, y, w, h, text_size=DEFAULT_FONT_SIZE, text_color="#000000",
text_font=DEFAULT_FONT, alignment=pango.ALIGN_LEFT,
wrap_width=None):
'''Draw string.'''
# Create pangocairo context.
context = pangocairo.CairoContext(cr)
# Set layout.
layout = context.create_layout()
layout.set_font_description(pango.FontDescription("%s %s" % (text_font, text_size)))
layout_set_markup(layout, markup)
layout.set_alignment(alignment)
if wrap_width == None:
layout.set_single_paragraph_mode(True)
layout.set_width(w * pango.SCALE)
layout.set_ellipsize(pango.ELLIPSIZE_END)
else:
layout.set_width(wrap_width * pango.SCALE)
layout.set_wrap(pango.WRAP_WORD)
(text_width, text_height) = layout.get_pixel_size()
# Draw text.
cr.move_to(x, y + (h - text_height) / 2)
cr.set_source_rgb(*color_hex_to_cairo(text_color))
context.update_layout(layout)
context.show_layout(layout)
示例9: on_expose_event
def on_expose_event(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
x, y, w, h = (
rect.x + self.bg_x_offset,
rect.y + self.point_height / 2,
rect.width,
rect.height - self.point_height,
)
fg_x = bg_x = rect.x + self.bg_x_offset
# Draw background.
draw_pixbuf(cr, self.bg_top_dpixbuf.get_pixbuf(), bg_x, y)
middle_height = h - self.bg_top_height - self.bg_bottom_height
self.__bg_cache_pixbuf.scale(self.bg_middle_dpixbuf.get_pixbuf(), self.bg_width, middle_height)
draw_pixbuf(cr, self.__bg_cache_pixbuf.get_cache(), bg_x, y + self.bg_top_height)
draw_pixbuf(cr, self.bg_bottom_dpixbuf.get_pixbuf(), bg_x, y + h - self.bg_top_height)
# Draw foreground.
cr.set_source_rgb(*color_hex_to_cairo("#2868c7"))
cr.rectangle(fg_x, y + self.current_y, self.fg_width, h - self.current_y)
cr.fill()
# # Draw point.
draw_pixbuf(cr, self.point_dpixbuf.get_pixbuf(), rect.x, rect.y + self.current_y)
return True
示例10: expose_event
def expose_event(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
cr.rectangle(*rect)
cr.fill()
if self.changable:
if widget.state == gtk.STATE_PRELIGHT:
x_offset = rect.width
elif widget.state == gtk.STATE_ACTIVE:
x_offset = rect.width * 2
elif self.show_state == "active":
x_offset = rect.width * 2
else:
x_offset = 0
pixbuf = self.image.scale_simple(rect.width * 3,
rect.height,
gtk.gdk.INTERP_BILINEAR)
pixbuf = pixbuf.subpixbuf(x_offset,
0,
rect.width,
rect.height)
else:
pixbuf = self.image.scale_simple(rect.width, rect.height,
gtk.gdk.INTERP_BILINEAR)
draw_pixbuf(cr, pixbuf, rect.x, rect.y)
propagate_expose(widget, event)
return True
示例11: __expose
def __expose(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
x, y = rect.x, rect.y
x -= self.padding_left
y -= self.padding_top * 2
with cairo_state(cr):
cr.set_source_rgb(*color_hex_to_cairo("#FFFFFF"))
cr.rectangle(x,
y,
rect.width,
rect.height + self.padding_top)
cr.fill()
if self.width < self.__const_width or self.height < self.__const_height:
self.cache_bg_pixbuf.scale(self.bg_pixbuf.get_pixbuf(),
self.width,
self.height)
self.cache_timezone_pixbuf.scale(self.timezone_pixbuf[self.__timezone].get_pixbuf(),
self.width,
self.height)
draw_pixbuf(cr, self.cache_bg_pixbuf.get_cache(), x, y)
draw_pixbuf(cr, self.cache_timezone_pixbuf.get_cache(), x, y)
else:
draw_pixbuf(cr, self.bg_pixbuf.get_pixbuf(), x, y)
draw_pixbuf(cr,
self.timezone_pixbuf[self.__timezone].get_pixbuf(),
x,
y)
return True
示例12: render_content
def render_content(self, cr, rect):
if self.is_select:
text_color = "#FFFFFF"
bg_color = "#3399FF"
if not self.is_double_click:
cr.set_source_rgb(*color_hex_to_cairo(bg_color))
cr.rectangle(rect.x, rect.y, rect.width, rect.height)
cr.paint()
else:
text_color = "#000000"
self.entry_buffer.move_to_start()
self.entry_buffer.set_text_color(text_color)
height = self.entry_buffer.get_pixel_size()[1]
offset = (self.height - height)/2
if offset < 0 :
offset = 0
rect.y += offset
if self.entry and self.entry.allocation.width == self.get_column_widths()[1]-4:
self.entry.calculate()
rect.x += 2
rect.width -= 4
self.entry_buffer.set_text_color("#000000")
self.entry_buffer.render(cr, rect, self.entry.im, self.entry.offset_x)
else:
self.entry_buffer.render(cr, rect)
示例13: draw_background
def draw_background(self, cr, rect):
with cairo_disable_antialias(cr):
# Draw frame.
x, y, w, h = rect.x, rect.y, rect.width, rect.height
cr.set_line_width(1)
cr.set_source_rgb(*color_hex_to_cairo(
self.frame_color.get_color()))
cr.rectangle(x, y, w, h)
cr.stroke()
# Draw background.
cr.set_source_rgba(*alpha_color_hex_to_cairo(
(ui_theme.get_color("combo_entry_background").get_color(), 0.9)))
cr.rectangle(x, y, w - 1, h - 1)
cr.fill()
# Draw mac dot.
cr.set_source_rgba(0.5, 0.5, 0.5, 0.8)
dot_distance = self.width / self.segment_number
dot_bottom_padding = 18
for index in range(0, self.last_segment_index):
draw_text(cr,
self.segment_split_char,
x + dot_distance * (index + 1) - self.dot_size / 2,
y + h - dot_bottom_padding,
self.dot_size,
self.dot_size,
)
示例14: expose_event
def expose_event(self, widget, event):
cr = widget.window.cairo_create()
rect = widget.allocation
cr.set_source_rgb(*color_hex_to_cairo(THEME['bg']))
cr.rectangle(0, 0, rect.width, rect.height)
cr.fill()
pixbuf = gtk.gdk.pixbuf_new_from_file(self.image)
image_size = [pixbuf.get_width(),
pixbuf.get_height()]
self.real_size = self.get_real_size(
[rect.width, rect.height], image_size
)
pixbuf = pixbuf.scale_simple(self.real_size[0],
self.real_size[1],
gtk.gdk.INTERP_HYPER)
pixbuf = pixbuf.rotate_simple(self.rotate_type[self.rotate])
offset_x = (rect.width - self.real_size[0]) / 2
offset_y = (rect.height - self.real_size[1]) / 2
draw_pixbuf(cr, pixbuf, offset_x, offset_y)
propagate_expose(widget, event)
return True
示例15: expose_button
def expose_button(self, widget, event):
'''Expose button.'''
# Init.
cr = widget.window.cairo_create()
rect = widget.allocation
x, y, w, h = rect.x, rect.y, rect.width, rect.height
# Get color info.
if widget.state == gtk.STATE_NORMAL:
text_color = ui_theme.get_color("button_font").get_color()
border_color = ui_theme.get_color("button_border_normal").get_color()
background_color = ui_theme.get_shadow_color("button_background_normal").get_color_info()
elif widget.state == gtk.STATE_PRELIGHT:
text_color = ui_theme.get_color("button_font").get_color()
border_color = ui_theme.get_color("button_border_prelight").get_color()
background_color = ui_theme.get_shadow_color("button_background_prelight").get_color_info()
elif widget.state == gtk.STATE_ACTIVE:
text_color = ui_theme.get_color("button_font").get_color()
border_color = ui_theme.get_color("button_border_active").get_color()
background_color = ui_theme.get_shadow_color("button_background_active").get_color_info()
elif widget.state == gtk.STATE_INSENSITIVE:
text_color = ui_theme.get_color("disable_text").get_color()
border_color = ui_theme.get_color("disable_frame").get_color()
disable_background_color = ui_theme.get_color("disable_background").get_color()
background_color = [(0, (disable_background_color, 1.0)),
(1, (disable_background_color, 1.0))]
# Draw background.
draw_vlinear(
cr,
x + 1, y + 1, w - 2, h - 2,
background_color)
# Draw border.
cr.set_source_rgb(*color_hex_to_cairo(border_color))
draw_line(cr, x + 2, y + 1, x + w - 2, y + 1) # top
draw_line(cr, x + 2, y + h, x + w - 2, y + h) # bottom
draw_line(cr, x + 1, y + 2, x + 1, y + h - 2) # left
draw_line(cr, x + w, y + 2, x + w, y + h - 2) # right
# Draw four point.
if widget.state == gtk.STATE_INSENSITIVE:
top_left_point = ui_theme.get_pixbuf("button/disable_corner.png").get_pixbuf()
else:
top_left_point = ui_theme.get_pixbuf("button/corner.png").get_pixbuf()
top_right_point = top_left_point.rotate_simple(270)
bottom_right_point = top_left_point.rotate_simple(180)
bottom_left_point = top_left_point.rotate_simple(90)
draw_pixbuf(cr, top_left_point, x, y)
draw_pixbuf(cr, top_right_point, x + w - top_left_point.get_width(), y)
draw_pixbuf(cr, bottom_left_point, x, y + h - top_left_point.get_height())
draw_pixbuf(cr, bottom_right_point, x + w - top_left_point.get_width(), y + h - top_left_point.get_height())
# Draw font.
draw_text(cr, self.label, x, y, w, h, self.font_size, text_color,
alignment=pango.ALIGN_CENTER)
return True