src/eric7/WebBrowser/QtHelp/QtHelpDocumentationSelectionDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
14 from PyQt6.QtCore import pyqtSlot, Qt 14 from PyQt6.QtCore import pyqtSlot, Qt
15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem 15 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QTreeWidgetItem
16 16
17 from EricWidgets import EricMessageBox 17 from EricWidgets import EricMessageBox
18 18
19 from .Ui_QtHelpDocumentationSelectionDialog import ( 19 from .Ui_QtHelpDocumentationSelectionDialog import Ui_QtHelpDocumentationSelectionDialog
20 Ui_QtHelpDocumentationSelectionDialog
21 )
22 20
23 21
24 class QtHelpDocumentationSelectionDialog( 22 class QtHelpDocumentationSelectionDialog(
25 QDialog, Ui_QtHelpDocumentationSelectionDialog): 23 QDialog, Ui_QtHelpDocumentationSelectionDialog
24 ):
26 """ 25 """
27 Class implementing a dialog to select QtHelp documentation sets to be 26 Class implementing a dialog to select QtHelp documentation sets to be
28 installed. 27 installed.
29 """ 28 """
29
30 AddMode = "Add" 30 AddMode = "Add"
31 ManageMode = "Manage" 31 ManageMode = "Manage"
32 32
33 def __init__(self, helpDocuments, mode, parent=None): 33 def __init__(self, helpDocuments, mode, parent=None):
34 """ 34 """
35 Constructor 35 Constructor
36 36
37 @param helpDocuments dictionary containing the lists of help documents 37 @param helpDocuments dictionary containing the lists of help documents
38 to be shown 38 to be shown
39 @type dict of lists of str 39 @type dict of lists of str
40 @param mode mode of the dialog 40 @param mode mode of the dialog
41 @type str 41 @type str
42 @param parent reference to the parent widget 42 @param parent reference to the parent widget
43 @type QWidget 43 @type QWidget
44 """ 44 """
45 super().__init__(parent) 45 super().__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.StandardButton.Close).hide() 49 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).hide()
50 else: 50 else:
51 self.buttonBox.button( 51 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).hide()
52 QDialogButtonBox.StandardButton.Ok).hide() 52 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).hide()
53 self.buttonBox.button( 53
54 QDialogButtonBox.StandardButton.Cancel).hide()
55
56 for category in helpDocuments: 54 for category in helpDocuments:
57 parentItem = QTreeWidgetItem(self.documentationList, [category]) 55 parentItem = QTreeWidgetItem(self.documentationList, [category])
58 for document in helpDocuments[category]: 56 for document in helpDocuments[category]:
59 item = QTreeWidgetItem(parentItem, 57 item = QTreeWidgetItem(parentItem, [os.path.basename(document)])
60 [os.path.basename(document)])
61 item.setData(0, Qt.ItemDataRole.UserRole, document) 58 item.setData(0, Qt.ItemDataRole.UserRole, document)
62 parentItem.setData(0, Qt.ItemDataRole.UserRole, 59 parentItem.setData(
63 os.path.dirname(document)) 60 0, Qt.ItemDataRole.UserRole, os.path.dirname(document)
61 )
64 self.documentationList.sortItems(0, Qt.SortOrder.AscendingOrder) 62 self.documentationList.sortItems(0, Qt.SortOrder.AscendingOrder)
65 63
66 self.on_documentationList_itemSelectionChanged() 64 self.on_documentationList_itemSelectionChanged()
67 65
68 @pyqtSlot() 66 @pyqtSlot()
69 def on_documentationList_itemSelectionChanged(self): 67 def on_documentationList_itemSelectionChanged(self):
70 """ 68 """
71 Private slot handling the selection of items. 69 Private slot handling the selection of items.
72 """ 70 """
75 for itm in self.documentationList.selectedItems(): 73 for itm in self.documentationList.selectedItems():
76 if itm.parent() is None: 74 if itm.parent() is None:
77 selectedCategoriesCount += 1 75 selectedCategoriesCount += 1
78 else: 76 else:
79 selectedDocumentSetCount += 1 77 selectedDocumentSetCount += 1
80 78
81 self.deleteButton.setEnabled(selectedDocumentSetCount > 0) 79 self.deleteButton.setEnabled(selectedDocumentSetCount > 0)
82 self.deleteCategoryButton.setEnabled(selectedCategoriesCount > 0) 80 self.deleteCategoryButton.setEnabled(selectedCategoriesCount > 0)
83 81
84 @pyqtSlot() 82 @pyqtSlot()
85 def on_deleteButton_clicked(self): 83 def on_deleteButton_clicked(self):
86 """ 84 """
87 Private slot to delete the selected documentation sets. 85 Private slot to delete the selected documentation sets.
88 """ 86 """
89 yes = EricMessageBox.yesNo( 87 yes = EricMessageBox.yesNo(
90 self, 88 self,
91 self.tr("Delete Documentation Sets"), 89 self.tr("Delete Documentation Sets"),
92 self.tr("""Shall the selected documentation sets really be""" 90 self.tr(
93 """ deleted?""")) 91 """Shall the selected documentation sets really be""" """ deleted?"""
92 ),
93 )
94 if yes: 94 if yes:
95 for itm in self.documentationList.selectedItems(): 95 for itm in self.documentationList.selectedItems():
96 if itm.parent is None: 96 if itm.parent is None:
97 # it is a category item, skip it 97 # it is a category item, skip it
98 continue 98 continue
99 99
100 category = itm.parent() 100 category = itm.parent()
101 fileName = itm.data(0, Qt.ItemDataRole.UserRole) 101 fileName = itm.data(0, Qt.ItemDataRole.UserRole)
102 try: 102 try:
103 os.remove(fileName) 103 os.remove(fileName)
104 except OSError as err: 104 except OSError as err:
105 EricMessageBox.warning( 105 EricMessageBox.warning(
106 self, 106 self,
107 self.tr("Delete Documentation Sets"), 107 self.tr("Delete Documentation Sets"),
108 self.tr("""<p>The documentation set <b>{0}</b> could""" 108 self.tr(
109 """ not be deleted.</p><p>Reason: {1}</p>""") 109 """<p>The documentation set <b>{0}</b> could"""
110 .format(fileName, str(err))) 110 """ not be deleted.</p><p>Reason: {1}</p>"""
111 ).format(fileName, str(err)),
112 )
111 continue 113 continue
112 114
113 category.removeChild(itm) 115 category.removeChild(itm)
114 del itm 116 del itm
115 117
116 if category.childCount() == 0: 118 if category.childCount() == 0:
117 self.__deleteCategory(category) 119 self.__deleteCategory(category)
118 120
119 @pyqtSlot() 121 @pyqtSlot()
120 def on_deleteCategoryButton_clicked(self): 122 def on_deleteCategoryButton_clicked(self):
121 """ 123 """
122 Private slot to delete the selected documentation set categories. 124 Private slot to delete the selected documentation set categories.
123 """ 125 """
124 yes = EricMessageBox.yesNo( 126 yes = EricMessageBox.yesNo(
125 self, 127 self,
126 self.tr("Delete Documentation Sets"), 128 self.tr("Delete Documentation Sets"),
127 self.tr("""Shall the selected documentation set categories""" 129 self.tr(
128 """ really be deleted?""")) 130 """Shall the selected documentation set categories"""
131 """ really be deleted?"""
132 ),
133 )
129 if yes: 134 if yes:
130 categories = [] 135 categories = []
131 for itm in self.documentationList.selectedItems(): 136 for itm in self.documentationList.selectedItems():
132 if itm.parent() is None: 137 if itm.parent() is None:
133 categories.append(itm) 138 categories.append(itm)
134 for category in categories: 139 for category in categories:
135 self.__deleteCategory(category) 140 self.__deleteCategory(category)
136 141
137 @pyqtSlot() 142 @pyqtSlot()
138 def on_deleteAllButton_clicked(self): 143 def on_deleteAllButton_clicked(self):
139 """ 144 """
140 Private slot to delete all documentation sets. 145 Private slot to delete all documentation sets.
141 """ 146 """
142 yes = EricMessageBox.yesNo( 147 yes = EricMessageBox.yesNo(
143 self, 148 self,
144 self.tr("Delete Documentation Sets"), 149 self.tr("Delete Documentation Sets"),
145 self.tr("""Shall all documentation sets really be deleted?""")) 150 self.tr("""Shall all documentation sets really be deleted?"""),
151 )
146 if yes: 152 if yes:
147 categories = [] 153 categories = []
148 for index in range(self.documentationList.topLevelItemCount()): 154 for index in range(self.documentationList.topLevelItemCount()):
149 categories.append( 155 categories.append(self.documentationList.topLevelItem(index))
150 self.documentationList.topLevelItem(index))
151 for category in categories: 156 for category in categories:
152 self.__deleteCategory(category) 157 self.__deleteCategory(category)
153 158
154 def __deleteCategory(self, category): 159 def __deleteCategory(self, category):
155 """ 160 """
156 Private method to delete a category. 161 Private method to delete a category.
157 162
158 @param category reference to the category item 163 @param category reference to the category item
159 @type QTreeWidgetItem 164 @type QTreeWidgetItem
160 """ 165 """
161 categoryDir = category.data(0, Qt.ItemDataRole.UserRole) 166 categoryDir = category.data(0, Qt.ItemDataRole.UserRole)
162 shutil.rmtree(categoryDir, True) 167 shutil.rmtree(categoryDir, True)
163 168
164 self.documentationList.takeTopLevelItem( 169 self.documentationList.takeTopLevelItem(
165 self.documentationList.indexOfTopLevelItem(category)) 170 self.documentationList.indexOfTopLevelItem(category)
171 )
166 del category 172 del category
167 173
168 def getData(self): 174 def getData(self):
169 """ 175 """
170 Public method to retrieve the selected help documents. 176 Public method to retrieve the selected help documents.
171 177
172 @return list of QtHelp documentation sets to be installed 178 @return list of QtHelp documentation sets to be installed
173 @rtype set of str 179 @rtype set of str
174 """ 180 """
175 documents = set() 181 documents = set()
176 for item in self.documentationList.selectedItems(): 182 for item in self.documentationList.selectedItems():

eric ide

mercurial