Example #1
0
    def read_metadata(filename):
        try:
            m = VarietyMetadata(filename)

            info = {}
            for k in [
                    "sourceName", "sourceLocation", "sourceURL", "sourceType",
                    "imageURL", "author", "authorURL"
            ]:
                if "Xmp.variety." + k in m:
                    info[k] = _u(m["Xmp.variety." + k])

            try:
                info['sfwRating'] = int(m['Xmp.variety.sfwRating'])
            except:
                pass

            try:
                info['author'] = _u(m['Xmp.dc.creator'][0])
            except:
                pass

            try:
                info['headline'] = _u(m['Iptc.Application2.Headline'][0])
            except:
                pass

            try:
                info['description'] = _u(m.get_comment())
            except:
                pass

            try:
                info['extraData'] = json.loads(m['Xmp.variety.extraData'])
            except:
                pass

            try:
                info['keywords'] = map(_u, m['Iptc.Application2.Keywords'])
            except:
                try:
                    info['keywords'] = map(_u, m['Xmp.dc.subject'])
                except:
                    pass

            return info

        except Exception, e:
            # could not read metadata inside file, try reading json metadata instead
            try:
                with io.open(filename + '.metadata.json',
                             encoding='utf8') as f:
                    return json.loads(f.read())

            except Exception:
                return None
Example #2
0
    def read_metadata(filename):
        try:
            m = VarietyMetadata(filename)

            info = {}
            for k in ["sourceName", "sourceLocation", "sourceURL", "sourceType", "imageURL", "author", "authorURL"]:
                if "Xmp.variety." + k in m:
                    info[k] = _u(m["Xmp.variety." + k])

            try:
                info['sfwRating'] = int(m['Xmp.variety.sfwRating'])
            except:
                pass

            try:
                info['author'] = _u(m['Xmp.dc.creator'][0])
            except:
                pass

            try:
                info['headline'] = _u(m['Iptc.Application2.Headline'][0])
            except:
                pass

            try:
                info['description'] = _u(m.get_comment())
            except:
                pass

            try:
                info['extraData'] = json.loads(m['Xmp.variety.extraData'])
            except:
                pass

            try:
                info['keywords'] = map(_u, m['Iptc.Application2.Keywords'])
            except:
                try:
                    info['keywords'] = map(_u, m['Xmp.dc.subject'])
                except:
                    pass

            return info

        except Exception, e:
            # could not read metadata inside file, try reading json metadata instead
            try:
                with io.open(filename + '.metadata.json', encoding='utf8') as f:
                    return json.loads(f.read())

            except Exception:
                return None
Example #3
0
    def browse(self, widget=None):
        try:
            self.chooser = Gtk.FileChooserDialog(
                _("Choose a folder"),
                parent=self.button.get_toplevel(),
                action=Gtk.FileChooserAction.SELECT_FOLDER,
                buttons=[
                    _("Cancel"), Gtk.ResponseType.CANCEL,
                    _("OK"), Gtk.ResponseType.OK
                ])
            self.chooser.set_filename(self.folder)
            self.chooser.set_select_multiple(False)
            self.chooser.set_local_only(False)

            if self.chooser.run() == Gtk.ResponseType.OK:
                self.set_folder(_u(self.chooser.get_filename()))
                try:
                    if self.on_change:
                        self.on_change()
                except Exception:
                    logger.exception(
                        lambda: "Exception during FolderChooser on_change:")
        finally:
            if self.chooser:
                try:
                    self.chooser.destroy()
                    self.chooser = None
                except Exception:
                    logger.exception(
                        lambda: "Exception during FolderChooser destroying:")
Example #4
0
    def on_click(self, thumbs_window, file, widget, event):
        file = _u(file)
        self.pin()

        def _resume_scrolling(menu=None):
            thumbs_window.resume_scrolling()

        thumbs_window.pause_scrolling()
        if event.button == 1:
            if self.is_showing("history"):
                index = [info["eventbox"]
                         for info in thumbs_window.all].index(widget)
                self.parent.move_to_history_position(index)
            else:
                self.parent.set_wallpaper(file)
            _resume_scrolling()
        else:
            menu = self.create_menu(file)

            def _compute_position(*args, **kwargs):
                x, y = event.get_root_coords()[0], event.get_root_coords()[1]
                h = menu.get_preferred_height()[1]
                return x, y - h if y - h >= 40 else y, True

            menu.connect("deactivate", _resume_scrolling)
            menu.popup(None, None, _compute_position, None, 0, event.time)
Example #5
0
 def on_click(self, thumbs_window, file, widget, event):
     file = _u(file)
     self.pin()
     def _resume_scrolling(menu=None):
         thumbs_window.resume_scrolling()
     thumbs_window.pause_scrolling()
     if event.button == 1:
         if self.is_showing("history"):
             index = [info["eventbox"] for info in thumbs_window.all].index(widget)
             self.parent.move_to_history_position(index)
         else:
             self.parent.set_wallpaper(file)
         _resume_scrolling()
     else:
         menu = self.create_menu(file)
         def _compute_position(a, b, event=event):
             x, y = event.get_root_coords()[0], event.get_root_coords()[1]
             h = menu.get_preferred_height()[1]
             return x, y - h if y - h >= 40 else y, True
         menu.connect("deactivate", _resume_scrolling)
         menu.popup(None, None, _compute_position, None, 0, event.time)
Example #6
0
    def browse(self, widget=None):
        try:
            self.chooser = Gtk.FileChooserDialog(
                _("Choose a folder"), parent=self.button.get_toplevel(), action=Gtk.FileChooserAction.SELECT_FOLDER,
                buttons=[_("Cancel"), Gtk.ResponseType.CANCEL, _("OK"), Gtk.ResponseType.OK])
            self.chooser.set_filename(self.folder)
            self.chooser.set_select_multiple(False)
            self.chooser.set_local_only(False)

            if self.chooser.run() == Gtk.ResponseType.OK:
                self.set_folder(_u(self.chooser.get_filename()))
                try:
                    if self.on_change:
                        self.on_change()
                except Exception:
                    logger.exception(lambda: "Exception during FolderChooser on_change:")
        finally:
            if self.chooser:
                try:
                    self.chooser.destroy()
                    self.chooser = None
                except Exception:
                    logger.exception(lambda: "Exception during FolderChooser destroying:")
Example #7
0
 def gtk_to_fcmatch_font(gtk_font_name):
     fd = Pango.FontDescription(gtk_font_name)
     family = _u(fd.get_family())
     size = gtk_font_name[gtk_font_name.rindex(' '):].strip()
     rest = gtk_font_name.replace(family, '').strip().replace(' ', ':')
     return family + ":" + rest, size
Example #8
0
 def gtk_to_fcmatch_font(gtk_font_name):
     fd = Pango.FontDescription(gtk_font_name)
     family = _u(fd.get_family())
     size = gtk_font_name[gtk_font_name.rindex(' '):].strip()
     rest = gtk_font_name.replace(family, '').strip().replace(' ', ':')
     return family + ":" + rest, size