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 getValue(self, id, fallbackToDefaults=True): """Returns the Value for the given setting. Falls back to the defaults profile. @param id Setting identifier. @param fallbackToDefaults If True, the value is retrieved from the Defaults profile if it isn't defined in this one. """ defaults = profdb.defaults # If this is a system setting, let's consult the system # configuration. if st.isDefined(id): return Value(id, st.getSystemString(id)) # First look in the Values in this profile. for v in self.values: if v.getId() == id: return v if id == 'game-mode': # We can look for the game mode in the system profile. sysProfFileName = os.path.join(paths.getSystemPath(paths.PROFILES), self.getFileName()) if os.path.exists(sysProfFileName): try: p = cfparser.FileParser(sysProfFileName) while True: element = p.get() if element.isKey() and element.getName() == 'game-mode': return Value(element.getName(), element.getValue()) except cfparser.OutOfElements: # The file ended normally. pass # Fall back to the Defaults profile. if fallbackToDefaults and self is not defaults: return defaults.getValue(id) elif self is defaults: # See if the setting itself has a default for this. try: setting = st.getSetting(id) if setting.getDefault(): return Value(id, str(setting.getDefault())) except: pass # No Value for this setting could be found. return None else: # A normal profile with no value for this setting. return None
def runWizard(): """Run the wizard dialog.""" # Make sure the help panel isn't updated during the wizard. #events.send(events.Command('freeze')) suggested = { 'doom1': 'DOOM.WAD', 'doom1-share': 'DOOM1.WAD', 'doom1-ultimate': 'DOOM.WAD', 'doom2': 'DOOM2.WAD', 'doom2-tnt': 'TNT.WAD', 'doom2-plut': 'PLUTONIA.WAD', 'heretic-ext': 'HERETIC.WAD', 'heretic-share': 'HERETIC.WAD', 'heretic': 'HERETIC.WAD', 'hexen': 'HEXEN.WAD', 'hexen-demo': 'HEXEN.WAD', 'hexen-dk': 'HEXEN.WAD', 'hacx': 'HACX.WAD', 'chex': 'CHEX.WAD' } events.mute() # Make the Defaults profile active. pr.setActive(pr.getDefaults()) wiz = WizardDialog(language.translate('setup-wizard'), paths.findBitmap('wizard')) # Language selection page. langPage = WizardPage(wiz, 'wizard-language') area = langPage.getArea() area.createText('wizard-language-explanation', maxLineLength=65).resizeToBestSize() sar, languageCheckBox = area.createSetting(st.getSetting('language')) languageCheckBox.getFromProfile(pr.getActive()) # Game selection. gamePage = ProfileWizardPage(wiz, 'wizard-games', None) gamePage.follows(langPage) area = gamePage.getArea() area.createText('wizard-select-games', maxLineLength=65).resizeToBestSize() area.setBorderDirs(ui.BORDER_NOT_BOTTOM) games = area.createList('', style=sb.widget.list.List.STYLE_CHECKBOX) area.setBorderDirs(ui.BORDER_NOT_TOP) games.setMinSize(50, 180) gamePage.setGameList(games) def allGames(): # Check the entire list. for item in games.getItems(): games.checkItem(item, True) def clearGames(): # Uncheck the entire list. for item in games.getItems(): games.checkItem(item, False) controls = area.createArea(alignment=ui.ALIGN_HORIZONTAL, border=2) controls.setWeight(0) button = controls.createButton('wizard-games-all', wb.Button.STYLE_MINI) button.addReaction(allGames) button.resizeToBestSize() button = controls.createButton('wizard-games-clear', wb.Button.STYLE_MINI) button.addReaction(clearGames) button.resizeToBestSize() # The pages will be linked together. previousPage = gamePage deathKingsWad = None # We'll do this dynamically. checkedProfiles = ['doom1', 'doom2', 'heretic', 'hexen'] # Only display the system profiles in the wizard (not any user # profiles). profiles = pr.getProfiles(lambda p: p.isSystemProfile()) for p in profiles: if p is not pr.getDefaults(): games.addItem(p.getId(), p.getId() in checkedProfiles) # Create a page for the profile. page = ProfileWizardPage(wiz, p.getId(), games) # Link the pages together. page.follows(previousPage) previousPage = page area = page.getArea() area.createText('wizard-locate-iwad', maxLineLength=65).resizeToBestSize() # The suggestion. if suggested.has_key(p.getId()): sugArea = area.createArea(alignment=ui.ALIGN_HORIZONTAL, border=2) sugArea.setExpanding(False) sugArea.setWeight(1) sugArea.createText('wizard-suggested-iwad', ':', align=wt.Text.RIGHT) sugArea.setWeight(2) sug = sugArea.createText('') sug.setText(suggested[p.getId()]) sar, page.iwadText = area.createSetting(st.getSetting('iwad')) if p.getId() == 'hexen-dk': area.setBorder(12, ui.BORDER_ALL) area.createLine() area.setBorder(6, ui.BORDER_ALL) area.createText('deathkings-selection-title').setHeadingStyle() # Death Kings is an extension to Hexen. It uses the # same Hexen IWAD, but also an addon IWAD. area.createText('wizard-locate-iwad-deathkings', maxLineLength=65).resizeToBestSize() entry = area.createArea(alignment=ui.ALIGN_HORIZONTAL, border=4) entry.setExpanding(False) entry.setWeight(1) entry.setBorderDirs(ui.BORDER_NOT_LEFT) deathKingsWad = entry.createTextField('') entry.setWeight(0) entry.setBorderDirs(ui.BORDER_TOP_BOTTOM) browseButton = entry.createButton('browse-button', wb.Button.STYLE_MINI) def browseDeathKings(): # Open a file browser. selection = sb.util.dialog.chooseFile('deathkings-selection-title', '', True, [('file-type-wad', 'wad')]) if len(selection) > 0: deathKingsWad.setText(selection) browseButton.addReaction(browseDeathKings) # Addon paths. pathsPage = ProfileWizardPage(wiz, 'wizard-addon-paths', games) pathsPage.follows(previousPage) area = pathsPage.getArea() area.createText('wizard-addon-paths-explanation', maxLineLength=65).resizeToBestSize() area.setBorderDirs(ui.BORDER_NOT_BOTTOM) pathList = area.createList('addon-paths-list') pathList.setMinSize(100, 120) # Insert the current custom paths into the list. for p in paths.getAddonPaths(): pathList.addItem(p) def addAddonPath(): selection = sb.util.dialog.chooseFolder('addon-paths-add-prompt', '') if selection: pathList.addItem(selection) pathList.selectItem(selection) def removeAddonPath(): selection = pathList.getSelectedItem() if selection: pathList.removeItem(selection) area.setWeight(0) area.setBorderDirs(ui.BORDER_NOT_TOP) commands = area.createArea(alignment=ui.ALIGN_HORIZONTAL, border=2) commands.setWeight(0) # Button for adding new paths. button = commands.createButton('new-addon-path', wb.Button.STYLE_MINI) button.addReaction(addAddonPath) # Button for removing a path. button = commands.createButton('delete-addon-path', wb.Button.STYLE_MINI) button.addReaction(removeAddonPath) # Launch options. quitPage = WizardPage(wiz, 'wizard-launching') quitPage.follows(pathsPage) area = quitPage.getArea() area.createText('wizard-launching-explanation').resizeToBestSize() sar, quitCheckBox = area.createSetting(st.getSetting('quit-on-launch')) quitCheckBox.getFromProfile(pr.getActive()) # List of unusable profiles, due to a missing IWAD. unusableProfiles = [] # When the page changes in the wizard, change the active profile. def changeActiveProfile(page): prof = pr.get(page.getId()) if prof: pr.setActive(prof) else: pr.setActive(pr.getDefaults()) # Update page with values from the current profile. page.update() wiz.setPageReaction(changeActiveProfile) if wiz.run(langPage) == 'ok': events.unmute() # Show the profiles that now have an IWAD. for prof in profiles: if prof.getValue('iwad', False) != None: pr.show(prof.getId()) if prof.getId() in unusableProfiles: unusableProfiles.remove(prof.getId()) else: pr.hide(prof.getId()) if prof.getId() not in unusableProfiles and \ prof.getId() in games.getSelectedItems(): unusableProfiles.append(prof.getId()) # Install the Death Kings WAD? if deathKingsWad: try: ident = ao.install(deathKingsWad.getText()) # Attach the WAD as an addon. kingsProfile = pr.get('hexen-dk') kingsProfile.useAddon(ident) except: # TODO: Handle error. pass # Update custom addon paths. currentAddonPaths = paths.getAddonPaths() wasModified = False for path in pathList.getItems(): if path not in currentAddonPaths: paths.addAddonPath(path) wasModified = True for path in currentAddonPaths: if path not in pathList.getItems(): paths.removeAddonPath(path) wasModified = True if wasModified: # Load addons from new paths. ao.refresh() events.send(events.Notify('addon-paths-changed')) # The wizard will only be shown once automatically. pr.getDefaults().setValue(HAS_BEEN_RUN, 'yes', False) else: # Wizard was canceled. events.unmute() pr.refresh() # This'll destroy all the pages of the wizard as well. wiz.destroy() # Enable help panel updates again. #events.send(events.Command('unfreeze')) # Tell the user about unusable profiles. if len(unusableProfiles) > 0: dialog, area = sb.util.dialog.createButtonDialog( 'wizard-unlaunchable-profiles', ['ok'], 'ok', resizable=False) # Compose a list of the unlaunchable profiles. profList = '' unusableProfiles.sort(lambda a, b: cmp(language.translate(a), language.translate(b))) for p in unusableProfiles: profList += "\n" + language.translate(p) msg = area.createText() msg.setText(language.translate('wizard-unlaunchable-profiles-listed') + "\n" + profList) msg.resizeToBestSize() dialog.run()
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()