def createWidgets(): """Create all the setting widgets and tabs. This is done at startup and when addons are installed or uninstalled.""" # Start with a fresh category tab area. categoryArea.removeAllTabs() # An array that contains all the existing setting groups. global categoryTabs categoryTabs = [] # Create all the category icons. allSettingGroups = st.getSettingGroups() for group in allSettingGroups: area = categoryArea.addTab(group) categoryTabs.append((group, area)) # Addon settings all go inside one tab. area = categoryArea.addTab('addons-options') categoryTabs.append(('addons-options', area)) # The Addons tab contains another tab area, where we'll have one # tab for each configurable addon that will be loaded. global addonArea addonArea = area.createTabArea('addontab', sb.widget.tab.TabArea.STYLE_DROP_LIST) # Get all addons that exist, get their identifiers, and sort them # by name. allAddons = map(lambda a: a.getId(), ao.getAddons()) ao.sortIdentifiersByName(allAddons) for addon in allAddons: # Only create tabs for the addons that actually have settings # defined for them. if st.haveSettingsForAddon(addon): area = addonArea.addTab(addon) categoryTabs.append((addon, area)) # Each addon may have multiple pages inside its area. # These are determined by the groups. addonGroups = st.getSettingGroups(addon) if len(addonGroups) > 0: # Create tabs for each group. area = area.createTabArea(addon + '-tab', sb.widget.tab.TabArea.STYLE_HORIZ_ICON) for group in addonGroups: groupId = addon + '-' + group categoryTabs.append((groupId, area.addTab(groupId))) # Populate all the tabs with the setting widgets. When a profile # becomes active, the settings that are not applicable will be # disabled. Certain tab pages may be hidden if they are not # applicable. populateTabs() # Request others to create additional widgets in the tabs. requestPopulation() # Redo the layout. ui.getArea(SETTINGS).updateLayout()
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()