def next_photo(self, *_args): """Changes to the next photo.""" reload_config() croot = config.get('collection.dir') if not self.wallpaper_list: self.wallpaper_list = glob.glob( os.path.join(croot, '*', '*.jpg')) png_images = glob.glob( os.path.join(croot, '*', '*.png')) self.wallpaper_list.extend(png_images) random.shuffle(self.wallpaper_list) if self.wallpaper_list: self.last_rotate = time.time()-15 # to ensure next time... wallpaper = self.wallpaper_list.pop() image_file = os.path.join(croot, wallpaper) set_wallpaper(image_file) dirname, base = os.path.split(image_file) basename, _unused_ext = os.path.splitext(base) info_file = os.path.join(dirname, basename)+'.inf' try: fileobj = open(info_file, 'r') inf = parse_metadata(fileobj.read()) fileobj.close() except IOError: inf = {} self.image_file = image_file self.info_file = info_file title = inf.get('title', basename) album = inf.get('albumTitle', dirname) self.set_tooltip_for_photo('%s - %s' % (title, album))
def next_photo(self, *_args): """Changes to the next photo.""" reload_config() croot = config.get('collection.dir') if not self.wallpaper_list: self.wallpaper_list = glob.glob(os.path.join(croot, '*', '*.jpg')) png_images = glob.glob(os.path.join(croot, '*', '*.png')) self.wallpaper_list.extend(png_images) random.shuffle(self.wallpaper_list) if self.wallpaper_list: self.last_rotate = time.time() - 15 # to ensure next time... wallpaper = self.wallpaper_list.pop() image_file = os.path.join(croot, wallpaper) set_wallpaper(image_file) dirname, base = os.path.split(image_file) basename, _unused_ext = os.path.splitext(base) info_file = os.path.join(dirname, basename) + '.inf' try: fileobj = open(info_file, 'r') inf = parse_metadata(fileobj.read()) fileobj.close() except IOError: inf = {} self.image_file = image_file self.info_file = info_file title = inf.get('title', basename) album = inf.get('albumTitle', dirname) self.set_tooltip_for_photo('%s - %s' % (title, album))
def info_current(self, *_args): """Opens the photo properties window.""" import os, time, commands from webilder.webshots.wbz import parse_metadata from webilder.uitricks import UITricks, open_browser currentfile = commands.getoutput('/usr/bin/gconftool-2 -g /desktop/gnome/background/picture_filename') if self.image_file == currentfile: currentinfo = self.info_file try: fileobj = open(currentinfo, 'r') infodata = parse_metadata(fileobj.read()) fileobj.close() except IOError: infodata = {} else: import getpass wbtestpath = '/home/' + getpass.getuser() + '/.webilder/Collection/' wbtest = currentfile.startswith(wbtestpath) if wbtest == True: currentinfo = os.path.splitext(currentfile)[0] + '.inf' try: fileobj = open(currentinfo, 'r') infodata = parse_metadata(fileobj.read()) fileobj.close() except IOError: infodata = {} else: try: infodata = parse_metadata("url=--\ncredit=--\ntitle=--\ntags=--\nalbumTitle=--\n") except IOError: infodata = {} applet_win = UITricks('ui/webilder.glade', 'PhotoPropertiesDialog') applet_win.title.set_markup('<b>%s</b>' % infodata['title']) applet_win.album.set_markup(infodata['albumTitle']) applet_win.file.set_text(currentfile) applet_win.tags.set_text(infodata['tags']) applet_win.size.set_text(_('%.1f KB') % (os.path.getsize(currentfile) / 1024.0)) applet_win.date.set_text(time.strftime('%c', time.localtime(os.path.getctime(currentfile)))) applet_win.url.set_text(infodata['url']) applet_win.closebutton.connect('clicked', lambda *args: applet_win.destroy()) applet_win.show()
def parse_info_file(info_file): """Parses a info file, returns a dictionary representation. Returns an empty dictionary on error. """ try: fileobj = open(info_file, 'r') try: inf = wbz.parse_metadata(fileobj.read()) finally: fileobj.close() except IOError, e: inf = {}
def load_collection(self, images, monitor_dir=None): """Loads a list of images into the photo browser.""" model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT) image_list = [] for image in images: dirname, filename = os.path.split(image) basename, ext = os.path.splitext(filename) thumb = os.path.join(dirname, '.thumbs', basename+'.thumbnail'+ext) info_file = os.path.join(dirname, basename)+'.inf' try: fileobj = open(info_file, 'r') inf = wbz.parse_metadata(fileobj.read()) fileobj.close() except IOError: inf = {} title = inf.get('title', basename) album = inf.get('albumTitle', dirname) credit = inf.get('credit', _('Not available')) tags = inf.get('tags', '') title = html_escape(title) album = html_escape(album) credit = html_escape(credit) tags = html_escape(tags) data = dict(title=title, filename=image, thumb=thumb, info_file=info_file, inf = inf, album = album, tags = tags, file_time = os.path.getctime(image), credit = credit) if len(title)>24: title = title[:21] + '...' if 0 <= time.time() - os.path.getmtime(image) < 24*3600: title = _('<b>*New* %s</b>') % title position = model.append((title, EMPTY_PICTURE, data)) image_list.append(dict( position=position, data=data)) old_model = self.iconview.get_model() if old_model is not None: old_model.clear() self.sort_photos(model) self.iconview.set_model(model) gobject.idle_add(ThumbLoader(self.iconview, model, reversed(image_list))) self.on_iconview_handle_selection_changed(self.iconview) if gnomevfs: if self.collection_monitor['monitor'] is not None: gobject.idle_add(gnomevfs.monitor_cancel, self.collection_monitor['monitor']) self.collection_monitor = dict(monitor=None, dir=None) if monitor_dir: self.collection_monitor['dir'] = monitor_dir self.collection_monitor['monitor'] = gnomevfs.monitor_add( monitor_dir, gnomevfs.MONITOR_DIRECTORY, self.collection_directory_changed) gc.collect()
def load_collection(self, images, monitor_dir=None): """Loads a list of images into the photo browser.""" model = gtk.ListStore(gobject.TYPE_STRING, gtk.gdk.Pixbuf, gobject.TYPE_PYOBJECT) image_list = [] for image in images: dirname, filename = os.path.split(image) basename, ext = os.path.splitext(filename) thumb = os.path.join(dirname, '.thumbs', basename + '.thumbnail' + ext) info_file = os.path.join(dirname, basename) + '.inf' try: fileobj = open(info_file, 'r') inf = wbz.parse_metadata(fileobj.read()) fileobj.close() except IOError: inf = {} title = inf.get('title', basename) album = inf.get('albumTitle', dirname) credit = inf.get('credit', _('Not available')) tags = inf.get('tags', '') title = html_escape(title) album = html_escape(album) credit = html_escape(credit) tags = html_escape(tags) data = dict(title=title, filename=image, thumb=thumb, info_file=info_file, inf=inf, album=album, tags=tags, file_time=os.path.getctime(image), credit=credit) if len(title) > 24: title = title[:21] + '...' if 0 <= time.time() - os.path.getmtime(image) < 24 * 3600: title = _('<b>*New* %s</b>') % title position = model.append((title, EMPTY_PICTURE, data)) image_list.append(dict(position=position, data=data)) old_model = self.iconview.get_model() if old_model is not None: old_model.clear() self.sort_photos(model) self.iconview.set_model(model) gobject.idle_add( ThumbLoader(self.iconview, model, reversed(image_list))) self.on_iconview_handle_selection_changed(self.iconview) if gnomevfs: if self.collection_monitor['monitor'] is not None: gobject.idle_add(gnomevfs.monitor_cancel, self.collection_monitor['monitor']) self.collection_monitor = dict(monitor=None, dir=None) if monitor_dir: self.collection_monitor['dir'] = monitor_dir self.collection_monitor['monitor'] = gnomevfs.monitor_add( monitor_dir, gnomevfs.MONITOR_DIRECTORY, self.collection_directory_changed) gc.collect()