Ejemplo n.º 1
0
def m_to_string(v):
    if isempty(v):
        return escape_html(BLANK)
    elif isinstance(v, unicode):
        return escape_html(v)
    elif isinstance(v, str):
        return escape_html(v.decode('utf8', 'replace'))
    else:
        return escape_html(SEPARATOR.join(v))
Ejemplo n.º 2
0
    def fillCombos(self, *args):
        audios = self._status['selectedfiles']
        self._audios = [z.usertags for z in audios]
        combos = self.combos

        if not audios:
            for combo in combos.values():
                combo.clear()
                combo.setEnabled(False)
            return

        [combo.blockSignals(True) for combo in combos.values()]
        self.initCombos(True)
        tags = dict((tag, set()) for tag in combos)
        for audio in audios:
            for field in tags:
                if field in audio:
                    value = audio[field]
                    if isinstance(value, basestring):
                        tags[field].add(value)
                    else:
                        tags[field].add(SEPARATOR.join(value))
                else:
                    tags[field].add(u'')

        for field, values in tags.iteritems():
            combo = combos[field]
            combo.addItems(sorted(values))
            if len(values) == 1: combo.setCurrentIndex(2)
            else: combo.setCurrentIndex(0)

        if 'genre' in tags and len(tags['genre']) == 1:
            combo = combos['genre']
            values = sorted(tags['genre'])
            index = combo.findText(values[0])
            if index > -1:
                combo.setCurrentIndex(index)
            else:
                combo.setEditText(values[0])
        elif 'genre' in tags:
            combos['genre'].setCurrentIndex(0)

        self._originalValues = dict([(field, unicode(combo.currentText()))
            for field, combo in self.combos.items()])
        self._originalValues['__image'] = self._status['images']
        [combo.blockSignals(False) for combo in combos.values()]
Ejemplo n.º 3
0
def pprint_tag(tags, fmt=u"<b>%s</b>: %s<br />", show_read_only=False):
    image_tr = translate('Defaults', '%s images')
    if tags:
        if isinstance(tags, basestring):
            return tags
        elif not hasattr(tags, 'items'):
            return SEPARATOR.join(filter(lambda x: x is not None, tags))

        if show_read_only:
            items = ((k,v) for k, v in tags.iteritems() if k != '__image')
        else:
            items = ((k,v) for k,v in tags.iteritems() if
                k not in READONLY and k != '__image')

        map_func = lambda v: fmt % (v[0], m_to_string(v[1]))

        items = sorted(items, cmp=natcasecmp, key=itemgetter(0))

        if u'__image' in tags:
            items.insert(0, ('__image', image_tr % len(tags['__image'])))

        return u"".join(imap(map_func, items))