ocarina/trunk/src/image.py

34 lines
783 B
Python

import gtk
class Image(gtk.Image):
def __init__(self,path,stock):
gtk.Image.__init__(self)
self.file = None
if path:
self.file = path
self.set_from_file(path)
self.pixbuf = self.get_pixbuf()
elif stock:
self.set_from_stock(stock,gtk.ICON_SIZE_SMALL_TOOLBAR)
self.show()
# Set image from a file
def set(self,file):
self.file = file
self.pixbuf = gtk.gdk.pixbuf_new_from_file(file)
self.set_from_pixbuf(self.pixbuf)
# Scale the image
def scale(self,divider):
if self.file:
self.set(self.file)
w = self.pixbuf.get_width()
h = self.pixbuf.get_height()
# w * scale = divider
scale = divider / float(w)
self.pixbuf = self.pixbuf.scale_simple(int(w*scale),int(h*scale),gtk.gdk.INTERP_BILINEAR)
self.set_from_pixbuf(self.pixbuf)