def setLaunchMessage(text): """Launch message is displayed next to the Play button.""" launchText.setText(text) launchText.resizeToBestSize() ui.getArea(ui.COMMAND).updateLayout() if text: # Clear the message after a short delay. launchTextTimer.start(4000)
def init(): """Create the Play button.""" area = ui.getArea(ui.COMMAND) area.addSpacer() global logFileName logFileName = os.path.join(paths.getUserPath(paths.RUNTIME), "Conflicts.log") global launchText launchText = area.createText('') #launch-message') global playButton playButton = area.createButton('play', wg.Button.STYLE_DEFAULT) global resolving resolving = ResolveStatus() playButton.setPopupMenu(['view-command-line']) # Register for listening to notifications. events.addNotifyListener(handleNotify, ['active-profile-changed']) # Register for listening to commands. events.addCommandListener(handleCommand, ['play', 'view-command-line', 'continue']) # Commands for the popup menu. ui.addMenuCommand(ui.MENU_APP, 'quit', group=ui.MENU_GROUP_APP) ui.addMenuCommand(ui.MENU_PROFILE, 'play', group=ui.MENU_GROUP_LAUNCH) ui.addMenuCommand(ui.MENU_TOOLS, 'view-command-line', group=ui.MENU_GROUP_LAUNCH)
def init(): "Create the HTML text widget into the help area." ui.addMenuCommand(ui.MENU_HELP, 'open-documentation', pos=0) try: helpArea = ui.getArea(ui.HELP) except KeyError: # The Help area does not exist. We don't have much to do here. events.addCommandListener(handleCommand, ['open-documentation']) return helpArea.setExpanding(True) helpArea.setWeight(1) # Create a HTML text widget. global helpText helpArea.setBorder(3) helpText = helpArea.createFormattedText() # Unfreeze the help text after a minor delay. This'll make the app # init a bit smoother. helpText.freeze() helpTextTimer.start(1000) # Set parameters suitable for the logo. helpArea.setWeight(0) helpArea.setBorder(0) # Register a listener. events.addCommandListener(handleCommand, ['help-addon-mode-brief', 'help-addon-mode-detailed', 'freeze', 'unfreeze', 'open-documentation']) events.addNotifyListener(handleNotify, ['show-help-text-now', 'init-done', 'active-profile-changed', 'tab-selected', 'addon-list-selected', 'maps-list-selected', 'focus-changed', 'value-changed', 'language-changed'] )
def showLogo(doShow=True): """Show or hide the Snowberry logo in the bottom of the help panel. @param doShow True, if the logo should be shown. """ global logo try: helpArea = ui.getArea(ui.HELP) except KeyError: # No Help area. return if not logo and doShow: logo = helpArea.createImage('help-logo') helpArea.updateLayout() elif logo and not doShow: helpArea.destroyWidget(logo) logo = None helpArea.updateLayout()
def init(): "Create the HTML text widget into the help area." ui.addMenuCommand(ui.MENU_HELP, 'open-documentation', pos=0) try: helpArea = ui.getArea(ui.HELP) except KeyError: # The Help area does not exist. We don't have much to do here. events.addCommandListener(handleCommand, ['open-documentation']) return helpArea.setExpanding(True) helpArea.setWeight(1) # Create a HTML text widget. global helpText helpArea.setBorder(3) helpText = helpArea.createFormattedText() # Unfreeze the help text after a minor delay. This'll make the app # init a bit smoother. helpText.freeze() helpTextTimer.start(1000) # Set parameters suitable for the logo. helpArea.setWeight(0) helpArea.setBorder(0) # Register a listener. events.addCommandListener(handleCommand, [ 'help-addon-mode-brief', 'help-addon-mode-detailed', 'freeze', 'unfreeze', 'open-documentation' ]) events.addNotifyListener(handleNotify, [ 'show-help-text-now', 'init-done', 'active-profile-changed', 'tab-selected', 'addon-list-selected', 'maps-list-selected', 'focus-changed', 'value-changed', 'language-changed' ])
def init(): print "Example init called!" area = ui.getArea(ui.COMMAND)
def init(): # Create the profile list and the profile control buttons. area = ui.getArea(ui.PROFILES) global profileList area.setBorder(0) if USE_MINIMAL_MODE: area.setWeight(1) area.addSpacer() area.setWeight(3) profileList = area.createDropList("profile-list") profileList.setSorted() area.setWeight(1) area.addSpacer() else: # Normal profile list mode. area.setWeight(1) profileList = area.createFormattedList("profile-list") if not st.getSystemBoolean("profile-hide-buttons"): # This should be a small button. area.setWeight(0) area.setBorder(3) controls = area.createArea(alignment=ALIGN_HORIZONTAL, border=2) controls.setExpanding(False) # area.setExpanding(False) controls.setWeight(0) controls.createButton("new-profile", wg.Button.STYLE_MINI) global deleteButton deleteButton = controls.createButton("delete-profile", wg.Button.STYLE_MINI) global dupeButton dupeButton = controls.createButton("duplicate-profile", wg.Button.STYLE_MINI) # Set the title graphics. global bannerImage try: area = ui.getArea(ui.TITLE) bannerImage = area.createImage("banner-default") except: # There is no title area. bannerImage = None # Register a listener for notifications. events.addNotifyListener( notifyHandler, ["quit", "language-changed", "profile-updated", "active-profile-changed", "profile-list-selected"], ) # Register a listener for commands. events.addCommandListener( commandHandler, [ "freeze", "unfreeze", "new-profile", "rename-profile", "reset-profile", "delete-profile", "duplicate-profile", "hide-profile", "unhide-profiles", ], ) # Commands for the menu. ui.addMenuCommand(ui.MENU_PROFILE, "new-profile", group=ui.MENU_GROUP_PROFDB) ui.addMenuCommand(ui.MENU_PROFILE, "unhide-profiles", group=ui.MENU_GROUP_PROFDB) ui.addMenuCommand(ui.MENU_PROFILE, "reset-profile", group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, "rename-profile", group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, "duplicate-profile", group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, "hide-profile", group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, "delete-profile", group=ui.MENU_GROUP_PROFILE)
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 init(): # Create the profile list and the profile control buttons. area = ui.getArea(ui.PROFILES) global profileList area.setBorder(0) if USE_MINIMAL_MODE: area.setWeight(1) area.addSpacer() area.setWeight(3) profileList = area.createDropList('profile-list') profileList.setSorted() area.setWeight(1) area.addSpacer() else: # Normal profile list mode. area.setWeight(1) profileList = area.createFormattedList("profile-list") if not st.getSystemBoolean('profile-hide-buttons'): # This should be a small button. area.setWeight(0) area.setBorder(3) controls = area.createArea(alignment=ALIGN_HORIZONTAL, border=2) controls.setExpanding(False) #area.setExpanding(False) controls.setWeight(0) controls.createButton('new-profile', wg.Button.STYLE_MINI) global deleteButton deleteButton = controls.createButton('delete-profile', wg.Button.STYLE_MINI) global dupeButton dupeButton = controls.createButton('duplicate-profile', wg.Button.STYLE_MINI) # Set the title graphics. global bannerImage try: area = ui.getArea(ui.TITLE) bannerImage = area.createImage('banner-default') except: # There is no title area. bannerImage = None # Register a listener for notifications. events.addNotifyListener(notifyHandler, [ 'quit', 'language-changed', 'profile-updated', 'active-profile-changed', 'profile-list-selected' ]) # Register a listener for commands. events.addCommandListener(commandHandler, [ 'freeze', 'unfreeze', 'new-profile', 'rename-profile', 'reset-profile', 'delete-profile', 'duplicate-profile', 'hide-profile', 'unhide-profiles' ]) # Commands for the menu. ui.addMenuCommand(ui.MENU_PROFILE, 'new-profile', group=ui.MENU_GROUP_PROFDB) ui.addMenuCommand(ui.MENU_PROFILE, 'unhide-profiles', group=ui.MENU_GROUP_PROFDB) ui.addMenuCommand(ui.MENU_PROFILE, 'reset-profile', group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, 'rename-profile', group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, 'duplicate-profile', group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, 'hide-profile', group=ui.MENU_GROUP_PROFILE) ui.addMenuCommand(ui.MENU_PROFILE, 'delete-profile', group=ui.MENU_GROUP_PROFILE)
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()