diff -r e9e7eca7efee -r bf71ee032bb4 src/eric7/Project/IdlCompilerOptionsDialog.py --- a/src/eric7/Project/IdlCompilerOptionsDialog.py Wed Jul 13 11:16:20 2022 +0200 +++ b/src/eric7/Project/IdlCompilerOptionsDialog.py Wed Jul 13 14:55:47 2022 +0200 @@ -24,11 +24,18 @@ """ Class implementing a dialog to enter some IDL compiler options. """ - def __init__(self, includeDirectories, definedNames, undefinedNames, - project=None, parent=None): + + def __init__( + self, + includeDirectories, + definedNames, + undefinedNames, + project=None, + parent=None, + ): """ Constructor - + @param includeDirectories list of include directories @type list of str @param definedNames list of defined variables with name and value @@ -43,33 +50,33 @@ """ super().__init__(parent) self.setupUi(self) - + self.__project = project - + self.idAddButton.setIcon(UI.PixmapCache.getIcon("plus")) self.idDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) self.idEditButton.setIcon(UI.PixmapCache.getIcon("edit")) - + self.dnAddButton.setIcon(UI.PixmapCache.getIcon("plus")) self.dnDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) self.dnEditButton.setIcon(UI.PixmapCache.getIcon("edit")) - + self.unAddButton.setIcon(UI.PixmapCache.getIcon("plus")) self.unDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) self.unEditButton.setIcon(UI.PixmapCache.getIcon("edit")) - + self.__populateIncludeDirectoriesList(includeDirectories) self.__populateDefineNamesList(definedNames) self.unList.addItems(undefinedNames) - + self.__updateIncludeDirectoryButtons() self.__updateDefineNameButtons() self.__updateUndefineNameButtons() - + ####################################################################### ## Methods implementing the 'Include Directory' option ####################################################################### - + def __updateIncludeDirectoryButtons(self): """ Private method to set the state of the 'Include Directory' buttons. @@ -77,11 +84,11 @@ enable = len(self.idList.selectedItems()) self.idDeleteButton.setEnabled(enable) self.idEditButton.setEnabled(enable) - + def __populateIncludeDirectoriesList(self, includeDirectories): """ Private method to populate the 'Include Directories' list. - + @param includeDirectories list of include directories @type list of str """ @@ -94,52 +101,47 @@ self.idList.addItem(path) else: self.idList.addItem(directory) - + def __generateIncludeDirectoriesList(self): """ Private method to prepare the list of 'Include Directories'. - + @return list of 'Include Directories' @rtype list of str """ - return [ - self.idList.item(row).text() - for row in range(self.idList.count()) - ] - + return [self.idList.item(row).text() for row in range(self.idList.count())] + def __includeDirectoriesContain(self, directory): """ Private method to test, if the currently defined 'Include Directories' contain a given one. - + @param directory directory name to be tested @type str @return flag indicating that the given directory is already included @rtype bool """ - return len(self.idList.findItems( - directory, Qt.MatchFlag.MatchExactly)) > 0 - + return len(self.idList.findItems(directory, Qt.MatchFlag.MatchExactly)) > 0 + @pyqtSlot() def on_idList_itemSelectionChanged(self): """ Private slot handling the selection of an 'Include Directory' entry. """ self.__updateIncludeDirectoryButtons() - + @pyqtSlot() def on_idAddButton_clicked(self): """ Private slot to add an 'Include Directory'. """ - defaultDirectory = (self.__project.getProjectPath() if self.__project - else "") + defaultDirectory = self.__project.getProjectPath() if self.__project else "" path, ok = EricPathPickerDialog.getPath( self, self.tr("Include Directory"), self.tr("Select Include Directory"), EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, - defaultDirectory=defaultDirectory + defaultDirectory=defaultDirectory, ) if ok and path: if self.__project: @@ -148,7 +150,7 @@ path = "." if not self.__includeDirectoriesContain(path): self.idList.addItem(path) - + @pyqtSlot() def on_idDeleteButton_clicked(self): """ @@ -158,7 +160,7 @@ row = self.idList.row(itm) self.idList.takeItem(row) del itm - + @pyqtSlot() def on_idEditButton_clicked(self): """ @@ -177,7 +179,7 @@ self.tr("Select Include Directory"), EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, path=path, - defaultDirectory=defaultDirectory + defaultDirectory=defaultDirectory, ) if ok and path: if self.__project: @@ -191,11 +193,11 @@ del itm else: itm.setText(path) - + ####################################################################### ## Methods implementing the 'Define Name' option ####################################################################### - + def __updateDefineNameButtons(self): """ Private method to set the state of the 'Define Name' buttons. @@ -203,11 +205,11 @@ enable = len(self.dnList.selectedItems()) self.dnDeleteButton.setEnabled(enable) self.dnEditButton.setEnabled(enable) - + def __populateDefineNamesList(self, definedNames): """ Private method to populate the list of defined names. - + @param definedNames list of defined variables with name and value separated by '=' @type list of str @@ -221,13 +223,13 @@ else: value = "" QTreeWidgetItem(self.dnList, [name, value]) - + self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) - + def __generateDefinedNamesList(self): """ Private method to prepare the list of 'Defined Names'. - + @return list of 'Defined Names' @rtype list of str """ @@ -240,29 +242,28 @@ definedNames.append("{0}={1}".format(name, value)) else: definedNames.append(name) - + return definedNames - + def __definedNamesContain(self, name): """ Private method to test, if the currently defined 'Defined Names' contain a given one. - + @param name variable name to be tested @type str @return flag indicating that the given name is already included @rtype bool """ - return len(self.dnList.findItems( - name, Qt.MatchFlag.MatchExactly, 0)) > 0 - + return len(self.dnList.findItems(name, Qt.MatchFlag.MatchExactly, 0)) > 0 + @pyqtSlot() def on_dnList_itemSelectionChanged(self): """ Private slot handling the selection of a 'Define Name' entry. """ self.__updateDefineNameButtons() - + @pyqtSlot() def on_dnAddButton_clicked(self): """ @@ -273,9 +274,9 @@ name, value = dlg.getData() if not self.__definedNamesContain(name): QTreeWidgetItem(self.dnList, [name, value]) - + self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) - + @pyqtSlot() def on_dnDeleteButton_clicked(self): """ @@ -285,16 +286,17 @@ index = self.dnList.indexOfTopLevelItem(itm) self.dnList.takeTopLevelItem(index) del itm - + @pyqtSlot() def on_dnEditButton_clicked(self): """ Private slot to edit the selected 'Define Name' entry. """ itm = self.dnList.selectedItems()[0] - + dlg = IdlCompilerDefineNameDialog( - name=itm.text(0), value=itm.text(1), parent=self) + name=itm.text(0), value=itm.text(1), parent=self + ) if dlg.exec() == QDialog.DialogCode.Accepted: name, value = dlg.getData() if self.__definedNamesContain(name) and itm.text(0) != name: @@ -302,21 +304,20 @@ index = self.dnList.indexOfTopLevelItem(itm) self.dnList.takeTopLevelItem(index) del itm - + # change the named one - itm = self.dnList.findItems( - name, Qt.MatchFlag.MatchExactly, 0)[0] + itm = self.dnList.findItems(name, Qt.MatchFlag.MatchExactly, 0)[0] itm.setText(1, value) else: itm.setText(0, name) itm.setText(1, value) - + self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) - + ####################################################################### ## Methods implementing the 'Undefine Name' option ####################################################################### - + def __updateUndefineNameButtons(self): """ Private method to set the state of the 'Undefine Name' buttons. @@ -324,38 +325,35 @@ enable = len(self.unList.selectedItems()) self.unDeleteButton.setEnabled(enable) self.unEditButton.setEnabled(enable) - + def __generateUndefinedNamesList(self): """ Private method to prepare the list of 'Undefined Names'. - + @return list of 'Undefined Names' @rtype list of str """ - return [ - self.unList.item(row).text() - for row in range(self.unList.count()) - ] - + return [self.unList.item(row).text() for row in range(self.unList.count())] + def __undefinedNamesContain(self, name): """ Private method to test, if the currently defined 'Undefined Names' contain a given one. - + @param name variable name to be tested @type str @return flag indicating that the given name is already included @rtype bool """ return len(self.unList.findItems(name, Qt.MatchFlag.MatchExactly)) > 0 - + @pyqtSlot() def on_unList_itemSelectionChanged(self): """ Private slot handling the selection of a 'Undefine Name' entry. """ self.__updateUndefineNameButtons() - + @pyqtSlot() def on_unAddButton_clicked(self): """ @@ -364,12 +362,12 @@ name, ok = QInputDialog.getText( self, self.tr("Undefine Name"), - self.tr("Enter a variable name to be undefined:") + self.tr("Enter a variable name to be undefined:"), ) name = name.strip() if ok and name and not self.__undefinedNamesContain(name): self.unList.addItem(name) - + @pyqtSlot() def on_unDeleteButton_clicked(self): """ @@ -379,7 +377,7 @@ row = self.unList.row(itm) self.unList.takeItem(row) del itm - + @pyqtSlot() def on_unEditButton_clicked(self): """ @@ -390,7 +388,7 @@ self, self.tr("Undefine Name"), self.tr("Enter a variable name to be undefined:"), - text=itm.text() + text=itm.text(), ) name = name.strip() if ok and name: @@ -401,15 +399,15 @@ del itm else: itm.setText(name) - + ####################################################################### ## Methods implementing the result preparation ####################################################################### - + def getData(self): """ Public method to return the data entered by the user. - + @return tuple containing the list of include directories, list of defined names and list of undefined names @rtype tuple of (list of str, list of str, list of str)