--- a/src/eric7/WebBrowser/QtHelp/QtHelpDocumentationSelectionDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/WebBrowser/QtHelp/QtHelpDocumentationSelectionDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -16,24 +16,24 @@ from EricWidgets import EricMessageBox -from .Ui_QtHelpDocumentationSelectionDialog import ( - Ui_QtHelpDocumentationSelectionDialog -) +from .Ui_QtHelpDocumentationSelectionDialog import Ui_QtHelpDocumentationSelectionDialog class QtHelpDocumentationSelectionDialog( - QDialog, Ui_QtHelpDocumentationSelectionDialog): + QDialog, Ui_QtHelpDocumentationSelectionDialog +): """ Class implementing a dialog to select QtHelp documentation sets to be installed. """ + AddMode = "Add" ManageMode = "Manage" - + def __init__(self, helpDocuments, mode, parent=None): """ Constructor - + @param helpDocuments dictionary containing the lists of help documents to be shown @type dict of lists of str @@ -44,27 +44,25 @@ """ super().__init__(parent) self.setupUi(self) - + if mode == QtHelpDocumentationSelectionDialog.AddMode: self.buttonBox.button(QDialogButtonBox.StandardButton.Close).hide() else: - self.buttonBox.button( - QDialogButtonBox.StandardButton.Ok).hide() - self.buttonBox.button( - QDialogButtonBox.StandardButton.Cancel).hide() - + self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).hide() + self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).hide() + for category in helpDocuments: parentItem = QTreeWidgetItem(self.documentationList, [category]) for document in helpDocuments[category]: - item = QTreeWidgetItem(parentItem, - [os.path.basename(document)]) + item = QTreeWidgetItem(parentItem, [os.path.basename(document)]) item.setData(0, Qt.ItemDataRole.UserRole, document) - parentItem.setData(0, Qt.ItemDataRole.UserRole, - os.path.dirname(document)) + parentItem.setData( + 0, Qt.ItemDataRole.UserRole, os.path.dirname(document) + ) self.documentationList.sortItems(0, Qt.SortOrder.AscendingOrder) - + self.on_documentationList_itemSelectionChanged() - + @pyqtSlot() def on_documentationList_itemSelectionChanged(self): """ @@ -77,10 +75,10 @@ selectedCategoriesCount += 1 else: selectedDocumentSetCount += 1 - + self.deleteButton.setEnabled(selectedDocumentSetCount > 0) self.deleteCategoryButton.setEnabled(selectedCategoriesCount > 0) - + @pyqtSlot() def on_deleteButton_clicked(self): """ @@ -89,14 +87,16 @@ yes = EricMessageBox.yesNo( self, self.tr("Delete Documentation Sets"), - self.tr("""Shall the selected documentation sets really be""" - """ deleted?""")) + self.tr( + """Shall the selected documentation sets really be""" """ deleted?""" + ), + ) if yes: for itm in self.documentationList.selectedItems(): if itm.parent is None: # it is a category item, skip it continue - + category = itm.parent() fileName = itm.data(0, Qt.ItemDataRole.UserRole) try: @@ -105,17 +105,19 @@ EricMessageBox.warning( self, self.tr("Delete Documentation Sets"), - self.tr("""<p>The documentation set <b>{0}</b> could""" - """ not be deleted.</p><p>Reason: {1}</p>""") - .format(fileName, str(err))) + self.tr( + """<p>The documentation set <b>{0}</b> could""" + """ not be deleted.</p><p>Reason: {1}</p>""" + ).format(fileName, str(err)), + ) continue - + category.removeChild(itm) del itm - + if category.childCount() == 0: self.__deleteCategory(category) - + @pyqtSlot() def on_deleteCategoryButton_clicked(self): """ @@ -124,8 +126,11 @@ yes = EricMessageBox.yesNo( self, self.tr("Delete Documentation Sets"), - self.tr("""Shall the selected documentation set categories""" - """ really be deleted?""")) + self.tr( + """Shall the selected documentation set categories""" + """ really be deleted?""" + ), + ) if yes: categories = [] for itm in self.documentationList.selectedItems(): @@ -133,7 +138,7 @@ categories.append(itm) for category in categories: self.__deleteCategory(category) - + @pyqtSlot() def on_deleteAllButton_clicked(self): """ @@ -142,33 +147,34 @@ yes = EricMessageBox.yesNo( self, self.tr("Delete Documentation Sets"), - self.tr("""Shall all documentation sets really be deleted?""")) + self.tr("""Shall all documentation sets really be deleted?"""), + ) if yes: categories = [] for index in range(self.documentationList.topLevelItemCount()): - categories.append( - self.documentationList.topLevelItem(index)) + categories.append(self.documentationList.topLevelItem(index)) for category in categories: self.__deleteCategory(category) - + def __deleteCategory(self, category): """ Private method to delete a category. - + @param category reference to the category item @type QTreeWidgetItem """ categoryDir = category.data(0, Qt.ItemDataRole.UserRole) shutil.rmtree(categoryDir, True) - + self.documentationList.takeTopLevelItem( - self.documentationList.indexOfTopLevelItem(category)) + self.documentationList.indexOfTopLevelItem(category) + ) del category - + def getData(self): """ Public method to retrieve the selected help documents. - + @return list of QtHelp documentation sets to be installed @rtype set of str """