--- a/eric7/PluginManager/PluginUninstallDialog.py Fri Aug 20 19:54:49 2021 +0200 +++ b/eric7/PluginManager/PluginUninstallDialog.py Fri Aug 20 19:56:17 2021 +0200 @@ -13,8 +13,8 @@ import shutil import glob -from PyQt6.QtCore import pyqtSlot, pyqtSignal -from PyQt6.QtWidgets import QWidget, QDialog, QDialogButtonBox, QVBoxLayout +from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt +from PyQt6.QtWidgets import QWidget, QDialog, QVBoxLayout, QListWidgetItem from EricWidgets import EricMessageBox from EricWidgets.EricMainWindow import EricMainWindow @@ -26,7 +26,6 @@ import UI.PixmapCache -# TODO: extend to be able to uninstall several plugins class PluginUninstallWidget(QWidget, Ui_PluginUninstallDialog): """ Class implementing a dialog for plugin deinstallation. @@ -63,9 +62,6 @@ self.pluginDirectoryCombo.addItem( self.tr("Global plugins directory"), globalDir) - - msh = self.minimumSizeHint() - self.resize(max(self.width(), msh.width()), msh.height()) @pyqtSlot(int) def on_pluginDirectoryCombo_currentIndexChanged(self, index): @@ -78,32 +74,67 @@ pluginDirectory = self.pluginDirectoryCombo.itemData(index) pluginNames = sorted(self.__pluginManager.getPluginModules( pluginDirectory)) - self.pluginNameCombo.clear() + + self.pluginsList.clear() for pluginName in pluginNames: fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName)) - self.pluginNameCombo.addItem(pluginName, fname) - self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( - self.pluginNameCombo.currentText() != "") + itm = QListWidgetItem(pluginName) + itm.setData(Qt.ItemDataRole.UserRole, fname) + itm.setFlags(Qt.ItemFlag.ItemIsEnabled | + Qt.ItemFlag.ItemIsUserCheckable) + itm.setCheckState(Qt.CheckState.Unchecked) + self.pluginsList.addItem(itm) @pyqtSlot() def on_buttonBox_accepted(self): """ Private slot to handle the accepted signal of the button box. """ - if self.__uninstallPlugin(): + if self.__uninstallPlugins(): self.accepted.emit() - def __uninstallPlugin(self): + def __getCheckedPlugins(self): + """ + Private method to get the list of plugins to be uninstalled. + + @return list of tuples with the plugin name and plugin file name + @rtype list of tuples of (str, str) + """ + plugins = [] + for row in range(self.pluginsList.count()): + itm = self.pluginsList.item(row) + if itm.checkState() == Qt.CheckState.Checked: + plugins.append((itm.text(), + itm.data(Qt.ItemDataRole.UserRole))) + return plugins + + def __uninstallPlugins(self): """ - Private slot to uninstall the selected plugin. + Private method to uninstall the selected plugins. - @return flag indicating success (boolean) + @return flag indicating success + @rtype bool + """ + checkedPlugins = self.__getCheckedPlugins() + uninstallCount = 0 + for pluginName, pluginFile in checkedPlugins: + if self.__uninstallPlugin(pluginName, pluginFile): + uninstallCount += 1 + return uninstallCount == len(checkedPlugins) + + def __uninstallPlugin(self, pluginName, pluginFile): + """ + Private method to uninstall a given plugin. + + @param pluginName name of the plugin + @type str + @param pluginFile file name of the plugin + @type str + @return flag indicating success + @rtype bool """ pluginDirectory = self.pluginDirectoryCombo.itemData( self.pluginDirectoryCombo.currentIndex()) - pluginName = self.pluginNameCombo.currentText() - pluginFile = self.pluginNameCombo.itemData( - self.pluginNameCombo.currentIndex()) if not self.__pluginManager.unloadPlugin(pluginName): EricMessageBox.critical(