def handleNotify(event): """This is called when somebody sends a notification. @param event A events.Notify object. """ if event.hasId('show-help-text-now'): helpText.unfreeze() return if helpDisabled: return if event.hasId('init-done'): setField(FIELD_MAIN, language.translate('help-welcome')) setField(FIELD_COMMAND, language.translate('help-command-defaults')) updateHelpText() elif event.hasId('show-help-text-now'): helpText.unfreeze() elif event.hasId('active-profile-changed'): if pr.getActive() is pr.getDefaults(): setField(FIELD_COMMAND, language.translate('help-command-defaults')) else: setField(FIELD_COMMAND, language.translate('help-command')) elif event.hasId('tab-selected'): setField(FIELD_MAIN, '') setField(FIELD_CURRENT_TAB, language.translate('help-' + event.getSelection())) elif event.hasId('addon-list-selected') or \ event.hasId('maps-list-selected'): # Display information about the selected addon in the panel. try: showAddonInfo(ao.get(event.getSelection())) except KeyError: # It wasn't an addon. pass elif event.hasId('focus-changed'): try: setting = st.getSetting(event.getFocus()) showSettingInfo(setting) except KeyError: # It was likely not a setting id. pass elif event.hasId('value-changed'): if currentSetting and event.getSetting() == currentSetting.getId(): showSettingInfo(currentSetting) elif event.hasId('language-changed'): pass
def refreshItemInList(item): addon = ao.get(item) defaultAddons = pr.getDefaults().getAddons() if pr.getActive() is not pr.getDefaults(): profileAddons = pr.getActive().getAddons() else: profileAddons = None # Update the image of the item. addonList.setItemImage(item, determineIcon(addon, pr.getActive(), defaultAddons, profileAddons))
def refreshItemInList(item): addon = ao.get(item) defaultAddons = pr.getDefaults().getAddons() if pr.getActive() is not pr.getDefaults(): profileAddons = pr.getActive().getAddons() else: profileAddons = None # Update the image of the item. addonList.setItemImage( item, determineIcon(addon, pr.getActive(), defaultAddons, profileAddons))
def settingFilter(s): if len(s.getRequiredAddons()) > 0: ident = s.getRequiredAddons()[0] properTab = ident # The addon does not exist? if not ao.exists(ident) or ao.get(ident).isUninstalled(): return False if s.getGroup(): # Addon setting with a group. properTab += '-' + s.getGroup() elif not s.getGroup(): properTab = 'general-options' else: properTab = s.getGroup() return properTab == areaId
def generateOptions(profile): """Generate a text string of all the command line options used when launching a game. @param profile A profiles.Profile object. The values of settings are retrieved from here. @return All the options in a single string. Returns None if there is an unresolved addon conflict. """ clearLog() # Determine which addons are in use. The final list of addons # includes all the addons that must be loaded at launch (defaults; # required parts of boxes). usedAddonIds = profile.getFinalAddons() usedAddons = map(lambda id: ao.get(id), usedAddonIds) # Form the command line. cmdLine = [] # Determine the settings that apply to the components and # addons. effectiveSettings = st.getCompatibleSettings(profile) # Are there any system-specific options defined? if st.isDefined('common-options'): cmdLine.append(ex.evaluate(st.getSystemString('common-options'), None)) # All profiles use the same runtime directory. if st.isDefined('doomsday-base'): basePath = os.path.abspath(st.getSystemString('doomsday-base')) cmdLine.append('-basedir ' + paths.quote(basePath)) # Determine the components used by the profile. for compId in profile.getComponents(): # Append the component's options to the command line as-is. cmdLine.append( st.getComponent(compId).getOption() ) # Resolve conflicting addons by letting the user choose between # them. if not resolveAddonConflicts(usedAddons, profile): # Launch aborted! return None # Get the command line options for loading all the addons. for addon in usedAddons: params = addon.getCommandLine(profile).strip() if params: cmdLine.append(params) # Update IDs of used addons. usedAddonsId = map(lambda a: a.getId(), usedAddons) # Get the command line options from each setting. for setting in effectiveSettings: # If the setting's required addons are not being loaded, skip # this setting. skipThis = False for req in setting.getRequiredAddons(): if req not in usedAddonIds: skipThis = True break if skipThis: continue # All settings can't be used at all times. In # case of a conflict, some of the settings are ignored. if setting.isEnabled(profile): params = setting.getCommandLine(profile).strip() if params: cmdLine.append(params) # Send a launch options notification. This is done so that # plugins are able to observe/modify the list of launch options. events.send(events.LaunchNotify(cmdLine)) return string.join(cmdLine, ' ')
def handleCommand(event): """This is called when someone sends a command event. @param event An events.Command object.""" # Figure out which addon has been currently selected in the addons # tree. The action will target this addon. selected = '' if event.hasId('refresh-addon-database'): ao.refresh() elif event.hasId('install-addon'): tab30.installer.run() elif event.hasId('uninstall-addon'): selectedItems = addonList.getSelectedItems() # Only take the uninstallable addons. addons = filter(lambda i: ao.isUninstallable(i), selectedItems) if len(addons) == 0: return # Make sure the user wants to uninstall. dialog, area = sb.util.dialog.createButtonDialog( 'uninstall-addon-dialog', ['no', 'yes'], 'no', resizable=False) if len(addons) == 1: text = language.translate('uninstall-addon-query') area.setExpanding(True) area.createRichText( language.expand(text, language.translate(addons[0]))) else: area.setWeight(0) area.createText('uninstall-addon-query-several') msg = '<html><ul>' for addon in addons: msg += '<li>' + language.translate(addon) + '</li>' msg += '</ul></html>' ft = area.createFormattedText() ft.setText(msg) ft.setMinSize(400, 150) if dialog.run() == 'yes': for addon in addons: ao.uninstall(addon) ao.refresh() elif event.hasId('addon-info'): sel = addonList.getSelectedItems() if len(sel) > 0: # Show the Addon Inspector. tab30.inspector.run(ao.get(sel[0])) elif event.hasId('addon-settings'): sel = addonList.getSelectedItems() if len(sel) > 0: command = events.Command('show-addon-settings') command.addon = sel[0] events.send(command) elif event.hasId('load-order'): # Open the Load Order dialog. tab30.loadorder.run(pr.getActive()) elif event.hasId('addon-list-check-selected'): for addon in addonList.getSelectedItems(): pr.getActive().useAddon(addon) elif event.hasId('addon-list-uncheck-selected'): for addon in addonList.getSelectedItems(): pr.getActive().dontUseAddon(addon) elif event.hasId('addon-list-check-all'): for addon in addonList.getItems(): pr.getActive().useAddon(addon) elif event.hasId('addon-list-uncheck-all'): for addon in addonList.getItems(): pr.getActive().dontUseAddon(addon) elif event.hasId('addon-show-parent-box'): for addon in addonList.getSelectedItems(): a = ao.get(addon) if a.getBox(): showInAddonList(a.getBox().getId()) break elif event.hasId('addon-show-box-category'): for addon in addonList.getSelectedItems(): a = ao.get(addon) if a.getType() == 'addon-type-box': addonList.deselectAllItems() tree.selectItem(a.getContentCategoryLongId()) refreshListIfVisible() break
def handleNotification(event): """This is called when someone sends a notification event. @param event An events.Notify object. """ global tabVisible global mustRefreshList if event.hasId('addon-list-icon-click'): # Clicking on the list icon will attach/detach the addon. profile = pr.getActive() if event.item in profile.getUsedAddons(): profile.dontUseAddon(event.item) else: profile.useAddon(event.item) elif event.hasId('addon-attached') or event.hasId('addon-detached'): refreshItemInList(event.getAddon()) elif event.hasId('addon-list-filter-mode-selected'): refreshListIfVisible() elif event.hasId('addon-list-check-column-click') or \ event.hasId('addon-list-name-column-click') or \ event.hasId('addon-list-version-column-click'): global listSortMode if 'check' in event.getId(): listSortMode = 'check' elif 'version' in event.getId(): listSortMode = 'version' else: listSortMode = 'name' sortList() elif event.hasId('tab-selected'): # If there is a refresh pending, do it now that the tab has # been selected. if event.getSelection() == ADDONS: tabVisible = True if mustRefreshList: refreshList() else: tabVisible = False elif event.hasId('active-profile-changed'): refreshListIfVisible() # Fill the tree with an updated listing of addons. #tree.populateWithAddons(pr.getActive()) #settingsButton.disable() elif event.hasId('addon-list-popup-update-request'): # The addon list is requesting an updated popup menu. # Menu items depend on which items are selected. items = addonList.getSelectedItems() menu = [] if len(items) == 1: # One addon is selected. if ao.get(items[0]).getBox(): menu += ['addon-show-parent-box'] if ao.get(items[0]).getType() == 'addon-type-box': menu += ['addon-show-box-category'] # Info is always available for all addons. menu += ['addon-info'] if st.haveSettingsForAddon(items[0]): menu += ['addon-settings'] elif len(items) > 1: # Multiple addons selected. menu += [ 'addon-list-check-selected', 'addon-list-uncheck-selected' ] if len(items) > 0: menu += ['uninstall-addon'] # Append the common items. if len(menu) > 0: menu.append('-') menu += ['install-addon'] menu += ['load-order'] menu += ['-', 'addon-list-check-all', 'addon-list-uncheck-all'] addonList.setPopupMenu(menu) elif event.hasId('category-tree-selected'): refreshListIfVisible() # Enable the settings button if there are settings for this # addon. #if st.haveSettingsForAddon(event.getSelection()): # settingsButton.enable() #else: # settingsButton.disable() # Can this be uninstalled? #uninstallButton.enable(ao.exists(event.getSelection()) and # ao.get(event.getSelection()).getBox() == None) elif event.hasId('addon-list-selected') or event.hasId( 'addon-list-deselected'): updateButtons() elif event.hasId('addon-installed'): refreshCategories() refreshListIfVisible() #tree.selectAddon(event.addon) elif event.hasId('addon-database-reloaded'): refreshCategories() refreshListIfVisible()
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 handleCommand(event): """This is called when someone sends a command event. @param event An events.Command object.""" # Figure out which addon has been currently selected in the addons # tree. The action will target this addon. selected = '' if event.hasId('refresh-addon-database'): ao.refresh() elif event.hasId('install-addon'): tab30.installer.run() elif event.hasId('uninstall-addon'): selectedItems = addonList.getSelectedItems() # Only take the uninstallable addons. addons = filter(lambda i: ao.isUninstallable(i), selectedItems) if len(addons) == 0: return # Make sure the user wants to uninstall. dialog, area = sb.util.dialog.createButtonDialog( 'uninstall-addon-dialog', ['no', 'yes'], 'no', resizable=False) if len(addons) == 1: text = language.translate('uninstall-addon-query') area.setExpanding(True) area.createRichText(language.expand(text, language.translate(addons[0]))) else: area.setWeight(0) area.createText('uninstall-addon-query-several') msg = '<html><ul>' for addon in addons: msg += '<li>' + language.translate(addon) + '</li>' msg += '</ul></html>' ft = area.createFormattedText() ft.setText(msg) ft.setMinSize(400, 150) if dialog.run() == 'yes': for addon in addons: ao.uninstall(addon) ao.refresh() elif event.hasId('addon-info'): sel = addonList.getSelectedItems() if len(sel) > 0: # Show the Addon Inspector. tab30.inspector.run(ao.get(sel[0])) elif event.hasId('addon-settings'): sel = addonList.getSelectedItems() if len(sel) > 0: command = events.Command('show-addon-settings') command.addon = sel[0] events.send(command) elif event.hasId('load-order'): # Open the Load Order dialog. tab30.loadorder.run(pr.getActive()) elif event.hasId('addon-list-check-selected'): for addon in addonList.getSelectedItems(): pr.getActive().useAddon(addon) elif event.hasId('addon-list-uncheck-selected'): for addon in addonList.getSelectedItems(): pr.getActive().dontUseAddon(addon) elif event.hasId('addon-list-check-all'): for addon in addonList.getItems(): pr.getActive().useAddon(addon) elif event.hasId('addon-list-uncheck-all'): for addon in addonList.getItems(): pr.getActive().dontUseAddon(addon) elif event.hasId('addon-show-parent-box'): for addon in addonList.getSelectedItems(): a = ao.get(addon) if a.getBox(): showInAddonList(a.getBox().getId()) break elif event.hasId('addon-show-box-category'): for addon in addonList.getSelectedItems(): a = ao.get(addon) if a.getType() == 'addon-type-box': addonList.deselectAllItems() tree.selectItem(a.getContentCategoryLongId()) refreshListIfVisible() break
def handleNotification(event): """This is called when someone sends a notification event. @param event An events.Notify object. """ global tabVisible global mustRefreshList if event.hasId('addon-list-icon-click'): # Clicking on the list icon will attach/detach the addon. profile = pr.getActive() if event.item in profile.getUsedAddons(): profile.dontUseAddon(event.item) else: profile.useAddon(event.item) elif event.hasId('addon-attached') or event.hasId('addon-detached'): refreshItemInList(event.getAddon()) elif event.hasId('addon-list-filter-mode-selected'): refreshListIfVisible() elif event.hasId('addon-list-check-column-click') or \ event.hasId('addon-list-name-column-click') or \ event.hasId('addon-list-version-column-click'): global listSortMode if 'check' in event.getId(): listSortMode = 'check' elif 'version' in event.getId(): listSortMode = 'version' else: listSortMode = 'name' sortList() elif event.hasId('tab-selected'): # If there is a refresh pending, do it now that the tab has # been selected. if event.getSelection() == ADDONS: tabVisible = True if mustRefreshList: refreshList() else: tabVisible = False elif event.hasId('active-profile-changed'): refreshListIfVisible() # Fill the tree with an updated listing of addons. #tree.populateWithAddons(pr.getActive()) #settingsButton.disable() elif event.hasId('addon-list-popup-update-request'): # The addon list is requesting an updated popup menu. # Menu items depend on which items are selected. items = addonList.getSelectedItems() menu = [] if len(items) == 1: # One addon is selected. if ao.get(items[0]).getBox(): menu += ['addon-show-parent-box'] if ao.get(items[0]).getType() == 'addon-type-box': menu += ['addon-show-box-category'] # Info is always available for all addons. menu += ['addon-info'] if st.haveSettingsForAddon(items[0]): menu += ['addon-settings'] elif len(items) > 1: # Multiple addons selected. menu += ['addon-list-check-selected', 'addon-list-uncheck-selected'] if len(items) > 0: menu += ['uninstall-addon'] # Append the common items. if len(menu) > 0: menu.append('-') menu += ['install-addon'] menu += ['load-order'] menu += ['-', 'addon-list-check-all', 'addon-list-uncheck-all'] addonList.setPopupMenu(menu) elif event.hasId('category-tree-selected'): refreshListIfVisible() # Enable the settings button if there are settings for this # addon. #if st.haveSettingsForAddon(event.getSelection()): # settingsButton.enable() #else: # settingsButton.disable() # Can this be uninstalled? #uninstallButton.enable(ao.exists(event.getSelection()) and # ao.get(event.getSelection()).getBox() == None) elif event.hasId('addon-list-selected') or event.hasId('addon-list-deselected'): updateButtons() elif event.hasId('addon-installed'): refreshCategories() refreshListIfVisible() #tree.selectAddon(event.addon) elif event.hasId('addon-database-reloaded'): refreshCategories() refreshListIfVisible()