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
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
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
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)
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
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
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()
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()
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
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, )
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
def draw_handle(self, e): ''' Draw the cusom handle apperance. ''' handle = self.get_handle_window() line_width = 1 cr = handle.cairo_create() cr.set_source_rgb(*color_hex_to_cairo(self.handle_color.get_color())) (width, height) = handle.get_size() if self.get_orientation() == gtk.ORIENTATION_HORIZONTAL: if self.shrink_first: if self.get_position() != 0: cr.rectangle(0, 0, line_width, height) cr.fill() if self.always_show_button or self.show_button: if self.get_position() == 0: pixbuf = ui_theme.get_pixbuf( "paned/paned_right_normal.png").get_pixbuf() else: pixbuf = ui_theme.get_pixbuf( "paned/paned_left_normal.png").get_pixbuf() draw_pixbuf(cr, pixbuf, 0, (height - self.bheight) / 2) else: cr.rectangle(width - line_width, 0, line_width, height) cr.fill() if self.always_show_button or self.show_button: if self.get_position() == 0: pixbuf = ui_theme.get_pixbuf( "paned/paned_left_normal.png").get_pixbuf() else: pixbuf = ui_theme.get_pixbuf( "paned/paned_right_normal.png").get_pixbuf() draw_pixbuf(cr, pixbuf, 0, (height - self.bheight) / 2) else: if self.shrink_first: cr.rectangle(0, 0, width, line_width) cr.fill() if self.always_show_button or self.show_button: if self.get_position() == 0: pixbuf = ui_theme.get_pixbuf( "paned/paned_down_normal.png").get_pixbuf() else: pixbuf = ui_theme.get_pixbuf( "paned/paned_up_normal.png").get_pixbuf() draw_pixbuf(cr, pixbuf, (width - self.bheight) / 2, 0) else: cr.rectangle(0, height - line_width, width, line_width) cr.fill() if self.always_show_button or self.show_button: if self.get_position() == 0: pixbuf = ui_theme.get_pixbuf( "paned/paned_up_normal.png").get_pixbuf() else: pixbuf = ui_theme.get_pixbuf( "paned/paned_down_normal.png").get_pixbuf() draw_pixbuf(cr, pixbuf, (width - self.bheight) / 2, 0)
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
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)
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
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)
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)
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 ipv4 dot. cr.set_source_rgba(0.5, 0.5, 0.5, 0.8) dot_distance = self.width / self.segment_number dot_bottom_padding = 9 for index in range(0, self.last_segment_index): cr.rectangle( x + dot_distance * (index + 1) - self.dot_size / 2, y + h - dot_bottom_padding, self.dot_size, self.dot_size) cr.fill()
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
def draw_single_mask(cr, x, y, width, height, color_name): if color_name.startswith("#"): color = color_name else: color = app_theme.get_color(color_name).get_color() cairo_color = color_hex_to_cairo(color) cr.set_source_rgb(*cairo_color) cr.rectangle(x, y, width, height) cr.fill()
def expose_tab_content_align(self, widget, event): '''Expose tab content box.''' cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2) cr.stroke()
def expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(THEME['bg'])) cr.rectangle(*rect) cr.fill() propagate_expose(widget, event) return True
def render_title(self, cr, rect): if self.is_select: text_color = "#FFFFFF" bg_color = "#3399FF" 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" draw_text(cr, self.title, rect.x, rect.y, rect.width, rect.height, text_color=text_color)
def expose_droplist_frame(self, widget, event): '''Expose droplist frame.''' cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("droplist_frame").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill()
def color_test_widget_expose(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # Draw pixbuf. draw_pixbuf(cr, self.pixbuf, 0, 0) # Draw mask. draw_vlinear(cr, rect.x, rect.y + self.pixbuf.get_height() - SHADOW_SIZE, rect.width, SHADOW_SIZE, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) draw_hlinear(cr, rect.x + self.pixbuf.get_width() - SHADOW_SIZE, rect.y, SHADOW_SIZE, rect.height, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) # Draw background. (similar_color_name, similar_color_value) = find_similar_color(self.background_color) print(similar_color_name, self.background_color, similar_color_value) cr.set_source_rgb(*color_hex_to_cairo(similar_color_value)) cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, rect.width - self.pixbuf.get_width(), rect.height) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), rect.width, rect.height - self.pixbuf.get_height()) cr.fill() # cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, # rect.width - self.pixbuf.get_width(), rect.height) # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), # rect.width, rect.height - self.pixbuf.get_height()) # cr.fill() propagate_expose(widget, event) return True
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
def draw_range(cr, x, y, width, height, color_name): if color_name.startswith("#"): color = color_name else: color = app_theme.get_color(color_name).get_color() cairo_color = color_hex_to_cairo(color) with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*cairo_color) cr.rectangle(x, y, width, height) cr.stroke()
def on_expose_alignment(widget, event): '''Expose tooltip label.''' rect = widget.allocation cr = widget.window.cairo_create() with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(*color_hex_to_cairo(ui_theme.get_color("tooltip_frame").get_color())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1) cr.stroke() return True
def color_test_widget_expose(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # Draw pixbuf. draw_pixbuf(cr, self.pixbuf, 0, 0) # Draw mask. draw_vlinear( cr, rect.x, rect.y + self.pixbuf.get_height() - SHADE_SIZE, rect.width, SHADE_SIZE, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) draw_hlinear( cr, rect.x + self.pixbuf.get_width() - SHADE_SIZE, rect.y, SHADE_SIZE, rect.height, [(0, (self.background_color, 0)), (1, (self.background_color, 1))]) # Draw background. (similar_color_name, similar_color_value) = find_similar_color(self.background_color) print (similar_color_name, self.background_color, similar_color_value) cr.set_source_rgb(*color_hex_to_cairo(similar_color_value)) cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, rect.width - self.pixbuf.get_width(), rect.height) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), rect.width, rect.height - self.pixbuf.get_height()) cr.fill() # cr.set_source_rgb(*color_hex_to_cairo(self.background_color)) # cr.rectangle(rect.x + self.pixbuf.get_width(), rect.y, # rect.width - self.pixbuf.get_width(), rect.height) # cr.rectangle(rect.x, rect.y + self.pixbuf.get_height(), # rect.width, rect.height - self.pixbuf.get_height()) # cr.fill() propagate_expose(widget, event) return True
def draw_progress_bar(self, cr, rect): # Draw progressbar background. bg_height = self.bg_dpixbuf.get_pixbuf().get_height() self.bg_cache_pixbuf.scale(self.bg_dpixbuf.get_pixbuf(), self.virtual_width, bg_height) # bg_y = rect.y + (rect.height - bg_height) / 2 draw_pixbuf(cr, self.bg_cache_pixbuf.get_cache(), rect.x + self.bg_offset, rect.y) # Draw progressbar foreground. if self.current_progress_width > 0: fg_height = self.default_height fg_y = rect.y lg_width = int(self.current_progress_width) pat = cairo.LinearGradient(rect.x + self.fg_offset, fg_y, rect.x + self.fg_offset + lg_width, fg_y) pat.add_color_stop_rgb( 0.7, *color_hex_to_cairo(self.fg_left_dcolor.get_color())) pat.add_color_stop_rgb( 1.0, *color_hex_to_cairo(self.fg_right_dcolor.get_color())) cr.set_operator(cairo.OPERATOR_OVER) cr.set_source(pat) cr.rectangle(rect.x + self.fg_offset, fg_y, lg_width, fg_height) cr.fill() with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(1, 1, 1, 0.5) cr.move_to(rect.x, fg_y + 1) cr.rel_line_to(lg_width, 0) cr.stroke() # Draw point. point_y = rect.y + (rect.height - self.point_dpixbuf.get_pixbuf().get_height()) / 2 draw_pixbuf(cr, self.point_dpixbuf.get_pixbuf(), rect.x + self.current_progress_width, point_y)
def expose_combo_list_frame(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(*rect) cr.fill() with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo(ui_theme.get_color("droplist_frame").get_color())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1) cr.stroke()
def draw_line(cr, start, end, color_name): if color_name.startswith("#"): color = color_name else: color = app_theme.get_color(color_name).get_color() cairo_color = color_hex_to_cairo(color) with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*cairo_color) cr.move_to(*start) cr.line_to(*end) cr.stroke()
def loading_flag(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() draw_text(cr, rect.x, rect.y, text_size=20, text_color=THEME['font_color']) propagate_expose(widget, event)
def on_expose_alignment(widget, event): '''Expose tooltip label.''' rect = widget.allocation cr = widget.window.cairo_create() with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(*color_hex_to_cairo( ui_theme.get_color("tooltip_frame").get_color())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1) cr.stroke() return True
def expose_display_button(self, widget, event): '''Expose display button.''' # Init. cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(*color_hex_to_cairo(self.color_string)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Propagate expose. propagate_expose(widget, event) return True
def expose_combo_list_frame(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(1, 1, 1) cr.rectangle(*rect) cr.fill() with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo( ui_theme.get_color("droplist_frame").get_color())) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 1, rect.height - 1) cr.stroke()
def expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation if self.direction == "v": real_rect = (rect.x, rect.y, self.width, rect.height) else: real_rect = (rect.x, rect.y, rect.width, self.width) cr.set_source_rgb(*color_hex_to_cairo(THEME['hover'])) cr.rectangle(*real_rect) cr.fill() return True
def draw_border(cr, color=THEME['border'], width=CONFIG["border_width"], rect=None, pos=(1, 1, 1, 1)): cr.set_line_width(width) cr.set_source_rgb(*color_hex_to_cairo(color)) rect = (rect[0] + (pos[0] - 1) * width, rect[1] + (pos[2] - 1) * width, rect[2] - (pos[3] - 1) * width, rect[3] - (pos[1] - 1) * width) cr.rectangle(*rect) cr.stroke()
def get_render_color(self, active=False): if active: return [color_hex_to_cairo(config.get("lyrics", "active_color_upper")), color_hex_to_cairo(config.get("lyrics", "active_color_middle")), color_hex_to_cairo(config.get("lyrics", "active_color_bottom"))] else: return [color_hex_to_cairo(config.get("lyrics", "inactive_color_upper")), color_hex_to_cairo(config.get("lyrics", "inactive_color_middle")), color_hex_to_cairo(config.get("lyrics", "inactive_color_bottom"))]
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()
def expose_droplist_frame(self, widget, event): ''' Callback for `expose-event` siangl of droplist frame. @param widget: Droplist widget. @param event: Expose event. ''' cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo( ui_theme.get_color("droplist_frame").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill()
def expose_display_button(self, widget, event): ''' Callback for `expose-event` signal. @param widget: Gtk.Widget instance. @param event: Expose event. @return: Always return True ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgb(*color_hex_to_cairo(self.color_string)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Propagate expose. propagate_expose(widget, event) return True
def draw_value(self, cr, rect, text, value, type_=None, mark_check=False): text_width, text_height = get_content_size(text) text_y = rect.y if gtk.POS_TOP == type_: text_y = text_y if gtk.POS_BOTTOM == type_: text_y = rect.y + (rect.height-self.bottom_space)/2 + self.point_height + self.bottom_space - text_height/2 x = rect.x + int(float(value) / self.value_max * (rect.width - self.point_width)) max_value = max(x - (text_width/2 - self.point_width/2), rect.x) min_value = min(max_value, rect.x + rect.width - text_width) if self.enable_check: draw_text(cr, text, min_value, text_y, rect.width, 0) else: draw_text(cr, text, min_value, text_y, rect.width, 0, DEFAULT_FONT_SIZE, self.bg_side_color) mark_y = text_y-self.bottom_space/2-(self.point_height-self.line_height)/2 if mark_check: cr.set_source_rgb(*color_hex_to_cairo(self.bg_side_color)) cr.rectangle(x + self.point_width/2, mark_y, self.mark_width, self.mark_height) cr.fill()
def expose_tab_content_align(self, widget, event): ''' Internal function to `expose-event` signal. ''' cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.rectangle(rect.x, rect.y, sum(self.tab_title_widths[0:self.tab_index]), rect.height) cr.rectangle( rect.x + sum(self.tab_title_widths[0:self.tab_index + 1]), rect.y, rect.width - sum(self.tab_title_widths[0:self.tab_index + 1]), rect.height) cr.clip() cr.set_source_rgb( *color_hex_to_cairo(self.tab_select_frame_color.get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.stroke()
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
def render_background(self, cr, widget, x, y, translate_width=0, translate_height=0): ''' Internal function to render background. ''' # Init. toplevel_rect = widget.get_toplevel().allocation render_width = toplevel_rect.width + translate_width render_height = toplevel_rect.height + translate_height # Draw background. background_x = int(self.x * self.scale_x) background_y = int(self.y * self.scale_y) background_width = int(self.background_pixbuf.get_width() * self.scale_x) background_height = int(self.background_pixbuf.get_height() * self.scale_y) self.cache_pixbuf.scale(self.background_pixbuf, background_width, background_height, self.vertical_mirror, self.horizontal_mirror) draw_pixbuf( cr, self.cache_pixbuf.get_cache(), x + background_x, y + background_y) # Draw dominant color if necessarily. if ((background_width + background_x) < render_width and (background_height + background_y) < render_height): cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x + background_x + background_width, y + background_y + background_height, render_width - (background_width + background_x), render_height - (background_height + background_y)) cr.fill() if (background_width + background_x) < render_width: draw_hlinear( cr, x + (background_width + background_x) - SHADOW_SIZE, y, SHADOW_SIZE, (background_height + background_y), [(0, (self.dominant_color, 0)), (1, (self.dominant_color, 1))]) cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x + (background_width + background_x), y, render_width - (background_width + background_x), (background_height + background_y)) cr.fill() if (background_height + background_y) < render_height: draw_vlinear( cr, x, y + (background_height + background_y) - SHADOW_SIZE, (background_width + background_x), SHADOW_SIZE, [(0, (self.dominant_color, 0)), (1, (self.dominant_color, 1))]) cr.set_source_rgb(*color_hex_to_cairo(self.dominant_color)) cr.rectangle( x, y + (background_height + background_y), (background_width + background_x), render_height - (background_height + background_y)) cr.fill()
def expose_h_scalebar(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # Init pixbuf. fg_pixbuf = self.fg_dpixbuf.get_pixbuf() bg_pixbuf = self.bg_dpixbuf.get_pixbuf() point_normal_pixbuf = self.point_normal_dpixbuf.get_pixbuf() # point_hover_pixbuf = self.point_hover_dpixbuf.get_pixbuf() # point_press_pixbuf = self.point_press_dpixbuf.get_pixbuf() # Init value. upper = self.get_adjustment().get_upper() lower = self.get_adjustment().get_lower() total_length = max(upper - lower, 1) point_width = point_normal_pixbuf.get_width() point_height = point_normal_pixbuf.get_height() x, y, w, h = rect.x + point_width / 2, rect.y, rect.width - point_width, rect.height line_height = bg_pixbuf.get_height() line_y = y + (point_height - line_height) / 2 value = int((self.get_value() - lower) / total_length * w) # Draw background. self.fg_cache_pixbuf.scale( bg_pixbuf, w + point_width, line_height) draw_pixbuf( cr, self.fg_cache_pixbuf.get_cache(), rect.x, line_y) self.bg_cache_pixbuf.scale( fg_pixbuf, point_width / 2, line_height) draw_pixbuf( cr, self.bg_cache_pixbuf.get_cache(), rect.x, line_y) if value > 0: pat = cairo.LinearGradient(0, 0, value + point_width, 0) pat.add_color_stop_rgb(0.7, *color_hex_to_cairo(self.fg_left_dcolor.get_color())) pat.add_color_stop_rgb(1.0, *color_hex_to_cairo(self.fg_right_dcolor.get_color())) cr.set_operator(cairo.OPERATOR_OVER) cr.set_source(pat) cr.rectangle(rect.x, line_y, value + point_width, line_height) cr.fill() with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(1, 1, 1, 0.5) cr.move_to(rect.x, line_y + 1) cr.rel_line_to(value + point_width, 0) cr.stroke() cr.set_source_rgba(1, 1, 1, 0.3) cr.move_to(rect.x, line_y + line_height) cr.rel_line_to(value + point_width, 0) cr.stroke() # self.side_cache_pixbuf.scale( # fg_pixbuf, value + point_width, line_height) # draw_pixbuf( # cr, # self.side_cache_pixbuf.get_cache(), # rect.x, line_y) if value > 0: draw_pixbuf(cr, point_normal_pixbuf, x + value - point_width / 2 + 2, y) else: draw_pixbuf(cr, point_normal_pixbuf, x + value - point_width / 2 - 1, y) return True
def get_blur_color(self): return color_hex_to_cairo(config.get("lyrics", "blur_color", "#000000"))
def expose_tab_title_box(self, widget, event): ''' Internal callback for `expose-event` signal. ''' cr = widget.window.cairo_create() rect = widget.allocation if self.dockfill: self.update_tab_title_widths(rect.width) # Draw background. self.draw_title_background(cr, widget) if len(self.tab_items) > 0: # Draw title unselect tab. tab_title_width = sum(self.tab_title_widths) with cairo_state(cr): with cairo_disable_antialias(cr): cr.set_source_rgba(*alpha_color_hex_to_cairo(( self.tab_unselect_bg_color.get_color(), 0.7))) cr.rectangle(1, 1, tab_title_width, self.tab_height) cr.fill() cr.set_line_width(1) cr.set_source_rgba(*alpha_color_hex_to_cairo(( self.tab_unselect_frame_color.get_color(), 1.0))) cr.rectangle(1, 1, tab_title_width, self.tab_height) cr.stroke() for (index, width) in enumerate(self.tab_title_widths[:-1]): cr.set_source_rgba(*alpha_color_hex_to_cairo(( self.tab_unselect_frame_color.get_color(), 1.0))) cr.rectangle( 1 + sum(self.tab_title_widths[0:index]) + width, 1, 1, self.tab_height) cr.fill() cr.set_source_rgb(*color_hex_to_cairo( self.tab_select_frame_color.get_color())) cr.rectangle(0, rect.height - 1, sum(self.tab_title_widths[0:self.tab_index]), 1) cr.fill() cr.set_source_rgb(*color_hex_to_cairo( self.tab_select_frame_color.get_color())) cr.rectangle( 1 + sum(self.tab_title_widths[0:self.tab_index]), rect.height - 1, rect.width - sum(self.tab_title_widths[0:self.tab_index]), 1) cr.fill() for (index, item) in enumerate(self.tab_items): # Draw title background. title = item[0] # Draw title tab. with cairo_disable_antialias(cr): if index == self.tab_index: # Draw title select tab. cr.set_source_rgba(*alpha_color_hex_to_cairo(( self.tab_select_bg_color.get_color(), 0.93))) if index == 0: cr.rectangle(sum(self.tab_title_widths[0:index]), 1, self.tab_title_widths[index] + 1, self.tab_height) else: cr.rectangle( 1 + sum(self.tab_title_widths[0:index]), 1, self.tab_title_widths[index], self.tab_height) cr.fill() if index == 0: cr.rectangle(0, 0, rect.width, self.tab_height) cr.clip() cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo( self.tab_select_frame_color.get_color())) if index == 0: cr.rectangle(sum(self.tab_title_widths[0:index]), 1, self.tab_title_widths[index] + 2, self.tab_height) else: cr.rectangle( 1 + sum(self.tab_title_widths[0:index]), 1, self.tab_title_widths[index] + 1, self.tab_height) cr.stroke() draw_text( cr, title, sum(self.tab_title_widths[0:index]) + self.tab_padding_x, self.tab_padding_y, self.tab_title_widths[index] - self.tab_padding_x * 2, self.tab_height - self.tab_padding_y * 2, ) # Draw close button. if self.can_close_tab: button_x = sum( self.tab_title_widths[0:index + 1] ) - self.close_button_padding_x - self.close_button_size button_y = self.close_button_padding_y if self.hover_close_button_index == index: cr.set_source_rgb(*color_hex_to_cairo( self.close_button_select_background_color)) draw_round_rectangle( cr, button_x - self.close_button_frame_size, button_y - self.close_button_frame_size, self.close_button_size + self.close_button_frame_size * 2, self.close_button_size + self.close_button_frame_size * 2, 2) cr.fill() cr.set_line_width(1.5) if self.hover_close_button_index == index: cr.set_source_rgb(*color_hex_to_cairo( self.close_button_select_foreground_color)) else: cr.set_source_rgb( *color_hex_to_cairo(self.close_button_color)) cr.move_to(button_x, button_y) cr.line_to(button_x + self.close_button_size, button_y + self.close_button_size) cr.stroke() cr.move_to(button_x + self.close_button_size, button_y) cr.line_to(button_x, button_y + self.close_button_size) cr.stroke() else: cr.set_source_rgba(*alpha_color_hex_to_cairo(( self.tab_select_bg_color.get_color(), 0.93))) cr.rectangle(0, 0, rect.width, rect.height) cr.fill()
def get_render_color(self, active=False): if active: return color_hex_to_cairo(config.get("scroll_lyrics", "active_color")) return color_hex_to_cairo(config.get("scroll_lyrics", "inactive_color"))
def expose_button(self, widget, event): ''' Internal function to handle `expose-event` signal. @param widget: ColorButton instance. @param event: Expose event. ''' # 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: 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: 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: 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: 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 color frame. cr.set_source_rgb(*color_hex_to_cairo("#c0c0c0")) cr.rectangle(x + (w - self.color_area_width) / 2, y + (h - self.color_area_height) / 2, self.color_area_width, self.color_area_height) cr.stroke() # Draw color. cr.set_source_rgb(*color_hex_to_cairo(self.color)) cr.rectangle(x + (w - self.color_area_width) / 2, y + (h - self.color_area_height) / 2, self.color_area_width, self.color_area_height) cr.fill() # Draw mask when widget is insensitive. if widget.state == gtk.STATE_INSENSITIVE: cr.set_source_rgba(*alpha_color_hex_to_cairo( ui_theme.get_alpha_color( "color_button_disable_mask").get_color_info())) cr.rectangle(x + (w - self.color_area_width) / 2, y + (h - self.color_area_height) / 2, self.color_area_width, self.color_area_height) cr.fill() return True
def expose_time_spin(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(x, y, w, h) 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(x, y, w - 1, h - 1) cr.fill() if self.set_time == self.SET_HOUR: cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color)) cr.rectangle(x + self.padding_x, y, self.time_width, h) cr.fill() if self.set_time == self.SET_MIN: cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color)) cr.rectangle( x + self.padding_x + self.time_width + self.time_comma_width, y, self.time_width, h) cr.fill() if self.set_time == self.SET_SEC: cr.set_source_rgba(*color_hex_to_cairo(self.set_time_bg_color)) cr.rectangle( x + self.padding_x + (self.time_width + self.time_comma_width) * 2, y, self.time_width, h) cr.fill() if not self.__pressed_button: if self.__24hour: self.hour_value = time.localtime().tm_hour else: self.hour_value = int(time.strftime('%I')) self.min_value = time.localtime().tm_min self.sec_value = time.localtime().tm_sec draw_text( cr, "%02d : %02d : %02d" % (self.hour_value, self.min_value, self.sec_value), x + self.padding_x, y, w, h) propagate_expose(widget, event) return False
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, underline=False, vertical_alignment=TEXT_ALIGN_MIDDLE, clip_line_count=None, ellipsize=pango.ELLIPSIZE_END, ): ''' Render text for function L{ I{draw_text} <draw_text>}, you can use this function individually. @param cr: Cairo context. @param markup: Pango markup string. @param x: X coordinate of draw area. @param y: Y coordinate of draw area. @param w: Width of draw area. @param h: Height of draw area. @param text_size: Text size, default is DEFAULT_FONT_SIZE. @param text_color: Text color, default is \"#000000\". @param text_font: Text font, default is DEFAULT_FONT. @param alignment: Font alignment option, default is pango.ALIGN_LEFT. You can set pango.ALIGN_MIDDLE or pango.ALIGN_RIGHT. @param wrap_width: Wrap width of text, default is None. @param underline: Whether draw underline for text, default is False. @param vertical_alignment: Vertical alignment value, default is TEXT_ALIGN_MIDDLE, can use below value: - TEXT_ALIGN_TOP - TEXT_ALIGN_MIDDLE - TEXT_ALIGN_BOTTOM @param clip_line_count: The line number to clip text area, if set 2, all lines that above 2 will clip out, default is None. @param ellipsize: Ellipsize style of text when text width longer than draw area, it can use below value: - pango.ELLIPSIZE_START - pango.ELLIPSIZE_CENTER - pango.ELLIPSIZE_END ''' with cairo_state(cr): # Set color. cr.set_source_rgb(*color_hex_to_cairo(text_color)) # 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(markup) layout.set_alignment(alignment) if wrap_width == None: layout.set_single_paragraph_mode(True) layout.set_width(w * pango.SCALE) layout.set_ellipsize(ellipsize) else: layout.set_width(wrap_width * pango.SCALE) layout.set_wrap(pango.WRAP_WORD) (text_width, text_height) = layout.get_pixel_size() if underline: if alignment == pango.ALIGN_LEFT: cr.rectangle(x, y + text_height + (h - text_height) / 2, text_width, 1) elif alignment == pango.ALIGN_CENTER: cr.rectangle(x + (w - text_width) / 2, y + text_height + (h - text_height) / 2, text_width, 1) else: cr.rectangle(x + w - text_width, y + text_height + (h - text_height) / 2, text_width, 1) cr.fill() # Set render y coordinate. if vertical_alignment == TEXT_ALIGN_TOP: render_y = y elif vertical_alignment == TEXT_ALIGN_MIDDLE: render_y = y + max(0, (h - text_height) / 2) else: render_y = y + max(0, h - text_height) # Clip area. if clip_line_count: line_count = layout.get_line_count() if line_count > 0: line_height = text_height / line_count cr.rectangle(x, render_y, text_width, line_height * clip_line_count) cr.clip() # Draw text. cr.move_to(x, render_y) context.update_layout(layout) context.show_layout(layout)