6 """ |
6 """ |
7 Module implementing a dialog to manage the QtHelp documentation database. |
7 Module implementing a dialog to manage the QtHelp documentation database. |
8 """ |
8 """ |
9 |
9 |
10 import sqlite3 |
10 import sqlite3 |
|
11 import contextlib |
11 |
12 |
12 from PyQt5.QtCore import pyqtSlot, Qt, QItemSelectionModel |
13 from PyQt5.QtCore import pyqtSlot, Qt, QItemSelectionModel |
13 from PyQt5.QtWidgets import ( |
14 from PyQt5.QtWidgets import ( |
14 QDialog, QTreeWidgetItem, QListWidgetItem, QInputDialog, QLineEdit |
15 QDialog, QTreeWidgetItem, QListWidgetItem, QInputDialog, QLineEdit |
15 ) |
16 ) |
267 self.removeFiltersButton.setEnabled(False) |
268 self.removeFiltersButton.setEnabled(False) |
268 self.removeAttributesButton.setEnabled(False) |
269 self.removeAttributesButton.setEnabled(False) |
269 |
270 |
270 # save the current and selected filters |
271 # save the current and selected filters |
271 currentFilter = self.filtersList.currentItem() |
272 currentFilter = self.filtersList.currentItem() |
272 if currentFilter: |
273 currentFilterText = currentFilter.text() if currentFilter else "" |
273 currentFilterText = currentFilter.text() |
|
274 else: |
|
275 currentFilterText = "" |
|
276 selectedFiltersText = [ |
274 selectedFiltersText = [ |
277 itm.text() for itm in self.filtersList.selectedItems()] |
275 itm.text() for itm in self.filtersList.selectedItems()] |
278 |
276 |
279 # save the selected attributes |
277 # save the selected attributes |
280 selectedAttributesText = [ |
278 selectedAttributesText = [ |
478 |
476 |
479 def __removeAttributes(self): |
477 def __removeAttributes(self): |
480 """ |
478 """ |
481 Private method to remove attributes from the Qt Help database. |
479 Private method to remove attributes from the Qt Help database. |
482 """ |
480 """ |
483 try: |
481 with contextlib.suppress(sqlite3.DatabaseError): |
484 self.__db = sqlite3.connect(self.__engine.collectionFile()) |
482 self.__db = sqlite3.connect(self.__engine.collectionFile()) |
485 except sqlite3.DatabaseError: |
|
486 pass # ignore database errors |
|
487 |
483 |
488 for attr in self.__removedAttributes: |
484 for attr in self.__removedAttributes: |
489 self.__db.execute( |
485 self.__db.execute( |
490 "DELETE FROM FilterAttributeTable WHERE Name = '{0}'" # secok |
486 "DELETE FROM FilterAttributeTable WHERE Name = '{0}'" # secok |
491 .format(attr)) |
487 .format(attr)) |