def __init__(self, identifier, source): """Construct a new Addon object. @param identifier The identifier of the addon. @param source The full path name of the source file. """ self.id = identifier self.name = '' self.category = aodb.getRootCategory() self.source = source self.priority = 'z' self.requiredComponents = [] self.excludedCategories = [] self.box = None # When an addon is uninstalled, it will be hidden in the user # interface. self.uninstalled = False # Contains tuples: (type, identifier). self.keywords = {} for t in [EXCLUDES, REQUIRES, PROVIDES, OFFERS]: self.keywords[t] = [] # Every addon provides itself. self.keywords[PROVIDES].append(identifier) self.lastModified = None # If no other translation is given, the identifier of the # addon is shown as the base name of the source. if not language.isDefined(identifier): language.define('english', identifier, os.path.basename(source))
def addItem(self, identifier, isChecked=False): """Append a new item into the listbox. @param identifier Identifier of the item. """ w = self.getWxWidget() if language.isDefined(identifier): visibleText = language.translate(identifier) else: visibleText = identifier w.Append(uniConv(visibleText)) self.items.append(identifier) # In a checklistbox, the items can be checked. if self.style == List.STYLE_CHECKBOX: if isChecked: w.Check(w.GetCount() - 1)
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
def get(self, identifier): """Finds the index number of the specified image. If the image hasn't yet been loaded, it is loaded now. @param identifier Identifier of the image. """ try: return self.bitmaps.index(identifier) except ValueError: # Load it now. Images are affected by the localisation. if language.isDefined(identifier): imageName = language.translate(identifier) else: imageName = identifier fileName = paths.findBitmap(imageName) if len(fileName) == 0: # Fallback icon. fileName = paths.findBitmap('deng') bmp = wx.Bitmap(fileName) self.imageList.Add(bmp) self.bitmaps.append(identifier) return len(self.bitmaps) - 1
def get(self, identifier): """Finds the index number of the specified image. If the image hasn't yet been loaded, it is loaded now. @param identifier Identifier of the image. """ try: return self.bitmaps.index(identifier) except ValueError: # Load it now. Images are affected by the localisation. if language.isDefined(identifier): imageName = language.translate(identifier) else: imageName = identifier fileName = paths.findBitmap(imageName) if len(fileName) == 0: # Fallback icon. fileName = paths.findBitmap("deng") bmp = wx.Bitmap(fileName) self.imageList.Add(bmp) self.bitmaps.append(identifier) return len(self.bitmaps) - 1
def refreshList(): """Fill the maps list with addons.""" # Clear the list. mapListBox.clear() wads = [a for a in ao.getAvailableAddons(pr.getActive()) if a.getType() == 'addon-type-wad' and a.isPWAD()] # Translate addon names. wads.sort(lambda a, b: cmp(a.getId(), b.getId())) for wad in wads: # TODO: More information titles. if not language.isDefined(wad.getId()): visibleName = language.translate(wad.getId()) else: visibleName = os.path.basename(wad.getContentPath()) mapListBox.addItemWithColumns(wad.getId(), 0, visibleName, wad.getShortContentAnalysis()) prof = pr.getActive() usedAddons = prof.getUsedAddons() theFirst = True # Select the addons currently attached to the profile. # Also make sure the first one is visible. for addonId in usedAddons: mapListBox.selectItem(addonId) mapListBox.setItemImage(addonId, 1) if theFirst: # Make sure it's visible. mapListBox.ensureVisible(addonId) theFirst = False
def refreshList(): """Fill the maps list with addons.""" # Clear the list. mapListBox.clear() wads = [ a for a in ao.getAvailableAddons(pr.getActive()) if a.getType() == 'addon-type-wad' and a.isPWAD() ] # Translate addon names. wads.sort(lambda a, b: cmp(a.getId(), b.getId())) for wad in wads: # TODO: More information titles. if not language.isDefined(wad.getId()): visibleName = language.translate(wad.getId()) else: visibleName = os.path.basename(wad.getContentPath()) mapListBox.addItemWithColumns(wad.getId(), 0, visibleName, wad.getShortContentAnalysis()) prof = pr.getActive() usedAddons = prof.getUsedAddons() theFirst = True # Select the addons currently attached to the profile. # Also make sure the first one is visible. for addonId in usedAddons: mapListBox.selectItem(addonId) mapListBox.setItemImage(addonId, 1) if theFirst: # Make sure it's visible. mapListBox.ensureVisible(addonId) theFirst = False
def valueToText(v): if language.isDefined(v): return language.translate(v) else: return v
def updateMenus(self): """Create the main frame menus based on menuItems array.""" global menuItems self.menuCommandMap = {} # Array of menus. Number to wxMenu. self.menus = {} # Three levels of priority. for level in range(len(menuItems)): if len(menuItems[level]) == 0: # No menu for this. self.menus[level] = None continue self.menus[level] = wx.Menu() self.menuBar.Append(self.menus[level], language.translate("menu-" + str(level))) # Sort the items based on groups, and append separators where necessary. menuItems[level].sort(lambda x, y: cmp(x[3], y[3])) separated = [] previousItem = None for item in menuItems[level]: if previousItem and previousItem[3] != item[3]: separated.append(('-', '', False, item[3])) separated.append(item) previousItem = item # Create the menu items. for itemId, itemCommand, itemSeparate, itemGroup in separated: if itemId == '-': # This is just a separator. self.menus[level].AppendSeparator() continue if itemSeparate and self.menus[level].GetMenuItemCount() > 0: self.menus[level].AppendSeparator() menuItemId = 'menu-' + itemId accel = '' if language.isDefined(menuItemId + '-accel'): accel = "\t" + language.translate(menuItemId + '-accel') # Generate a new ID for the item. wxId = wx.NewId() self.menuCommandMap[wxId] = itemCommand self.menus[level].Append(wxId, uniConv(language.translate(menuItemId) + accel)) wx.EVT_MENU(self, wxId, self.onPopupCommand) if host.isMac(): # Special menu items on Mac. if itemId == 'about': wx.App_SetMacAboutMenuItemId(wxId) if itemId == 'quit': wx.App_SetMacExitMenuItemId(wxId) if itemId == 'show-snowberry-settings': wx.App_SetMacPreferencesMenuItemId(wxId) if host.isMac(): # Special Help menu on Mac. wx.App_SetMacHelpMenuTitleName(language.translate('menu-' + str(MENU_HELP))) self.SetMenuBar(self.menuBar)
def showSettingInfo(setting): """Display information about the focused setting in the help panel. @param setting A settings.Setting object. """ # Values will be taken from the active profile. prof = pr.getActive() # The identifier of the setting. ident = setting.getId() msg = '<html>' # The name of the setting. msg += '<b><font size="+1">' + language.translate(ident) + \ '</font></b>' # The command line option. msg += '<br><table bgcolor="' + bgColor + '" width="100%"><tr><td>' + \ '<font size="-1"><tt>' + \ setting.getCommandLine(prof) + '</tt></font></table><p>' fromDefaults = False if prof.getValue(ident, False) == None: fromDefaults = True # The value comes from the default profile. msg += language.expand(language.translate('help-value-from-defaults'), pr.getDefaults().getName()) + '<p>' def valueToText(v): if language.isDefined(v): return language.translate(v) else: return v msg += tableBegin # The current value of the setting. value = prof.getValue(ident) if value: #msg += '<b>%s:</b><br>' % language.translate('help-value-current') #msg += valueToText(value.getValue()) #msg += '<p>' msg += tableRow + \ entryHeader(language.translate('help-value-current')) + \ entryContent(valueToText(value.getValue())) # Min and max for the range and slider settings. if setting.getType() == 'slider' or setting.getType() == 'range': #msg += '<b>' + language.translate('help-value-min') + ':</b><br>' + \ # str(setting.getMinimum()) #msg += '<p><b>' + language.translate('help-value-max') + \ # ':</b><br>' + str(setting.getMaximum()) #msg += '<p>' msg += tableRow + entryHeader(language.translate('help-value-min')) + \ entryContent(str(setting.getMinimum())) + \ tableRow + entryHeader(language.translate('help-value-max')) + \ entryContent(str(setting.getMaximum())) # The default. if prof.getValue(ident, False) != None and prof is pr.getDefaults(): if setting.getDefault() != None: #msg += '<b>%s:</b><br>' % language.translate('help-value-default') #msg += valueToText(str(setting.getDefault())) #msg += '<p>' msg += tableRow + \ entryHeader(language.translate('help-value-default')) + \ entryContent(valueToText(str(setting.getDefault()))) elif not fromDefaults and prof is not pr.getDefaults(): defValue = pr.getDefaults().getValue(ident) if defValue: #msg += '<b>%s:</b><br>' % language.translate('help-value-default') #msg += valueToText(defValue.getValue()) #msg += '<p>' msg += tableRow + \ entryHeader(language.translate('help-value-default')) + \ entryContent(valueToText(defValue.getValue())) msg += tableEnd # The help text of this setting. helpId = ident + '-help' if language.isDefined(helpId): msg += language.translate(helpId) msg += '</html>' # Display the setting information in the help panel. helpText.setText(msg) showLogo(False) # The info will be automatically updated in case it changes while # displayed. global currentSetting currentSetting = setting
def createResolver(problem, addons): """Create the necessary widgets in the area to resolve the problem. @param area An ui.Area object. Will be cleared. @param problem The problem description as returned by addons.findConflicts. @param addons Set of Addon objects. This should be modified according to the user's selections. """ global resolving # Set the general parameters of the resolver. resolving.problem = problem resolving.addons = addons resolving.area.clear() resolving.area.setWeight(2) message = resolving.area.createFormattedText() message.setMinSize(250, 250) resolving.area.setWeight(1) # Enter this problem into the log. log(problem) # The name of the problem. problemName = problem[0] if problemName == 'exclusion-by-category': # The list of excluded addons. names = map(lambda a: language.translate(a.getId()), problem[2]) names.sort() msg = "<ul><li>" + string.join(names, '<li>') + "</ul>" message.setText(language.expand( language.translate('category-conflict-message'), language.translate(problem[1].getId()), msg)) # Create the radio buttons. resolving.createConflictButtons(language.translate(problem[1].getId())) elif problemName == 'exclusion-by-keyword': msg = '<ul>' for addon, key in problem[2]: msg += '<li>' if addon.getId() != key: msg += key + " in " msg += language.translate(addon.getId()) msg += '</ul>' message.setText(language.expand( language.translate('keyword-conflict-message'), language.translate(problem[1].getId()), msg)) # Create the radio buttons. resolving.createConflictButtons(language.translate(problem[1].getId())) elif problemName == 'exclusion-by-value': # The list of excluded values. names = [] for v in problem[2]: if language.isDefined(v): names.append(language.translate(v)) else: names.append(v) msg = "<ul><li>" + string.join(names, '<li>') + "</ul>" message.setText(language.expand( language.translate('value-conflict-message'), language.translate(problem[1].getId()), msg)) elif problemName == 'provide-conflict': # Collect the conflicting addons into a list. resolving.conflicted = [] keys = [] for a, b, key in problem[1]: if a not in resolving.conflicted: resolving.conflicted.append(a) if b not in resolving.conflicted: resolving.conflicted.append(b) if key not in keys: keys.append(key) #ao.sortIdentifiersByName(conflicting) message.setText(language.expand( language.translate('provide-conflict-message'), "<ul><li>" + string.join(keys, '<li>') + "</ul>")) resolving.list = resolving.area.createList('') for a in resolving.conflicted: resolving.list.addItem(a.getId()) elif problemName == 'missing-requirements': resolving.conflicted = problem[1] res = "<p><ul>" res += "<li>" + string.join(problem[2], '<li>') + "</ul>" msg = language.expand( language.translate('missing-requirements-message'), language.translate(problem[1].getId())) message.setText(msg + res) resolving.list = None resolving.area.updateLayout()
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)
def updateSummary(profile): """Update the fields on the summary tab. Each tab summarises certain aspects of the profile's settings. @param profile A profiles.Profile object. The values will be taken from this profile. """ # Addon listing. summary = [] usedAddons = profile.getUsedAddons() ao.sortIdentifiersByName(usedAddons) usedAddons = filter(lambda a: ao.get(a).getBox() == None, usedAddons) for addon in usedAddons: # Don't let the list get too long; there is no scrolling, the # extra text will just get clipped... if len(summary) < 8: summary.append(language.translate(addon)) if len(summary) == 0: summary = ['-'] if len(summary) < len(usedAddons): # Indicate that all are not shown. summary[-1] += ' ...' addonListing.setText(string.join(summary, "\n")) addonListing.resizeToBestSize() # Values defined in the profile. summary = [] # These are displayed in another summary field or shouldn't be # shown at all. ignoredValues = [] #'window-size', 'window-width', 'window-height', 'color-depth', 'run-in-window'] for value in profile.getAllValues(): # Don't let the list get too long; there is no scrolling, the # extra text will just get clipped... if len(summary) >= 10: summary.append('...') break # Many settings are ignored in the summary. try: setting = st.getSetting(value.getId()) if (setting.getGroup() == 'general-options' or (setting.getGroup() == 'game-options' and 'server' not in setting.getId())): continue except KeyError: # This isn't even a valid setting! continue if value.getId() in ignoredValues: continue msg = language.translate(value.getId()) if language.isDefined(value.getValue()): if value.getValue() != 'yes': msg += ' = ' + language.translate(value.getValue()) else: msg += ' = ' + value.getValue() summary.append(msg) if len(summary) == 0: summary = ['-'] valuesListing.setText(string.join(summary, "\n")) valuesListing.resizeToBestSize() # The system summary shows the basic display settings. summary = [] # Begin with the resolution. #value = profile.getValue('window-size') #if value and value.getValue() != 'window-size-custom': # summary.append(language.translate(value.getValue())) #else: # w = profile.getValue('window-width') # h = profile.getValue('window-height') # if w and h: # summary.append(w.getValue() + ' x ' + h.getValue()) # Windowed mode is a special case. #value = profile.getValue('run-in-window') #if value and value.getValue() == 'yes': # summary.append(language.translate('summary-run-in-window')) #else: # value = profile.getValue('color-depth') # if value: # summary.append(language.translate('summary-' + \ # value.getValue())) #systemSummary.setText(string.join(summary, '\n')) #systemSummary.resizeToBestSize() ui.getArea(SUMMARY).updateLayout()
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
def updateMenus(self): """Create the main frame menus based on menuItems array.""" global menuItems self.menuCommandMap = {} # Array of menus. Number to wxMenu. self.menus = {} # Three levels of priority. for level in range(len(menuItems)): if len(menuItems[level]) == 0: # No menu for this. self.menus[level] = None continue self.menus[level] = wx.Menu() self.menuBar.Append(self.menus[level], language.translate("menu-" + str(level))) # Sort the items based on groups, and append separators where necessary. menuItems[level].sort(lambda x, y: cmp(x[3], y[3])) separated = [] previousItem = None for item in menuItems[level]: if previousItem and previousItem[3] != item[3]: separated.append(('-', '', False, item[3])) separated.append(item) previousItem = item # Create the menu items. for itemId, itemCommand, itemSeparate, itemGroup in separated: if itemId == '-': # This is just a separator. self.menus[level].AppendSeparator() continue if itemSeparate and self.menus[level].GetMenuItemCount() > 0: self.menus[level].AppendSeparator() menuItemId = 'menu-' + itemId accel = '' if language.isDefined(menuItemId + '-accel'): accel = "\t" + language.translate(menuItemId + '-accel') # Generate a new ID for the item. wxId = wx.NewId() self.menuCommandMap[wxId] = itemCommand self.menus[level].Append( wxId, uniConv(language.translate(menuItemId) + accel)) wx.EVT_MENU(self, wxId, self.onPopupCommand) if host.isMac(): # Special menu items on Mac. if itemId == 'about': wx.App_SetMacAboutMenuItemId(wxId) if itemId == 'quit': wx.App_SetMacExitMenuItemId(wxId) if itemId == 'show-snowberry-settings': wx.App_SetMacPreferencesMenuItemId(wxId) if host.isMac(): # Special Help menu on Mac. wx.App_SetMacHelpMenuTitleName( language.translate('menu-' + str(MENU_HELP))) self.SetMenuBar(self.menuBar)
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()
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)
def showSettingInfo(setting): """Display information about the focused setting in the help panel. @param setting A settings.Setting object. """ # Values will be taken from the active profile. prof = pr.getActive() # The identifier of the setting. ident = setting.getId() msg = '<html>' # The name of the setting. msg += '<b><font size="+1">' + language.translate(ident) + \ '</font></b>' # The command line option. msg += '<br><table bgcolor="' + bgColor + '" width="100%"><tr><td>' + \ '<font size="-1"><tt>' + \ setting.getCommandLine(prof) + '</tt></font></table><p>' fromDefaults = False if prof.getValue(ident, False) == None: fromDefaults = True # The value comes from the default profile. msg += language.expand( language.translate('help-value-from-defaults'), pr.getDefaults().getName()) + '<p>' def valueToText(v): if language.isDefined(v): return language.translate(v) else: return v msg += tableBegin # The current value of the setting. value = prof.getValue(ident) if value: #msg += '<b>%s:</b><br>' % language.translate('help-value-current') #msg += valueToText(value.getValue()) #msg += '<p>' msg += tableRow + \ entryHeader(language.translate('help-value-current')) + \ entryContent(valueToText(value.getValue())) # Min and max for the range and slider settings. if setting.getType() == 'slider' or setting.getType() == 'range': #msg += '<b>' + language.translate('help-value-min') + ':</b><br>' + \ # str(setting.getMinimum()) #msg += '<p><b>' + language.translate('help-value-max') + \ # ':</b><br>' + str(setting.getMaximum()) #msg += '<p>' msg += tableRow + entryHeader(language.translate('help-value-min')) + \ entryContent(str(setting.getMinimum())) + \ tableRow + entryHeader(language.translate('help-value-max')) + \ entryContent(str(setting.getMaximum())) # The default. if prof.getValue(ident, False) != None and prof is pr.getDefaults(): if setting.getDefault() != None: #msg += '<b>%s:</b><br>' % language.translate('help-value-default') #msg += valueToText(str(setting.getDefault())) #msg += '<p>' msg += tableRow + \ entryHeader(language.translate('help-value-default')) + \ entryContent(valueToText(str(setting.getDefault()))) elif not fromDefaults and prof is not pr.getDefaults(): defValue = pr.getDefaults().getValue(ident) if defValue: #msg += '<b>%s:</b><br>' % language.translate('help-value-default') #msg += valueToText(defValue.getValue()) #msg += '<p>' msg += tableRow + \ entryHeader(language.translate('help-value-default')) + \ entryContent(valueToText(defValue.getValue())) msg += tableEnd # The help text of this setting. helpId = ident + '-help' if language.isDefined(helpId): msg += language.translate(helpId) msg += '</html>' # Display the setting information in the help panel. helpText.setText(msg) showLogo(False) # The info will be automatically updated in case it changes while # displayed. global currentSetting currentSetting = setting
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()
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