Helpviewer/QtHelpDocumentationSelectionDialog.py

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

eric ide

mercurial