225 value = "" |
223 value = "" |
226 QTreeWidgetItem(self.dnList, [name, value]) |
224 QTreeWidgetItem(self.dnList, [name, value]) |
227 |
225 |
228 self.dnList.sortItems(0, Qt.AscendingOrder) |
226 self.dnList.sortItems(0, Qt.AscendingOrder) |
229 |
227 |
|
228 def __generateDefinedNamesList(self): |
|
229 """ |
|
230 Private method to prepare the list of 'Defined Names'. |
|
231 |
|
232 @return list of 'Defined Names' |
|
233 @rtype list of str |
|
234 """ |
|
235 definedNames = [] |
|
236 for row in range(self.dnList.topLevelItemCount()): |
|
237 itm = self.dnList.topLevelItem(row) |
|
238 name = itm.text(0).strip() |
|
239 value = itm.text(1).strip() |
|
240 if value: |
|
241 definedNames.append("{0}={1}".format(name, value)) |
|
242 else: |
|
243 definedNames.append(name) |
|
244 |
|
245 return definedNames |
|
246 |
|
247 def __definedNamesContain(self, name): |
|
248 """ |
|
249 Private method to test, if the currently defined 'Defined Names' |
|
250 contain a given one. |
|
251 |
|
252 @param name variable name to be tested |
|
253 @type str |
|
254 @return flag indicating that the given name is already included |
|
255 @rtype bool |
|
256 """ |
|
257 return len(self.dnList.findItems(name, Qt.MatchExactly, 0)) > 0 |
|
258 |
230 @pyqtSlot() |
259 @pyqtSlot() |
231 def on_dnList_itemSelectionChanged(self): |
260 def on_dnList_itemSelectionChanged(self): |
232 """ |
261 """ |
233 Private slot handling the selection of a 'Define Name' entry. |
262 Private slot handling the selection of a 'Define Name' entry. |
234 """ |
263 """ |
235 self.__updateDefineNameButtons() |
264 self.__updateDefineNameButtons() |
236 |
265 |
237 @pyqtSlot() |
266 @pyqtSlot() |
238 def on_dnAddButton_clicked(self): |
267 def on_dnAddButton_clicked(self): |
239 """ |
268 """ |
240 Slot documentation goes here. |
269 Private slot to add a 'Define Name' entry. |
241 """ |
270 """ |
242 # TODO: not implemented yet |
271 dlg = IdlCompilerDefineNameDialog(parent=self) |
243 raise NotImplementedError |
272 if dlg.exec_() == QDialog.Accepted: |
|
273 name, value = dlg.getData() |
|
274 if not self.__definedNamesContain(name): |
|
275 QTreeWidgetItem(self.dnList, [name, value]) |
|
276 |
|
277 self.dnList.sortItems(0, Qt.AscendingOrder) |
244 |
278 |
245 @pyqtSlot() |
279 @pyqtSlot() |
246 def on_dnDeleteButton_clicked(self): |
280 def on_dnDeleteButton_clicked(self): |
247 """ |
281 """ |
248 Slot documentation goes here. |
282 Private slot to delete the selected 'Define Name' entry. |
249 """ |
283 """ |
250 # TODO: not implemented yet |
284 itm = self.dnList.selectedItems()[0] |
251 raise NotImplementedError |
285 index = self.dnList.indexOfTopLevelItem(itm) |
|
286 self.dnList.takeTopLevelItem(index) |
|
287 del itm |
252 |
288 |
253 @pyqtSlot() |
289 @pyqtSlot() |
254 def on_dnEditButton_clicked(self): |
290 def on_dnEditButton_clicked(self): |
255 """ |
291 """ |
256 Slot documentation goes here. |
292 Private slot to edit the selected 'Define Name' entry. |
257 """ |
293 """ |
258 # TODO: not implemented yet |
294 itm = self.dnList.selectedItems()[0] |
259 raise NotImplementedError |
295 |
|
296 dlg = IdlCompilerDefineNameDialog( |
|
297 name=itm.text(0), value=itm.text(1), parent=self) |
|
298 if dlg.exec_() == QDialog.Accepted: |
|
299 name, value = dlg.getData() |
|
300 if self.__definedNamesContain(name) and itm.text(0) != name: |
|
301 # the entry exists already, delete the edited one |
|
302 index = self.dnList.indexOfTopLevelItem(itm) |
|
303 self.dnList.takeTopLevelItem(index) |
|
304 del itm |
|
305 |
|
306 # change the named one |
|
307 itm = self.dnList.findItems(name, Qt.MatchExactly, 0)[0] |
|
308 itm.setText(1, value) |
|
309 else: |
|
310 itm.setText(0, name) |
|
311 itm.setText(1, value) |
|
312 |
|
313 self.dnList.sortItems(0, Qt.AscendingOrder) |
260 |
314 |
261 ####################################################################### |
315 ####################################################################### |
262 ## Methods implementing the 'Undefine Name' option |
316 ## Methods implementing the 'Undefine Name' option |
263 ####################################################################### |
317 ####################################################################### |
264 |
318 |