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 render_name(self, cr, rect): ''' Render icon and name of DirItem. ''' # Draw select background. if self.is_select: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Init. expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_right.png").get_pixbuf() # Draw directory icon. draw_pixbuf(cr, self.pixbuf, rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT, rect.y + (rect.height - ICON_SIZE) / 2, ) # Draw directory name. draw_text(cr, self.name, rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT, rect.y, rect.width, rect.height) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
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 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 render_size(self, cr, rect): ''' Render size of DirItem. ''' # Draw select background. if self.is_select or self.is_highlight: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Draw directory size. draw_text(cr, self.size_name, rect.x, rect.y, rect.width, rect.height, alignment=pango.ALIGN_RIGHT, ) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
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 render_size(self, cr, rect): ''' Render size of DirItem. ''' # Draw select background. if self.is_select: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Draw directory size. draw_text(cr, self.size_name, rect.x, rect.y, rect.width, rect.height, alignment=pango.ALIGN_RIGHT, ) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) 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 select_button_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # # get font width/height. font_w, font_h = get_text_size(self.text, text_size=self.font_size) # draw text. x_padding = rect.x + self.ali_padding x_padding = max(20, x_padding) if self.__selected or self.hover: # draw rectangle. with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.selected_bg_color)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_text(cr, self.text, x_padding, rect.y + rect.height/2 - font_h/2, text_size=self.font_size, text_color=self.selected_font_color) else: with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.normal_bg_color)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() draw_text(cr, self.text, x_padding, rect.y + rect.height/2 - font_h/2, text_size=self.font_size, text_color=self.normal_font_color) # set size. if font_h > rect.height: widget.set_size_request(rect.width, font_h) return True
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 expose_bread_menu_frame(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation with cairo_disable_antialias(cr): outside_border = alpha_color_hex_to_cairo(("#666666", 0.5)) cr.set_line_width(1) cr.set_source_rgba(*outside_border) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2) cr.fill()
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_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 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 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 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_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 draw_window_rectangle(cr, sx, sy, ex, ey, r): ''' Draw window rectangle. @param cr: Cairo context. @param sx: Source x coordinate. @param sy: Source y coordinate. @param ex: Target x coordinate. @param ey: Target x coordinate. @param r: Window frame radious. ''' with cairo_disable_antialias(cr): # Set line width. cr.set_line_width(1) # Set OPERATOR_OVER operator. cr.set_operator(cairo.OPERATOR_OVER) cr.move_to(sx + r, sy) # top line cr.line_to(ex - r, sy) cr.stroke() cr.move_to(ex, sy + r) # right side cr.line_to(ex, ey - r) cr.stroke() cr.move_to(ex - r, ey) # bottom side cr.line_to(sx + r, ey) cr.stroke() cr.move_to(sx, ey - r) # left side cr.line_to(sx, sy + r) cr.stroke() cr.arc(sx + r, sy + r, r, pi, pi * 3 / 2) # top-left cr.stroke() cr.arc(ex - r, sy + r, r, pi * 3 / 2, pi * 2) # top-right cr.stroke() cr.arc(ex - r, ey - r, r, 0, pi / 2) # bottom-right cr.stroke() cr.arc(sx + r, ey - r, r, pi / 2, pi) # bottom-left cr.stroke()
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 render_name(self, cr, rect): ''' Render icon and name of DirItem. ''' if self.pixbuf == None: self.pixbuf = get_file_icon_pixbuf(self.directory_path, ICON_SIZE) # Draw select background. if self.is_select or self.is_highlight: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Draw directory arrow icon. if self.is_expand: expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_down.png").get_pixbuf() else: expand_indicator_pixbuf = ui_theme.get_pixbuf("treeview/arrow_right.png").get_pixbuf() draw_pixbuf(cr, expand_indicator_pixbuf, rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT, rect.y + (rect.height - expand_indicator_pixbuf.get_height()) / 2, ) # Draw directory icon. draw_pixbuf(cr, self.pixbuf, rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT, rect.y + (rect.height - ICON_SIZE) / 2, ) # Draw directory name. draw_text(cr, self.name, rect.x + COLUMN_OFFSET * self.column_index + INDICATOR_PADDING_LEFT + expand_indicator_pixbuf.get_width() + INDICATOR_PADDING_RIGHT + ICON_PADDING_LEFT + ICON_SIZE + ICON_PADDING_RIGHT, rect.y, rect.width, rect.height) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
def expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation if self.hover or self.steady: background_color = THEME['hover'] text_color = THEME['bg'] bg_opacity = self.opacity[1] content_opacity = self.opacity[3] if bg_opacity == 0: text_color = THEME['hover'] else: background_color = THEME['bg'] text_color = self.color bg_opacity = self.opacity[0] content_opacity = self.opacity[2] font_width, font_height = get_text_size(self.text, text_size=self.font_size) x_padding = rect.x + (rect.width - font_width) / 2 y_padding = rect.y + (rect.height - font_height) / 2 with cairo_disable_antialias(cr): cr.set_source_rgba(*alpha_color_hex_to_cairo( (background_color, bg_opacity))) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() if self.border: draw_border(cr, rect=rect, pos=(1, 1, 0, 0)) if self.icon: draw_icon(cr, self.symbol, text_color, rect, opacity=content_opacity) else: draw_text(cr, self.text, x_padding, y_padding, text_size=self.font_size, text_color=text_color) if font_height > rect.height: widget.set_size_request(rect.width, font_height) 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 expose_event(self, widget, event): self.set_size_request(*self.size) cr = widget.window.cairo_create() rect = widget.allocation font_width, font_height = get_text_size("Loading ...", text_size=20) with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(THEME['bg'])) cr.rectangle(*rect) cr.fill() if self.haveLoadingHint: draw_text(cr, "Loading ...", rect.x + (rect.width - font_width) / 2, rect.y + (rect.height - font_height) / 2, text_size=20, text_color=THEME['font_color']) propagate_expose(widget, event) return True
def expose_text_entry(self, widget, event): '''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(ui_theme.get_color("combo_entry_frame").get_color())) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.stroke() 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 True
def select_button_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation # if widget.state == gtk.STATE_PRELIGHT: # draw rectangle. with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.bg_color)) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() cr.set_line_width(1) cr.set_source_rgb(*color_hex_to_cairo(self.line_color)) cr.rectangle(rect.x + 1, rect.y + 1, rect.width - 2, rect.height - 2) cr.stroke() if widget.state == gtk.STATE_INSENSITIVE: text_color = "#a6a6a6" else: text_color = self.text_color # get font width/height. font_w, font_h = get_text_size(self.text, text_size=self.font_size) # draw text. x_padding = rect.x + rect.width - font_w - self.ali_padding x_padding = max(20, x_padding) draw_text(cr, self.text, x_padding, rect.y + rect.height/2 - font_h/2, text_size=self.font_size, text_color=text_color) # set size. if font_h > rect.height: widget.set_size_request(rect.width, font_h) return True
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 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_type(self, cr, rect): ''' Render type of DirItem. ''' # Draw select background. if self.is_select or self.is_highlight: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Draw directory type. draw_text(cr, self.content_type, rect.x + CONTENT_TYPE_PADDING_LEFT, rect.y, rect.width, rect.height) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
def render_type(self, cr, rect): ''' Render type of DirItem. ''' # Draw select background. if self.is_select: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Draw directory type. draw_text(cr, self.content_type, rect.x + CONTENT_TYPE_PADDING_LEFT, rect.y, rect.width, rect.height) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
def draw_window_rectangle(cr, sx, sy, ex, ey, r): '''Draw window rectangle.''' with cairo_disable_antialias(cr): # Set line width. cr.set_line_width(1) # Set OPERATOR_OVER operator. cr.set_operator(cairo.OPERATOR_OVER) cr.move_to(sx + r, sy) # top line cr.line_to(ex - r, sy) cr.stroke() cr.move_to(ex, sy + r) # right side cr.line_to(ex, ey - r) cr.stroke() cr.move_to(ex - r, ey) # bottom side cr.line_to(sx + r, ey) cr.stroke() cr.move_to(sx, ey - r) # left side cr.line_to(sx, sy + r) cr.stroke() cr.arc(sx + r, sy + r, r, pi, pi * 3 / 2) # top-left cr.stroke() cr.arc(ex - r, sy + r, r, pi * 3 / 2, pi * 2) # top-right cr.stroke() cr.arc(ex - r, ey - r, r, 0, pi / 2) # bottom-right cr.stroke() cr.arc(sx + r, ey - r, r, pi / 2, pi) # bottom-left cr.stroke()
def render_modification_time(self, cr, rect): ''' Render type of DirItem. ''' # Draw select background. if self.is_select or self.is_highlight: draw_vlinear(cr, rect.x ,rect.y, rect.width, rect.height, ui_theme.get_shadow_color("listview_select").get_color_info()) # Draw directory type. draw_text(cr, self.modification_time, rect.x + MODIFICATION_TIME_PADDING_LEFT, rect.y, rect.width, rect.height) # Draw drag line. if self.drag_line: with cairo_disable_antialias(cr): cr.set_line_width(1) if self.drag_line_at_bottom: cr.rectangle(rect.x, rect.y + rect.height - 1, rect.width, 1) else: cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
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 expose_tab_title_box(self, widget, event): '''Expose tab title box.''' cr = widget.window.cairo_create() rect = widget.allocation # Draw title unselect tab. tab_title_width = sum(self.tab_title_widths) with cairo_state(cr): with cairo_disable_antialias(cr): cr.rectangle(rect.x, rect.y, sum(self.tab_title_widths[0:self.tab_index]), self.tab_height) cr.rectangle(rect.x + sum(self.tab_title_widths[0:min(self.tab_index + 1, len(self.tab_items))]) + 1, rect.y, sum(self.tab_title_widths) - sum(self.tab_title_widths[0:min(self.tab_index + 1, len(self.tab_items))]), self.tab_height) cr.clip() cr.set_source_rgba(*alpha_color_hex_to_cairo((self.tab_unselect_bg_color.get_color(), 0.7))) cr.rectangle(rect.x + 1, rect.y + 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(rect.x + 1, rect.y + 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(rect.x + 1 + sum(self.tab_title_widths[0:index]) + width, rect.y + 1, 1, self.tab_height) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(self.tab_select_frame_color.get_color())) cr.rectangle(rect.x, rect.y + 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(rect.x + 1 + sum(self.tab_title_widths[0:self.tab_index]), rect.y + 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(rect.x + sum(self.tab_title_widths[0:index]), rect.y + 1, self.tab_title_widths[index] + 1, self.tab_height) else: cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]), rect.y + 1, self.tab_title_widths[index], self.tab_height) cr.fill() if index == 0: cr.rectangle(rect.x, rect.y, 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(rect.x + sum(self.tab_title_widths[0:index]), rect.y + 1, self.tab_title_widths[index] + 2, self.tab_height) else: cr.rectangle(rect.x + 1 + sum(self.tab_title_widths[0:index]), rect.y + 1, self.tab_title_widths[index] + 1, self.tab_height) cr.stroke() draw_text(cr, title, rect.x + sum(self.tab_title_widths[0:index]) + self.tab_padding_x, rect.y + self.tab_padding_y, self.tab_title_widths[index] - self.tab_padding_x * 2, self.tab_height - self.tab_padding_y * 2, )
def draw_bg_and_fg(self, cr, rect): with cairo_disable_antialias(cr): x, y, w, h = rect progress_x = rect.x progress_y = rect.y + (rect.height-self.bottom_space)/2 - self.line_height/2 progress_width = rect.width value_width = int(float(self.value) / self.value_max * (rect.width - self.point_width/2)) if int(float(self.value)) == self.value_max: value_width = value_width - 1 # there is less 1px for 100% mark line # Background inner. cr.set_source_rgb(*color_hex_to_cairo(self.bg_inner2_color)) cr.rectangle(progress_x+value_width, progress_y+self.progress_border, progress_width-value_width-self.progress_border, self.line_height-self.progress_border*2) cr.fill() # Background border. cr.set_source_rgb(*color_hex_to_cairo(self.bg_side_color)) # Top border. cr.rectangle( progress_x+value_width, progress_y, progress_width-value_width-self.progress_border, self.progress_border) cr.fill() # Bottom border. cr.rectangle( progress_x+value_width, progress_y+self.line_height-self.progress_border, progress_width-value_width-self.progress_border, self.progress_border) cr.fill() # Right border. cr.rectangle( progress_x+progress_width-self.progress_border, progress_y+self.progress_border, self.progress_border, self.line_height-self.progress_border*2) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(self.bg_corner_color)) # Top right corner. cr.rectangle( progress_x+progress_width-self.progress_border, progress_y, self.progress_border, self.progress_border) cr.fill() # Bottom right corner. cr.rectangle( progress_x+progress_width-self.progress_border, progress_y+self.line_height-self.progress_border, self.progress_border, self.progress_border) cr.fill() if self.enable_check: fg_inner_color = self.fg_inner_color fg_side_color = self.fg_side_color fg_corner_color = self.fg_corner_color else: fg_inner_color = self.bg_inner1_color fg_side_color = self.bg_side_color fg_corner_color = self.bg_corner_color if self.gray_progress: fg_inner_color = self.bg_inner2_color fg_side_color = self.bg_side_color fg_corner_color = self.bg_corner_color # Foreground inner. cr.set_source_rgb(*color_hex_to_cairo(fg_inner_color)) cr.rectangle(progress_x+self.progress_border, progress_y+self.progress_border, value_width-self.progress_border, self.line_height-self.progress_border*2) cr.fill() # Foreground border. cr.set_source_rgb(*color_hex_to_cairo(fg_side_color)) # Top border. cr.rectangle( progress_x+self.progress_border, progress_y, value_width-self.progress_border, self.progress_border) cr.fill() # Bottom border. cr.rectangle( progress_x+self.progress_border, progress_y+self.line_height-self.progress_border, value_width-self.progress_border, self.progress_border) cr.fill() # Left border. cr.rectangle( progress_x, progress_y+self.progress_border, self.progress_border, self.line_height-self.progress_border*2) cr.fill() cr.set_source_rgb(*color_hex_to_cairo(fg_corner_color)) # Top left corner. cr.rectangle( progress_x, progress_y, self.progress_border, self.progress_border) cr.fill() # Bottom left corner. cr.rectangle( progress_x, progress_y+self.line_height-self.progress_border, self.progress_border, self.progress_border) cr.fill()
def draw_window_frame( cr, x, y, w, h, color_frame_outside_1, color_frame_outside_2, color_frame_outside_3, color_frame_inside_1, color_frame_inside_2, ): ''' Draw window frame. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. @param color_frame_outside_1: Use for draw outside 8 points. @param color_frame_outside_2: Use for draw middle 4 points. @param color_frame_outside_3: Use for draw inside 4 points. @param color_frame_inside_1: Use for draw outside frame. @param color_frame_inside_2: Use for draw inner frame and inside 4 points. ''' with cairo_disable_antialias(cr): # Set line width. cr.set_line_width(1) # Set OPERATOR_OVER operator. cr.set_operator(cairo.OPERATOR_OVER) # Draw outside 8 points. cr.set_source_rgba( *alpha_color_hex_to_cairo(color_frame_outside_1.get_color_info())) cr.rectangle(x, y + 1, 1, 1) # top-left cr.rectangle(x + 1, y, 1, 1) cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right cr.rectangle(x + w - 2, y, 1, 1) cr.rectangle(x, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + 1, y + h - 1, 1, 1) cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right cr.rectangle(x + w - 2, y + h - 1, 1, 1) cr.fill() # Draw outside 4 points. cr.set_source_rgba( *alpha_color_hex_to_cairo(color_frame_outside_2.get_color_info())) cr.rectangle(x + 1, y + 1, 1, 1) # top-left cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right cr.fill() # Draw outside frame. cr.set_source_rgba( *alpha_color_hex_to_cairo(color_frame_outside_3.get_color_info())) cr.rectangle(x + 2, y, w - 4, 1) # top side cr.rectangle(x + 2, y + h - 1, w - 4, 1) # bottom side cr.rectangle(x, y + 2, 1, h - 4) # left side cr.rectangle(x + w - 1, y + 2, 1, h - 4) # right side cr.fill() # Draw outside 4 points. cr.set_source_rgba( *alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info())) cr.rectangle(x + 1, y + 1, 1, 1) # top-left cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right cr.fill() # Draw inside 4 points. cr.set_source_rgba( *alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info())) cr.rectangle(x + 2, y + 2, 1, 1) # top-left cr.rectangle(x + w - 3, y + 2, 1, 1) # top-right cr.rectangle(x + 2, y + h - 3, 1, 1) # bottom-left cr.rectangle(x + w - 3, y + h - 3, 1, 1) # bottom-right cr.fill() # Draw inside frame. cr.set_source_rgba( *alpha_color_hex_to_cairo(color_frame_inside_2.get_color_info())) cr.rectangle(x + 2, y + 1, w - 4, 1) # top side cr.rectangle(x + 2, y + h - 2, w - 4, 1) # bottom side cr.rectangle(x + 1, y + 2, 1, h - 4) # left side cr.rectangle(x + w - 2, y + 2, 1, h - 4) # right side cr.fill()
def draw_window_frame(cr, x, y, w, h, color_frame_outside_1, color_frame_outside_2, color_frame_outside_3, color_frame_inside_1, color_frame_inside_2, ): ''' Draw window frame. @param cr: Cairo context. @param x: X coordiante of draw area. @param y: Y coordiante of draw area. @param w: Width of draw area. @param h: Height of draw area. @param color_frame_outside_1: Use for draw outside 8 points. @param color_frame_outside_2: Use for draw middle 4 points. @param color_frame_outside_3: Use for draw inside 4 points. @param color_frame_inside_1: Use for draw outside frame. @param color_frame_inside_2: Use for draw inner frame and inside 4 points. ''' with cairo_disable_antialias(cr): # Set line width. cr.set_line_width(1) # Set OPERATOR_OVER operator. cr.set_operator(cairo.OPERATOR_OVER) # Draw outside 8 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_1.get_color_info())) cr.rectangle(x, y + 1, 1, 1) # top-left cr.rectangle(x + 1, y, 1, 1) cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right cr.rectangle(x + w - 2, y, 1, 1) cr.rectangle(x, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + 1, y + h - 1, 1, 1) cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right cr.rectangle(x + w - 2, y + h - 1, 1, 1) cr.fill() # Draw outside 4 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_2.get_color_info())) cr.rectangle(x + 1, y + 1, 1, 1) # top-left cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right cr.fill() # Draw outside frame. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_3.get_color_info())) cr.rectangle(x + 2, y, w - 4, 1) # top side cr.rectangle(x + 2, y + h - 1, w - 4, 1) # bottom side cr.rectangle(x, y + 2, 1, h - 4) # left side cr.rectangle(x + w - 1, y + 2, 1, h - 4) # right side cr.fill() # Draw outside 4 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info())) cr.rectangle(x + 1, y + 1, 1, 1) # top-left cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right cr.fill() # Draw inside 4 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info())) cr.rectangle(x + 2, y + 2, 1, 1) # top-left cr.rectangle(x + w - 3, y + 2, 1, 1) # top-right cr.rectangle(x + 2, y + h - 3, 1, 1) # bottom-left cr.rectangle(x + w - 3, y + h - 3, 1, 1) # bottom-right cr.fill() # Draw inside frame. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_2.get_color_info())) cr.rectangle(x + 2, y + 1, w - 4, 1) # top side cr.rectangle(x + 2, y + h - 2, w - 4, 1) # bottom side cr.rectangle(x + 1, y + 2, 1, h - 4) # left side cr.rectangle(x + w - 2, y + 2, 1, h - 4) # right side cr.fill()
def draw_window_frame(cr, x, y, w, h, color_frame_outside_1, color_frame_outside_2, color_frame_outside_3, color_frame_inside_1, color_frame_inside_2, ): '''Draw window frame.''' with cairo_disable_antialias(cr): # Set line width. cr.set_line_width(1) # Set OPERATOR_OVER operator. cr.set_operator(cairo.OPERATOR_OVER) # Draw outside 8 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_1.get_color_info())) cr.rectangle(x, y + 1, 1, 1) # top-left cr.rectangle(x + 1, y, 1, 1) cr.rectangle(x + w - 1, y + 1, 1, 1) # top-right cr.rectangle(x + w - 2, y, 1, 1) cr.rectangle(x, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + 1, y + h - 1, 1, 1) cr.rectangle(x + w - 1, y + h - 2, 1, 1) # bottom-right cr.rectangle(x + w - 2, y + h - 1, 1, 1) cr.fill() # Draw outside 4 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_2.get_color_info())) cr.rectangle(x + 1, y + 1, 1, 1) # top-left cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right cr.fill() # Draw outside frame. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_outside_3.get_color_info())) cr.rectangle(x + 2, y, w - 4, 1) # top side cr.rectangle(x + 2, y + h - 1, w - 4, 1) # bottom side cr.rectangle(x, y + 2, 1, h - 4) # left side cr.rectangle(x + w - 1, y + 2, 1, h - 4) # right side cr.fill() # Draw outside 4 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info())) cr.rectangle(x + 1, y + 1, 1, 1) # top-left cr.rectangle(x + w - 2, y + 1, 1, 1) # top-right cr.rectangle(x + 1, y + h - 2, 1, 1) # bottom-left cr.rectangle(x + w - 2, y + h - 2, 1, 1) # bottom-right cr.fill() # Draw inside 4 points. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_1.get_color_info())) cr.rectangle(x + 2, y + 2, 1, 1) # top-left cr.rectangle(x + w - 3, y + 2, 1, 1) # top-right cr.rectangle(x + 2, y + h - 3, 1, 1) # bottom-left cr.rectangle(x + w - 3, y + h - 3, 1, 1) # bottom-right cr.fill() # Draw inside frame. cr.set_source_rgba(*alpha_color_hex_to_cairo(color_frame_inside_2.get_color_info())) cr.rectangle(x + 2, y + 1, w - 4, 1) # top side cr.rectangle(x + 2, y + h - 2, w - 4, 1) # bottom side cr.rectangle(x + 1, y + 2, 1, h - 4) # left side cr.rectangle(x + w - 2, y + 2, 1, h - 4) # right side cr.fill()
def draw_tab(self, cr, x, y, tab_name, tab_index): # Init. (text_width, text_height) = get_content_size(tab_name) tab_x = x tab_y = y tab_height = self.height triangle_width = int(tab_height / math.tan(math.radians(self.tab_angle))) middle_width = text_width + self.tab_name_padding_x * 2 tab_width = middle_width + self.tab_radious * 4 + triangle_width * 2 round_radious = self.tab_radious * math.tan(math.radians((180 - self.tab_angle) / 2)) round_angle = self.tab_angle if tab_index == self.active_index: frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_active_frame").get_color_info()) background_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_active_background").get_color_info()) top_frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_top_active_frame").get_color_info()) else: frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_inactive_frame").get_color_info()) background_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_inactive_background").get_color_info()) top_frame_color = alpha_color_hex_to_cairo(ui_theme.get_alpha_color("dragable_tab_top_inactive_frame").get_color_info()) # Init round coordinate. round_left_bottom_x = tab_x round_left_bottom_y = tab_y + tab_height - round_radious round_left_up_x = tab_x + self.tab_radious * 2 + triangle_width round_left_up_y = tab_y + round_radious round_right_bottom_x = tab_x + tab_width round_right_bottom_y = tab_y + tab_height - round_radious round_right_up_x = tab_x + tab_width - (self.tab_radious * 2 + triangle_width) round_right_up_y = tab_y + round_radious # Clip. with cairo_state(cr): # Clip. if tab_index != self.active_index and tab_index != 0: clip_offset_x = tab_width - (self.triangle_width + self.tab_radious * 2) cr.move_to(tab_x + tab_width - clip_offset_x, tab_y + tab_height) cr.arc(round_right_bottom_x - clip_offset_x, round_right_bottom_y, round_radious, math.radians(90), math.radians(90 + round_angle), ) cr.line_to(tab_x + tab_width - self.tab_radious - self.triangle_width + self.tab_radious_offset_x - clip_offset_x, tab_y) cr.line_to(tab_x + tab_width, tab_y) cr.line_to(tab_x + tab_width, tab_y + tab_height) cr.line_to(tab_x + tab_width - clip_offset_x, tab_y + tab_height) else: cr.rectangle(tab_x, tab_y, tab_width, tab_height) cr.clip() # Draw background. # Draw left area. with cairo_state(cr): cr.move_to(tab_x, tab_y + tab_height) cr.arc_negative(round_left_bottom_x, round_left_bottom_y, round_radious, math.radians(90), math.radians(90 - round_angle), ) cr.line_to(tab_x + self.tab_radious + self.tab_radious_offset_x, tab_y + tab_height - self.tab_radious_offset_y) cr.arc(round_left_up_x, round_left_up_y, round_radious, math.radians(270 - round_angle), math.radians(270)) # Draw top area. with cairo_disable_antialias(cr): cr.set_source_rgba(*frame_color) cr.set_line_width(1) cr.line_to(tab_x + self.tab_radious * 2 + triangle_width + middle_width, tab_y + 1) # Draw right area. with cairo_state(cr): cr.arc(round_right_up_x, round_right_up_y, round_radious, math.radians(270), math.radians(270 + round_angle), ) cr.line_to(tab_x + tab_width - (self.tab_radious + self.tab_radious_offset_x), tab_y + tab_height - self.tab_radious_offset_y) cr.arc_negative(round_right_bottom_x, round_right_bottom_y, round_radious, math.radians(90 + round_angle), math.radians(90)) cr.line_to(tab_x, tab_y + tab_height) cr.set_source_rgba(*background_color) cr.fill() # Draw frame. # Draw left area. with cairo_state(cr): cr.move_to(tab_x, tab_y + tab_height) cr.arc_negative(round_left_bottom_x, round_left_bottom_y, round_radious, math.radians(90), math.radians(90 - round_angle), ) cr.line_to(tab_x + self.tab_radious + self.tab_radious_offset_x, tab_y + tab_height - self.tab_radious_offset_y) cr.arc(round_left_up_x, round_left_up_y, round_radious, math.radians(270 - round_angle), math.radians(270)) cr.set_source_rgba(*frame_color) cr.set_line_width(1) cr.stroke() # Draw top area. with cairo_disable_antialias(cr): offset = 1 cr.set_source_rgba(*top_frame_color) cr.set_line_width(1) cr.move_to(tab_x + self.tab_radious * 2 + triangle_width - offset, tab_y + 1) cr.line_to(tab_x + self.tab_radious * 2 + triangle_width + middle_width + offset * 2, tab_y + 1) cr.stroke() # Draw right area. with cairo_state(cr): cr.move_to(tab_x + tab_width - (self.tab_radious * 2 + triangle_width), tab_y) cr.arc(round_right_up_x, round_right_up_y, round_radious, math.radians(270), math.radians(270 + round_angle), ) cr.line_to(tab_x + tab_width - (self.tab_radious + self.tab_radious_offset_x), tab_y + tab_height - self.tab_radious_offset_y) cr.arc_negative(round_right_bottom_x, round_right_bottom_y, round_radious, math.radians(90 + round_angle), math.radians(90)) cr.set_source_rgba(*frame_color) cr.set_line_width(1) cr.stroke() # Draw text. draw_text(cr, tab_name, tab_x, tab_y, tab_width, tab_height, alignment=pango.ALIGN_CENTER)
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 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 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 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