def updateButtons(): items = addonList.getSelectedItems() if len(items) == 0: settingsButton.disable() uninstallButton.disable() infoButton.disable() return if len(items) > 1: # More than one. settingsButton.disable() canUninstall = False # At least one uninstallable? for addon in items: if ao.isUninstallable(addon): uninstallButton.enable() canUninstall = True break if not canUninstall: uninstallButton.disable() infoButton.disable() return sel = items[0] settingsButton.enable(st.haveSettingsForAddon(sel)) infoButton.enable() # Can this be uninstalled? uninstallButton.enable(ao.isUninstallable(sel))
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 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