Ejemplo n.º 1
0
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))
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
    def onClick(self, event):
        """Swap through the three states when the check box is clicked."""

        if self.widgetId:
            w = self.getWxWidget()
            state = w.Get3StateValue()

            if (state == wx.CHK_UNDETERMINED and 
                pr.getActive() is pr.getDefaults()):
                state = wx.CHK_UNCHECKED
                w.Set3StateValue(state)

            if state == wx.CHK_CHECKED:
                pr.getActive().setValue(self.widgetId, 'yes')
                newValue = 'yes'
                
            elif state == wx.CHK_UNCHECKED:
                pr.getActive().setValue(self.widgetId, 'no')
                newValue = 'no'

            else:
                pr.getActive().removeValue(self.widgetId)
                newValue = 'default'

            self.updateState()
            events.send(events.EditNotify(self.widgetId, newValue))
        
        # Let wxWidgets process the event, too.
        event.Skip()
Ejemplo n.º 4
0
    def onClick(self, event):
        """Swap through the three states when the check box is clicked."""

        if self.widgetId:
            w = self.getWxWidget()
            state = w.Get3StateValue()

            if (state == wx.CHK_UNDETERMINED
                    and pr.getActive() is pr.getDefaults()):
                state = wx.CHK_UNCHECKED
                w.Set3StateValue(state)

            if state == wx.CHK_CHECKED:
                pr.getActive().setValue(self.widgetId, 'yes')
                newValue = 'yes'

            elif state == wx.CHK_UNCHECKED:
                pr.getActive().setValue(self.widgetId, 'no')
                newValue = 'no'

            else:
                pr.getActive().removeValue(self.widgetId)
                newValue = 'default'

            self.updateState()
            events.send(events.EditNotify(self.widgetId, newValue))

        # Let wxWidgets process the event, too.
        event.Skip()
Ejemplo n.º 5
0
def handleNotify(event):
    """Handle notifications."""

    if event.hasId('init-done'):
        # If this is the first launch ever, we'll display the wizard.
        if not pr.getDefaults().getValue(HAS_BEEN_RUN):
            runWizard()
Ejemplo n.º 6
0
 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()
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
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
Ejemplo n.º 9
0
def handleNotify(event):
    if event.hasId('active-profile-changed'):
        # Disable or enable controls based on which profile is selected.
        if pr.getActive() is pr.getDefaults():
            playButton.disable()
            ui.disableMenuCommand('play')
            ui.disableMenuCommand('view-command-line')
        else:
            playButton.enable()
            ui.enableMenuCommand('play')
            ui.enableMenuCommand('view-command-line')
Ejemplo n.º 10
0
    def updateState(self):
        """Update the state of the indicator to match one of the three
        states."""

        if self.indicator:
            w = self.getWxWidget()
            if w.Get3StateValue() == wx.CHK_UNDETERMINED:
                self.indicator.setText(
                    '(' + language.translate('toggle-use-default-value') + \
                    language.translate(
                    pr.getDefaults().getValue(self.widgetId).getValue()) + ')')
            else:
                self.indicator.setText('')
Ejemplo n.º 11
0
    def updateState(self):
        """Update the state of the indicator to match one of the three
        states."""

        if self.indicator:
            w = self.getWxWidget()
            if w.Get3StateValue() == wx.CHK_UNDETERMINED:
                self.indicator.setText(
                    '(' + language.translate('toggle-use-default-value') + \
                    language.translate(
                    pr.getDefaults().getValue(self.widgetId).getValue()) + ')')
            else:
                self.indicator.setText('')
Ejemplo n.º 12
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.º 13
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.º 14
0
def handleCommand(event):
    if pr.getActive() is pr.getDefaults():
        return

    if event.hasId('play'):
        # Launch the game with the active profile.
        startGame(pr.getActive())

    elif event.hasId('continue') and resolving:
        continueResolving()

    elif event.hasId('view-command-line'):
        # Generate a command line and display it in a dialog.
        options = generateOptions(pr.getActive())
        if options == None:
            return

        # Escape any angle brackets.
        options = options.replace('<', '&lt;')
        options = options.replace('>', '&gt;')
        options = options.replace(' -', '<br>-')

        # Highlight all the options with a bold font.
        pos = 0
        while pos < len(options):
            if options[pos:pos + 5] == '<br>-' or \
                   pos == 0 and options[pos] == '-':
                options = options[:pos] + '<b>' + options[pos:]
                pos += 5
                while pos < len(options) and \
                      options[pos] not in string.whitespace:
                    pos += 1
                options = options[:pos] + '</b>' + options[pos:]
            pos += 1

        dialog, area = sb.util.dialog.createButtonDialog(
            'view-command-line-dialog',            
            ['ok'], 'ok')

        msg = area.createFormattedText()
        msg.setMinSize(500, 400)
        msg.setText('<tt>' + options + '</tt>')
        dialog.run()        
Ejemplo n.º 15
0
def makeProfileHTML(profile):
    if profile is pr.getDefaults():
        return makeHTML(profile.getName(), "defaults", boldName=True)
        # iconPath = paths.findBitmap('defaults')
        # iconSize = iconSizeString()
        # return '<table width="100%" border=0 cellspacing=2 cellpadding=5>' + \
        #   '<tr><td width="' + iconSize + \
        #   '"><img width="%s" height="%s"' % (iconSize, iconSize) + \
        #   ' src="' + iconPath + \
        #   '"><td align=left><font size="+1"><b>' + profile.getName() + \
        #   '</b></font></table>'
    else:
        game = "game-undefined"
        for c in profile.getComponents():
            if c[:5] == "game-":
                game = c
                break

        return makeHTML(profile.getName(), language.translate(game + "-icon"), language.translate(game))
Ejemplo n.º 16
0
def makeProfileHTML(profile):
    if profile is pr.getDefaults():
        return makeHTML(profile.getName(), 'defaults', boldName=True)
        #iconPath = paths.findBitmap('defaults')
        #iconSize = iconSizeString()
        #return '<table width="100%" border=0 cellspacing=2 cellpadding=5>' + \
        #   '<tr><td width="' + iconSize + \
        #   '"><img width="%s" height="%s"' % (iconSize, iconSize) + \
        #   ' src="' + iconPath + \
        #   '"><td align=left><font size="+1"><b>' + profile.getName() + \
        #   '</b></font></table>'
    else:
        game = 'game-undefined'
        for c in profile.getComponents():
            if c[:5] == 'game-':
                game = c
                break

        return makeHTML(profile.getName(), language.translate(game + '-icon'),
                        language.translate(game))
Ejemplo n.º 17
0
def handleCommand(event):
    """Handle commands."""
    if event.hasId('show-addon-settings'):
        # Switch to the Settings tab.
        ui.selectTab(SETTINGS)

        # Switch to the Addons category.
        categoryArea.selectTab('addons-options')

        # Switch to the correct tab.
        addonArea.selectTab(event.addon)
        
    elif event.hasId('show-snowberry-settings'):
        # Change to the Defaults profile.
        pr.setActive(pr.getDefaults())
    
        # Switch to the Settings tab.
        ui.selectTab(SETTINGS)
        
        # Switch to the Snowberry category.
        categoryArea.selectTab('general-options')        
Ejemplo n.º 18
0
def handleNotify(event):
    """This is called when someone sends a notification event."""

    #if event.hasId('init-done'):

    if (event.hasId('value-changed') or
          event.hasId('active-profile-changed')):
        # Update any settings with value dependencies.
        enableByRequirements(pr.getActive())
        showCompatibleAddons(pr.getActive())

        # Only the defaults profile has the General category.
        if pr.getActive() is pr.getDefaults():
            wasIt = (categoryArea.getSelectedTab() == 'game-options')
            
            categoryArea.showTab('general-options')
            categoryArea.showTab('game-options', False)

            if wasIt:
                categoryArea.selectTab('general-options')
        else:
            wasIt = (categoryArea.getSelectedTab() == 'general-options')

            categoryArea.showTab('game-options')
            categoryArea.showTab('general-options', False)

            if wasIt:
                categoryArea.selectTab('game-options')

            categoryArea.updateIcon('game-options')

    elif event.hasId('addon-database-reloaded'):
        # Since the new addon will most likely introduce new settings,
        # we'll need to recreate the all the settings tabs.
        createWidgets()

        # The newly-created widgets don't have any data in them.  Make
        # them refresh their values.
        pr.refresh()
Ejemplo n.º 19
0
def notifyHandler(event):
    "This is called when a Notify event is broadcasted."

    # We are interested in notifications that concern profiles.
    if event.hasId('quit'):
        # Save the current profile configuration.
        pr.save()

    elif event.hasId('language-changed'):
        # Just update the Defaults, because it's the only profile whose name
        # is translated.
        addListItem(pr.getDefaults())

    elif event.hasId('profile-updated'):
        # A profile has been loaded or updated.  Make sure it's in the
        # list.
        p = event.getProfile()

        # The Defaults profile should be first in the list.
        if p is pr.getDefaults():
            destIndex = 0
        else:
            # The new profile will be added to wherever the widget
            # wants to put it.
            destIndex = None

        if profileList.hasItem(p.getId()):
            # This already exists in the list.
            if p.isHidden():
                # Remove it completely.
                profileList.removeItem(p.getId())

                # Update the selected item since the active one is now
                # hidden.
                pr.setActive(pr.get(profileList.getSelectedItem()))
            else:
                # Just update the item.
                addListItem(p)

        elif not p.isHidden():
            # The item does not yet exist in the list.
            addListItem(p, toIndex=destIndex)

    elif event.hasId('active-profile-changed') and not profileListDisabled:
        # Highlight the correct profile in the list.
        profileList.selectItem(pr.getActive().getId())

        if pr.getActive() is pr.getDefaults():
            if deleteButton: deleteButton.disable()
            if dupeButton: dupeButton.disable()
            ui.disableMenuCommand('rename-profile')
            ui.disableMenuCommand('delete-profile')
            ui.disableMenuCommand('hide-profile')
            ui.disableMenuCommand('duplicate-profile')
            profileList.setPopupMenu(defaultsMenu)
        else:
            isSystem = pr.getActive().isSystemProfile()
            if deleteButton: deleteButton.enable(not isSystem)
            if dupeButton: dupeButton.enable()
            ui.enableMenuCommand('rename-profile')
            ui.enableMenuCommand('delete-profile', not isSystem)
            ui.enableMenuCommand('hide-profile')
            ui.enableMenuCommand('duplicate-profile')
            if isSystem:
                menu = systemMenu
            else:
                menu = normalMenu
            profileList.setPopupMenu(menu)

        # Update the banner image.
        if bannerImage:
            bannerImage.setImage(pr.getActive().getBanner())

    elif event.hasId('profile-list-selected'):
        # Change the currently active profile.
        p = pr.get(event.getSelection())
        pr.setActive(p)

        # Double-clicking causes a Play command.
        if event.isDoubleClick() and p is not pr.getDefaults():
            events.sendAfter(events.Command('play'))
Ejemplo n.º 20
0
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()
Ejemplo n.º 21
0
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
Ejemplo n.º 22
0
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
Ejemplo n.º 23
0
def notifyHandler(event):
    "This is called when a Notify event is broadcasted."

    # We are interested in notifications that concern profiles.
    if event.hasId("quit"):
        # Save the current profile configuration.
        pr.save()

    elif event.hasId("language-changed"):
        # Just update the Defaults, because it's the only profile whose name
        # is translated.
        addListItem(pr.getDefaults())

    elif event.hasId("profile-updated"):
        # A profile has been loaded or updated.  Make sure it's in the
        # list.
        p = event.getProfile()

        # The Defaults profile should be first in the list.
        if p is pr.getDefaults():
            destIndex = 0
        else:
            # The new profile will be added to wherever the widget
            # wants to put it.
            destIndex = None

        if profileList.hasItem(p.getId()):
            # This already exists in the list.
            if p.isHidden():
                # Remove it completely.
                profileList.removeItem(p.getId())

                # Update the selected item since the active one is now
                # hidden.
                pr.setActive(pr.get(profileList.getSelectedItem()))
            else:
                # Just update the item.
                addListItem(p)

        elif not p.isHidden():
            # The item does not yet exist in the list.
            addListItem(p, toIndex=destIndex)

    elif event.hasId("active-profile-changed") and not profileListDisabled:
        # Highlight the correct profile in the list.
        profileList.selectItem(pr.getActive().getId())

        if pr.getActive() is pr.getDefaults():
            if deleteButton:
                deleteButton.disable()
            if dupeButton:
                dupeButton.disable()
            ui.disableMenuCommand("rename-profile")
            ui.disableMenuCommand("delete-profile")
            ui.disableMenuCommand("hide-profile")
            ui.disableMenuCommand("duplicate-profile")
            profileList.setPopupMenu(defaultsMenu)
        else:
            isSystem = pr.getActive().isSystemProfile()
            if deleteButton:
                deleteButton.enable(not isSystem)
            if dupeButton:
                dupeButton.enable()
            ui.enableMenuCommand("rename-profile")
            ui.enableMenuCommand("delete-profile", not isSystem)
            ui.enableMenuCommand("hide-profile")
            ui.enableMenuCommand("duplicate-profile")
            if isSystem:
                menu = systemMenu
            else:
                menu = normalMenu
            profileList.setPopupMenu(menu)

        # Update the banner image.
        if bannerImage:
            bannerImage.setImage(pr.getActive().getBanner())

    elif event.hasId("profile-list-selected"):
        # Change the currently active profile.
        p = pr.get(event.getSelection())
        pr.setActive(p)

        # Double-clicking causes a Play command.
        if event.isDoubleClick() and p is not pr.getDefaults():
            events.sendAfter(events.Command("play"))
Ejemplo n.º 24
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.º 25
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