def add_pango_attributes(self, attrs, start_index, end_index): """Insert attributes for this StyleSpec into a pango.AttrList. Not every property of StyleSpec maps into a pango.Attribute - the ones that don't map are ignored and need to be handled separately. @param attrs: pango.AttrList to insert attributes into. @param start_index: byte offset of the start of the range this spec applies to @param end_index: byte offset of the ned of the range this spec applies to """ if self.family is not None: attrs.insert(pango.AttrFamily(self.family, start_index, end_index)) if self.foreground is not None: color = pango.Color(self.foreground) attrs.insert( pango.AttrForeground(color.red, color.green, color.blue, start_index, end_index)) if self.style is not None: attrs.insert(pango.AttrStyle(self.style, start_index, end_index)) if self.underline is not None: attrs.insert( pango.AttrUnderline(self.underline, start_index, end_index)) if self.weight is not None: attrs.insert(pango.AttrWeight(self.weight, start_index, end_index)) if self.weight is not None: attrs.insert(pango.AttrWeight(self.weight, start_index, end_index))
def override_font_attributes(self, attr, text): window_width, window_height = self.get_size() lines = text.count('\n') + 1 attr.insert( pango.AttrSizeAbsolute((50 * window_height // lines // 100) * 1000, 0, -1)) attr.insert(pango.AttrFamily(self.font.get_family(), 0, -1)) attr.insert(pango.AttrWeight(self.font.get_weight(), 0, -1))
def __init__(self): gtk.EventBox.__init__(self) self.label = gtk.Label() attrs = pango.AttrList() font_attr = pango.AttrFamily("monospace") attrs.insert(font_attr) self.label.set_attributes(attrs) self.add(self.label) self.connect("button-press-event", self.on_mouse) self.peak = fpconst.NegInf
def set_window_size(self, setting): """Set window and label size.""" window_width = self.screen_width window_height = -1 window_height = setting * self.screen_height / 100 attr = pango.AttrList() attr.change(pango.AttrSize((50 * window_height / 100) * 1000, 0, -1)) attr.change(pango.AttrFamily(self.options['font'], 0, -1)) attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)) attr.change(pango.AttrForeground(*self.options['color'])) self.label.set_attributes(attr) self.resize(window_width, window_height)
def set_window_size(self, setting): """Set window and label size.""" window_width = self.screen_width window_height = -1 if setting == SIZE_LARGE: window_height = 24 * self.screen_height / 100 if setting == SIZE_MEDIUM: window_height = 12 * self.screen_height / 100 if setting == SIZE_SMALL: window_height = 8 * self.screen_height / 100 attr = pango.AttrList() attr.change(pango.AttrSize((50 * window_height / 100) * 1000, 0, -1)) attr.change(pango.AttrFamily("Sans", 0, -1)) attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)) attr.change(pango.AttrForeground(65535, 65535, 65535, 0, -1)) self.label.set_attributes(attr) self.resize(window_width, window_height)
def _generate_thumb_with_text(self): """ Generate the text on the pixbuf """ # This technique is used to compose image with text # create a pixmap with the data of the pixbuf then insert text # cf. pygtk FAQ How do I draw a text [or something else] on a gtk.gdk.pixbuf? for mor explication # (http://faq.pygtk.org/index.py?req=show&file=faq08.020.htp ) pixmap, mask = self._pixbuf_thumb.render_pixmap_and_mask() # graphic context and Drawarea any created to allow generation of pixbuf composition gc = pixmap.new_gc() area = gtk.DrawingArea() # create pango layout self.pangolayout = area.create_pango_layout("") # extract only the image name without extenstion text_buffer, ext = os.path.splitext(self._name) text_buffer = " " + text_buffer + " " self.pangolayout.set_text(text_buffer) # set text attributes attrs = pango.AttrList() attrs.insert(pango.AttrFamily(LCONST.THUMB_TEXT_FAMILY, 0, -1)) attrs.insert(pango.AttrStyle(pango.STYLE_ITALIC, 0, -1)) attrs.insert( pango.AttrForeground(LCONST.THUMB_TEXT_COLOR[0], LCONST.THUMB_TEXT_COLOR[1], LCONST.THUMB_TEXT_COLOR[2], 0, -1)) attrs.insert(pango.AttrBackground(0, 0, 0, 0, -1)) attrs.insert(pango.AttrSize(LCONST.THUMB_TEXT_SIZE, 0, -1)) self.pangolayout.set_attributes(attrs) # compute text layout position and set it on pixmap (w, h) = (self._pixbuf_thumb.get_width(), self._pixbuf_thumb.get_height()) (lw, lh) = self.pangolayout.get_pixel_size() pixmap.draw_layout(gc, (w - lw) // 2, (h - lh - 2), self.pangolayout) # function get_from_drawable gets the the pixbuf from the pixmap # no need to affect resuly to a new pisbuf: self._pixbuf_thumb is changed whe get_from_drawable is used self._pixbuf_thumb.get_from_drawable(pixmap, pixmap.get_colormap(), 0, 0, 0, 0, -1, -1)
def on_configure(self, _, event): window_height = event.height attr = pango.AttrList() attr.change(pango.AttrSize(int(self.options['fontsize']) * 1000, 0, -1)) attr.change(pango.AttrFamily(self.options['font'], 0, -1)) attr.change(pango.AttrWeight(pango.WEIGHT_BOLD, 0, -1)) fgcolor = gtk.gdk.color_parse(self.fg) attr.change(pango.AttrForeground( fgcolor.red, fgcolor.green, fgcolor.blue, 0, -1)) self.pos_x = event.x self.pos_y = event.y if self.timer: self.timer.cancel() self.timer = Timer(self.options['timeout'], self.on_timeout) self.timer.start() self.label.set_attributes(attr)