Preferences/ConfigurationPages/EditorAPIsPage.py

branch
APIs
changeset 5350
57e82ffafdfc
parent 5349
bccda3b5920a
child 5358
2584d0a08bf4
equal deleted inserted replaced
5349:bccda3b5920a 5350:57e82ffafdfc
21 21
22 import Preferences 22 import Preferences
23 import Utilities 23 import Utilities
24 24
25 25
26 # TODO: add combo box to select project type
27 # getEditorAPI und setEditorAPI
28 class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage): 26 class EditorAPIsPage(ConfigurationPageBase, Ui_EditorAPIsPage):
29 """ 27 """
30 Class implementing the Editor APIs configuration page. 28 Class implementing the Editor APIs configuration page.
31 """ 29 """
32 def __init__(self): 30 def __init__(self):
58 [''] + list(QScintilla.Lexers.getSupportedLanguages().keys())) 56 [''] + list(QScintilla.Lexers.getSupportedLanguages().keys()))
59 for lang in apiLanguages: 57 for lang in apiLanguages:
60 if lang != "Guessed": 58 if lang != "Guessed":
61 self.apiLanguageComboBox.addItem(lang) 59 self.apiLanguageComboBox.addItem(lang)
62 apiProjectTypes = sorted( 60 apiProjectTypes = sorted(
63 [("", "")] + [(trans, ptype) for ptype, trans in 61 [("", "")] +
64 e5App().getObject("Project").getProjectTypes().items()] 62 [(trans, ptype) for ptype, trans in
63 e5App().getObject("Project").getProjectTypes().items()
64 ]
65 ) 65 )
66 for projectTypeStr, projectType in apiProjectTypes: 66 for projectTypeStr, projectType in apiProjectTypes:
67 self.projectTypeComboBox.addItem(projectTypeStr, projectType) 67 self.projectTypeComboBox.addItem(projectTypeStr, projectType)
68 self.__currentApiLanguage = "" 68 self.__currentApiLanguage = ""
69 self.__currentApiProjectTypeIndex = 0
69 self.__currentApiProjectType = "" 70 self.__currentApiProjectType = ""
70 self.on_apiLanguageComboBox_activated(self.__currentApiLanguage) 71 self.on_apiLanguageComboBox_activated(self.__currentApiLanguage)
71 ## self.on_projectTypeComboBox_activated(self.__currentApiProjectType) 72 self.on_projectTypeComboBox_activated(
72 ## 73 self.__currentApiProjectTypeIndex)
73 ## for lang in apiLanguages[1:]:
74 ## self.apis[lang] = Preferences.getEditorAPI(lang)[:]
75 74
76 def __apiKey(self, language, projectType): 75 def __apiKey(self, language, projectType):
77 """ 76 """
78 Private method to generate a key for the apis dictionary. 77 Private method to generate a key for the apis dictionary.
79 78
96 """ 95 """
97 Preferences.setEditor( 96 Preferences.setEditor(
98 "AutoPrepareAPIs", 97 "AutoPrepareAPIs",
99 self.apiAutoPrepareCheckBox.isChecked()) 98 self.apiAutoPrepareCheckBox.isChecked())
100 99
101 lang = self.apiLanguageComboBox.currentText() 100 language = self.apiLanguageComboBox.currentText()
102 self.apis[self.__apiKey()] = self.__editorGetApisFromApiList() 101 projectType = self.projectTypeComboBox.itemData(
102 self.projectTypeComboBox.currentIndex())
103 key = self.__apiKey(language, projectType)
104 self.apis[key] = self.__editorGetApisFromApiList()
103 105
104 for (language, projectType), apis in self.apis.items(): 106 for (language, projectType), apis in self.apis.items():
105 Preferences.setEditorAPI(lang, projectType, apis) 107 Preferences.setEditorAPI(language, projectType, apis)
106 108
107 # TODO: carry on from here 109 @pyqtSlot(int)
108 @pyqtSlot(str) 110 def on_projectTypeComboBox_activated(self, index):
109 def on_projectTypeComboBox_activated(self, p0): 111 """
110 """ 112 Private slot to handle the selection of a project type.
111 Slot documentation goes here. 113
112 114 @param index index of the selected entry
113 @param p0 DESCRIPTION
114 @type str 115 @type str
115 """ 116 """
116 return 117 if self.__currentApiProjectTypeIndex == index:
117 # TODO: not implemented yet 118 return
118 raise NotImplementedError 119
120 self.__currentApiProjectTypeIndex = index
121 self.__fillApisList()
119 122
120 @pyqtSlot(str) 123 @pyqtSlot(str)
121 def on_apiLanguageComboBox_activated(self, language): 124 def on_apiLanguageComboBox_activated(self, language):
122 """ 125 """
123 Private slot to fill the api listbox of the api page. 126 Private slot to fill the api listbox of the api page.
124 127
125 @param language selected API language (string) 128 @param language selected API language (string)
126 """ 129 """
127 if self.__currentApiLanguage == language: 130 if self.__currentApiLanguage == language:
128 return 131 return
129 132
130 self.apis[self.__currentApiLanguage] = self.__editorGetApisFromApiList() 133 self.__fillApisList()
131 self.__currentApiLanguage = language 134
135 def __fillApisList(self):
136 """
137 Private slot to fill the list of API files.
138 """
139 self.apis[self.__apiKey(self.__currentApiLanguage,
140 self.__currentApiProjectType)] = \
141 self.__editorGetApisFromApiList()
142
143 self.__currentApiLanguage = self.apiLanguageComboBox.currentText()
144 self.__currentApiProjectType = self.projectTypeComboBox.itemData(
145 self.projectTypeComboBox.currentIndex())
132 self.apiList.clear() 146 self.apiList.clear()
133 147
134 if not language: 148 if not self.__currentApiLanguage:
135 self.apiGroup.setEnabled(False) 149 self.apiGroup.setEnabled(False)
136 return 150 return
137 151
138 self.apiGroup.setEnabled(True) 152 self.apiGroup.setEnabled(True)
139 self.deleteApiFileButton.setEnabled(False) 153 self.deleteApiFileButton.setEnabled(False)
140 self.addApiFileButton.setEnabled(False) 154 self.addApiFileButton.setEnabled(False)
141 self.apiFilePicker.clear() 155 self.apiFilePicker.clear()
142 156
143 for api in self.apis[self.__currentApiLanguage]: 157 key = self.__apiKey(self.__currentApiLanguage,
158 self.__currentApiProjectType)
159 if key not in self.apis:
160 # populate on demand
161 self.apis[key] = Preferences.getEditorAPI(
162 self.__currentApiLanguage,
163 projectType=self.__currentApiProjectType)[:]
164 for api in self.apis[key]:
144 if api: 165 if api:
145 self.apiList.addItem(api) 166 self.apiList.addItem(api)
146 self.prepareApiButton.setEnabled(self.apiList.count() > 0) 167 self.prepareApiButton.setEnabled(self.apiList.count() > 0)
147 168
148 # TODO: add project type
149 from QScintilla.APIsManager import APIsManager 169 from QScintilla.APIsManager import APIsManager
150 self.__currentAPI = APIsManager().getAPIs(self.__currentApiLanguage) 170 self.__currentAPI = APIsManager().getAPIs(
171 self.__currentApiLanguage,
172 projectType=self.__currentApiProjectType)
151 if self.__currentAPI is not None: 173 if self.__currentAPI is not None:
152 self.__currentAPI.apiPreparationFinished.connect( 174 self.__currentAPI.apiPreparationFinished.connect(
153 self.__apiPreparationFinished) 175 self.__apiPreparationFinished)
154 self.__currentAPI.apiPreparationCancelled.connect( 176 self.__currentAPI.apiPreparationCancelled.connect(
155 self.__apiPreparationCancelled) 177 self.__apiPreparationCancelled)
293 315
294 def saveState(self): 316 def saveState(self):
295 """ 317 """
296 Public method to save the current state of the widget. 318 Public method to save the current state of the widget.
297 319
298 @return index of the selected lexer language (integer) 320 @return tuple containing the index of the selected lexer language
299 """ 321 and the index of the selected project type
300 return self.apiLanguageComboBox.currentIndex() 322 @rtype tuple of int and int
323 """
324 return (
325 self.apiLanguageComboBox.currentIndex(),
326 self.projectTypeComboBox.currentIndex()
327 )
301 328
302 def setState(self, state): 329 def setState(self, state):
303 """ 330 """
304 Public method to set the state of the widget. 331 Public method to set the state of the widget.
305 332
306 @param state state data generated by saveState 333 @param state state data generated by saveState
307 """ 334 """
308 self.apiLanguageComboBox.setCurrentIndex(state) 335 self.apiLanguageComboBox.setCurrentIndex(state[0])
336 self.projectTypeComboBox.setCurrentIndex(state[1])
309 self.on_apiLanguageComboBox_activated( 337 self.on_apiLanguageComboBox_activated(
310 self.apiLanguageComboBox.currentText()) 338 self.apiLanguageComboBox.currentText())
339 self.on_projectTypeComboBox_activated(state[1])
311 340
312 @pyqtSlot() 341 @pyqtSlot()
313 def on_apiList_itemSelectionChanged(self): 342 def on_apiList_itemSelectionChanged(self):
314 """ 343 """
315 Private slot to react on changes of API selections. 344 Private slot to react on changes of API selections.

eric ide

mercurial