41 @param parent reference to the parent widget |
48 @param parent reference to the parent widget |
42 @type QWidget |
49 @type QWidget |
43 """ |
50 """ |
44 super().__init__(parent) |
51 super().__init__(parent) |
45 self.setupUi(self) |
52 self.setupUi(self) |
46 |
53 |
47 self.__project = project |
54 self.__project = project |
48 |
55 |
49 self.idAddButton.setIcon(UI.PixmapCache.getIcon("plus")) |
56 self.idAddButton.setIcon(UI.PixmapCache.getIcon("plus")) |
50 self.idDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
57 self.idDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
51 self.idEditButton.setIcon(UI.PixmapCache.getIcon("edit")) |
58 self.idEditButton.setIcon(UI.PixmapCache.getIcon("edit")) |
52 |
59 |
53 self.dnAddButton.setIcon(UI.PixmapCache.getIcon("plus")) |
60 self.dnAddButton.setIcon(UI.PixmapCache.getIcon("plus")) |
54 self.dnDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
61 self.dnDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
55 self.dnEditButton.setIcon(UI.PixmapCache.getIcon("edit")) |
62 self.dnEditButton.setIcon(UI.PixmapCache.getIcon("edit")) |
56 |
63 |
57 self.unAddButton.setIcon(UI.PixmapCache.getIcon("plus")) |
64 self.unAddButton.setIcon(UI.PixmapCache.getIcon("plus")) |
58 self.unDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
65 self.unDeleteButton.setIcon(UI.PixmapCache.getIcon("minus")) |
59 self.unEditButton.setIcon(UI.PixmapCache.getIcon("edit")) |
66 self.unEditButton.setIcon(UI.PixmapCache.getIcon("edit")) |
60 |
67 |
61 self.__populateIncludeDirectoriesList(includeDirectories) |
68 self.__populateIncludeDirectoriesList(includeDirectories) |
62 self.__populateDefineNamesList(definedNames) |
69 self.__populateDefineNamesList(definedNames) |
63 self.unList.addItems(undefinedNames) |
70 self.unList.addItems(undefinedNames) |
64 |
71 |
65 self.__updateIncludeDirectoryButtons() |
72 self.__updateIncludeDirectoryButtons() |
66 self.__updateDefineNameButtons() |
73 self.__updateDefineNameButtons() |
67 self.__updateUndefineNameButtons() |
74 self.__updateUndefineNameButtons() |
68 |
75 |
69 ####################################################################### |
76 ####################################################################### |
70 ## Methods implementing the 'Include Directory' option |
77 ## Methods implementing the 'Include Directory' option |
71 ####################################################################### |
78 ####################################################################### |
72 |
79 |
73 def __updateIncludeDirectoryButtons(self): |
80 def __updateIncludeDirectoryButtons(self): |
74 """ |
81 """ |
75 Private method to set the state of the 'Include Directory' buttons. |
82 Private method to set the state of the 'Include Directory' buttons. |
76 """ |
83 """ |
77 enable = len(self.idList.selectedItems()) |
84 enable = len(self.idList.selectedItems()) |
78 self.idDeleteButton.setEnabled(enable) |
85 self.idDeleteButton.setEnabled(enable) |
79 self.idEditButton.setEnabled(enable) |
86 self.idEditButton.setEnabled(enable) |
80 |
87 |
81 def __populateIncludeDirectoriesList(self, includeDirectories): |
88 def __populateIncludeDirectoriesList(self, includeDirectories): |
82 """ |
89 """ |
83 Private method to populate the 'Include Directories' list. |
90 Private method to populate the 'Include Directories' list. |
84 |
91 |
85 @param includeDirectories list of include directories |
92 @param includeDirectories list of include directories |
86 @type list of str |
93 @type list of str |
87 """ |
94 """ |
88 for directory in includeDirectories: |
95 for directory in includeDirectories: |
89 if self.__project: |
96 if self.__project: |
92 # it is the project directory |
99 # it is the project directory |
93 path = "." |
100 path = "." |
94 self.idList.addItem(path) |
101 self.idList.addItem(path) |
95 else: |
102 else: |
96 self.idList.addItem(directory) |
103 self.idList.addItem(directory) |
97 |
104 |
98 def __generateIncludeDirectoriesList(self): |
105 def __generateIncludeDirectoriesList(self): |
99 """ |
106 """ |
100 Private method to prepare the list of 'Include Directories'. |
107 Private method to prepare the list of 'Include Directories'. |
101 |
108 |
102 @return list of 'Include Directories' |
109 @return list of 'Include Directories' |
103 @rtype list of str |
110 @rtype list of str |
104 """ |
111 """ |
105 return [ |
112 return [self.idList.item(row).text() for row in range(self.idList.count())] |
106 self.idList.item(row).text() |
113 |
107 for row in range(self.idList.count()) |
|
108 ] |
|
109 |
|
110 def __includeDirectoriesContain(self, directory): |
114 def __includeDirectoriesContain(self, directory): |
111 """ |
115 """ |
112 Private method to test, if the currently defined 'Include Directories' |
116 Private method to test, if the currently defined 'Include Directories' |
113 contain a given one. |
117 contain a given one. |
114 |
118 |
115 @param directory directory name to be tested |
119 @param directory directory name to be tested |
116 @type str |
120 @type str |
117 @return flag indicating that the given directory is already included |
121 @return flag indicating that the given directory is already included |
118 @rtype bool |
122 @rtype bool |
119 """ |
123 """ |
120 return len(self.idList.findItems( |
124 return len(self.idList.findItems(directory, Qt.MatchFlag.MatchExactly)) > 0 |
121 directory, Qt.MatchFlag.MatchExactly)) > 0 |
125 |
122 |
|
123 @pyqtSlot() |
126 @pyqtSlot() |
124 def on_idList_itemSelectionChanged(self): |
127 def on_idList_itemSelectionChanged(self): |
125 """ |
128 """ |
126 Private slot handling the selection of an 'Include Directory' entry. |
129 Private slot handling the selection of an 'Include Directory' entry. |
127 """ |
130 """ |
128 self.__updateIncludeDirectoryButtons() |
131 self.__updateIncludeDirectoryButtons() |
129 |
132 |
130 @pyqtSlot() |
133 @pyqtSlot() |
131 def on_idAddButton_clicked(self): |
134 def on_idAddButton_clicked(self): |
132 """ |
135 """ |
133 Private slot to add an 'Include Directory'. |
136 Private slot to add an 'Include Directory'. |
134 """ |
137 """ |
135 defaultDirectory = (self.__project.getProjectPath() if self.__project |
138 defaultDirectory = self.__project.getProjectPath() if self.__project else "" |
136 else "") |
|
137 path, ok = EricPathPickerDialog.getPath( |
139 path, ok = EricPathPickerDialog.getPath( |
138 self, |
140 self, |
139 self.tr("Include Directory"), |
141 self.tr("Include Directory"), |
140 self.tr("Select Include Directory"), |
142 self.tr("Select Include Directory"), |
141 EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, |
143 EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE, |
142 defaultDirectory=defaultDirectory |
144 defaultDirectory=defaultDirectory, |
143 ) |
145 ) |
144 if ok and path: |
146 if ok and path: |
145 if self.__project: |
147 if self.__project: |
146 path = self.__project.getRelativeUniversalPath(path) |
148 path = self.__project.getRelativeUniversalPath(path) |
147 if not path: |
149 if not path: |
148 path = "." |
150 path = "." |
149 if not self.__includeDirectoriesContain(path): |
151 if not self.__includeDirectoriesContain(path): |
150 self.idList.addItem(path) |
152 self.idList.addItem(path) |
151 |
153 |
152 @pyqtSlot() |
154 @pyqtSlot() |
153 def on_idDeleteButton_clicked(self): |
155 def on_idDeleteButton_clicked(self): |
154 """ |
156 """ |
155 Private slot to delete the selected 'Include Directory' entry. |
157 Private slot to delete the selected 'Include Directory' entry. |
156 """ |
158 """ |
157 itm = self.idList.selectedItems()[0] |
159 itm = self.idList.selectedItems()[0] |
158 row = self.idList.row(itm) |
160 row = self.idList.row(itm) |
159 self.idList.takeItem(row) |
161 self.idList.takeItem(row) |
160 del itm |
162 del itm |
161 |
163 |
162 @pyqtSlot() |
164 @pyqtSlot() |
163 def on_idEditButton_clicked(self): |
165 def on_idEditButton_clicked(self): |
164 """ |
166 """ |
165 Private slot to edit the selected 'Include Directory' entry. |
167 Private slot to edit the selected 'Include Directory' entry. |
166 """ |
168 """ |
238 value = itm.text(1).strip() |
240 value = itm.text(1).strip() |
239 if value: |
241 if value: |
240 definedNames.append("{0}={1}".format(name, value)) |
242 definedNames.append("{0}={1}".format(name, value)) |
241 else: |
243 else: |
242 definedNames.append(name) |
244 definedNames.append(name) |
243 |
245 |
244 return definedNames |
246 return definedNames |
245 |
247 |
246 def __definedNamesContain(self, name): |
248 def __definedNamesContain(self, name): |
247 """ |
249 """ |
248 Private method to test, if the currently defined 'Defined Names' |
250 Private method to test, if the currently defined 'Defined Names' |
249 contain a given one. |
251 contain a given one. |
250 |
252 |
251 @param name variable name to be tested |
253 @param name variable name to be tested |
252 @type str |
254 @type str |
253 @return flag indicating that the given name is already included |
255 @return flag indicating that the given name is already included |
254 @rtype bool |
256 @rtype bool |
255 """ |
257 """ |
256 return len(self.dnList.findItems( |
258 return len(self.dnList.findItems(name, Qt.MatchFlag.MatchExactly, 0)) > 0 |
257 name, Qt.MatchFlag.MatchExactly, 0)) > 0 |
259 |
258 |
|
259 @pyqtSlot() |
260 @pyqtSlot() |
260 def on_dnList_itemSelectionChanged(self): |
261 def on_dnList_itemSelectionChanged(self): |
261 """ |
262 """ |
262 Private slot handling the selection of a 'Define Name' entry. |
263 Private slot handling the selection of a 'Define Name' entry. |
263 """ |
264 """ |
264 self.__updateDefineNameButtons() |
265 self.__updateDefineNameButtons() |
265 |
266 |
266 @pyqtSlot() |
267 @pyqtSlot() |
267 def on_dnAddButton_clicked(self): |
268 def on_dnAddButton_clicked(self): |
268 """ |
269 """ |
269 Private slot to add a 'Define Name' entry. |
270 Private slot to add a 'Define Name' entry. |
270 """ |
271 """ |
271 dlg = IdlCompilerDefineNameDialog(parent=self) |
272 dlg = IdlCompilerDefineNameDialog(parent=self) |
272 if dlg.exec() == QDialog.DialogCode.Accepted: |
273 if dlg.exec() == QDialog.DialogCode.Accepted: |
273 name, value = dlg.getData() |
274 name, value = dlg.getData() |
274 if not self.__definedNamesContain(name): |
275 if not self.__definedNamesContain(name): |
275 QTreeWidgetItem(self.dnList, [name, value]) |
276 QTreeWidgetItem(self.dnList, [name, value]) |
276 |
277 |
277 self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) |
278 self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) |
278 |
279 |
279 @pyqtSlot() |
280 @pyqtSlot() |
280 def on_dnDeleteButton_clicked(self): |
281 def on_dnDeleteButton_clicked(self): |
281 """ |
282 """ |
282 Private slot to delete the selected 'Define Name' entry. |
283 Private slot to delete the selected 'Define Name' entry. |
283 """ |
284 """ |
284 itm = self.dnList.selectedItems()[0] |
285 itm = self.dnList.selectedItems()[0] |
285 index = self.dnList.indexOfTopLevelItem(itm) |
286 index = self.dnList.indexOfTopLevelItem(itm) |
286 self.dnList.takeTopLevelItem(index) |
287 self.dnList.takeTopLevelItem(index) |
287 del itm |
288 del itm |
288 |
289 |
289 @pyqtSlot() |
290 @pyqtSlot() |
290 def on_dnEditButton_clicked(self): |
291 def on_dnEditButton_clicked(self): |
291 """ |
292 """ |
292 Private slot to edit the selected 'Define Name' entry. |
293 Private slot to edit the selected 'Define Name' entry. |
293 """ |
294 """ |
294 itm = self.dnList.selectedItems()[0] |
295 itm = self.dnList.selectedItems()[0] |
295 |
296 |
296 dlg = IdlCompilerDefineNameDialog( |
297 dlg = IdlCompilerDefineNameDialog( |
297 name=itm.text(0), value=itm.text(1), parent=self) |
298 name=itm.text(0), value=itm.text(1), parent=self |
|
299 ) |
298 if dlg.exec() == QDialog.DialogCode.Accepted: |
300 if dlg.exec() == QDialog.DialogCode.Accepted: |
299 name, value = dlg.getData() |
301 name, value = dlg.getData() |
300 if self.__definedNamesContain(name) and itm.text(0) != name: |
302 if self.__definedNamesContain(name) and itm.text(0) != name: |
301 # the entry exists already, delete the edited one |
303 # the entry exists already, delete the edited one |
302 index = self.dnList.indexOfTopLevelItem(itm) |
304 index = self.dnList.indexOfTopLevelItem(itm) |
303 self.dnList.takeTopLevelItem(index) |
305 self.dnList.takeTopLevelItem(index) |
304 del itm |
306 del itm |
305 |
307 |
306 # change the named one |
308 # change the named one |
307 itm = self.dnList.findItems( |
309 itm = self.dnList.findItems(name, Qt.MatchFlag.MatchExactly, 0)[0] |
308 name, Qt.MatchFlag.MatchExactly, 0)[0] |
|
309 itm.setText(1, value) |
310 itm.setText(1, value) |
310 else: |
311 else: |
311 itm.setText(0, name) |
312 itm.setText(0, name) |
312 itm.setText(1, value) |
313 itm.setText(1, value) |
313 |
314 |
314 self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) |
315 self.dnList.sortItems(0, Qt.SortOrder.AscendingOrder) |
315 |
316 |
316 ####################################################################### |
317 ####################################################################### |
317 ## Methods implementing the 'Undefine Name' option |
318 ## Methods implementing the 'Undefine Name' option |
318 ####################################################################### |
319 ####################################################################### |
319 |
320 |
320 def __updateUndefineNameButtons(self): |
321 def __updateUndefineNameButtons(self): |
321 """ |
322 """ |
322 Private method to set the state of the 'Undefine Name' buttons. |
323 Private method to set the state of the 'Undefine Name' buttons. |
323 """ |
324 """ |
324 enable = len(self.unList.selectedItems()) |
325 enable = len(self.unList.selectedItems()) |
325 self.unDeleteButton.setEnabled(enable) |
326 self.unDeleteButton.setEnabled(enable) |
326 self.unEditButton.setEnabled(enable) |
327 self.unEditButton.setEnabled(enable) |
327 |
328 |
328 def __generateUndefinedNamesList(self): |
329 def __generateUndefinedNamesList(self): |
329 """ |
330 """ |
330 Private method to prepare the list of 'Undefined Names'. |
331 Private method to prepare the list of 'Undefined Names'. |
331 |
332 |
332 @return list of 'Undefined Names' |
333 @return list of 'Undefined Names' |
333 @rtype list of str |
334 @rtype list of str |
334 """ |
335 """ |
335 return [ |
336 return [self.unList.item(row).text() for row in range(self.unList.count())] |
336 self.unList.item(row).text() |
337 |
337 for row in range(self.unList.count()) |
|
338 ] |
|
339 |
|
340 def __undefinedNamesContain(self, name): |
338 def __undefinedNamesContain(self, name): |
341 """ |
339 """ |
342 Private method to test, if the currently defined 'Undefined Names' |
340 Private method to test, if the currently defined 'Undefined Names' |
343 contain a given one. |
341 contain a given one. |
344 |
342 |
345 @param name variable name to be tested |
343 @param name variable name to be tested |
346 @type str |
344 @type str |
347 @return flag indicating that the given name is already included |
345 @return flag indicating that the given name is already included |
348 @rtype bool |
346 @rtype bool |
349 """ |
347 """ |
350 return len(self.unList.findItems(name, Qt.MatchFlag.MatchExactly)) > 0 |
348 return len(self.unList.findItems(name, Qt.MatchFlag.MatchExactly)) > 0 |
351 |
349 |
352 @pyqtSlot() |
350 @pyqtSlot() |
353 def on_unList_itemSelectionChanged(self): |
351 def on_unList_itemSelectionChanged(self): |
354 """ |
352 """ |
355 Private slot handling the selection of a 'Undefine Name' entry. |
353 Private slot handling the selection of a 'Undefine Name' entry. |
356 """ |
354 """ |
357 self.__updateUndefineNameButtons() |
355 self.__updateUndefineNameButtons() |
358 |
356 |
359 @pyqtSlot() |
357 @pyqtSlot() |
360 def on_unAddButton_clicked(self): |
358 def on_unAddButton_clicked(self): |
361 """ |
359 """ |
362 Private slot to add a 'Undefine Name' entry. |
360 Private slot to add a 'Undefine Name' entry. |
363 """ |
361 """ |
364 name, ok = QInputDialog.getText( |
362 name, ok = QInputDialog.getText( |
365 self, |
363 self, |
366 self.tr("Undefine Name"), |
364 self.tr("Undefine Name"), |
367 self.tr("Enter a variable name to be undefined:") |
365 self.tr("Enter a variable name to be undefined:"), |
368 ) |
366 ) |
369 name = name.strip() |
367 name = name.strip() |
370 if ok and name and not self.__undefinedNamesContain(name): |
368 if ok and name and not self.__undefinedNamesContain(name): |
371 self.unList.addItem(name) |
369 self.unList.addItem(name) |
372 |
370 |
373 @pyqtSlot() |
371 @pyqtSlot() |
374 def on_unDeleteButton_clicked(self): |
372 def on_unDeleteButton_clicked(self): |
375 """ |
373 """ |
376 Private slot to delete the selected 'Undefine Name' entry. |
374 Private slot to delete the selected 'Undefine Name' entry. |
377 """ |
375 """ |
378 itm = self.unList.selectedItems()[0] |
376 itm = self.unList.selectedItems()[0] |
379 row = self.unList.row(itm) |
377 row = self.unList.row(itm) |
380 self.unList.takeItem(row) |
378 self.unList.takeItem(row) |
381 del itm |
379 del itm |
382 |
380 |
383 @pyqtSlot() |
381 @pyqtSlot() |
384 def on_unEditButton_clicked(self): |
382 def on_unEditButton_clicked(self): |
385 """ |
383 """ |
386 Private slot to edit the selected 'Undefine Name' entry. |
384 Private slot to edit the selected 'Undefine Name' entry. |
387 """ |
385 """ |
388 itm = self.unList.selectedItems()[0] |
386 itm = self.unList.selectedItems()[0] |
389 name, ok = QInputDialog.getText( |
387 name, ok = QInputDialog.getText( |
390 self, |
388 self, |
391 self.tr("Undefine Name"), |
389 self.tr("Undefine Name"), |
392 self.tr("Enter a variable name to be undefined:"), |
390 self.tr("Enter a variable name to be undefined:"), |
393 text=itm.text() |
391 text=itm.text(), |
394 ) |
392 ) |
395 name = name.strip() |
393 name = name.strip() |
396 if ok and name: |
394 if ok and name: |
397 if self.__undefinedNamesContain(name) and itm.text() != name: |
395 if self.__undefinedNamesContain(name) and itm.text() != name: |
398 # the entry exists already, delete the edited one |
396 # the entry exists already, delete the edited one |
399 row = self.unList.row(itm) |
397 row = self.unList.row(itm) |
400 self.unList.takeItem(row) |
398 self.unList.takeItem(row) |
401 del itm |
399 del itm |
402 else: |
400 else: |
403 itm.setText(name) |
401 itm.setText(name) |
404 |
402 |
405 ####################################################################### |
403 ####################################################################### |
406 ## Methods implementing the result preparation |
404 ## Methods implementing the result preparation |
407 ####################################################################### |
405 ####################################################################### |
408 |
406 |
409 def getData(self): |
407 def getData(self): |
410 """ |
408 """ |
411 Public method to return the data entered by the user. |
409 Public method to return the data entered by the user. |
412 |
410 |
413 @return tuple containing the list of include directories, list of |
411 @return tuple containing the list of include directories, list of |
414 defined names and list of undefined names |
412 defined names and list of undefined names |
415 @rtype tuple of (list of str, list of str, list of str) |
413 @rtype tuple of (list of str, list of str, list of str) |
416 """ |
414 """ |
417 return ( |
415 return ( |