def on_expose_event(self, widget, event): ''' docs ''' cr = widget.window.cairo_create() rect = widget.allocation cr.set_operator(cairo.OPERATOR_CLEAR) cr.rectangle(*rect) cr.fill() # trayicon's location is relavant to root, but cairo need coordinates related to this widget. (self.x, self.y) = root_coords_to_widget_coords(self.x, self.y, self) # draw border and blur cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_surface(img_surf, 0, 0) cr.rectangle(*rect) cr.fill() #draw content background draw_round_rectangle_with_triangle(cr, rect.x + BORDER_LINE_WIDTH, rect.y + BORDER_LINE_WIDTH, rect.width - 2 * BORDER_LINE_WIDTH, rect.height - 2 * BORDER_LINE_WIDTH, ROUND_RADIUS, ARROW_WIDHT, ARROW_HEIGHT) cr.set_source_rgb(1, 1, 1) cr.fill() propagate_expose(widget, event) return True
def expose_button(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation x,y,w,h = rect.x, rect.y, rect.width, rect.height if widget.state == gtk.STATE_NORMAL: if self.start_bool: image = self.start_button_normal.get_pixbuf() else: image = self.pause_button_normal.get_pixbuf() elif widget.state == gtk.STATE_PRELIGHT: if self.start_bool: image = self.start_button_hover.get_pixbuf() else: image = self.pause_button_hover.get_pixbuf() elif widget.state == gtk.STATE_ACTIVE: if self.start_bool: image = self.start_button_press.get_pixbuf() else: image = self.pause_button_press.get_pixbuf() widget.set_size_request(image.get_width(), image.get_height()) self.cache_pixbuf.scale(image, image.get_width(), image.get_height()) draw_pixbuf(cr, self.cache_pixbuf.get_cache(), widget.allocation.x, widget.allocation.y - self.image_y_padding) # Set widget size. propagate_expose(widget, event) return True
def expose_simple_item(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation font_color = app_theme.get_color("labelText").get_color() item_pixbuf = self.normal_dpixbuf.get_pixbuf() # Draw pixbuf. draw_pixbuf(cr, item_pixbuf, rect.x + self.padding_left, rect.y + (rect.height - item_pixbuf.get_height()) / 2) # Draw content. draw_text(cr, self.content, rect.x + self.padding_left + self.font_offset, rect.y, rect.width - self.padding_left - self.font_offset - self.padding_right, rect.height, self.font_size, font_color, alignment=self.x_align) propagate_expose(widget, event) return True
def expose_button_cb(self, widget, event): # Init. rect = widget.allocation bg_normal_dpixbuf, bg_hover_dpixbuf, bg_press_dpixbuf = self.bg_image_group fg_normal_dpixbuf, fg_hover_dpixbuf, fg_press_dpixbuf = self.icon_group if widget.state == gtk.STATE_NORMAL: bg_image = bg_normal_dpixbuf.get_pixbuf() fg_image = fg_normal_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_PRELIGHT: bg_image = bg_hover_dpixbuf.get_pixbuf() fg_image = fg_hover_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_ACTIVE: bg_image = bg_press_dpixbuf.get_pixbuf() fg_image = fg_press_dpixbuf.get_pixbuf() image_width = bg_image.get_width() image_height = bg_image.get_height() fg_rect_x = rect.x + (image_width - fg_image.get_width()) / 2 fg_rect_y = rect.y + (image_height - fg_image.get_height()) / 2 cr = widget.window.cairo_create() draw_pixbuf(cr, bg_image, rect.x, rect.y) draw_pixbuf(cr, fg_image, fg_rect_x, fg_rect_y) propagate_expose(widget, event) return True
def screenshot_box_expose(self, widget, event): rect = widget.allocation cr = widget.window.cairo_create() #cr.set_source_rgba(1.0, 1.0, 1.0, 0.0) #cr.set_operator(cairo.OPERATOR_SOURCE) #cr.paint() if self.screenshot_pixbuf: draw_pixbuf( cr, self.screenshot_pixbuf, rect.x + (rect.width - self.screenshot_pixbuf.get_width()) / 2, rect.y + (rect.height - self.screenshot_pixbuf.get_height()) / 2, ) cr.set_source_rgba(0, 0, 0, 0.7) cr.rectangle(*rect) cr.fill() # Propagate expose to children. propagate_expose(widget, event) return True
def expose_simple_item(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation rect.x += 1 rect.width -= 2 font_color = app_theme.get_color("labelText").get_color() item_pixbuf = self.normal_dpixbuf.get_pixbuf() select_index = self.get_index() if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_NORMAL elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_HOVER elif widget.state == gtk.STATE_ACTIVE: select_status = BUTTON_PRESS if select_status == BUTTON_PRESS: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHighlight") # font_color = app_theme.get_color("simpleSelectItem").get_color() font_color = "#FFFFFF" item_pixbuf = self.press_dpixbuf.get_pixbuf() elif select_status == BUTTON_HOVER: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHover") # Draw pixbuf. draw_pixbuf(cr, item_pixbuf, rect.x + self.padding_left, rect.y + (rect.height - item_pixbuf.get_height()) / 2) # Draw content. draw_text(cr, self.content, rect.x + self.padding_left + self.font_offset, rect.y, rect.width - self.padding_left - self.font_offset - self.padding_right, rect.height, self.font_size, font_color, alignment=self.x_align) propagate_expose(widget, event) return True
def mid_combo_event_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation cr.rectangle(*rect) cr.set_source_rgba(0, 0, 0, 0.7) #cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() # propagate_expose(widget, event) return True
def __expose_text_entry(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation x, y, w, h = rect.x, rect.y, rect.width, rect.height draw_pixbuf(cr, self.search_bg_pixbuf, rect.x, rect.y) propagate_expose(widget, event) return True
def expose_category_item(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation font_color = app_theme.get_color("labelText").get_color() arrow_pixbuf = self.arrow_dpixbuf.get_pixbuf() select_index = self.get_index() if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_NORMAL elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_HOVER elif widget.state == gtk.STATE_ACTIVE: select_status = BUTTON_PRESS if select_status == BUTTON_PRESS: draw_vlinear( cr, rect.x, rect.y, rect.width, rect.height, app_theme.get_shadow_color("simpleItemPress").get_color_info()) font_color = app_theme.get_color("simpleSelectItem").get_color() elif select_status == BUTTON_HOVER: draw_vlinear( cr, rect.x, rect.y, rect.width, rect.height, app_theme.get_shadow_color("simpleItemHover").get_color_info()) # Draw content. draw_text(cr, self.content, rect.x + self.padding_left, rect.y, rect.width - self.padding_left - self.arrow_width - self.padding_right, rect.height, self.font_size, font_color, alignment=self.x_align) # Draw pixbuf. draw_pixbuf( cr, arrow_pixbuf, rect.x + rect.width - self.arrow_width - self.padding_right, rect.y + (rect.height - arrow_pixbuf.get_height()) / 2) propagate_expose(widget, event) return True
def search_ali_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # bg_color = "#272727" cr.set_source_rgba(*alpha_color_hex_to_cairo((bg_color, 1.0))) cr.rectangle(rect.x, rect.y, rect.width + 1, rect.height) cr.fill() # propagate_expose(widget, event) return True
def expose_star_view(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation self.star_buffer.render(cr, rect) # Propagate expose. propagate_expose(widget, event) return True
def search_ali_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # bg_color = "#272727" cr.set_source_rgba(*alpha_color_hex_to_cairo((bg_color,1.0))) cr.rectangle(rect.x, rect.y, rect.width + 1, rect.height) cr.fill() # propagate_expose(widget, event) return True
def __draw_panel_background(self, widget, event): cr = widget.window.cairo_create() x, y, w, h = widget.allocation cr.set_source_rgb(0, 0, 0) cr.set_operator(OPERATOR_SOURCE) cr.paint() cr.set_source_rgba(0, 0, 0, 0.5) cr.rectangle(x, y, w, h) cr.paint() propagate_expose(widget, event) return True
def double_click_test_expose(self, widget, event): '''double_test button expsoe''' cr = widget.window.cairo_create() cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR)) cr.rectangle(*widget.allocation) cr.paint() if widget.get_data("has_double_clicked"): cr.set_source_pixbuf(self.image_widgets["double_test_2"].get_pixbuf(), 0, 0) else: cr.set_source_pixbuf(self.image_widgets["double_test_1"].get_pixbuf(), 0, 0) cr.paint() propagate_expose(widget, event) return True
def expose_simple_item(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation rect.x += 1 rect.width -= 2 font_color = app_theme.get_color("labelText").get_color() item_pixbuf = self.normal_dpixbuf.get_pixbuf() select_index = self.get_index() if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_NORMAL elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_HOVER elif widget.state == gtk.STATE_ACTIVE: select_status = BUTTON_PRESS if select_status == BUTTON_PRESS: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHighlight") # font_color = app_theme.get_color("simpleSelectItem").get_color() font_color = "#FFFFFF" item_pixbuf = self.press_dpixbuf.get_pixbuf() elif select_status == BUTTON_HOVER: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHover") # Draw pixbuf. draw_pixbuf(cr, item_pixbuf, rect.x + self.padding_left, rect.y + (rect.height - item_pixbuf.get_height()) / 2) # Draw content. draw_text(cr, self.content, rect.x + self.padding_left + self.font_offset , rect.y, rect.width - self.padding_left - self.font_offset - self.padding_right, rect.height, self.font_size, font_color, alignment=self.x_align) propagate_expose(widget, event) return True
def draw_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # cr.rectangle(*rect) cr.set_source_rgba(1, 1, 1, 0.0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() cr = widget.window.cairo_create() x, y, w, h = rect self.expose_event_draw(cr, rect) propagate_expose(widget, event) return True
def expose_progressbar(self, widget, event): ''' Internal callback for `expose` signal. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation self.progress_buffer.render(cr, rect) # Propagate expose. propagate_expose(widget, event) return True
def double_click_test_expose(self, widget, event): '''double_test button expsoe''' cr = widget.window.cairo_create() cr = widget.window.cairo_create() cr.set_source_rgb(*color_hex_to_cairo(MODULE_BG_COLOR)) cr.rectangle(*widget.allocation) cr.paint() if widget.get_data("has_double_clicked"): cr.set_source_pixbuf(self.image_widgets["double_test_2"].get_pixbuf(), 0, 0) else: cr.set_source_pixbuf(self.image_widgets["double_test_1"].get_pixbuf(), 0, 0) cr.paint() propagate_expose(widget, event) return True
def expose_category_item(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation font_color = app_theme.get_color("labelText").get_color() arrow_pixbuf = self.arrow_dpixbuf.get_pixbuf() select_index = self.get_index() if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_NORMAL elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_status = BUTTON_PRESS else: select_status = BUTTON_HOVER elif widget.state == gtk.STATE_ACTIVE: select_status = BUTTON_PRESS if select_status == BUTTON_PRESS: draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, app_theme.get_shadow_color("simpleItemPress").get_color_info()) font_color = app_theme.get_color("simpleSelectItem").get_color() elif select_status == BUTTON_HOVER: draw_vlinear(cr, rect.x, rect.y, rect.width, rect.height, app_theme.get_shadow_color("simpleItemHover").get_color_info()) # Draw content. draw_text(cr, self.content, rect.x + self.padding_left, rect.y, rect.width - self.padding_left - self.arrow_width - self.padding_right, rect.height, self.font_size, font_color, alignment=self.x_align) # Draw pixbuf. draw_pixbuf(cr, arrow_pixbuf, rect.x + rect.width - self.arrow_width - self.padding_right ,rect.y + (rect.height - arrow_pixbuf.get_height()) / 2) propagate_expose(widget, event) return True
def expose_button(self, widget, event, font_size, label_dcolor): # Init. rect = widget.allocation image = self.pixbuf_normal.get_pixbuf() # Get pixbuf along with button's sate. if widget.state == gtk.STATE_NORMAL: image = self.pixbuf_normal.get_pixbuf() label_dcolor = app_theme.get_color('button_text_fg_normal') bg_dcolor = app_theme.get_alpha_color('button_bg_normal') elif widget.state == gtk.STATE_PRELIGHT: image = self.pixbuf_hover.get_pixbuf() label_dcolor = app_theme.get_color('button_text_fg_hover') bg_dcolor = app_theme.get_alpha_color('button_bg_hover') elif widget.state == gtk.STATE_ACTIVE: image = self.pixbuf_press.get_pixbuf() label_dcolor = app_theme.get_color('button_text_fg_press') bg_dcolor = app_theme.get_alpha_color('button_bg_press') # Draw button. cr = widget.window.cairo_create() draw_pixbuf(cr, image, rect.x + self.padding_edge, rect.y) # Draw font. if widget.state == gtk.STATE_INSENSITIVE: label_color = ui_theme.get_color("disable_text").get_color() else: label_color = label_dcolor.get_color() if self.button_label: draw_text(cr, self.button_label, rect.x + image.get_width() + self.padding_edge + self.padding_middle, rect.y, rect.width - image.get_width() - self.padding_middle - self.padding_edge*2, rect.height, font_size, label_color, alignment=pango.ALIGN_LEFT ) if self.draw_background: cr.set_source_rgba(*alpha_color_hex_to_cairo(bg_dcolor.get_color_info())) draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, rect.height/2) cr.fill() # Propagate expose to children. propagate_expose(widget, event) return True
def on_top_hbox_expose(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(*color_hex_to_cairo("#C3C4C5")) cr.move_to(rect.x + 1, rect.y + 1) cr.rel_line_to(0, rect.height - 1) cr.rel_line_to(rect.width - 2, 0) cr.rel_line_to(0, -rect.height + 1) cr.stroke() propagate_expose(widget, event) return True
def center_play_box_expose(self, widget, event): rect = widget.allocation cr = widget.window.cairo_create() if widget.state == gtk.STATE_PRELIGHT: play_pixbuf = utils.get_common_image_pixbuf('pause/play_hover.png') else: play_pixbuf = utils.get_common_image_pixbuf('pause/play_normal.png') draw_pixbuf( cr, play_pixbuf, rect.x + (rect.width - play_pixbuf.get_width())/2, rect.y + (rect.height - play_pixbuf.get_height())/2, ) # Propagate expose to children. propagate_expose(widget, event) return True
def center_play_box_expose(self, widget, event): rect = widget.allocation cr = widget.window.cairo_create() if widget.state == gtk.STATE_PRELIGHT: play_pixbuf = utils.get_common_image_pixbuf('pause/play_hover.png') else: play_pixbuf = utils.get_common_image_pixbuf( 'pause/play_normal.png') draw_pixbuf( cr, play_pixbuf, rect.x + (rect.width - play_pixbuf.get_width()) / 2, rect.y + (rect.height - play_pixbuf.get_height()) / 2, ) # Propagate expose to children. propagate_expose(widget, event) return True
def expose_button(self, widget, event, cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf): # Get pixbuf along with button's sate. if widget.state == gtk.STATE_NORMAL or widget.state == gtk.STATE_INSENSITIVE: image = normal_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_PRELIGHT: image = hover_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_ACTIVE: image = press_dpixbuf.get_pixbuf() # Draw button. pixbuf = image image_width = self.image_width image_height = self.image_height if pixbuf.get_width() != image_width or pixbuf.get_height( ) != image_height: cache_pixbuf.scale(image, image_width, image_height) pixbuf = cache_pixbuf.get_cache() cr = widget.window.cairo_create() draw_pixbuf(cr, pixbuf, widget.allocation.x, widget.allocation.y) text_color = '#FFFFFF' if widget.state == gtk.STATE_INSENSITIVE: #color = "#A2A2A2" #color = color_hex_to_cairo(color) #cr.set_source_rgba(color[0], color[1], color[2], 0.7) #cr.rectangle(*widget.allocation) #cr.fill() text_color = '#A2A2A2' if self.content: draw_text(cr, self.content, widget.allocation.x + image_width + self.spacing, widget.allocation.y + (self.image_height - self.text_size[1]) / 2, *self.text_size, text_color=text_color) # Propagate expose to children. propagate_expose(widget, event) return True
def expose_test_panel(self, widget, event): '''Expose test panel.''' # Init. cr = widget.window.cairo_create() rect = widget.allocation # Clear color to transparent window. cr.set_source_rgba(0.0, 0.0, 0.0, 0.0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.paint() # Draw background. cr.set_source_rgba(1.0, 0.0, 0.0, 0.5) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Propagate expose. propagate_expose(widget, event) return True
def expose_input_entry(self, widget, event): ''' Internal callback for `expose-event` signal. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation cr.set_source_rgba(*alpha_color_hex_to_cairo(("#FFFFFF", 0.9))) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Draw frame. with cairo_disable_antialias(cr): cr.set_line_width(1) cr.set_source_rgba(*color_hex_to_cairo("#C3C4C5")) cr.move_to(rect.x + rect.width, rect.y) cr.rel_line_to(0, rect.height) cr.stroke() propagate_expose(widget, event)
def expose_entry(self, widget, event): ''' Internal callback for `expose-event` signal. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation # Draw background. if self.get_sensitive(): self.draw_entry_background(cr, rect) # Draw text. self.draw_entry_text(cr, rect) # Draw cursor. if self.cursor_visible_flag and self.get_sensitive(): self.draw_entry_cursor(cr, rect) # Propagate expose. propagate_expose(widget, event) return True
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation if self.is_composited(): cr.rectangle(*rect) cr.set_source_rgba(0, 0, 0, 0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.fill() else: cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.set_operator(cairo.OPERATOR_SOURCE) cr.set_source_rgb(0.9, 0.9, 0.9) cr.fill() cr.set_operator(cairo.OPERATOR_OVER) self.draw_notification(cr, rect) propagate_expose(widget, event) return True
def expose_button(self, widget, event, cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf): # Get pixbuf along with button's sate. if widget.state == gtk.STATE_NORMAL or widget.state == gtk.STATE_INSENSITIVE: image = normal_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_PRELIGHT: image = hover_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_ACTIVE: image = press_dpixbuf.get_pixbuf() # Draw button. pixbuf = image image_width = self.image_width image_height = self.image_height if pixbuf.get_width() != image_width or pixbuf.get_height() != image_height: cache_pixbuf.scale(image, image_width, image_height) pixbuf = cache_pixbuf.get_cache() cr = widget.window.cairo_create() draw_pixbuf(cr, pixbuf, widget.allocation.x, widget.allocation.y) text_color = '#FFFFFF' if widget.state == gtk.STATE_INSENSITIVE: #color = "#A2A2A2" #color = color_hex_to_cairo(color) #cr.set_source_rgba(color[0], color[1], color[2], 0.7) #cr.rectangle(*widget.allocation) #cr.fill() text_color = '#A2A2A2' if self.content: draw_text(cr, self.content, widget.allocation.x+image_width+self.spacing, widget.allocation.y+(self.image_height-self.text_size[1])/2, *self.text_size, text_color=text_color) # Propagate expose to children. propagate_expose(widget, event) return True
def expose_input_entry(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) cr.set_source_rgb(*color_hex_to_cairo(self.border_color)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.stroke() cr.set_source_rgba(*alpha_color_hex_to_cairo(("#ffffff", 0.9))) cr.rectangle(rect.x, rect.y, rect.width - 1, rect.height - 1) cr.fill() propagate_expose(widget, event) return True
def expose_simple_item(self, widget, event): # Init. cr = widget.window.cairo_create() rect = widget.allocation font_color = app_theme.get_color("labelText").get_color() item_pixbuf = self.normal_dpixbuf.get_pixbuf() # Draw pixbuf. draw_pixbuf(cr, item_pixbuf, rect.x + self.padding_left, rect.y + (rect.height - item_pixbuf.get_height()) / 2) # Draw content. draw_text(cr, self.content, rect.x + self.padding_left + self.font_offset , rect.y, rect.width - self.padding_left - self.font_offset - self.padding_right, rect.height, self.font_size, font_color, alignment=self.x_align) propagate_expose(widget, event) return True
def __render(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation x, y, w, h = rect cr.rectangle(*rect) cr.set_source_rgba(0, 0, 0, 0) cr.set_operator(cairo.OPERATOR_SOURCE) cr.fill() cr.set_operator(cairo.OPERATOR_OVER) # Draw border self.__render_blur(cr, rect) # Render background skin_config.render_background(cr, self, rect.x, rect.y) # Draw mask self.draw_mask_single_page(cr, rect.x, rect.y, rect.width, rect.height) propagate_expose(widget, event) return True
def draw_button(self, widget, event): if widget.state == gtk.STATE_NORMAL: if self.flags: image = self.normal_pixbuf_1.get_pixbuf() else: image = self.normal_pixbuf_2.get_pixbuf() elif widget.state == gtk.STATE_PRELIGHT: if self.flags: image = self.hover_pixbuf_1.get_pixbuf() else: image = self.hover_pixbuf_2.get_pixbuf() elif widget.state == gtk.STATE_ACTIVE: if self.flags: image = self.hover_pixbuf_1.get_pixbuf() else: image = self.hover_pixbuf_2.get_pixbuf() widget.set_size_request(image.get_width(), image.get_height()) self.cache_pixbuf.scale(image, image.get_width(), image.get_height()) cr = widget.window.cairo_create() draw_pixbuf(cr, self.cache_pixbuf.get_cache(), widget.allocation.x, widget.allocation.y) propagate_expose(widget, event) return True
def screenshot_box_expose(self, widget, event): rect = widget.allocation cr = widget.window.cairo_create() #cr.set_source_rgba(1.0, 1.0, 1.0, 0.0) #cr.set_operator(cairo.OPERATOR_SOURCE) #cr.paint() if self.screenshot_pixbuf: draw_pixbuf( cr, self.screenshot_pixbuf, rect.x + (rect.width - self.screenshot_pixbuf.get_width())/2, rect.y + (rect.height - self.screenshot_pixbuf.get_height())/2, ) cr.set_source_rgba(0, 0, 0, 0.7) cr.rectangle(*rect) cr.fill() # Propagate expose to children. propagate_expose(widget, event) return True
def expose_nav_item(self, widget, event): ''' Internal callback `expose-event` signal. ''' # Init. cr = widget.window.cairo_create() rect = widget.allocation select_index = self.get_index() hover_pixbuf = self.item_hover_pixbuf.get_pixbuf() press_pixbuf = self.item_press_pixbuf.get_pixbuf() # Draw background. if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_pixbuf = press_pixbuf else: select_pixbuf = None elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_pixbuf = press_pixbuf else: select_pixbuf = hover_pixbuf elif widget.state == gtk.STATE_ACTIVE: select_pixbuf = press_pixbuf if select_pixbuf: to_draw_pixbuf = select_pixbuf elif self.item_normal_pixbuf: to_draw_pixbuf = self.item_normal_pixbuf.get_pixbuf() if self.pixbuf_width_scale: to_draw_pixbuf = to_draw_pixbuf.scale_simple( self.item_button.get_size_request()[0], self.item_button.get_size_request()[1], gtk.gdk.INTERP_BILINEAR) draw_pixbuf(cr, to_draw_pixbuf, rect.x, rect.y) #cr.set_source_rgba(1, 1, 1, 0.3) #draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 0) #cr.fill() # Draw navigate item. if self.icon_dpixbuf: nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf() nav_item_pixbuf_width = nav_item_pixbuf.get_width() nav_item_pixbuf_height = nav_item_pixbuf.get_height() padding_x = (rect.width - nav_item_pixbuf_width - self.text_width) / 2 draw_pixbuf(cr, nav_item_pixbuf, rect.x + padding_x, rect.y + (rect.height - nav_item_pixbuf_height) / 2) else: nav_item_pixbuf_width = 0 nav_item_pixbuf_height = 0 padding_x = (rect.width - nav_item_pixbuf_width - self.text_width) / 2 - 1 draw_text( cr, self.content, rect.x + nav_item_pixbuf_width + padding_x, rect.y, rect.width, rect.height, text_size=self.font_size, text_color="#FFFFFF", gaussian_radious=2, gaussian_color="#000000", border_radious=1, border_color="#000000", ) # Draw notify number. text_size = 8 (number_width, number_height) = get_content_size(str(self.notify_num), text_size) padding_x = 2 padding_y = 0 radious = 3 draw_offset_x = -5 draw_offset_y = 8 draw_x = rect.x + nav_item_pixbuf_width + padding_x + draw_offset_x draw_y = rect.y + draw_offset_y if self.notify_num > 0: cr.set_source_rgb(*color_hex_to_cairo("#BF0000")) draw_round_rectangle(cr, draw_x, draw_y, number_width + padding_x * 2, number_height + padding_y * 2, radious) cr.fill() draw_text( cr, str(self.notify_num), draw_x + padding_x, draw_y + padding_y, number_width, number_height, text_color="#FFFFFF", text_size=text_size, ) # Propagate expose to children. propagate_expose(widget, event) return True
def expose_toggle_button(self, widget, event, font_size, label_dcolor): ''' Callback for `expose-event` signal. @param widget: ToggleButton widget. @param event: Expose event. @param button_label: Button label string. @param padding_x: horticultural padding value. @param font_size: Font size. @param label_dcolor: Label DynamicColor. ''' # Init. inactive_normal_dpixbuf, inactive_hover_dpixbuf, inactive_press_dpixbuf, inactive_disable_dpixbuf = self.inactive_pixbuf_group active_normal_dpixbuf, active_hover_dpixbuf, active_press_dpixbuf, active_disable_dpixbuf = self.active_pixbuf_group rect = widget.allocation image = inactive_normal_dpixbuf.get_pixbuf() if not widget.get_active(): button_label = self.active_button_label else: button_label = self.inactive_button_label # Get pixbuf along with button's sate. if widget.state == gtk.STATE_INSENSITIVE: if widget.get_active(): image = active_disable_dpixbuf.get_pixbuf() else: image = inactive_disable_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_NORMAL: label_dcolor = app_theme.get_color('button_text_fg_normal') bg_dcolor = app_theme.get_alpha_color('button_bg_normal') image = inactive_normal_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_PRELIGHT: label_dcolor = app_theme.get_color('button_text_fg_hover') bg_dcolor = app_theme.get_alpha_color('button_bg_hover') if not inactive_hover_dpixbuf and not active_hover_dpixbuf: if widget.get_active(): image = active_normal_dpixbuf.get_pixbuf() else: image = inactive_normal_dpixbuf.get_pixbuf() else: if inactive_hover_dpixbuf and active_hover_dpixbuf: if widget.get_active(): image = active_hover_dpixbuf.get_pixbuf() else: image = inactive_hover_dpixbuf.get_pixbuf() elif inactive_hover_dpixbuf: image = inactive_hover_dpixbuf.get_pixbuf() elif active_hover_dpixbuf: image = active_hover_dpixbuf.get_pixbuf() elif widget.state == gtk.STATE_ACTIVE: if inactive_press_dpixbuf and active_press_dpixbuf: if self.button_press_flag: label_dcolor = app_theme.get_color('button_text_fg_press') bg_dcolor = app_theme.get_alpha_color('button_bg_press') if widget.get_active(): image = active_press_dpixbuf.get_pixbuf() else: image = inactive_press_dpixbuf.get_pixbuf() else: label_dcolor = app_theme.get_color('button_text_fg_normal') bg_dcolor = app_theme.get_alpha_color('button_bg_normal') image = active_normal_dpixbuf.get_pixbuf() else: image = active_normal_dpixbuf.get_pixbuf() # Draw button. cr = widget.window.cairo_create() draw_pixbuf(cr, image, rect.x + self.padding_edge, rect.y) # Draw font. if widget.state == gtk.STATE_INSENSITIVE: label_color = ui_theme.get_color("disable_text").get_color() else: label_color = label_dcolor.get_color() if button_label: draw_text(cr, button_label, rect.x + image.get_width() + self.padding_edge + self.padding_middle, rect.y, rect.width - image.get_width() - self.padding_edge * 2 - self.padding_middle + self.more_width, rect.height, font_size, label_color, alignment=pango.ALIGN_LEFT ) if self.draw_background: cr.set_source_rgba(*alpha_color_hex_to_cairo(bg_dcolor.get_color_info())) draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, rect.height/2) cr.fill() # Propagate expose to children. propagate_expose(widget, event) return True
def expose_nav_item(self, widget, event): """ Internal callback `expose-event` signal. """ # Init. cr = widget.window.cairo_create() rect = widget.allocation select_index = self.get_index() hover_pixbuf = self.item_hover_pixbuf.get_pixbuf() press_pixbuf = self.item_press_pixbuf.get_pixbuf() # Draw background. if widget.state == gtk.STATE_NORMAL: if select_index == self.index: select_pixbuf = press_pixbuf else: select_pixbuf = None elif widget.state == gtk.STATE_PRELIGHT: if select_index == self.index: select_pixbuf = press_pixbuf else: select_pixbuf = hover_pixbuf elif widget.state == gtk.STATE_ACTIVE: select_pixbuf = press_pixbuf if select_pixbuf: to_draw_pixbuf = select_pixbuf elif self.item_normal_pixbuf: to_draw_pixbuf = self.item_normal_pixbuf.get_pixbuf() if self.pixbuf_width_scale: to_draw_pixbuf = to_draw_pixbuf.scale_simple( self.item_button.get_size_request()[0], self.item_button.get_size_request()[1], gtk.gdk.INTERP_BILINEAR ) draw_pixbuf(cr, to_draw_pixbuf, rect.x, rect.y) # cr.set_source_rgba(1, 1, 1, 0.3) # draw_round_rectangle(cr, rect.x, rect.y, rect.width, rect.height, 0) # cr.fill() # Draw navigate item. if self.icon_dpixbuf: nav_item_pixbuf = self.icon_dpixbuf.get_pixbuf() nav_item_pixbuf_width = nav_item_pixbuf.get_width() nav_item_pixbuf_height = nav_item_pixbuf.get_height() padding_x = (rect.width - nav_item_pixbuf_width - self.text_width) / 2 draw_pixbuf(cr, nav_item_pixbuf, rect.x + padding_x, rect.y + (rect.height - nav_item_pixbuf_height) / 2) else: nav_item_pixbuf_width = 0 nav_item_pixbuf_height = 0 padding_x = (rect.width - nav_item_pixbuf_width - self.text_width) / 2 - 1 draw_text( cr, self.content, rect.x + nav_item_pixbuf_width + padding_x, rect.y, rect.width, rect.height, text_size=self.font_size, text_color="#FFFFFF", gaussian_radious=2, gaussian_color="#000000", border_radious=1, border_color="#000000", ) # Draw notify number. text_size = 8 (number_width, number_height) = get_content_size(str(self.notify_num), text_size) padding_x = 2 padding_y = 0 radious = 3 draw_offset_x = -5 draw_offset_y = 8 draw_x = rect.x + nav_item_pixbuf_width + padding_x + draw_offset_x draw_y = rect.y + draw_offset_y if self.notify_num > 0: cr.set_source_rgb(*color_hex_to_cairo("#BF0000")) draw_round_rectangle( cr, draw_x, draw_y, number_width + padding_x * 2, number_height + padding_y * 2, radious ) cr.fill() draw_text( cr, str(self.notify_num), draw_x + padding_x, draw_y + padding_y, number_width, number_height, text_color="#FFFFFF", text_size=text_size, ) # Propagate expose to children. propagate_expose(widget, event) return True