def update(self, query_info): self.title = query_info["title"] self.artist = query_info["artist"] self.album = query_info["album"] self.song_type = query_info["type"] self.song_size = query_info["size"] self.downlink = query_info["down"] self.song_from = query_info["from"] # Calculate item size. self.title_padding_x = 10 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.artist_padding_x = 10 self.artist_padding_y = 5 (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE) self.album_padding_x = 10 self.album_padding_y = 5 (self.album_width, self.album_height) = get_content_size(self.album, DEFAULT_FONT_SIZE) self.song_type_padding_x = 10 self.song_type_padding_y = 5 (self.song_type_width, self.song_type_height) = get_content_size(self.song_type, DEFAULT_FONT_SIZE) self.song_size_padding_x = 10 self.song_size_padding_y = 5 (self.song_size_width, self.song_size_height) = get_content_size(self.song_size, DEFAULT_FONT_SIZE)
def update(self, playlist, redraw=False): '''update''' self.playlist = playlist self.list_id = playlist['id'] self.title = playlist["name"] self.creator = playlist["creator"]['nickname'] self.count = playlist["trackCount"] # Calculate item size. self.title_padding_x = 15 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.creator_padding_x = 10 self.creator_padding_y = 5 (self.creator_width, self.creator_height) = get_content_size(self.creator, DEFAULT_FONT_SIZE) self.count_padding_x = 2 self.count_padding_y = 5 (self.count_width, self.count_height) = get_content_size(str(self.count), DEFAULT_FONT_SIZE) if redraw: self.emit_redraw_request()
def __update(self): self.title = self.trans_data["song"].get_str("title") self.status_icon_padding_x = 10 self.status_icon_padding_y = 5 self.status_icon_w, self.status_icon_h = ( self.status_icon.get_width(), self.status_icon.get_height()) self.title_padding_x = 5 self.title_padding_y = 5 self.title_w, self.title_h = get_content_size(self.title, DEFAULT_FONT_SIZE) self.progress_padding_x = 10 self.progress_padding_y = 5 self.progress_w, self.progress_h = 100, 10 self.stop_icon_padding_x = 5 self.stop_icon_padding_y = 5 self.stop_icon_w, self.stop_icon_h = (self.stop_icon.get_width(), self.stop_icon.get_height()) self.ext_padding_x = 5 self.ext_padding_y = 5 self.ext_w, self.ext_h = get_content_size(self.output_ext, DEFAULT_FONT_SIZE)
def update(self, song, redraw=False): '''update''' self.song = song self.title = song.get_str("name") self.artist = ','.join([artist['name'] for artist in song['artists']]) self.album = song["album"]["name"] self.length = utils.duration_to_string(int(song.get_str("duration"))) self.tooltip_text = "曲名:" + self.title + "\n歌手:" + self.artist + "\n时长:" + self.length + "\n专辑:" + self.album # Calculate item size. self.title_padding_x = 15 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.artist_padding_x = 10 self.artist_padding_y = 5 (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE) self.length_padding_x = 2 self.length_padding_y = 5 (self.length_width, self.length_height) = get_content_size(self.length, DEFAULT_FONT_SIZE) if redraw: self.emit_redraw_request()
def update(self, song, redraw=False): """update""" self.song = song self.title = song.get_str("title") self.artist = song.get_str("artist") self.length = song.get_str("#duration") self.add_time = song.get_str("#added") self.album = song.get_str("album") # Calculate item size. self.title_padding_x = 15 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.artist_padding_x = 10 self.artist_padding_y = 5 (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE) self.length_padding_x = 2 self.length_padding_y = 5 (self.length_width, self.length_height) = get_content_size(self.length, DEFAULT_FONT_SIZE) self.add_time_padding_x = 10 self.add_time_padding_y = 5 (self.add_time_width, self.add_time_height) = get_content_size(self.add_time, DEFAULT_FONT_SIZE) self.album_padding_x = 10 self.album_padding_y = 5 (self.album_width, self.album_height) = get_content_size(self.album, DEFAULT_FONT_SIZE) if redraw: self.emit_redraw_request()
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation text_y = rect.y + self.text_padding_y text_x = rect.x + self.text_padding_x left_text, click_text, right_text = self.prompt_text.partition(self.click_text) if left_text: _w, _h = get_content_size(left_text) draw_text(cr, left_text, text_x, text_y, _w, _h, text_color=self.normal_text_dcolor.get_color()) text_x += _w _w, _h = get_content_size(click_text) self.text_rect = gtk.gdk.Rectangle(text_x - rect.x, text_y - rect.y, _w, _h) if self.is_hover: text_color = self.hover_text_dcolor.get_color() else: text_color = "#66B0E2" # self.normal_text_dcolor.get_color() draw_text(cr, click_text, text_x, text_y, _w, _h, text_color=text_color, underline=True) text_x += _w if right_text: _w, _h = get_content_size(left_text) draw_text(cr, right_text, text_x, text_y, _w, _h, text_color=self.normal_text_dcolor.get_color()) return True
def init_size(self): tw = self.default_width - self.padding_x * 2 intro = self.channel_info.get("intro", "").strip() intro = utils.xmlescape(intro) intro_text = "<b>%s:</b> %s" % ("简介", intro) intro_th = 0 if intro: intro_tw, intro_th = get_content_size(intro_text, wrap_width=tw, text_size=9) if intro_th > self.line_height * 2: intro_th = self.line_height * 2 hotsongs = " / ".join(self.channel_info.get("hot_songs", [])).strip() hotsongs = utils.xmlescape(hotsongs) hotsongs_text = "<b>%s:</b> %s" % ("热门歌曲", hotsongs) hotsongs_tw, hotsongs_th = get_content_size(hotsongs_text, wrap_width=tw, text_size=9) if hotsongs_th > self.line_height * 2: hotsongs_th = self.line_height * 2 if intro_th == 0: height = hotsongs_th + self.line_height * 2 else: height = hotsongs_th + intro_th + self.line_height * 4 self.set_size_request(self.default_width, height)
def update(self, song, redraw=False): '''update''' self.song = song self.title = song.get_str("title") self.artist = song.get_str("artist") self.length = song.get_str("#duration") self.add_time = song.get_str("#added") self.album = song.get_str("album") # Calculate item size. self.title_padding_x = 15 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.artist_padding_x = 10 self.artist_padding_y = 5 (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE) self.length_padding_x = 2 self.length_padding_y = 5 (self.length_width, self.length_height) = get_content_size(self.length, DEFAULT_FONT_SIZE) self.add_time_padding_x = 10 self.add_time_padding_y = 5 (self.add_time_width, self.add_time_height) = get_content_size(self.add_time, DEFAULT_FONT_SIZE) self.album_padding_x = 10 self.album_padding_y = 5 (self.album_width, self.album_height) = get_content_size(self.album, DEFAULT_FONT_SIZE) if redraw: self.emit_redraw_request()
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation rect.x += self.padding_x rect.width -= self.padding_x * 2 keyword_span = self.red_span % self.keyword from_keyword_span = self.black_span % self.from_keyword from_keyword_dict = { "keyword": keyword_span, "from": from_keyword_span } self.prompt_text = self.prompt_format_text.format(**from_keyword_dict) _width, _height = get_content_size(self.prompt_text) draw_text(cr, self.prompt_text, rect.x, rect.y, rect.width, _height, text_color=app_theme.get_color("labelText").get_color()) # draw dash rect.y += _height + self.padding_y dash_line_width = 1 with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo("#D6D6D6")) cr.set_line_width(dash_line_width) cr.set_dash([4.0, 4.0]) cr.move_to(rect.x, rect.y) cr.rel_line_to(rect.width, 0) cr.stroke() rect.y += self.padding_y + dash_line_width _width, _height = get_content_size(self.suggest_title) draw_text(cr, self.suggest_title, rect.x, rect.y, rect.width, _height) rect.y += _height + self.padding_y _width, _height = get_content_size(self.suggest_first_line) draw_text(cr, self.suggest_first_line, rect.x, rect.y, rect.width, _height, text_color=app_theme.get_color("labelText").get_color()) rect.y += _height + self.padding_y _width, _height = get_content_size(self.suggest_second_line) draw_text(cr, self.suggest_second_line, rect.x, rect.y, rect.width, _height, text_color=app_theme.get_color("labelText").get_color()) return True
def render_url(self, cr, rect): self.render_background(cr, rect) self.mirror_url = self.mirror.hostname self.name = "<b>%s</b>" % self.mirror.name (name_width, name_height) = get_content_size(self.name) draw_text(cr, self.name, rect.x, rect.y + self.PADDING_Y, rect.width, name_height, alignment = pango.ALIGN_LEFT) (url_width, url_height) = get_content_size(self.mirror_url) draw_text(cr, self.mirror_url, rect.x, rect.y + name_height + self.PADDING_Y + self.PADDING_MIDDLE, rect.width, url_height, alignment = pango.ALIGN_LEFT)
def update_size(self): self.channel_name = utils.xmlescape(self.channel_info.get("name", "")) __, self.name_h = get_content_size(self.channel_name, text_size=9) self.detail_info = "%s首歌曲 %s制作" % (self.channel_info.get("song_num"), utils.xmlescape(self.channel_info.get("creator", {}).get("name", ""))) __, self.detail_h = get_content_size(self.detail_info, text_size=8) intro = utils.xmlescape(self.channel_info.get("intro", "").strip()) hotsongs = utils.xmlescape(" ".join(self.channel_info.get("hot_songs"))) self.channel_intro = intro or hotsongs __, self.intro_h = get_content_size(self.channel_intro, text_size=8)
def render_info(self, cr, rect): if self.is_hover: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHover") if self.icon_pixbuf is None: self.icon_pixbuf = cache_manager.get_small_pixbuf(self.image_object, 37, 38) icon_width = self.icon_pixbuf.get_width() icon_height = self.icon_pixbuf.get_height() icon_x = rect.x + self.info_padding_x icon_y = rect.y + (rect.height - icon_height) / 2 # Draw shadow. drop_shadow_padding = 3 drop_shadow_radious = 3 draw_shadow( cr, icon_x, icon_y, icon_width + drop_shadow_padding, icon_height + drop_shadow_padding, drop_shadow_radious, app_theme.get_shadow_color("window_shadow") ) outside_shadow_padding = 2 outside_shadow_radious = 3 draw_shadow( cr, icon_x - outside_shadow_padding, icon_y - outside_shadow_padding, icon_width + outside_shadow_padding * 2, icon_height + outside_shadow_padding * 2, outside_shadow_radious, app_theme.get_shadow_color("window_shadow") ) # Draw wallpaper. draw_pixbuf(cr, self.icon_pixbuf, icon_x, icon_y) rect.x = icon_x + self.icon_pixbuf.get_width() + self.info_padding_x rect.width -= self.info_padding_x * 2 - self.icon_pixbuf.get_width() _width, _height = get_content_size(self.image_object.get_display_name()) draw_text(cr, "<b>%s</b>" % self.image_object.get_display_name(), rect.x, icon_y, rect.width, _height, text_size=10) rect.y = icon_y + icon_width - _height _width, _height = get_content_size(self.status_text) draw_text(cr, self.status_text, rect.x, rect.y, rect.width, _height)
def on_panel_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation draw_line(cr, (rect.x, rect.y + 1), (rect.x + rect.width, rect.y + 1), "#c7c7c7") draw_line(cr, (rect.x + rect.width, rect.y), (rect.x + rect.width, rect.y + rect.height), "#c7c7c7") draw_line(cr, (rect.x, rect.y + rect.height), (rect.x + rect.width, rect.y + rect.height), "#c7c7c7") draw_line(cr, (rect.x + 1, rect.y), (rect.x + 1, rect.y + rect.height), "#c7c7c7") tx = rect.x + self.padding_x ty = rect.y + self.padding_y tw = rect.width - self.padding_x * 2 intro = self.channel_info.get("intro", "").strip() intro = utils.xmlescape(intro) if intro: intro_text = "<b>%s:</b> %s" % ("简介", intro) intro_tw, intro_th = get_content_size(intro_text, wrap_width=tw,text_size=9) if intro_th > self.line_height * 2: intro_th = self.line_height * 2 cr.save() cr.rectangle(tx, ty, intro_tw, intro_th) cr.clip() draw_text(cr, intro_text, tx, ty, intro_tw, intro_th, text_size=9, text_color="#878787", wrap_width=tw) cr.restore() with cairo_disable_antialias(cr): cr.save() cr.move_to(tx, ty + intro_th + self.line_height) cr.rel_line_to(tw, 0) cr.set_dash([2.0, 2.0]) cr.stroke() cr.restore() hotsongs = " / ".join(self.channel_info.get("hot_songs", [])).strip() hotsongs = utils.xmlescape(hotsongs) hotsongs_text = "<b>%s:</b> %s" % ("热门歌曲", hotsongs) if intro: new_ty = ty + intro_th + self.line_height * 2 else: new_ty = ty hotsongs_tw, hotsongs_th = get_content_size(hotsongs_text, wrap_width=tw,text_size=9) if hotsongs_th > self.line_height * 2: hotsongs_th = self.line_height * 2 cr.save() cr.rectangle(tx, new_ty, hotsongs_tw, hotsongs_th) cr.clip() draw_text(cr, hotsongs_text, tx, new_ty, hotsongs_tw, hotsongs_th, text_size=9, text_color="#878787", wrap_width=tw) return True
def update(self, lrc_list): self.__url = lrc_list[2] self.title = lrc_list[1] self.artist = lrc_list[0] self.netcode = lrc_list[3] # Calculate item size. self.title_padding_x = 10 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.artist_padding_x = 10 self.artist_padding_y = 5 (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE)
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation rect.x += self.padding_x rect.width -= self.padding_x * 2 # Draw title. # _width, _height = get_content_size(self.title) # draw_text(cr, self.title, rect.x, rect.y, rect.width, _height) # rect.y += self.padding_y + _height # Draw dashed. dash_line_width = 1 with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo("#D6D6D6")) cr.set_line_width(dash_line_width) cr.set_dash([4.0, 4.0]) cr.move_to(rect.x, rect.y) cr.rel_line_to(rect.width, 0) cr.stroke() rect.y += self.padding_y + dash_line_width # Draw plugin name. if self.plugin_info: plugin_name = "%s: %s" % ( _("Name"), utils.xmlescape(self.plugin_info.get("Name", ""))) _width, _height = get_content_size(plugin_name) draw_text(cr, plugin_name, rect.x, rect.y, rect.width, _height) rect.y += self.padding_y + _height # Draw plugin Authors. plugin_authors = plugin_authors = "%s: %s" % ( _("Author(s)"), utils.xmlescape(self.plugin_info.get("Authors", ""))) _width, _height = get_content_size(plugin_authors) draw_text(cr, plugin_authors, rect.x, rect.y, rect.width, _height) rect.y += self.padding_y + _height # Draw plugin description plugin_description = self.plugin_info.get("Description", "") _width, _height = get_content_size(plugin_description) draw_text(cr, plugin_description, rect.x, rect.y, rect.width, _height) return True
def render_info(self, cr, rect): if self.is_hover: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHover") if self.icon_pixbuf is None: self.icon_pixbuf = cache_manager.get_small_pixbuf( self.image_object, 37, 38) icon_width = self.icon_pixbuf.get_width() icon_height = self.icon_pixbuf.get_height() icon_x = rect.x + self.info_padding_x icon_y = rect.y + (rect.height - icon_height) / 2 # Draw shadow. drop_shadow_padding = 3 drop_shadow_radious = 3 draw_shadow(cr, icon_x, icon_y, icon_width + drop_shadow_padding, icon_height + drop_shadow_padding, drop_shadow_radious, app_theme.get_shadow_color("window_shadow")) outside_shadow_padding = 2 outside_shadow_radious = 3 draw_shadow(cr, icon_x - outside_shadow_padding, icon_y - outside_shadow_padding, icon_width + outside_shadow_padding * 2, icon_height + outside_shadow_padding * 2, outside_shadow_radious, app_theme.get_shadow_color("window_shadow")) # Draw wallpaper. draw_pixbuf(cr, self.icon_pixbuf, icon_x, icon_y) rect.x = icon_x + self.icon_pixbuf.get_width() + self.info_padding_x rect.width -= self.info_padding_x * 2 - self.icon_pixbuf.get_width() _width, _height = get_content_size( self.image_object.get_display_name()) draw_text(cr, "<b>%s</b>" % self.image_object.get_display_name(), rect.x, icon_y, rect.width, _height, text_size=10) rect.y = icon_y + icon_width - _height _width, _height = get_content_size(self.status_text) draw_text(cr, self.status_text, rect.x, rect.y, rect.width, _height)
def update_size(self): self.channel_name = utils.xmlescape(self.channel_info.get("name", "")) __, self.name_h = get_content_size(self.channel_name, text_size=9) self.detail_info = "%s首歌曲 %s制作" % ( self.channel_info.get("song_num"), utils.xmlescape( self.channel_info.get("creator", {}).get("name", ""))) __, self.detail_h = get_content_size(self.detail_info, text_size=8) intro = utils.xmlescape(self.channel_info.get("intro", "").strip()) hotsongs = utils.xmlescape(" ".join( self.channel_info.get("hot_songs"))) self.channel_intro = intro or hotsongs __, self.intro_h = get_content_size(self.channel_intro, text_size=8)
def __init__(self, tab_index, tab_name, active_flag): ''' init docs ''' # Init. gtk.Button.__init__(self) self.tab_index = tab_index self.tab_name = tab_name self.tab_name_size = 10 self.tab_padding_x = 10 self.tab_padding_y = 0 (self.tab_name_width, self.tab_name_height) = get_content_size(self.tab_name) self.tab_width = self.tab_name_width + self.tab_padding_x * 2 self.tab_height = self.tab_name_height + self.tab_padding_y * 2 self.active_flag = active_flag self.set_size_request(self.tab_width, RANK_TAB_HEIGHT) self.connect("expose-event", self.expose_rank_tab) self.connect("motion-notify-event", self.motion_rank_tab) self.connect("clicked", self.button_press_rank_tab) self.connect("leave-notify-event", self.leave_rank_tab) global_event.register_event("click-rank-tab", self.click_rank_tab)
def render_app(self, cr, rect): app_name = str_mark_down(self.item.name) self.render_background(cr, rect) # Draw Text (text_width, text_height) = get_content_size(app_name) rect.x += self.padding_x rect.width -= self.padding_x * 2 if self.item.type == self.item.TYPE_SYS: draw_text(cr, app_name, rect.x, rect.y, rect.width, rect.height, text_color=self.TYPE_SYS_COLOR, alignment=pango.ALIGN_LEFT) else: draw_text(cr, app_name, rect.x, rect.y, rect.width, rect.height, alignment=pango.ALIGN_LEFT)
def render_exec(self, cr, rect): exec_ = self.item.exec_ self.render_background(cr, rect) rect.x += self.padding_x rect.width -= self.padding_x * 2 if exec_: text_to_draw = exec_ else: text_to_draw = _("No exec") (text_width, text_height) = get_content_size(text_to_draw) if self.item.type == self.item.TYPE_SYS: draw_text(cr, text_to_draw, rect.x, rect.y, rect.width, rect.height, text_color=self.TYPE_SYS_COLOR, alignment=pango.ALIGN_LEFT) else: draw_text(cr, text_to_draw, rect.x, rect.y, rect.width, rect.height, alignment=pango.ALIGN_LEFT)
def draw_complie_show_text(self, cr, rect): text_index = 0 for text in self.message_text_list: offset_y = (text_index * self.draw_height) height = get_content_size(text)[1] + self.draw_height / 2 draw_text(cr, text, rect.x, rect.y + offset_y, rect.width, height) text_index += 1
def render_description(self, cr, rect): self.description = str_mark_down(self.item.comment) self.render_background(cr, rect) rect.x += self.padding_x rect.width -= self.padding_x * 2 if self.description: text_to_draw = self.description else: text_to_draw = _("No description") (text_width, text_height) = get_content_size(text_to_draw) if self.item.type == self.item.TYPE_SYS: draw_text(cr, text_to_draw, rect.x, rect.y, rect.width, rect.height, text_color=self.TYPE_SYS_COLOR, alignment=pango.ALIGN_LEFT) else: draw_text(cr, text_to_draw, rect.x, rect.y, rect.width, rect.height, alignment=pango.ALIGN_LEFT)
def render_essid(self, cr, rect): self.render_background(cr, rect) ssid = self.ssid.replace("&", "&").replace("<", "<").replace(">", ">") (text_width, text_height) = get_content_size(ssid) if self.active: text_color = "#3da1f7" else: text_color = "#000000" draw_text(cr, ssid, rect.x + ALIGN_SPACING, rect.y, rect.width, rect.height, alignment=pango.ALIGN_LEFT, text_color=text_color) if self.is_hover: with cairo_disable_antialias(cr): cr.set_source_rgb(*BORDER_COLOR) cr.set_line_width(1) #if self.is_last: #cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1) cr.rectangle(rect.x + 1, rect.y + 1, rect.width, rect.height - 1) cr.stroke()
def update_size(self): text_w, text_h = get_content_size(self.prompt_text, self.font_size) widget_w = text_w + self.padding_x * 2 if widget_w > self.max_width: widget_w = self.max_width self.set_size_request(widget_w, self.widget_h) self.queue_draw()
def __init__(self, normal_dpixbuf, hover_dpixbuf, press_dpixbuf, content=""): ''' Initialize ImageButton class. @param normal_dpixbuf: DynamicPixbuf for button normal status. @param hover_dpixbuf: DynamicPixbuf for button hover status. @param press_dpixbuf: DynamicPixbuf for button press status. ''' gtk.Button.__init__(self) self.cache_pixbuf = CachePixbuf() self.spacing = 5 self.content = content self.text_size = get_content_size(content) if self.text_size[1] > 68: self.text_size[1] = 68 self.image_width = self.request_width = normal_dpixbuf.get_pixbuf( ).get_width() self.image_height = self.request_height = normal_dpixbuf.get_pixbuf( ).get_height() if content: self.request_width = self.image_width + self.text_size[ 0] + self.spacing self.set_size_request(self.request_width, self.request_height) # Expose button. self.connect("expose-event", self.expose_button, self.cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf)
def __init__(self, normal_dpixbuf, hover_dpixbuf, press_dpixbuf, content=""): ''' Initialize ImageButton class. @param normal_dpixbuf: DynamicPixbuf for button normal status. @param hover_dpixbuf: DynamicPixbuf for button hover status. @param press_dpixbuf: DynamicPixbuf for button press status. ''' gtk.Button.__init__(self) self.cache_pixbuf = CachePixbuf() self.spacing = 5 self.content = content self.text_size = get_content_size(content) if self.text_size[1] > 68: self.text_size[1] = 68 self.image_width = self.request_width = normal_dpixbuf.get_pixbuf().get_width() self.image_height = self.request_height = normal_dpixbuf.get_pixbuf().get_height() if content: self.request_width = self.image_width + self.text_size[0] + self.spacing self.set_size_request(self.request_width, self.request_height) # Expose button. self.connect("expose-event", self.expose_button, self.cache_pixbuf, normal_dpixbuf, hover_dpixbuf, press_dpixbuf)
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation failed_pixbuf = self.failed_dpixbuf #draw_alpha_mask(cr, rect.x, rect.y, rect.width, rect.height, "layoutLeft") pixbuf_offset_x = (rect.width - failed_pixbuf.get_width()) / 2 pixbuf_offset_y = (rect.height - failed_pixbuf.get_height()) / 2 - 20 icon_x = rect.x + pixbuf_offset_x icon_y = rect.y + pixbuf_offset_y draw_pixbuf(cr, failed_pixbuf, icon_x, icon_y) text_y = icon_y + failed_pixbuf.get_height() + self.text_padding_y text_x = icon_x + self.text_padding_x _width, _height = dutils.get_content_size(self.prompt_text) self.text_rect = gtk.gdk.Rectangle( text_x - rect.x, text_y - rect.y, rect.x + rect.width - text_x - pixbuf_offset_x, _height) if self.is_hover: text_color = self.hover_text_dcolor.get_color() else: text_color = self.normal_text_dcolor.get_color() draw_text(cr, self.prompt_text, text_x, text_y, self.text_rect.width, _height, text_color=text_color, underline=True, alignment=pango.ALIGN_CENTER) return True
def change_text(self, text): self.text = text self.draw_text = text size = dutils.get_content_size(self.text + "." * self.total_dot_number, self.text_size) self.set_size_request(*size) self.dot_number = 0 self.queue_draw()
def __init__(self, tab_names): ''' init docs ''' gtk.EventBox.__init__(self) self.set_visible_window(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.tab_names = tab_names self.tab_name_size = 10 self.tab_number = len(self.tab_names) tab_sizes = map(lambda tab_name: get_content_size(tab_name, self.tab_name_size), self.tab_names) self.tab_name_padding_x = 10 self.tab_name_padding_y = 2 self.tab_width = max(map(lambda (width, height): width, tab_sizes)) + self.tab_name_padding_x * 2 self.tab_height = tab_sizes[0][1] + self.tab_name_padding_y * 2 self.tab_line_height = 1 self.tab_index = 0 self.tab_animation_x = 0 self.tab_animation_time = 200 # milliseconds self.padding_x = 0 self.padding_y = 15 self.in_animiation = False self.set_size_request(-1, self.tab_height + self.tab_line_height) self.line_dcolor = app_theme.get_color("globalItemHighlight") self.connect("expose-event", self.expose_tab_switcher) self.connect("button-press-event", self.button_press_tab_switcher)
def is_in_name_area(self, x, y): (text_width, text_height) = get_content_size(self.alias_name, text_size=NAME_SIZE) return is_in_rect( (x, y), (self.DRAW_PADDING_LEFT + self.pkg_icon_width + self.DRAW_INFO_PADDING_X, self.DRAW_PADDING_Y, text_width, NAME_SIZE))
def render_content(self, cr, rect): (text_width, text_height) = get_content_size(self.html_escape(self.content)) render_background(self, cr, rect) if self.show_arrow: if self.is_expand: draw_pixbuf(cr, self.arrow_down.get_pixbuf(), rect.x + 5, rect.y + (rect.height - self.arrow_height) / 2) else: draw_pixbuf(cr, self.arrow_right.get_pixbuf(), rect.x + 5, rect.y + (rect.height - self.arrow_height) / 2) if self.is_select: text_color = "#ffffff" else: text_color = "#000000" content = gettext.gettext(self.content) draw_text(cr, self.html_escape(content), rect.x + IMG_WIDTH + 10, rect.y, rect.width, rect.height, alignment=pango.ALIGN_LEFT, text_color=text_color)
def __init__(self, items): ''' init docs ''' gtk.EventBox.__init__(self) self.set_visible_window(False) self.add_events(gtk.gdk.ALL_EVENTS_MASK) self.items = items self.tab_name_size = 10 self.tab_number = len(self.items) tab_sizes = map( lambda item: get_content_size(item.title, self.tab_name_size), self.items) self.tab_name_padding_x = 10 self.tab_name_padding_y = 2 self.tab_width = max(map(lambda (width, height): width, tab_sizes)) + self.tab_name_padding_x * 2 self.tab_height = tab_sizes[0][1] + self.tab_name_padding_y * 2 self.tab_line_height = 1 self.tab_index = 0 self.tab_animation_x = 0 self.tab_animation_time = 200 # milliseconds self.padding_x = 0 self.padding_y = 15 self.in_animiation = False self.set_size_request(-1, self.tab_height + self.tab_line_height) self.line_dcolor = app_theme.get_color("globalItemHighlight") self.connect("expose-event", self.expose_tab_switcher) self.connect("button-press-event", self.button_press_tab_switcher)
def is_in_name_area(self, x, y): (name_width, name_height) = get_content_size(self.alias_name, DEFAULT_FONT_SIZE) return is_in_rect((x, y), (0, self.icon_padding_y + self.icon_pixbuf.get_height() + self.name_padding_y, name_width, name_height))
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation failed_pixbuf = self.failed_dpixbuf.get_pixbuf() draw_alpha_mask(cr, rect.x, rect.y, rect.width, rect.height, "layoutLeft") pixbuf_offset_x = (rect.width - failed_pixbuf.get_width()) / 2 pixbuf_offset_y = (rect.height - failed_pixbuf.get_height()) / 2 - 50 icon_x = rect.x + pixbuf_offset_x icon_y = rect.y + pixbuf_offset_y draw_pixbuf(cr, failed_pixbuf, icon_x, icon_y) text_y = icon_y + failed_pixbuf.get_height() + self.text_padding_y text_x = icon_x + self.text_padding_x _width, _height = get_content_size(self.prompt_text) self.text_rect = gtk.gdk.Rectangle(text_x - rect.x, text_y - rect.y, rect.x + rect.width - text_x - pixbuf_offset_x, _height) if self.is_hover: text_color = self.hover_text_dcolor.get_color() else: text_color = self.normal_text_dcolor.get_color() draw_text(cr, self.prompt_text, text_x, text_y, self.text_rect.width, _height, text_color=text_color, underline=True, alignment=pango.ALIGN_CENTER) return True
def is_in_name_area(self, x, y): (text_width, text_height) = get_content_size(self.alias_name, text_size=NAME_SIZE) return is_in_rect((x, y), (self.DRAW_PADDING_LEFT + self.pkg_icon_width + self.DRAW_INFO_PADDING_X, self.DRAW_PADDING_Y, text_width, NAME_SIZE))
def is_in_name_area(self, column, offset_x, offset_y): (name_width, name_height) = get_content_size(self.alias_name, NAME_SIZE) return (column == 0 and is_in_rect( (offset_x, offset_y), (ITEM_PADDING_X + ITEM_PKG_OFFSET_X + ICON_SIZE + ITEM_PADDING_MIDDLE, ITEM_PADDING_Y, name_width, NAME_SIZE)))
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation rect.x += self.padding_x rect.width -= self.padding_x * 2 # Draw title. # _width, _height = get_content_size(self.title) # draw_text(cr, self.title, rect.x, rect.y, rect.width, _height) # rect.y += self.padding_y + _height # Draw dashed. dash_line_width = 1 with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo("#D6D6D6")) cr.set_line_width(dash_line_width) cr.set_dash([4.0, 4.0]) cr.move_to(rect.x, rect.y) cr.rel_line_to(rect.width, 0) cr.stroke() rect.y += self.padding_y + dash_line_width # Draw plugin name. if self.plugin_info: plugin_name = "%s: %s" % (_("Add-on"), utils.xmlescape(self.plugin_info.get("Name", ""))) _width, _height = get_content_size(plugin_name) draw_text(cr, plugin_name, rect.x, rect.y, rect.width, _height) rect.y += self.padding_y + _height # Draw plugin Authors. plugin_authors = plugin_authors = "%s: %s" % (_("Author(s)"), utils.xmlescape(self.plugin_info.get("Authors", ""))) _width, _height = get_content_size(plugin_authors) draw_text(cr, plugin_authors, rect.x, rect.y, rect.width, _height) rect.y += self.padding_y + _height # Draw plugin description plugin_description = self.plugin_info.get("Description", "") _width, _height = get_content_size(plugin_description) draw_text(cr, plugin_description, rect.x, rect.y, rect.width, _height) return True
def is_in_name_area(self, column, offset_x, offset_y): (name_with, name_height) = get_content_size(self.pkg_title, self.TITLE_SIZE) return (column == 1 and is_in_rect((offset_x, offset_y), (0, self.PICTURE_PADDING_Y, name_with, name_height)))
def expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.child.allocation width, height = get_content_size(self.label_name) cr.set_source_rgb( *color_hex_to_cairo(ui_theme.get_color("link_text").get_color())) draw_line(cr, rect.x, rect.y + rect.height, rect.x + width, rect.y + rect.height)
def is_in_name_area(self, column, offset_x, offset_y): (name_width, name_height) = get_content_size(self.alias_name, NAME_SIZE) return (column == 0 and is_in_rect((offset_x, offset_y), (ITEM_PADDING_X + ITEM_PKG_OFFSET_X + ICON_SIZE + ITEM_PADDING_MIDDLE, ITEM_PADDING_Y, name_width, NAME_SIZE)))
def update(self, lrc_list): self.__url = lrc_list[2] self.title = utils.xmlescape(lrc_list[1]) self.artist = utils.xmlescape(lrc_list[0]) if len(lrc_list) > 3: self.netcode = lrc_list[3] else: self.netcode = "utf-8" # Calculate item size. self.title_padding_x = 10 self.title_padding_y = 5 (self.title_width, self.title_height) = get_content_size(self.title, DEFAULT_FONT_SIZE) self.artist_padding_x = 10 self.artist_padding_y = 5 (self.artist_width, self.artist_height) = get_content_size(self.artist, DEFAULT_FONT_SIZE)
def update_size(self): if not self.prompt_pixbuf: return pixbuf_w = self.prompt_pixbuf.get_width() text_w, text_h = get_content_size(self.prompt_text, self.font_size) widget_w = pixbuf_w + text_w + self.padding_x * 3 if widget_w > self.max_width: widget_w = self.max_width self.set_size_request(widget_w, self.widget_h) self.queue_draw()
def set_content(self, content): self.content = content self.resize(1, 1) self.text_size = get_content_size(self.content, self.font_size) self.width, self.height = (self.text_size[0] + 26, self.text_size[1] + 18 + self.arrow_height) self.set_geometry_hints(None, self.width, self.height, self.width, self.height, \ -1, -1, -1, -1, -1, -1) self.offset = (self.width - self.arrow_width) / 2 self.queue_draw()
def repack_items(self): self.tab_number = len(self.items) tab_sizes = map( lambda item: get_content_size(item.title, self.tab_name_size), self.items) self.tab_width = max(map(lambda (width, height): width, tab_sizes)) + self.tab_name_padding_x * 2 self.tab_height = tab_sizes[0][1] + self.tab_name_padding_y * 2 self.set_size_request(-1, self.tab_height + self.tab_line_height)
def show_image_text(self, text, image_path): self.content = text self.text_size = get_content_size(self.content, self.font_size) self.pixbuf = utils.get_common_image_pixbuf(image_path) self.width, self.height = 140, 78 self.offset = (self.width - self.arrow_width) / 2 self.set_geometry_hints(None, self.width, self.height, self.width, self.height, \ -1, -1, -1, -1, -1, -1) self.queue_draw()
def on_expose_event(self, widget, event): cr = widget.window.cairo_create() rect = widget.allocation rect.x += self.padding_x rect.width -= self.padding_x * 2 keyword_span = self.red_span % self.keyword from_keyword_span = self.black_span % self.from_keyword from_keyword_dict = {"keyword" : keyword_span, "from" : from_keyword_span} self.prompt_text = self.prompt_format_text.format(**from_keyword_dict) _width, _height = get_content_size(self.prompt_text) draw_text(cr, self.prompt_text, rect.x, rect.y, rect.width, _height, text_color=app_theme.get_color("labelText").get_color()) # draw dash rect.y += _height + self.padding_y dash_line_width = 1 with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo("#D6D6D6")) cr.set_line_width(dash_line_width) cr.set_dash([4.0, 4.0]) cr.move_to(rect.x, rect.y) cr.rel_line_to(rect.width, 0) cr.stroke() rect.y += self.padding_y + dash_line_width _width, _height = get_content_size(self.suggest_title) draw_text(cr, self.suggest_title, rect.x, rect.y, rect.width, _height) rect.y += _height + self.padding_y _width, _height = get_content_size(self.suggest_first_line) draw_text(cr, self.suggest_first_line, rect.x, rect.y, rect.width, _height, text_color=app_theme.get_color("labelText").get_color()) rect.y += _height + self.padding_y _width, _height = get_content_size(self.suggest_second_line) draw_text(cr, self.suggest_second_line, rect.x, rect.y, rect.width, _height, text_color=app_theme.get_color("labelText").get_color()) return True
def draw_complie_show_text(self, cr, rect): text_index = 0 for text in self.message_text_list: offset_y = (text_index * self.draw_height) height = get_content_size(text)[1] + self.draw_height /2 draw_text(cr, text, rect.x, rect.y + offset_y, rect.width, height ) text_index += 1
def render_title(self, cr, rect): # Draw select background. rect.width -= 2 if not self.is_parent: if self.is_highlight: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemSelect") elif self.is_hover: draw_single_mask(cr, rect.x, rect.y, rect.width, rect.height, "globalItemHover") if self.is_highlight: text_color = "#FFFFFF" else: text_color = "#000000" else: text_color = "#000000" # draw arrow and blacklist icon left_pixbuf_width = 18 if not self.is_parent: rect.x += self.child_offset rect.width -= self.child_offset if self.is_in_blacklist: if self.is_highlight: pixbuf = pixbuf_blacklist_white else: pixbuf = pixbuf_blacklist_grey else: pixbuf = None if pixbuf: draw_pixbuf(cr, pixbuf, rect.x + self.draw_padding_x, rect.y + 5) else: left_pixbuf_width = 0 if self.is_expand: pixbuf = pixbuf_arrow_down else: pixbuf = pixbuf_arrow_right content_width, content_height = get_content_size(self.title) draw_pixbuf(cr, pixbuf, rect.x + content_width + 20, rect.y + 10) draw_text(cr, " " + self.title, rect.x + self.draw_padding_x + left_pixbuf_width, rect.y, rect.width - self.draw_padding_x * 2, rect.height, text_color = text_color, alignment=pango.ALIGN_LEFT)
def render_info(self, cr ,rect): self.render_background(cr, rect) (text_width, text_height) = get_content_size(self.info) draw_text(cr, self.info, rect.x, rect.y, rect.width, rect.height, alignment = pango.ALIGN_LEFT) with cairo_disable_antialias(cr): cr.set_source_rgb(*color_hex_to_cairo(self.border_color)) cr.set_line_width(1) if self.is_last: cr.rectangle(rect.x, rect.y + rect.height -1, rect.width, 1) cr.rectangle(rect.x, rect.y, rect.width, 1) cr.fill()
def render_pkg_status(self, cr, rect): if self.row_index % 2 == 1: cr.set_source_rgba(1, 1, 1, 0.5) cr.rectangle(rect.x, rect.y, rect.width, rect.height) cr.fill() # Render star. self.star_buffer.render(cr, gtk.gdk.Rectangle(rect.x, rect.y, ITEM_STAR_AREA_WIDTH, ITEM_HEIGHT)) # Draw button. name = "" draw_str = "" if self.install_status == "uninstalled": name = "button/install_small" elif self.install_status == "unknown": draw_str = _("Not found") else: desktops = json.loads(self.install_status) if desktops: name = "button/start_small" self.desktops = self.data_manager.get_pkg_desktop_info(desktops) else: draw_str = _("Installed") # Render button. if name: if self.button_status == BUTTON_NORMAL: status = "normal" elif self.button_status == BUTTON_HOVER: status = "hover" elif self.button_status == BUTTON_PRESS: status = "press" pixbuf = app_theme.get_pixbuf("%s_%s.png" % (name, status)).get_pixbuf() draw_pixbuf( cr, pixbuf, rect.x + rect.width - ITEM_BUTTON_PADDING_RIGHT - pixbuf.get_width(), rect.y + (rect.height - pixbuf.get_height()) / 2 ) else: str_width, str_height = get_content_size(draw_str, 10) draw_text( cr, draw_str, rect.x + rect.width - ITEM_BUTTON_PADDING_RIGHT - str_width, rect.y + (rect.height - str_height) / 2, rect.width, str_height, wrap_width=rect.width )
def __init__(self, text, text_size=10, text_color="#003399"): gtk.VBox.__init__(self) self.text = text self.draw_text = self.text self.text_size = text_size self.text_color = text_color size = dutils.get_content_size(self.text + "." * self.total_dot_number, text_size) self.set_size_request(*size) self.dot_number = 0 self.connect("expose-event", self.on_expose_event) gtk.timeout_add(600, self.loading_loop)
def __update(self): self.title = self.trans_data["song"].get_str("title") self.status_icon_padding_x = 10 self.status_icon_padding_y = 5 self.status_icon_w, self.status_icon_h = (self.status_icon.get_width(), self.status_icon.get_height()) self.title_padding_x = 5 self.title_padding_y = 5 self.title_w, self.title_h = get_content_size(self.title, DEFAULT_FONT_SIZE) self.progress_padding_x = 10 self.progress_padding_y = 5 self.progress_w, self.progress_h = 100, 10 self.stop_icon_padding_x = 5 self.stop_icon_padding_y = 5 self.stop_icon_w, self.stop_icon_h = (self.stop_icon.get_width(), self.stop_icon.get_height()) self.ext_padding_x = 5 self.ext_padding_y = 5 self.ext_w, self.ext_h = get_content_size(self.output_ext, DEFAULT_FONT_SIZE)
def init_size(self): tw = self.default_width - self.padding_x * 2 intro = self.channel_info.get("intro", "").strip() intro = utils.xmlescape(intro) intro_text = "<b>%s:</b> %s" % ("简介", intro) intro_th = 0 if intro: intro_tw, intro_th = get_content_size(intro_text, wrap_width=tw,text_size=9) if intro_th > self.line_height * 2: intro_th = self.line_height * 2 hotsongs = " / ".join(self.channel_info.get("hot_songs", [])).strip() hotsongs = utils.xmlescape(hotsongs) hotsongs_text = "<b>%s:</b> %s" % ("热门歌曲", hotsongs) hotsongs_tw, hotsongs_th = get_content_size(hotsongs_text, wrap_width=tw,text_size=9) if hotsongs_th > self.line_height * 2: hotsongs_th = self.line_height * 2 if intro_th == 0: height = hotsongs_th + self.line_height * 2 else: height = hotsongs_th + intro_th + self.line_height * 4 self.set_size_request(self.default_width, height)