#!/usr/bin/python import cairo import gtk class MirroredCover(gtk.DrawingArea): def __init__(self): gtk.DrawingArea.__init__(self) self.connect('realize', self.realize) self.connect('expose_event', self.expose) self.image = cairo.ImageSurface.create_from_png('cover.png') self.mirror_factor = 0.7 def realize(self, drawingarea): self.window.set_background(gtk.gdk.Color(0, 0, 0)) h = self.image.get_height() h = h + h * self.mirror_factor self.set_property('height_request', h) self.set_property('width_request', self.image.get_width()) def expose(self, drawingarea, event): cr = self.window.cairo_create() img_w = self.image.get_width() img_h = self.image.get_height() cr.set_source_surface(self.image) cr.rectangle(0, 0, img_w, img_h) cr.fill() mirror_m = cairo.Matrix(1, 0, 0, -self.mirror_factor, 0, img_h + self.mirror_factor*img_h) cr.transform(mirror_m) gradient = cairo.LinearGradient(0, 0, 0, img_h) gradient.add_color_stop_rgba(0, 0, 0, 0, 0) gradient.add_color_stop_rgba(1, 0, 0, 0, 0.3) cr.set_source_surface(self.image) cr.mask(gradient) cr.fill() def main(): win = gtk.Window() win.connect('destroy', gtk.main_quit) win.set_default_size(600, 700) win.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(0, 0, 0)) alignment = gtk.Alignment() alignment.set_property('xalign', 0.5) alignment.set_property('yalign', 0.5) cover = MirroredCover() alignment.add(cover) win.add(alignment) win.show_all() gtk.main() if __name__ == '__main__': main()