Ejemplo n.º 1
0
def determineIcon(addon, profile, defaultAddons, profileAddons):
    """Determines which icon to use for an addon.
    
    @param addon  addon.Addon.
    @param profile  profile.Profile.
    @param defaultAddons  List of addon identifiers from Defaults.
    @param profileAddons  List of addon identifiers from the profile.
    
    @return Icon index.
    """
    ident = addon.getId()
    icon = addonIcons[0]
    if profile is pr.getDefaults():
        # In the defaults profile, addons are either checked or unchecked.
        checked = ident in defaultAddons

        # Invert the check mark on opt-out addons.
        if addon.isInversed():
            checked = not checked

        if checked:
            icon = addonIcons[1]
        else:
            icon = addonIcons[0]
    else:
        # In other profiles, addons may have the defcheck as well.
        checked = ident in profileAddons

        # Being in the Defaults inverts the selection.
        if ident in defaultAddons:
            checked = not checked
            inDefaults = True
        else:
            inDefaults = False

        if addon.isInversed():
            checked = not checked

        if checked:
            if inDefaults:
                icon = addonIcons[2]
            else:
                icon = addonIcons[1]
        else:
            icon = addonIcons[0]
    return icon
Ejemplo n.º 2
0
def determineIcon(addon, profile, defaultAddons, profileAddons):
    """Determines which icon to use for an addon.
    
    @param addon  addon.Addon.
    @param profile  profile.Profile.
    @param defaultAddons  List of addon identifiers from Defaults.
    @param profileAddons  List of addon identifiers from the profile.
    
    @return Icon index.
    """
    ident = addon.getId()
    icon = addonIcons[0]
    if profile is pr.getDefaults():
        # In the defaults profile, addons are either checked or unchecked.
        checked = ident in defaultAddons

        # Invert the check mark on opt-out addons.
        if addon.isInversed():
            checked = not checked

        if checked:
            icon = addonIcons[1]
        else:
            icon = addonIcons[0]
    else:
        # In other profiles, addons may have the defcheck as well.
        checked = ident in profileAddons
        
        # Being in the Defaults inverts the selection.
        if ident in defaultAddons:
            checked = not checked
            inDefaults = True
        else:
            inDefaults = False
            
        if addon.isInversed():
            checked = not checked
            
        if checked:
            if inDefaults:
                icon = addonIcons[2]
            else:
                icon = addonIcons[1]
        else:
            icon = addonIcons[0]
    return icon
Ejemplo n.º 3
0
def run(addon):
    """Show a dialog box that contains a lot of information (all there
    is to know) about the addon.

    @param An addons.Addon object.
    """
    ident = addon.getId()

    dialog, area = sb.util.dialog.createButtonDialog('addon-inspector-dialog',
                                                     ['ok'],
                                                     'ok',
                                                     size=(570, 450))

    msg = ""

    msg += '<h3>' + language.translate(ident) + '</h3>'
    if language.isDefined(ident + '-readme'):
        msg += "<p>" + language.translate(ident + '-readme')

    def makeField(header, content):
        return '<tr><td width="20%" bgcolor="#E8E8E8" align="right"><b>' + header + \
               '</b></td><td width="80%">' + content + '</td></tr>'

    beginTable = '<p><table width="100%" border=0 cellpadding=6 cellspacing=0>'
    endTable = '</table>'

    #
    # General Information
    #
    msg += beginTable
    msg += makeField('Summary:', language.translate(ident + '-summary', '-'))
    msg += makeField('Version:', language.translate(ident + '-version', '-'))
    msg += makeField(
        'Last Modified:',
        time.strftime("%a, %d %b %Y %H:%M:%S",
                      time.localtime(addon.getLastModified())))
    msg += makeField('Author(s):', language.translate(ident + '-author', '-'))
    msg += makeField('Contact:', language.translate(ident + '-contact', '-'))
    msg += makeField('Copyright:', language.translate(ident + '-copyright',
                                                      '-'))
    msg += makeField('License:', language.translate(ident + '-license', '-'))
    msg += makeField('Category:', addon.getCategory().getPath())
    msg += makeField('Format:', language.translate(addon.getType()))
    msg += makeField('Identifier:', addon.getId())
    msg += endTable

    #
    # Raw Dependencies
    #
    msg += '<h3>Dependencies</h3>' + beginTable
    allDeps = []

    # Excluded categories.
    dep = []
    for category in addon.getExcludedCategories():
        dep.append(category.getPath())
    allDeps.append(('Excluded Categories:', dep))

    # Keywords.
    for type, label in [(sb.addon.EXCLUDES, 'Excludes:'),
                        (sb.addon.REQUIRES, 'Requires:'),
                        (sb.addon.PROVIDES, 'Provides:'),
                        (sb.addon.OFFERS, 'Offers:')]:
        # Make a copy of the list so we can modify it.
        dep = []
        for kw in addon.getKeywords(type):
            dep.append(kw)
        allDeps.append((label, dep))

    # Create a table out of each dependency type.
    for heading, listing in allDeps:
        msg += makeField(heading, string.join(listing, '<br>'))

    msg += endTable

    #
    # Content Analysis
    #
    msg += '<h3>Contents</h3>' + beginTable
    msg += makeField('Content Path:', addon.getContentPath())
    msg += endTable

    #msg += "<p>format-specific data"
    #msg += "<br>content analysis, size"
    #msg += "<br>list of files, if a bundle"

    #msg += '<h3>Identifiers</h3>'
    #msg += "<br>all internal identifiers used by the addon"

    #msg += '<h3>Metadata</h3>'
    #msg += "<br>metadata analysis, source"

    text = area.createFormattedText()
    text.setMinSize(500, 200)
    text.setText(msg)
    dialog.run()
Ejemplo n.º 4
0
def showAddonInfo(addon):
    """Display a summary of an addon in the help panel.

    @param addon An addons.Addon object.
    """
    global currentAddon, currentSetting

    # No longer showing a setting.
    currentSetting = None

    # The current addon that is displayed in the help.
    currentAddon = addon

    oneLiners = (detailedAddonMode == False)
    ident = addon.getId()

    # Begin the page with a table that contains the basic info.
    msg = '<html>'

    def optLink(id, isLink):
        if isLink:
            return '<a href="%s">%s</a>' % (id, language.translate(id))
        else:
            return language.translate(id)

    # The detail selection links.
    msg += '<center><font size="-1">'
    msg += optLink('help-addon-mode-brief', detailedAddonMode) + ' | '
    msg += optLink('help-addon-mode-detailed', not detailedAddonMode)
    msg += '</font></center><br>'

    # Summary table.
    msg += tableBegin

    msg += '<tr><td colspan="2"><b><font size="+1">' + \
           language.translate(ident) + \
           '</font></b>'

    def makeField(msg, fieldId, oneLiner=True):
        title = language.translate('help-addon-' + fieldId)
        contentId = ident + '-' + fieldId

        text = ''
        if language.isDefined(contentId):
            # This information has been defined.
            text = language.translate(contentId)
        elif detailedAddonMode:
            # Force all fields to show.
            text = '-'

        if text:
            if oneLiner:
                msg += tableRow + entryHeader(title) + entryContent(text)
            else:
                msg += tableRow + entryHeader(title, 2) + \
                       tableRow + entryContent(text, 2)

        return msg

    msg = makeField(msg, 'version')

    if detailedAddonMode:
        # Get the last modification time from the addon.
        modTime = time.localtime(addon.getLastModified())
        msg += tableRow + entryHeader(language.translate('help-addon-date')) \
               + entryContent(time.strftime("%d %b %Y", modTime))

    msg = makeField(msg, 'summary', oneLiners)

    if detailedAddonMode:
        msg = makeField(msg, 'contact', oneLiners)
        msg = makeField(msg, 'author', oneLiners)
        msg = makeField(msg, 'copyright', oneLiners)
        msg = makeField(msg, 'license', oneLiners)

    # Dependencies.
    deps = []

    exCats = addon.getExcludedCategories()
    if len(exCats):
        deps.append((language.translate('help-addon-excluded-categories'),
                     map(lambda c: language.translate(c.getLongId()), exCats)))

    for type, label in [(sb.addon.EXCLUDES, 'help-addon-excludes'),
                        (sb.addon.REQUIRES, 'help-addon-requires'),
                        (sb.addon.PROVIDES, 'help-addon-provides'),
                        (sb.addon.OFFERS, 'help-addon-offers')]:
        # Make a copy of the list so we can modify it.
        keywords = [kw for kw in addon.getKeywords(type)]

        # In the Brief mode, hide the identifier of the addon in the
        # Provides field.
        if not detailedAddonMode and type == sb.addon.PROVIDES:
            keywords.remove(addon.getId())

        if len(keywords) > 0:
            # Include this in the info.
            def xlate(key):
                if ao.exists(key):
                    return '<a href="%s">%s</a>' % \
                           (key, language.translate(key))
                else:
                    return key

            deps.append((language.translate(label), map(xlate, keywords)))

    if len(deps):
        # Print a dependencies table.
        msg += tableRow + entryHeader(
            language.translate('help-addon-dependencies'), 2)

        content = ""

        for dep in deps:
            if dep is not deps[0]:
                content += '<br>'
            content += "<b>" + dep[0] + ":</b><ul><li>"
            content += string.join(dep[1], '<li>')
            content += '</ul>'

        msg += tableRow + entryContent(content, 2)

    msg += tableEnd

    # Inside a box?
    if addon.getBox():
        box = addon.getBox()
        msg += language.expand(language.translate('help-addon-part-of-box'),
                               box.getId(), language.translate(
                                   box.getId())) + '<p>'

    # The overview.
    if language.isDefined(ident + '-readme'):
        msg += language.translate(ident + '-readme')

    msg += '</html>'

    helpText.setText(msg)
    showLogo(False)
Ejemplo n.º 5
0
def refreshList():
    """Refreshes the list of addons."""
    addonList.freeze()

    # Try to keep the old selection, if there is one.
    oldSelections = addonList.getSelectedItems()

    addonList.clear()

    # Filtering parameters.
    profile = pr.getActive()
    isDefaults = profile is pr.getDefaults()
    if tree.getSelectedItem():
        filterCategory = ao.getCategory(tree.getSelectedItem())
    else:
        filterCategory = None

    # Which addons are currently attached?
    defaultAddons = pr.getDefaults().getAddons()
    if not isDefaults:
        profileAddons = pr.getActive().getAddons()
    else:
        profileAddons = None

    # Categories that will be in bold font in category-tree.
    boldCategories = []

    # Determine filtering options.
    mode = listFilter.getSelectedItem()
    onlyCompatible = False
    onlyPWAD = False
    alsoBoxes = False
    if 'compatible' in mode:
        onlyCompatible = True
    if 'pwad' in mode:
        onlyPWAD = True
    if 'with-boxes' in mode:
        alsoBoxes = True

    for addon in ao.getAddons():
        # Does this addon pass the filter?
        if not isDefaults and onlyCompatible:
            if not addon.isCompatibleWith(pr.getActive()):
                # Cannot be listed.
                continue
        if onlyPWAD and (addon.getType() != 'addon-type-wad'
                         or not addon.isPWAD()):
            continue
        # Has a category been selected?
        if filterCategory and not filterCategory.isAncestorOf(
                addon.getCategory()):
            # Not in the category.
            continue
        # Addons in boxes are not listed unless the correct category is selected.
        if not alsoBoxes and addon.getBox():
            # Addons in boxes are only visible if the selected category is a box category.
            boxCateg = addon.getBox().getContentCategoryLongId()
            if not filterCategory: continue
            if filterCategory.getLongId().find(boxCateg) != 0:
                # Not the right category.
                continue
        # Passed the filter!
        id = addon.getId()
        versionStr = ''
        icon = determineIcon(addon, profile, defaultAddons, profileAddons)

        if language.isDefined(id + '-version'):
            versionStr = language.translate(id + '-version')

        name = language.translate(id)
        if addon.getBox() and alsoBoxes:
            name += ' ' + language.translate('addon-list-in-box')

        addonList.addItemWithColumns(id, icon, name, versionStr)

    # Reselect old items.
    oldSelections.reverse()
    for sel in oldSelections:
        addonList.selectItem(sel)
        addonList.ensureVisible(sel)

    sortList()
    updateButtons()

    addonList.unfreeze()

    # Update the counter text.
    countText.setText(
        language.expand(language.translate('addon-counter'),
                        str(len(addonList.getItems())),
                        str(ao.getAddonCount())))

    # Update boldings in category-tree.
    # --TODO!--

    global mustRefreshList
    mustRefreshList = False
Ejemplo n.º 6
0
def showAddonInfo(addon):
    """Display a summary of an addon in the help panel.

    @param addon An addons.Addon object.
    """
    global currentAddon, currentSetting

    # No longer showing a setting.
    currentSetting = None

    # The current addon that is displayed in the help.
    currentAddon = addon

    oneLiners = (detailedAddonMode == False)
    ident = addon.getId()
    
    # Begin the page with a table that contains the basic info.
    msg = '<html>'

    def optLink(id, isLink):
        if isLink:
            return '<a href="%s">%s</a>' % (id, language.translate(id))
        else:
            return language.translate(id)

    # The detail selection links.
    msg += '<center><font size="-1">'
    msg += optLink('help-addon-mode-brief', detailedAddonMode) + ' | '
    msg += optLink('help-addon-mode-detailed', not detailedAddonMode)
    msg += '</font></center><br>'

    # Summary table.
    msg += tableBegin

    msg += '<tr><td colspan="2"><b><font size="+1">' + \
           language.translate(ident) + \
           '</font></b>'

    def makeField(msg, fieldId, oneLiner=True):
        title = language.translate('help-addon-' + fieldId)
        contentId = ident + '-' + fieldId

        text = ''
        if language.isDefined(contentId):
            # This information has been defined.
            text = language.translate(contentId)
        elif detailedAddonMode:
            # Force all fields to show.
            text = '-'

        if text:
            if oneLiner:
                msg += tableRow + entryHeader(title) + entryContent(text)
            else:
                msg += tableRow + entryHeader(title, 2) + \
                       tableRow + entryContent(text, 2)

        return msg

    msg = makeField(msg, 'version')

    if detailedAddonMode:
        # Get the last modification time from the addon.
        modTime = time.localtime(addon.getLastModified())
        msg += tableRow + entryHeader(language.translate('help-addon-date')) \
               + entryContent(time.strftime("%d %b %Y", modTime))
    
    msg = makeField(msg, 'summary', oneLiners)

    if detailedAddonMode:
        msg = makeField(msg, 'contact', oneLiners)
        msg = makeField(msg, 'author', oneLiners)
        msg = makeField(msg, 'copyright', oneLiners)
        msg = makeField(msg, 'license', oneLiners)

    # Dependencies.
    deps = []
    
    exCats = addon.getExcludedCategories()
    if len(exCats):
        deps.append((language.translate('help-addon-excluded-categories'),
                     map(lambda c: language.translate(c.getLongId()), exCats)))

    for type, label in [(sb.addon.EXCLUDES, 'help-addon-excludes'),
                        (sb.addon.REQUIRES, 'help-addon-requires'),
                        (sb.addon.PROVIDES, 'help-addon-provides'),
                        (sb.addon.OFFERS, 'help-addon-offers')]:
        # Make a copy of the list so we can modify it.
        keywords = [kw for kw in addon.getKeywords(type)]

        # In the Brief mode, hide the identifier of the addon in the
        # Provides field.
        if not detailedAddonMode and type == sb.addon.PROVIDES:
            keywords.remove(addon.getId())            
        
        if len(keywords) > 0:
            # Include this in the info.
            def xlate(key):
                if ao.exists(key):
                    return '<a href="%s">%s</a>' % \
                           (key, language.translate(key))
                else:
                    return key
            deps.append((language.translate(label), map(xlate, keywords)))

    if len(deps):
        # Print a dependencies table.
        msg += tableRow + entryHeader(
            language.translate('help-addon-dependencies'), 2)

        content = ""

        for dep in deps:
            if dep is not deps[0]:
                content += '<br>'
            content += "<b>" + dep[0] + ":</b><ul><li>"
            content += string.join(dep[1], '<li>')
            content += '</ul>'

        msg += tableRow + entryContent(content, 2)            

    msg += tableEnd

    # Inside a box?
    if addon.getBox():
        box = addon.getBox()
        msg += language.expand(
            language.translate('help-addon-part-of-box'),
            box.getId(), language.translate(box.getId())) + '<p>'

    # The overview.
    if language.isDefined(ident + '-readme'):
        msg += language.translate(ident + '-readme')

    msg += '</html>'

    helpText.setText(msg)
    showLogo(False)
Ejemplo n.º 7
0
def run(addon):
    """Show a dialog box that contains a lot of information (all there
    is to know) about the addon.

    @param An addons.Addon object.
    """
    ident = addon.getId()
    
    dialog, area = sb.util.dialog.createButtonDialog(
        'addon-inspector-dialog',
         ['ok'], 'ok', size=(570, 450))

    msg = ""

    msg += '<h3>' + language.translate(ident) + '</h3>'
    if language.isDefined(ident + '-readme'):
        msg += "<p>" + language.translate(ident + '-readme')

    def makeField(header, content):
        return '<tr><td width="20%" bgcolor="#E8E8E8" align="right"><b>' + header + \
               '</b></td><td width="80%">' + content + '</td></tr>'

    beginTable = '<p><table width="100%" border=0 cellpadding=6 cellspacing=0>'
    endTable = '</table>'

    #
    # General Information
    #
    msg += beginTable
    msg += makeField('Summary:', language.translate(ident + '-summary', '-'))
    msg += makeField('Version:', language.translate(ident + '-version', '-'))
    msg += makeField('Last Modified:',
                     time.strftime("%a, %d %b %Y %H:%M:%S",
                                   time.localtime(addon.getLastModified())))
    msg += makeField('Author(s):', language.translate(ident + '-author', '-'))
    msg += makeField('Contact:', language.translate(ident + '-contact', '-'))
    msg += makeField('Copyright:',
                     language.translate(ident + '-copyright', '-'))
    msg += makeField('License:', language.translate(ident + '-license', '-'))
    msg += makeField('Category:', addon.getCategory().getPath())
    msg += makeField('Format:', language.translate(addon.getType()))
    msg += makeField('Identifier:', addon.getId())
    msg += endTable

    #
    # Raw Dependencies
    #
    msg += '<h3>Dependencies</h3>' + beginTable
    allDeps = []
    
    # Excluded categories.
    dep = []
    for category in addon.getExcludedCategories():
        dep.append(category.getPath())
    allDeps.append(('Excluded Categories:', dep))

    # Keywords.
    for type, label in [(sb.addon.EXCLUDES, 'Excludes:'),
                        (sb.addon.REQUIRES, 'Requires:'),
                        (sb.addon.PROVIDES, 'Provides:'),
                        (sb.addon.OFFERS, 'Offers:')]:
        # Make a copy of the list so we can modify it.
        dep = []
        for kw in addon.getKeywords(type):
            dep.append(kw)
        allDeps.append((label, dep))

    # Create a table out of each dependency type.
    for heading, listing in allDeps:
        msg += makeField(heading, string.join(listing, '<br>'))

    msg += endTable

    #
    # Content Analysis
    # 
    msg += '<h3>Contents</h3>' + beginTable
    msg += makeField('Content Path:', addon.getContentPath())
    msg += endTable
    
    #msg += "<p>format-specific data"
    #msg += "<br>content analysis, size"
    #msg += "<br>list of files, if a bundle"

    #msg += '<h3>Identifiers</h3>'
    #msg += "<br>all internal identifiers used by the addon"

    #msg += '<h3>Metadata</h3>'
    #msg += "<br>metadata analysis, source"

    text = area.createFormattedText()
    text.setMinSize(500, 200)
    text.setText(msg)
    dialog.run()        
Ejemplo n.º 8
0
def refreshList():
    """Refreshes the list of addons."""
    addonList.freeze()

    # Try to keep the old selection, if there is one.
    oldSelections = addonList.getSelectedItems()

    addonList.clear()
    
    # Filtering parameters.
    profile = pr.getActive()
    isDefaults = profile is pr.getDefaults()
    if tree.getSelectedItem():
        filterCategory = ao.getCategory(tree.getSelectedItem())
    else:
        filterCategory = None
        
    # Which addons are currently attached?
    defaultAddons = pr.getDefaults().getAddons()
    if not isDefaults:
        profileAddons = pr.getActive().getAddons()
    else:
        profileAddons = None
    
    # Categories that will be in bold font in category-tree.
    boldCategories = []
    
    # Determine filtering options.
    mode = listFilter.getSelectedItem()
    onlyCompatible = False
    onlyPWAD = False
    alsoBoxes = False
    if 'compatible' in mode:
        onlyCompatible = True
    if 'pwad' in mode:
        onlyPWAD = True
    if 'with-boxes' in mode:
        alsoBoxes = True
        
    for addon in ao.getAddons():
        # Does this addon pass the filter?
        if not isDefaults and onlyCompatible:
            if not addon.isCompatibleWith(pr.getActive()):
                # Cannot be listed.
                continue
        if onlyPWAD and (addon.getType() != 'addon-type-wad' or not addon.isPWAD()):
            continue
        # Has a category been selected?
        if filterCategory and not filterCategory.isAncestorOf(addon.getCategory()):
            # Not in the category.
            continue
        # Addons in boxes are not listed unless the correct category is selected.
        if not alsoBoxes and addon.getBox():
            # Addons in boxes are only visible if the selected category is a box category.
            boxCateg = addon.getBox().getContentCategoryLongId()
            if not filterCategory: continue
            if filterCategory.getLongId().find(boxCateg) != 0:
                # Not the right category.
                continue
        # Passed the filter!
        id = addon.getId()
        versionStr = ''
        icon = determineIcon(addon, profile, defaultAddons, profileAddons)
            
        if language.isDefined(id + '-version'):
            versionStr = language.translate(id + '-version')
            
        name = language.translate(id)
        if addon.getBox() and alsoBoxes:
            name += ' ' + language.translate('addon-list-in-box')
            
        addonList.addItemWithColumns(id,  icon, name, versionStr)
      
    # Reselect old items.
    oldSelections.reverse()
    for sel in oldSelections:
        addonList.selectItem(sel)
        addonList.ensureVisible(sel)

    sortList()
    updateButtons()

    addonList.unfreeze()
    
    # Update the counter text.
    countText.setText(language.expand(language.translate('addon-counter'),
                                      str(len(addonList.getItems())), 
                                      str(ao.getAddonCount())))
    
    # Update boldings in category-tree.
    # --TODO!--   
    
    global mustRefreshList
    mustRefreshList = False