def fetch_thumbnail(filename, size=Gst.get_int('thumbnail-size')): """Load a photo's thumbnail from disk, avoiding EXIF data if possible. >>> fetch_thumbnail('gg/widgets.py') Traceback (most recent call last): IOError: gg/widgets.py: The file contains data of an unknown image type >>> type(fetch_thumbnail('demo/IMG_2411.JPG')) <class 'gi.repository.GdkPixbuf.Pixbuf'> """ #TODO: The above IOError is raise by pyexiv2 in fetch_exif, # I need to find a file that pyexiv2 thinks is an image, but has # no thumbnail and thus raises IOError here anyway. try: return GdkPixbuf.Pixbuf.new_from_file_at_size(filename, size, size) except GObject.GError: exif = fetch_exif(filename) if len(exif.previews) > 0: data = exif.previews[-1].data elif len(exif.exif_thumbnail.data) > 0: data = exif.exif_thumbnail.data else: raise IOError('%s: No thumbnail found.' % filename) return GdkPixbuf.Pixbuf.new_from_stream_at_scale( Gio.MemoryInputStream.new_from_data(data, None), size, size, True, None)
def animate_in(anim=True): """Fade in all the map actors.""" for i in xrange(Gst.get_int('animation-steps') if anim else 1, 0, -1): for actor in (Crosshair, Box, Scale): actor.set_opacity(256 - i) Widgets.redraw_interface() sleep(0.01)