Adjusted the APIs configuration page to support project type specific API sets. APIs

Thu, 01 Dec 2016 19:17:30 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 01 Dec 2016 19:17:30 +0100
branch
APIs
changeset 5350
57e82ffafdfc
parent 5349
bccda3b5920a
child 5351
e87b1fec71d1

Adjusted the APIs configuration page to support project type specific API sets.

Preferences/ConfigurationPages/EditorAPIsPage.py file | annotate | diff | comparison | revisions
--- a/Preferences/ConfigurationPages/EditorAPIsPage.py	Wed Nov 30 19:59:57 2016 +0100
+++ b/Preferences/ConfigurationPages/EditorAPIsPage.py	Thu Dec 01 19:17:30 2016 +0100
@@ -23,8 +23,6 @@
 import Utilities
 
 
-# TODO: add combo box to select project type
-#       getEditorAPI und setEditorAPI
 class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage):
     """
     Class implementing the Editor APIs configuration page.
@@ -60,18 +58,19 @@
             if lang != "Guessed":
                 self.apiLanguageComboBox.addItem(lang)
         apiProjectTypes = sorted(
-            [("", "")] + [(trans, ptype) for ptype, trans in 
-                e5App().getObject("Project").getProjectTypes().items()]
+            [("", "")] +
+            [(trans, ptype) for ptype, trans in
+                e5App().getObject("Project").getProjectTypes().items()
+             ]
         )
         for projectTypeStr, projectType in apiProjectTypes:
             self.projectTypeComboBox.addItem(projectTypeStr, projectType)
         self.__currentApiLanguage = ""
+        self.__currentApiProjectTypeIndex = 0
         self.__currentApiProjectType = ""
         self.on_apiLanguageComboBox_activated(self.__currentApiLanguage)
-##        self.on_projectTypeComboBox_activated(self.__currentApiProjectType)
-##        
-##        for lang in apiLanguages[1:]:
-##            self.apis[lang] = Preferences.getEditorAPI(lang)[:]
+        self.on_projectTypeComboBox_activated(
+            self.__currentApiProjectTypeIndex)
     
     def __apiKey(self, language, projectType):
         """
@@ -98,24 +97,28 @@
             "AutoPrepareAPIs",
             self.apiAutoPrepareCheckBox.isChecked())
         
-        lang = self.apiLanguageComboBox.currentText()
-        self.apis[self.__apiKey()] = self.__editorGetApisFromApiList()
+        language = self.apiLanguageComboBox.currentText()
+        projectType = self.projectTypeComboBox.itemData(
+            self.projectTypeComboBox.currentIndex())
+        key = self.__apiKey(language, projectType)
+        self.apis[key] = self.__editorGetApisFromApiList()
         
         for (language, projectType), apis in self.apis.items():
-            Preferences.setEditorAPI(lang, projectType, apis)
+            Preferences.setEditorAPI(language, projectType, apis)
     
-    # TODO: carry on from here
-    @pyqtSlot(str)
-    def on_projectTypeComboBox_activated(self, p0):
+    @pyqtSlot(int)
+    def on_projectTypeComboBox_activated(self, index):
         """
-        Slot documentation goes here.
+        Private slot to handle the selection of a project type.
         
-        @param p0 DESCRIPTION
+        @param index index of the selected entry
         @type str
         """
-        return
-        # TODO: not implemented yet
-        raise NotImplementedError
+        if self.__currentApiProjectTypeIndex == index:
+            return
+        
+        self.__currentApiProjectTypeIndex = index
+        self.__fillApisList()
         
     @pyqtSlot(str)
     def on_apiLanguageComboBox_activated(self, language):
@@ -126,12 +129,23 @@
         """
         if self.__currentApiLanguage == language:
             return
-            
-        self.apis[self.__currentApiLanguage] = self.__editorGetApisFromApiList()
-        self.__currentApiLanguage = language
+        
+        self.__fillApisList()
+    
+    def __fillApisList(self):
+        """
+        Private slot to fill the list of API files.
+        """
+        self.apis[self.__apiKey(self.__currentApiLanguage,
+                                self.__currentApiProjectType)] = \
+            self.__editorGetApisFromApiList()
+        
+        self.__currentApiLanguage = self.apiLanguageComboBox.currentText()
+        self.__currentApiProjectType = self.projectTypeComboBox.itemData(
+            self.projectTypeComboBox.currentIndex())
         self.apiList.clear()
         
-        if not language:
+        if not self.__currentApiLanguage:
             self.apiGroup.setEnabled(False)
             return
             
@@ -140,14 +154,22 @@
         self.addApiFileButton.setEnabled(False)
         self.apiFilePicker.clear()
         
-        for api in self.apis[self.__currentApiLanguage]:
+        key = self.__apiKey(self.__currentApiLanguage,
+                            self.__currentApiProjectType)
+        if key not in self.apis:
+            # populate on demand
+            self.apis[key] = Preferences.getEditorAPI(
+                self.__currentApiLanguage,
+                projectType=self.__currentApiProjectType)[:]
+        for api in self.apis[key]:
             if api:
                 self.apiList.addItem(api)
         self.prepareApiButton.setEnabled(self.apiList.count() > 0)
         
-        # TODO: add project type
         from QScintilla.APIsManager import APIsManager
-        self.__currentAPI = APIsManager().getAPIs(self.__currentApiLanguage)
+        self.__currentAPI = APIsManager().getAPIs(
+            self.__currentApiLanguage,
+            projectType=self.__currentApiProjectType)
         if self.__currentAPI is not None:
             self.__currentAPI.apiPreparationFinished.connect(
                 self.__apiPreparationFinished)
@@ -295,9 +317,14 @@
         """
         Public method to save the current state of the widget.
         
-        @return index of the selected lexer language (integer)
+        @return tuple containing the index of the selected lexer language
+            and the index of the selected project type
+        @rtype tuple of int and int
         """
-        return self.apiLanguageComboBox.currentIndex()
+        return (
+            self.apiLanguageComboBox.currentIndex(),
+            self.projectTypeComboBox.currentIndex()
+        )
         
     def setState(self, state):
         """
@@ -305,9 +332,11 @@
         
         @param state state data generated by saveState
         """
-        self.apiLanguageComboBox.setCurrentIndex(state)
+        self.apiLanguageComboBox.setCurrentIndex(state[0])
+        self.projectTypeComboBox.setCurrentIndex(state[1])
         self.on_apiLanguageComboBox_activated(
             self.apiLanguageComboBox.currentText())
+        self.on_projectTypeComboBox_activated(state[1])
     
     @pyqtSlot()
     def on_apiList_itemSelectionChanged(self):

eric ide

mercurial