eric7/Project/PropertiesDialog.py

branch
eric7
changeset 9125
3d2411181b3c
parent 9108
19a57544f32c
child 9128
62cf3eb8b1f2
diff -r a27836f4ad69 -r 3d2411181b3c eric7/Project/PropertiesDialog.py
--- a/eric7/Project/PropertiesDialog.py	Sat Jun 04 17:07:11 2022 +0200
+++ b/eric7/Project/PropertiesDialog.py	Sun Jun 05 16:52:05 2022 +0200
@@ -13,6 +13,7 @@
 from PyQt6.QtCore import QDir, pyqtSlot
 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
 
+from EricWidgets import EricMessageBox
 from EricWidgets.EricApplication import ericApp
 from EricWidgets.EricPathPicker import EricPathPickerModes
 
@@ -89,6 +90,8 @@
             Utilities.fromNativeSeparators(ipath) + "/",
         ]
         
+        self.__populateLicenseComboBox()
+        
         if not new:
             name = os.path.splitext(self.project.pfile)[0]
             self.nameEdit.setText(os.path.basename(name))
@@ -140,9 +143,11 @@
                 cindex = self.testingFrameworkComboBox.findData(
                     self.project.pdata["TESTING_FRAMEWORK"])
                 self.testingFrameworkComboBox.setCurrentIndex(cindex)
+            with contextlib.suppress(KeyError):
+                self.licenseComboBox.setCurrentText(
+                    self.project.pdata["LICENSE"])
         else:
-            self.languageComboBox.setCurrentIndex(
-                self.languageComboBox.findText("Python3"))
+            self.languageComboBox.setCurrentText("Python3")
             self.projectTypeComboBox.setCurrentIndex(
                 self.projectTypeComboBox.findData("PyQt6"))
             self.dirPicker.setText(self.__initPaths[0])
@@ -156,6 +161,36 @@
             bool(self.dirPicker.text()) and
             self.dirPicker.text() not in self.__initPaths)
     
+    def __populateLicenseComboBox(self):
+        """
+        Private method to populate the license selector with the list of trove
+        license types.
+        
+        Note: The trove licanese list file was created from querying
+        "https://pypi.org/pypi?%3Aaction=list_classifiers".
+        """
+        filename = os.path.join(
+            os.path.dirname(__file__), "..", "data",
+            "trove_license_classifiers.txt")
+        try:
+            with open(filename, "r") as f:
+                lines = f.readlines()
+        except OSError as err:
+            EricMessageBox.warning(
+                self,
+                self.tr("Reading Trove License Classifiers"),
+                self.tr("""<p>The Trove Classifiers file <b>{0}</b>"""
+                        """ could not be read.</p><p>Reason: {1}</p>""")
+                .format(filename, str(err)))
+            return
+        
+        self.licenseComboBox.addItem("")
+        self.licenseComboBox.addItems(
+            line.split("::")[-1].strip()
+            for line in lines
+            if line.startswith("License ")      # play it safe
+        )
+    
     @pyqtSlot(str)
     def on_languageComboBox_currentTextChanged(self, language):
         """
@@ -353,3 +388,5 @@
         self.project.pdata["TESTING_FRAMEWORK"] = (
             self.testingFrameworkComboBox.currentData()
         )
+        
+        self.project.pdata["LICENSE"] = self.licenseComboBox.currentText()

eric ide

mercurial