Example #1
0
def qicon(filename, default=None, paths=None, save_filepath=None, packages=None):
    if isinstance(filename, QtGui.QIcon):
        return filename

    if not filename:
        if default is None:
            default = get_shared_data('icons/oxygen_application-x-desktop.png')
        return qicon(default, default, save_filepath=save_filepath)
    elif filename.startswith(':/'):
        pixmap = QtGui.QPixmap(filename).scaled(*DEFAULT_SCALE, aspectRatioMode=QtCore.Qt.KeepAspectRatio)
        icon = QtGui.QIcon(pixmap)
        if save_filepath:
            icon.addFile(save_filepath)
            pixmap.save(save_filepath)
        return icon
    else:
        if packages is None:
            packages = [openalea.core, openalea.oalab]
        found = icon_path(filename, default=default, paths=paths, packages=packages)
        if found:
            pixmap = QtGui.QPixmap(found).scaled(*DEFAULT_SCALE, aspectRatioMode=QtCore.Qt.KeepAspectRatio)
            icon = QtGui.QIcon(pixmap)
            if save_filepath:
                icon.addFile(save_filepath)
                pixmap.save(save_filepath)
            return icon
        else:
            return qicon(":/images/resources/%s" % filename, save_filepath=save_filepath)
Example #2
0
def html_summary(item, **kwargs):
    if hasattr(item, 'icon'):
        p = kwargs.get('icon_path', icon_path(item.icon))
        image = u'<img style="vertical-align:middle;" src="%s" width="128" />' % p
    else:
        image = u''
    args = dict(image=image,
                title=format_html(item.label),
                name=format_html(item.name))
    html = u'<div class="summary"><p class="title"> %(image)s' % args
    html += u'%(title)s</p>' % args
    html += u'\n<hr>'

    criteria = item.criteria

    # Crédits
    items = []
    for label in ('author', 'authors'):
        value = criteria.get(label, 'None')
        if not value:
            continue
        if not isinstance(value, (list, tuple, set)):
            value = [value]
        for author in value:
            if author and author != "None":
                items.append(format_author(author, key=label, show_all=True))

    items.sort()
    html += html_section(u'credits', u'Credits', items)

    # Criteria
    items = []
    for label, value in item.criteria.items():
        if label in ('icon', 'author', 'authors') or not value:
            continue
        items.append(
            u'<span class="key">%s</span>: <span class="value">%s</span>\n' %
            (format_html(label).capitalize(), format_html(value, key=label)))
    html += html_section(u'criteria', u'Criteria', items)

    # Tags
    items = []
    for tag in item.tags:
        items.append(u'<span class="key">%s</span>\n' % tag)
    html += html_section(u'tags', u'Tags', items)

    html += u'</div>'
    return html
Example #3
0
def html_summary(item, **kwargs):
    if hasattr(item, 'icon'):
        p = kwargs.get('icon_path', icon_path(item.icon))
        image = u'<img style="vertical-align:middle;" src="%s" width="128" />' % p
    else:
        image = u''
    args = dict(image=image, title=format_html(item.label), name=format_html(item.name))
    html = u'<div class="summary"><p class="title"> %(image)s' % args
    html += u'%(title)s</p>' % args
    html += u'\n<hr>'

    criteria = item.criteria

    # Crédits
    items = []
    for label in ('author', 'authors'):
        value = criteria.get(label, 'None')
        if not value:
            continue
        if not isinstance(value, (list, tuple, set)):
            value = [value]
        for author in value:
            if author and author != "None":
                items.append(format_author(author, key=label, show_all=True))

    items.sort()
    html += html_section(u'credits', u'Credits', items)

    # Criteria
    items = []
    for label, value in item.criteria.items():
        if label in ('icon', 'author', 'authors') or not value:
            continue
        items.append(
            u'<span class="key">%s</span>: <span class="value">%s</span>\n' %
            (format_html(label).capitalize(), format_html(value, key=label)))
    html += html_section(u'criteria', u'Criteria', items)

    # Tags
    items = []
    for tag in item.tags:
        items.append(u'<span class="key">%s</span>\n' % tag)
    html += html_section(u'tags', u'Tags', items)

    html += u'</div>'
    return html
Example #4
0
def qicon(filename,
          default=None,
          paths=None,
          save_filepath=None,
          packages=None):
    if isinstance(filename, QtGui.QIcon):
        return filename

    if not filename:
        if default is None:
            default = get_shared_data('icons/oxygen_application-x-desktop.png')
        return qicon(default, default, save_filepath=save_filepath)
    elif filename.startswith(':/'):
        pixmap = QtGui.QPixmap(filename).scaled(
            *DEFAULT_SCALE, aspectRatioMode=QtCore.Qt.KeepAspectRatio)
        icon = QtGui.QIcon(pixmap)
        if save_filepath:
            icon.addFile(save_filepath)
            pixmap.save(save_filepath)
        return icon
    else:
        if packages is None:
            packages = [openalea.core, openalea.oalab]
        found = icon_path(filename,
                          default=default,
                          paths=paths,
                          packages=packages)
        if found:
            pixmap = QtGui.QPixmap(found).scaled(
                *DEFAULT_SCALE, aspectRatioMode=QtCore.Qt.KeepAspectRatio)
            icon = QtGui.QIcon(pixmap)
            if save_filepath:
                icon.addFile(save_filepath)
                pixmap.save(save_filepath)
            return icon
        else:
            return qicon(":/images/resources/%s" % filename,
                         save_filepath=save_filepath)