def clone_image(self, image): storage = image.get_storage_type() if storage == gtk.IMAGE_PIXMAP: img, mask = image.get_pixmap() return gtk.image_new_from_pixmap(img, mask) if storage == gtk.IMAGE_IMAGE: img, mask = image.get_image() return gtk.image_new_from_image(img, mask) if storage == gtk.IMAGE_PIXBUF: return gtk.image_new_from_pixbuf(image.get_pixbuf()) if storage == gtk.IMAGE_STOCK: img, size = image.get_stock() return gtk.image_new_from_stock(img, size) if storage == gtk.IMAGE_ICON_SET: img, size = image.get_icon_set() return gtk.image_new_from_icon_set(img, size) if storage == gtk.IMAGE_ANIMATION: return gtk.image_new_from_animation(image.get_animation()) if storage == gtk.IMAGE_ICON_NAME: img, size = image.get_icon_name() return gtk.image_new_from_icon_name(img, size) # if storage == gtk.IMAGE_EMPTY: img = gtk.Image() img.set_from_stock(gtk.STOCK_NEW, gtk.ICON_SIZE_MENU) return img
def draw_unread_count(self, count): # Copy unread base indicator to new pixmap pixmap, mask = self.unreadBase.render_pixmap_and_mask() # Drawing steps cr = pixmap.cairo_create() cr.set_source_rgb(1, 1, 1) cr.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) x_bearing, y_bearing, width, height = cr.text_extents(str(count))[:4] # use these to fake right-justify # The drawing position (specified by move_to) defines the left end of the baseline. # x_bearing and y_bearing define the position of the upper-left corner of the bounding box # relative to the baseline point (drawing position) cr.move_to(21 - width, 11) print(x_bearing, y_bearing, width, height) cr.show_text(str(count)) # Convert to Image final = gtk.image_new_from_pixmap(pixmap, mask) final.show() return final
def __reload (self, pixbuf): child = self.get_child () if child is not None: self.remove (child) drawable, mask = pixbuf.render_pixmap_and_mask() textLay = self.create_pango_layout('') textLay.set_markup ('<span color="%s" size="%s">%s</span>' % (self.text_color, self.size, self.text)) text_w, text_h = textLay.get_pixel_size() dw_w, dw_h = drawable.get_size () if self.centered: x = dw_w/2 - text_w/2 y = dw_h/2 - text_h/2 else: x = 10 y = dw_h/2 - text_h/2 drawable.draw_layout(drawable.new_gc(), x, y, textLay, None, None) self.image = gtk.image_new_from_pixmap(drawable, mask) self.add (self.image) self.show_all()
def __reload(self, pixbuf): child = self.get_child() if child is not None: self.remove(child) drawable, mask = pixbuf.render_pixmap_and_mask() textLay = self.create_pango_layout('') textLay.set_markup('<span color="%s" size="%s">%s</span>' % (self.text_color, self.size, self.text)) text_w, text_h = textLay.get_pixel_size() dw_w, dw_h = drawable.get_size() if self.centered: x = dw_w / 2 - text_w / 2 y = dw_h / 2 - text_h / 2 else: x = 10 y = dw_h / 2 - text_h / 2 drawable.draw_layout(drawable.new_gc(), x, y, textLay, None, None) self.image = gtk.image_new_from_pixmap(drawable, mask) self.add(self.image) self.show_all()
def set_from_pixmap(self, pixmap, mask): """Load image from gtk.gdk.Pixmap.""" image = gtk.image_new_from_pixmap(pixmap, mask) self.set_from_pixbuf(image.get_pixbuf())
def __init__(self): gtksheet.Sheet.__init__(self, 1000, 26) self.set_background(gdk.color_parse("light yellow")) self.set_grid(gdk.color_parse("light blue")) for column in xrange(self.get_columns_count()): name = chr(ord("A") + column) self.column_button_add_label(column, name) self.set_column_title(column, name) self.row_button_add_label(0, "This is\na multiline\nlabel") self.row_button_add_label(1, "This is long label") self.row_button_justify(0, gtk.JUSTIFY_RIGHT) range = gtksheet.SheetRange(1,1,2,3) self.clip_range(range) self.range_set_font(range, pango.FontDescription("Arial 28")) self.range_set_foreground(range, gdk.color_parse("red")) self.set_cell(1,2, gtk.JUSTIFY_CENTER, "Welcome to") range.row0 = 2 self.range_set_font(range, pango.FontDescription("Arial 36")) self.range_set_foreground(range, gdk.color_parse("blue")) self.set_cell(2,2, gtk.JUSTIFY_CENTER, "python-gtksheet") range = gtksheet.SheetRange(3,0,3,4) self.range_set_background(range, gdk.color_parse("dark gray")) self.range_set_foreground(range, gdk.color_parse("green")) self.set_cell(3, 2, gtk.JUSTIFY_CENTER, "a Matrix widget for Gtk+") texts =["GtkSheet is a matrix where you can allocate cells of text.", "Cell contents can be edited interactively with an specially designed entry", "You can change colors, borders, and many other attributes", "Drag & drop or resize the selection clicking the corner or border", "Store the selection on the clipboard pressing Ctrl-C", "You can add buttons, charts, pixmaps, and other widgets"] for i in xrange(len(texts)): self.set_cell(i+4, 1, gtk.JUSTIFY_LEFT, texts[i]) colormap = gdk.colormap_get_system() pixmap, mask = gdk.pixmap_colormap_create_from_xpm_d(None, colormap, None, bullet_xpm) for i in xrange(6): image = gtk.image_new_from_pixmap(pixmap, mask) image.show() self.attach( image, 4+i, 0, gtk.EXPAND, gtk.EXPAND, 0, 0) pixmap, mask = gdk.pixmap_colormap_create_from_xpm_d(None, colormap, None, smile_xpm) self.button_attach( gtk.image_new_from_pixmap(pixmap, mask), -1, 5) self.curve = gtk.Curve() self.curve.show() self.curve.set_range(0, 200, 0, 200) show_button = gtk.Button("Show me a plot") show_button.show() show_button.set_size_request(100, 60) self.attach(show_button, 12, 2, gtk.FILL, gtk.FILL, 5, 5) show_button.connect("clicked", self._show_child_cb) self.connect("key_press_event", self._key_press_cb)