--- a/src/eric7/Project/FiletypeAssociationDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Project/FiletypeAssociationDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -19,10 +19,11 @@ """ Class implementing a dialog to enter filetype associations for the project. """ + def __init__(self, project, parent=None): """ Constructor - + @param project reference to the project object @param parent reference to the parent widget (QWidget) """ @@ -30,64 +31,78 @@ self.setupUi(self) self.filetypeAssociationList.headerItem().setText( - self.filetypeAssociationList.columnCount(), "") + self.filetypeAssociationList.columnCount(), "" + ) self.filetypeAssociationList.header().setSortIndicator( - 0, Qt.SortOrder.AscendingOrder) - + 0, Qt.SortOrder.AscendingOrder + ) + # keep these lists in sync - self.filetypes = ["SOURCES", "FORMS", "TRANSLATIONS", "RESOURCES", - "INTERFACES", "PROTOCOLS", "OTHERS", "__IGNORE__"] - self.filetypeStrings = [self.tr("Sources"), self.tr("Forms"), - self.tr("Translations"), - self.tr("Resources"), - self.tr("Interfaces"), - self.tr("Protocols"), - self.tr("Others"), - self.tr("Ignore")] + self.filetypes = [ + "SOURCES", + "FORMS", + "TRANSLATIONS", + "RESOURCES", + "INTERFACES", + "PROTOCOLS", + "OTHERS", + "__IGNORE__", + ] + self.filetypeStrings = [ + self.tr("Sources"), + self.tr("Forms"), + self.tr("Translations"), + self.tr("Resources"), + self.tr("Interfaces"), + self.tr("Protocols"), + self.tr("Others"), + self.tr("Ignore"), + ] self.filetypeCombo.addItems(self.filetypeStrings) - + self.project = project for pattern, filetype in list(self.project.pdata["FILETYPES"].items()): with contextlib.suppress(ValueError): index = self.filetypes.index(filetype) self.__createItem(pattern, self.filetypeStrings[index]) - + self.__resort() self.__reformat() - + def __resort(self): """ Private method to resort the tree. """ self.filetypeAssociationList.sortItems( self.filetypeAssociationList.sortColumn(), - self.filetypeAssociationList.header().sortIndicatorOrder()) - + self.filetypeAssociationList.header().sortIndicatorOrder(), + ) + def __reformat(self): """ Private method to reformat the tree. """ self.filetypeAssociationList.header().resizeSections( - QHeaderView.ResizeMode.ResizeToContents) + QHeaderView.ResizeMode.ResizeToContents + ) self.filetypeAssociationList.header().setStretchLastSection(True) - + def __createItem(self, pattern, filetype): """ Private slot to create a new entry in the association list. - + @param pattern pattern of the entry (string) @param filetype file type of the entry (string) @return reference to the newly generated entry (QTreeWidgetItem) """ - itm = QTreeWidgetItem( - self.filetypeAssociationList, [pattern, filetype]) + itm = QTreeWidgetItem(self.filetypeAssociationList, [pattern, filetype]) return itm - + def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm): """ Private slot to handle the currentItemChanged signal of the association list. - + @param itm reference to the new current item (QTreeWidgetItem) @param prevItm reference to the previous current item (QTreeWidgetItem) """ @@ -97,8 +112,7 @@ self.deleteAssociationButton.setEnabled(False) else: self.filePatternEdit.setText(itm.text(0)) - self.filetypeCombo.setCurrentIndex( - self.filetypeCombo.findText(itm.text(1))) + self.filetypeCombo.setCurrentIndex(self.filetypeCombo.findText(itm.text(1))) self.deleteAssociationButton.setEnabled(True) @pyqtSlot() @@ -110,10 +124,12 @@ filetype = self.filetypeCombo.currentText() if pattern: items = self.filetypeAssociationList.findItems( - pattern, Qt.MatchFlag.MatchExactly, 0) + pattern, Qt.MatchFlag.MatchExactly, 0 + ) for itm in items: itm = self.filetypeAssociationList.takeTopLevelItem( - self.filetypeAssociationList.indexOfTopLevelItem(itm)) + self.filetypeAssociationList.indexOfTopLevelItem(itm) + ) del itm itm = self.__createItem(pattern, filetype) self.__resort() @@ -130,9 +146,10 @@ """ for itm in self.filetypeAssociationList.selectedItems(): itm = self.filetypeAssociationList.takeTopLevelItem( - self.filetypeAssociationList.indexOfTopLevelItem(itm)) + self.filetypeAssociationList.indexOfTopLevelItem(itm) + ) del itm - + self.filetypeAssociationList.clearSelection() self.filePatternEdit.clear() self.filetypeCombo.setCurrentIndex(0) @@ -140,7 +157,7 @@ def on_filePatternEdit_textChanged(self, txt): """ Private slot to handle the textChanged signal of the pattern lineedit. - + @param txt text of the lineedit (string) """ if not txt: @@ -152,8 +169,8 @@ self.deleteAssociationButton.setEnabled(False) else: self.deleteAssociationButton.setEnabled( - self.filetypeAssociationList.selectedItems()[0] - .text(0) == txt) + self.filetypeAssociationList.selectedItems()[0].text(0) == txt + ) def transferData(self): """