Package conduit :: Package datatypes :: Module Photo
[hide private]

Source Code for Module conduit.datatypes.Photo

 1  import conduit 
 2   
 3  import conduit.datatypes.File as File 
 4  import conduit.utils as Utils 
 5   
 6  PRESET_ENCODINGS = { 
 7      "jpeg":{'formats':'image/jpeg','default-format':'image/jpeg'}, 
 8      "png":{'formats':'image/png','default-format':'image/png'} 
 9      } 
10       
11 -def mimetype_is_photo(mimetype):
12 """ 13 @returns: True if the given mimetype string represents an image file 14 """ 15 if mimetype.startswith("image/"): 16 return True 17 else: 18 return False
19
20 -class Photo(File.File):
21 """ 22 A Small wrapper around a Pixbuf 23 """ 24 25 _name_ = "file/photo" 26
27 - def __init__(self, URI, **kwargs):
28 File.File.__init__(self, URI, **kwargs) 29 self.pb = None 30 self._caption = None
31
32 - def get_photo_pixbuf(self):
33 """ 34 Defer actually getting the pixbuf till as 35 late as possible, as it is really only needed for 36 conversion 37 """ 38 import gtk.gdk 39 if self.pb == None: 40 self.pb = gtk.gdk.pixbuf_new_from_file(self.get_local_uri()) 41 return self.pb
42
43 - def get_photo_size(self):
44 """ 45 Returns the pb size, width, height 46 """ 47 self.get_photo_pixbuf() 48 return self.pb.get_width(),self.pb.get_height()
49
50 - def get_caption(self):
51 """ 52 @returns: the photo's caption 53 """ 54 return self._caption
55
56 - def set_caption(self, caption):
57 self._caption = caption
58
59 - def get_hash(self):
60 # Combine the file hash with other photo metadata. 61 file_hash = File.File.get_hash(self) 62 hash_data = "%s%s%s" % (file_hash, self.get_photo_size(), 63 self.get_caption()) 64 return hash(hash_data)
65
66 - def __getstate__(self):
67 data = File.File.__getstate__(self) 68 data["caption"] = self._caption 69 return data
70
71 - def __setstate__(self, data):
72 self.pb = None 73 self._caption = data["caption"] 74 File.File.__setstate__(self, data)
75