src/eric7/WebBrowser/QtHelp/QtHelpDocumentationSettingsWidget.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2021 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a widget to manage the QtHelp documentation settings.
8 """
9
10 from PyQt6.QtCore import pyqtSlot, pyqtSignal
11 from PyQt6.QtWidgets import QWidget, QListWidgetItem, QDialog
12
13 from EricWidgets.EricApplication import ericApp
14 from EricWidgets import EricMessageBox, EricFileDialog
15
16 from .Ui_QtHelpDocumentationSettingsWidget import (
17 Ui_QtHelpDocumentationSettingsWidget
18 )
19
20 from .QtHelpDocumentationSettings import QtHelpDocumentationSettings
21
22
23 class QtHelpDocumentationSettingsWidget(QWidget,
24 Ui_QtHelpDocumentationSettingsWidget):
25 """
26 Class implementing a widget to manage the QtHelp documentation settings.
27
28 @signal documentationSettingsChanged(settings) emitted to signal a change
29 of the documentation configuration
30 """
31 documentationSettingsChanged = pyqtSignal(QtHelpDocumentationSettings)
32
33 def __init__(self, parent=None):
34 """
35 Constructor
36
37 @param parent reference to the parent widget (defaults to None)
38 @type QWidget (optional)
39 """
40 super().__init__(parent)
41 self.setupUi(self)
42
43 self.__settings = None
44
45 try:
46 self.__pluginHelpDocuments = (
47 ericApp().getObject("PluginManager").getPluginQtHelpFiles()
48 )
49 except KeyError:
50 from PluginManager.PluginManager import PluginManager
51 pluginManager = PluginManager(self, doLoadPlugins=False)
52 pluginManager.loadDocumentationSetPlugins()
53 pluginManager.activatePlugins()
54 self.__pluginHelpDocuments = pluginManager.getPluginQtHelpFiles()
55 self.addPluginButton.setEnabled(bool(self.__pluginHelpDocuments))
56
57 @pyqtSlot()
58 def on_removeDocumentsButton_clicked(self):
59 """
60 Private slot to remove a document from the help database.
61 """
62 selectedItems = self.documentsList.selectedItems()[:]
63 if not selectedItems:
64 return
65
66 for itm in selectedItems:
67 namespace = itm.text()
68 self.documentsList.takeItem(self.documentsList.row(itm))
69 del itm
70
71 self.__settings.removeDocumentation(namespace)
72
73 self.documentationSettingsChanged.emit(self.__settings)
74
75 @pyqtSlot()
76 def on_addDocumentsButton_clicked(self):
77 """
78 Private slot to add QtHelp documents to the help database.
79 """
80 filenames = EricFileDialog.getOpenFileNames(
81 self,
82 self.tr("Add Documentation"),
83 "",
84 self.tr("Qt Compressed Help Files (*.qch)"))
85 if not filenames:
86 return
87
88 self.__registerDocumentation(filenames)
89
90 @pyqtSlot()
91 def on_addPluginButton_clicked(self):
92 """
93 Private slot to add QtHelp documents provided by plug-ins to
94 the help database.
95 """
96 from .QtHelpDocumentationSelectionDialog import (
97 QtHelpDocumentationSelectionDialog
98 )
99 dlg = QtHelpDocumentationSelectionDialog(
100 self.__pluginHelpDocuments,
101 QtHelpDocumentationSelectionDialog.AddMode,
102 self)
103 if dlg.exec() == QDialog.DialogCode.Accepted:
104 documents = dlg.getData()
105 if documents:
106 self.__registerDocumentation(documents)
107
108 def __registerDocumentation(self, filenames):
109 """
110 Private method to register a given list of documentations.
111
112 @param filenames list of documentation files to be registered
113 @type list of str
114 """
115 added = False
116
117 for filename in filenames:
118 if not self.__settings.addDocumentation(filename):
119 EricMessageBox.warning(
120 self,
121 self.tr("Add Documentation"),
122 self.tr("""The file <b>{0}</b> could not be added.""")
123 .format(filename)
124 )
125 continue
126
127 if not added:
128 added = True
129 self.documentsList.clearSelection()
130
131 namespace = self.__settings.namespace(filename)
132 itm = QListWidgetItem(namespace)
133 self.documentsList.addItem(itm)
134
135 itm.setSelected(True)
136 self.__applyDocumentsListFilter()
137
138 if added:
139 self.documentationSettingsChanged.emit(self.__settings)
140
141 @pyqtSlot()
142 def on_managePluginButton_clicked(self):
143 """
144 Private slot to manage the QtHelp documents provided by plug-ins.
145 """
146 from .QtHelpDocumentationSelectionDialog import (
147 QtHelpDocumentationSelectionDialog
148 )
149 dlg = QtHelpDocumentationSelectionDialog(
150 self.__pluginHelpDocuments,
151 QtHelpDocumentationSelectionDialog.ManageMode,
152 self)
153 dlg.exec()
154
155 @pyqtSlot()
156 def on_documentsList_itemSelectionChanged(self):
157 """
158 Private slot handling a change of the documents selection.
159 """
160 self.removeDocumentsButton.setEnabled(
161 len(self.documentsList.selectedItems()) != 0)
162
163 @pyqtSlot(str)
164 def on_filterEdit_textChanged(self, txt):
165 """
166 Private slot to react on changes of the document filter text.
167
168 @param txt current entry of the filter
169 @type str
170 """
171 self.__applyDocumentsListFilter()
172
173 @pyqtSlot()
174 def __applyDocumentsListFilter(self):
175 """
176 Private slot to apply the current documents filter.
177 """
178 filterStr = self.filterEdit.text()
179 for row in range(self.documentsList.count()):
180 itm = self.documentsList.item(row)
181 matches = filterStr == "" or filterStr in itm.text()
182
183 if not matches:
184 itm.setSelected(False)
185 itm.setHidden(not matches)
186
187 def setDocumentationSettings(self, settings):
188 """
189 Public method to set the reference to the QtHelp documentation
190 configuration object.
191
192 @param settings reference to the created QtHelpDocumentationSettings
193 object
194 @type QtHelpDocumentationSettings
195 """
196 self.__settings = settings
197
198 self.documentsList.clear()
199
200 for namespace in self.__settings.namespaces():
201 itm = QListWidgetItem(namespace)
202 self.documentsList.addItem(itm)
203 self.__applyDocumentsListFilter()
204
205 self.removeDocumentsButton.setEnabled(False)
206
207 def documentationSettings(self):
208 """
209 Public method to get the reference to the QtHelp documentation
210 configuration object.
211
212 @return reference to the created QtHelpDocumentationSettings object
213 @rtype QtHelpDocumentationSettings
214 """
215 return self.__settings

eric ide

mercurial