src/eric7/WebBrowser/QtHelp/QtHelpDocumentationSettingsWidget.py

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

eric ide

mercurial