44 """ |
44 """ |
45 super(QtHelpDocumentationSelectionDialog, self).__init__(parent) |
45 super(QtHelpDocumentationSelectionDialog, self).__init__(parent) |
46 self.setupUi(self) |
46 self.setupUi(self) |
47 |
47 |
48 if mode == QtHelpDocumentationSelectionDialog.AddMode: |
48 if mode == QtHelpDocumentationSelectionDialog.AddMode: |
49 self.buttonBox.button(QDialogButtonBox.Close).hide() |
49 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).hide() |
50 else: |
50 else: |
51 self.buttonBox.button(QDialogButtonBox.Ok).hide() |
51 self.buttonBox.button( |
52 self.buttonBox.button(QDialogButtonBox.Cancel).hide() |
52 QDialogButtonBox.StandardButton.Ok).hide() |
|
53 self.buttonBox.button( |
|
54 QDialogButtonBox.StandardButton.Cancel).hide() |
53 |
55 |
54 for category in helpDocuments: |
56 for category in helpDocuments: |
55 parentItem = QTreeWidgetItem(self.documentationList, [category]) |
57 parentItem = QTreeWidgetItem(self.documentationList, [category]) |
56 for document in helpDocuments[category]: |
58 for document in helpDocuments[category]: |
57 item = QTreeWidgetItem(parentItem, |
59 item = QTreeWidgetItem(parentItem, |
58 [os.path.basename(document)]) |
60 [os.path.basename(document)]) |
59 item.setData(0, Qt.UserRole, document) |
61 item.setData(0, Qt.ItemDataRole.UserRole, document) |
60 parentItem.setData(0, Qt.UserRole, os.path.dirname(document)) |
62 parentItem.setData(0, Qt.ItemDataRole.UserRole, |
61 self.documentationList.sortItems(0, Qt.AscendingOrder) |
63 os.path.dirname(document)) |
|
64 self.documentationList.sortItems(0, Qt.SortOrder.AscendingOrder) |
62 |
65 |
63 self.on_documentationList_itemSelectionChanged() |
66 self.on_documentationList_itemSelectionChanged() |
64 |
67 |
65 @pyqtSlot() |
68 @pyqtSlot() |
66 def on_documentationList_itemSelectionChanged(self): |
69 def on_documentationList_itemSelectionChanged(self): |
93 if itm.parent is None: |
96 if itm.parent is None: |
94 # it is a category item, skip it |
97 # it is a category item, skip it |
95 continue |
98 continue |
96 |
99 |
97 category = itm.parent() |
100 category = itm.parent() |
98 fileName = itm.data(0, Qt.UserRole) |
101 fileName = itm.data(0, Qt.ItemDataRole.UserRole) |
99 try: |
102 try: |
100 os.remove(fileName) |
103 os.remove(fileName) |
101 except OSError as err: |
104 except OSError as err: |
102 E5MessageBox.warning( |
105 E5MessageBox.warning( |
103 self, |
106 self, |
153 Private method to delete a category. |
156 Private method to delete a category. |
154 |
157 |
155 @param category reference to the category item |
158 @param category reference to the category item |
156 @type QTreeWidgetItem |
159 @type QTreeWidgetItem |
157 """ |
160 """ |
158 categoryDir = category.data(0, Qt.UserRole) |
161 categoryDir = category.data(0, Qt.ItemDataRole.UserRole) |
159 shutil.rmtree(categoryDir, True) |
162 shutil.rmtree(categoryDir, True) |
160 |
163 |
161 self.documentationList.takeTopLevelItem( |
164 self.documentationList.takeTopLevelItem( |
162 self.documentationList.indexOfTopLevelItem(category)) |
165 self.documentationList.indexOfTopLevelItem(category)) |
163 del category |
166 del category |
173 for item in self.documentationList.selectedItems(): |
176 for item in self.documentationList.selectedItems(): |
174 if item.parent() is None: |
177 if item.parent() is None: |
175 # it is a category item; add all files of that category |
178 # it is a category item; add all files of that category |
176 for childIndex in range(item.childCount()): |
179 for childIndex in range(item.childCount()): |
177 child = item.child(childIndex) |
180 child = item.child(childIndex) |
178 fileName = child.data(0, Qt.UserRole) |
181 fileName = child.data(0, Qt.ItemDataRole.UserRole) |
179 if fileName: |
182 if fileName: |
180 documents.add(fileName) |
183 documents.add(fileName) |
181 else: |
184 else: |
182 fileName = item.data(0, Qt.UserRole) |
185 fileName = item.data(0, Qt.ItemDataRole.UserRole) |
183 if fileName: |
186 if fileName: |
184 documents.add(fileName) |
187 documents.add(fileName) |
185 return documents |
188 return documents |