src/eric7/HelpViewer/HelpViewerWidget.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
11 11
12 from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QTimer, QByteArray 12 from PyQt6.QtCore import pyqtSlot, Qt, QUrl, QTimer, QByteArray
13 from PyQt6.QtGui import QAction, QFont, QFontMetrics 13 from PyQt6.QtGui import QAction, QFont, QFontMetrics
14 from PyQt6.QtHelp import QHelpEngine 14 from PyQt6.QtHelp import QHelpEngine
15 from PyQt6.QtWidgets import ( 15 from PyQt6.QtWidgets import (
16 QWidget, QHBoxLayout, QVBoxLayout, QComboBox, QSizePolicy, QStackedWidget, 16 QWidget,
17 QToolButton, QButtonGroup, QAbstractButton, QMenu, QFrame, QLabel, 17 QHBoxLayout,
18 QProgressBar, QSplitter 18 QVBoxLayout,
19 QComboBox,
20 QSizePolicy,
21 QStackedWidget,
22 QToolButton,
23 QButtonGroup,
24 QAbstractButton,
25 QMenu,
26 QFrame,
27 QLabel,
28 QProgressBar,
29 QSplitter,
19 ) 30 )
31
20 try: 32 try:
21 from PyQt6.QtWebEngineCore import QWebEngineProfile, QWebEngineSettings 33 from PyQt6.QtWebEngineCore import QWebEngineProfile, QWebEngineSettings
34
22 WEBENGINE_AVAILABLE = True 35 WEBENGINE_AVAILABLE = True
23 except ImportError: 36 except ImportError:
24 WEBENGINE_AVAILABLE = False 37 WEBENGINE_AVAILABLE = False
25 38
26 from EricWidgets import EricFileDialog, EricMessageBox 39 from EricWidgets import EricFileDialog, EricMessageBox
27 from EricWidgets.EricApplication import ericApp 40 from EricWidgets.EricApplication import ericApp
28 from EricWidgets.EricTextEditSearchWidget import ( 41 from EricWidgets.EricTextEditSearchWidget import (
29 EricTextEditSearchWidget, EricTextEditType 42 EricTextEditSearchWidget,
43 EricTextEditType,
30 ) 44 )
31 45
32 import UI.PixmapCache 46 import UI.PixmapCache
33 import Utilities 47 import Utilities
34 import Preferences 48 import Preferences
43 57
44 class HelpViewerWidget(QWidget): 58 class HelpViewerWidget(QWidget):
45 """ 59 """
46 Class implementing an embedded viewer for QtHelp and local HTML files. 60 Class implementing an embedded viewer for QtHelp and local HTML files.
47 """ 61 """
48 MaxHistoryItems = 20 # max. number of history items to be shown 62
49 63 MaxHistoryItems = 20 # max. number of history items to be shown
64
50 EmpytDocument_Light = ( 65 EmpytDocument_Light = (
51 '''<!DOCTYPE html>\n''' 66 """<!DOCTYPE html>\n"""
52 '''<html lang="EN">\n''' 67 """<html lang="EN">\n"""
53 '''<head>\n''' 68 """<head>\n"""
54 '''<style type="text/css">\n''' 69 """<style type="text/css">\n"""
55 '''html {background-color: #ffffff;}\n''' 70 """html {background-color: #ffffff;}\n"""
56 '''body {background-color: #ffffff;\n''' 71 """body {background-color: #ffffff;\n"""
57 ''' color: #000000;\n''' 72 """ color: #000000;\n"""
58 ''' margin: 10px 10px 10px 10px;\n''' 73 """ margin: 10px 10px 10px 10px;\n"""
59 '''}\n''' 74 """}\n"""
60 '''</style''' 75 """</style"""
61 '''</head>\n''' 76 """</head>\n"""
62 '''<body>\n''' 77 """<body>\n"""
63 '''</body>\n''' 78 """</body>\n"""
64 '''</html>''' 79 """</html>"""
65 ) 80 )
66 EmpytDocument_Dark = ( 81 EmpytDocument_Dark = (
67 '''<!DOCTYPE html>\n''' 82 """<!DOCTYPE html>\n"""
68 '''<html lang="EN">\n''' 83 """<html lang="EN">\n"""
69 '''<head>\n''' 84 """<head>\n"""
70 '''<style type="text/css">\n''' 85 """<style type="text/css">\n"""
71 '''html {background-color: #262626;}\n''' 86 """html {background-color: #262626;}\n"""
72 '''body {background-color: #262626;\n''' 87 """body {background-color: #262626;\n"""
73 ''' color: #ffffff;\n''' 88 """ color: #ffffff;\n"""
74 ''' margin: 10px 10px 10px 10px;\n''' 89 """ margin: 10px 10px 10px 10px;\n"""
75 '''}\n''' 90 """}\n"""
76 '''</style''' 91 """</style"""
77 '''</head>\n''' 92 """</head>\n"""
78 '''<body>\n''' 93 """<body>\n"""
79 '''</body>\n''' 94 """</body>\n"""
80 '''</html>''' 95 """</html>"""
81 ) 96 )
82 97
83 def __init__(self, parent=None): 98 def __init__(self, parent=None):
84 """ 99 """
85 Constructor 100 Constructor
86 101
87 @param parent reference to the parent widget (defaults to None) 102 @param parent reference to the parent widget (defaults to None)
88 @type QWidget (optional) 103 @type QWidget (optional)
89 """ 104 """
90 super().__init__(parent) 105 super().__init__(parent)
91 self.setObjectName("HelpViewerWidget") 106 self.setObjectName("HelpViewerWidget")
92 107
93 self.__ui = parent 108 self.__ui = parent
94 109
95 self.__initHelpEngine() 110 self.__initHelpEngine()
96 111
97 self.__layout = QVBoxLayout() 112 self.__layout = QVBoxLayout()
98 self.__layout.setObjectName("MainLayout") 113 self.__layout.setObjectName("MainLayout")
99 self.__layout.setContentsMargins(0, 3, 0, 0) 114 self.__layout.setContentsMargins(0, 3, 0, 0)
100 115
101 ################################################################### 116 ###################################################################
102 ## Help Topic Selector 117 ## Help Topic Selector
103 ################################################################### 118 ###################################################################
104 119
105 self.__selectorLayout = QHBoxLayout() 120 self.__selectorLayout = QHBoxLayout()
106 121
107 self.__helpSelector = QComboBox(self) 122 self.__helpSelector = QComboBox(self)
108 self.__helpSelector.setSizePolicy( 123 self.__helpSelector.setSizePolicy(
109 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) 124 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
125 )
110 self.__selectorLayout.addWidget(self.__helpSelector) 126 self.__selectorLayout.addWidget(self.__helpSelector)
111 self.__populateHelpSelector() 127 self.__populateHelpSelector()
112 self.__helpSelector.activated.connect(self.__helpTopicSelected) 128 self.__helpSelector.activated.connect(self.__helpTopicSelected)
113 129
114 self.__openButton = QToolButton(self) 130 self.__openButton = QToolButton(self)
115 self.__openButton.setIcon(UI.PixmapCache.getIcon("open")) 131 self.__openButton.setIcon(UI.PixmapCache.getIcon("open"))
116 self.__openButton.setToolTip(self.tr("Open a local file")) 132 self.__openButton.setToolTip(self.tr("Open a local file"))
117 self.__openButton.clicked.connect(self.__openFile) 133 self.__openButton.clicked.connect(self.__openFile)
118 self.__selectorLayout.addWidget(self.__openButton) 134 self.__selectorLayout.addWidget(self.__openButton)
119 135
120 self.__actionsButton = QToolButton(self) 136 self.__actionsButton = QToolButton(self)
121 self.__actionsButton.setIcon( 137 self.__actionsButton.setIcon(UI.PixmapCache.getIcon("actionsToolButton"))
122 UI.PixmapCache.getIcon("actionsToolButton")) 138 self.__actionsButton.setToolTip(self.tr("Select action from menu"))
123 self.__actionsButton.setToolTip( 139 self.__actionsButton.setPopupMode(QToolButton.ToolButtonPopupMode.InstantPopup)
124 self.tr("Select action from menu"))
125 self.__actionsButton.setPopupMode(
126 QToolButton.ToolButtonPopupMode.InstantPopup)
127 self.__selectorLayout.addWidget(self.__actionsButton) 140 self.__selectorLayout.addWidget(self.__actionsButton)
128 141
129 self.__layout.addLayout(self.__selectorLayout) 142 self.__layout.addLayout(self.__selectorLayout)
130 143
131 ################################################################### 144 ###################################################################
132 ## Navigation Buttons 145 ## Navigation Buttons
133 ################################################################### 146 ###################################################################
134 147
135 self.__navButtonsLayout = QHBoxLayout() 148 self.__navButtonsLayout = QHBoxLayout()
136 149
137 self.__navButtonsLayout.addStretch() 150 self.__navButtonsLayout.addStretch()
138 151
139 self.__backwardButton = QToolButton(self) 152 self.__backwardButton = QToolButton(self)
140 self.__backwardButton.setIcon(UI.PixmapCache.getIcon("back")) 153 self.__backwardButton.setIcon(UI.PixmapCache.getIcon("back"))
141 self.__backwardButton.setToolTip(self.tr("Move one page backward")) 154 self.__backwardButton.setToolTip(self.tr("Move one page backward"))
142 self.__backwardButton.clicked.connect(self.__backward) 155 self.__backwardButton.clicked.connect(self.__backward)
143 156
144 self.__forwardButton = QToolButton(self) 157 self.__forwardButton = QToolButton(self)
145 self.__forwardButton.setIcon(UI.PixmapCache.getIcon("forward")) 158 self.__forwardButton.setIcon(UI.PixmapCache.getIcon("forward"))
146 self.__forwardButton.setToolTip(self.tr("Move one page forward")) 159 self.__forwardButton.setToolTip(self.tr("Move one page forward"))
147 self.__forwardButton.clicked.connect(self.__forward) 160 self.__forwardButton.clicked.connect(self.__forward)
148 161
149 self.__backForButtonLayout = QHBoxLayout() 162 self.__backForButtonLayout = QHBoxLayout()
150 self.__backForButtonLayout.setContentsMargins(0, 0, 0, 0) 163 self.__backForButtonLayout.setContentsMargins(0, 0, 0, 0)
151 self.__backForButtonLayout.setSpacing(0) 164 self.__backForButtonLayout.setSpacing(0)
152 self.__backForButtonLayout.addWidget(self.__backwardButton) 165 self.__backForButtonLayout.addWidget(self.__backwardButton)
153 self.__backForButtonLayout.addWidget(self.__forwardButton) 166 self.__backForButtonLayout.addWidget(self.__forwardButton)
154 self.__navButtonsLayout.addLayout(self.__backForButtonLayout) 167 self.__navButtonsLayout.addLayout(self.__backForButtonLayout)
155 168
156 self.__reloadButton = QToolButton(self) 169 self.__reloadButton = QToolButton(self)
157 self.__reloadButton.setIcon(UI.PixmapCache.getIcon("reload")) 170 self.__reloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
158 self.__reloadButton.setToolTip(self.tr("Reload the current page")) 171 self.__reloadButton.setToolTip(self.tr("Reload the current page"))
159 self.__reloadButton.clicked.connect(self.__reload) 172 self.__reloadButton.clicked.connect(self.__reload)
160 self.__navButtonsLayout.addWidget(self.__reloadButton) 173 self.__navButtonsLayout.addWidget(self.__reloadButton)
161 174
162 self.__buttonLine1 = QFrame(self) 175 self.__buttonLine1 = QFrame(self)
163 self.__buttonLine1.setFrameShape(QFrame.Shape.VLine) 176 self.__buttonLine1.setFrameShape(QFrame.Shape.VLine)
164 self.__buttonLine1.setFrameShadow(QFrame.Shadow.Sunken) 177 self.__buttonLine1.setFrameShadow(QFrame.Shadow.Sunken)
165 self.__navButtonsLayout.addWidget(self.__buttonLine1) 178 self.__navButtonsLayout.addWidget(self.__buttonLine1)
166 179
167 self.__zoomInButton = QToolButton(self) 180 self.__zoomInButton = QToolButton(self)
168 self.__zoomInButton.setIcon(UI.PixmapCache.getIcon("zoomIn")) 181 self.__zoomInButton.setIcon(UI.PixmapCache.getIcon("zoomIn"))
169 self.__zoomInButton.setToolTip( 182 self.__zoomInButton.setToolTip(self.tr("Zoom in on the current page"))
170 self.tr("Zoom in on the current page"))
171 self.__zoomInButton.clicked.connect(self.__zoomIn) 183 self.__zoomInButton.clicked.connect(self.__zoomIn)
172 self.__navButtonsLayout.addWidget(self.__zoomInButton) 184 self.__navButtonsLayout.addWidget(self.__zoomInButton)
173 185
174 self.__zoomOutButton = QToolButton(self) 186 self.__zoomOutButton = QToolButton(self)
175 self.__zoomOutButton.setIcon(UI.PixmapCache.getIcon("zoomOut")) 187 self.__zoomOutButton.setIcon(UI.PixmapCache.getIcon("zoomOut"))
176 self.__zoomOutButton.setToolTip( 188 self.__zoomOutButton.setToolTip(self.tr("Zoom out on the current page"))
177 self.tr("Zoom out on the current page"))
178 self.__zoomOutButton.clicked.connect(self.__zoomOut) 189 self.__zoomOutButton.clicked.connect(self.__zoomOut)
179 self.__navButtonsLayout.addWidget(self.__zoomOutButton) 190 self.__navButtonsLayout.addWidget(self.__zoomOutButton)
180 191
181 self.__zoomResetButton = QToolButton(self) 192 self.__zoomResetButton = QToolButton(self)
182 self.__zoomResetButton.setIcon(UI.PixmapCache.getIcon("zoomReset")) 193 self.__zoomResetButton.setIcon(UI.PixmapCache.getIcon("zoomReset"))
183 self.__zoomResetButton.setToolTip( 194 self.__zoomResetButton.setToolTip(
184 self.tr("Reset the zoom level of the current page")) 195 self.tr("Reset the zoom level of the current page")
196 )
185 self.__zoomResetButton.clicked.connect(self.__zoomReset) 197 self.__zoomResetButton.clicked.connect(self.__zoomReset)
186 self.__navButtonsLayout.addWidget(self.__zoomResetButton) 198 self.__navButtonsLayout.addWidget(self.__zoomResetButton)
187 199
188 self.__buttonLine2 = QFrame(self) 200 self.__buttonLine2 = QFrame(self)
189 self.__buttonLine2.setFrameShape(QFrame.Shape.VLine) 201 self.__buttonLine2.setFrameShape(QFrame.Shape.VLine)
190 self.__buttonLine2.setFrameShadow(QFrame.Shadow.Sunken) 202 self.__buttonLine2.setFrameShadow(QFrame.Shadow.Sunken)
191 self.__navButtonsLayout.addWidget(self.__buttonLine2) 203 self.__navButtonsLayout.addWidget(self.__buttonLine2)
192 204
193 self.__addPageButton = QToolButton(self) 205 self.__addPageButton = QToolButton(self)
194 self.__addPageButton.setIcon(UI.PixmapCache.getIcon("plus")) 206 self.__addPageButton.setIcon(UI.PixmapCache.getIcon("plus"))
195 self.__addPageButton.setToolTip( 207 self.__addPageButton.setToolTip(self.tr("Add a new empty page"))
196 self.tr("Add a new empty page"))
197 self.__addPageButton.clicked.connect(self.__addNewPage) 208 self.__addPageButton.clicked.connect(self.__addNewPage)
198 self.__navButtonsLayout.addWidget(self.__addPageButton) 209 self.__navButtonsLayout.addWidget(self.__addPageButton)
199 210
200 self.__closePageButton = QToolButton(self) 211 self.__closePageButton = QToolButton(self)
201 self.__closePageButton.setIcon(UI.PixmapCache.getIcon("minus")) 212 self.__closePageButton.setIcon(UI.PixmapCache.getIcon("minus"))
202 self.__closePageButton.setToolTip( 213 self.__closePageButton.setToolTip(self.tr("Close the current page"))
203 self.tr("Close the current page"))
204 self.__closePageButton.clicked.connect(self.closeCurrentPage) 214 self.__closePageButton.clicked.connect(self.closeCurrentPage)
205 self.__navButtonsLayout.addWidget(self.__closePageButton) 215 self.__navButtonsLayout.addWidget(self.__closePageButton)
206 216
207 self.__buttonLine3 = QFrame(self) 217 self.__buttonLine3 = QFrame(self)
208 self.__buttonLine3.setFrameShape(QFrame.Shape.VLine) 218 self.__buttonLine3.setFrameShape(QFrame.Shape.VLine)
209 self.__buttonLine3.setFrameShadow(QFrame.Shadow.Sunken) 219 self.__buttonLine3.setFrameShadow(QFrame.Shadow.Sunken)
210 self.__navButtonsLayout.addWidget(self.__buttonLine3) 220 self.__navButtonsLayout.addWidget(self.__buttonLine3)
211 221
212 self.__searchButton = QToolButton(self) 222 self.__searchButton = QToolButton(self)
213 self.__searchButton.setIcon(UI.PixmapCache.getIcon("find")) 223 self.__searchButton.setIcon(UI.PixmapCache.getIcon("find"))
214 self.__searchButton.setToolTip( 224 self.__searchButton.setToolTip(self.tr("Show or hide the search pane"))
215 self.tr("Show or hide the search pane"))
216 self.__searchButton.setCheckable(True) 225 self.__searchButton.setCheckable(True)
217 self.__searchButton.setChecked(False) 226 self.__searchButton.setChecked(False)
218 self.__searchButton.clicked.connect(self.showHideSearch) 227 self.__searchButton.clicked.connect(self.showHideSearch)
219 self.__navButtonsLayout.addWidget(self.__searchButton) 228 self.__navButtonsLayout.addWidget(self.__searchButton)
220 229
221 self.__navButtonsLayout.addStretch() 230 self.__navButtonsLayout.addStretch()
222 231
223 self.__layout.addLayout(self.__navButtonsLayout) 232 self.__layout.addLayout(self.__navButtonsLayout)
224 233
225 self.__backMenu = QMenu(self) 234 self.__backMenu = QMenu(self)
226 self.__backMenu.triggered.connect(self.__navigationMenuActionTriggered) 235 self.__backMenu.triggered.connect(self.__navigationMenuActionTriggered)
227 self.__backwardButton.setMenu(self.__backMenu) 236 self.__backwardButton.setMenu(self.__backMenu)
228 self.__backMenu.aboutToShow.connect(self.__showBackMenu) 237 self.__backMenu.aboutToShow.connect(self.__showBackMenu)
229 238
230 self.__forwardMenu = QMenu(self) 239 self.__forwardMenu = QMenu(self)
231 self.__forwardMenu.triggered.connect( 240 self.__forwardMenu.triggered.connect(self.__navigationMenuActionTriggered)
232 self.__navigationMenuActionTriggered)
233 self.__forwardButton.setMenu(self.__forwardMenu) 241 self.__forwardButton.setMenu(self.__forwardMenu)
234 self.__forwardMenu.aboutToShow.connect(self.__showForwardMenu) 242 self.__forwardMenu.aboutToShow.connect(self.__showForwardMenu)
235 243
236 ################################################################### 244 ###################################################################
237 ## Center widget with help pages, search widget and navigation 245 ## Center widget with help pages, search widget and navigation
238 ## widgets 246 ## widgets
239 ################################################################### 247 ###################################################################
240 248
241 self.__centerSplitter = QSplitter(Qt.Orientation.Vertical, self) 249 self.__centerSplitter = QSplitter(Qt.Orientation.Vertical, self)
242 self.__centerSplitter.setChildrenCollapsible(False) 250 self.__centerSplitter.setChildrenCollapsible(False)
243 self.__layout.addWidget(self.__centerSplitter) 251 self.__layout.addWidget(self.__centerSplitter)
244 252
245 self.__helpCenterWidget = QWidget(self) 253 self.__helpCenterWidget = QWidget(self)
246 self.__helpCenterLayout = QVBoxLayout() 254 self.__helpCenterLayout = QVBoxLayout()
247 self.__helpCenterLayout.setContentsMargins(0, 0, 0, 0) 255 self.__helpCenterLayout.setContentsMargins(0, 0, 0, 0)
248 self.__helpCenterWidget.setLayout(self.__helpCenterLayout) 256 self.__helpCenterWidget.setLayout(self.__helpCenterLayout)
249 257
250 ################################################################### 258 ###################################################################
251 259
252 self.__helpStack = QStackedWidget(self) 260 self.__helpStack = QStackedWidget(self)
253 self.__helpStack.setSizePolicy( 261 self.__helpStack.setSizePolicy(
254 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding) 262 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding
263 )
255 self.__helpCenterLayout.addWidget(self.__helpStack) 264 self.__helpCenterLayout.addWidget(self.__helpStack)
256 265
257 ################################################################### 266 ###################################################################
258 267
259 self.__searchWidget = EricTextEditSearchWidget( 268 self.__searchWidget = EricTextEditSearchWidget(
260 self, widthForHeight=False, enableClose=True) 269 self, widthForHeight=False, enableClose=True
270 )
261 self.__helpCenterLayout.addWidget(self.__searchWidget) 271 self.__helpCenterLayout.addWidget(self.__searchWidget)
262 self.__searchWidget.closePressed.connect(self.__searchWidgetClosed) 272 self.__searchWidget.closePressed.connect(self.__searchWidgetClosed)
263 self.__searchWidget.hide() 273 self.__searchWidget.hide()
264 274
265 self.__centerSplitter.addWidget(self.__helpCenterWidget) 275 self.__centerSplitter.addWidget(self.__helpCenterWidget)
266 276
267 ################################################################### 277 ###################################################################
268 278
269 self.__helpNavigationStack = QStackedWidget(self) 279 self.__helpNavigationStack = QStackedWidget(self)
270 self.__helpNavigationStack.setSizePolicy( 280 self.__helpNavigationStack.setSizePolicy(
271 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred) 281 QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred
282 )
272 self.__helpNavigationStack.setMinimumHeight(100) 283 self.__helpNavigationStack.setMinimumHeight(100)
273 self.__centerSplitter.addWidget(self.__helpNavigationStack) 284 self.__centerSplitter.addWidget(self.__helpNavigationStack)
274 self.__populateNavigationStack() 285 self.__populateNavigationStack()
275 286
276 ################################################################### 287 ###################################################################
277 ## Bottom buttons 288 ## Bottom buttons
278 ################################################################### 289 ###################################################################
279 290
280 self.__buttonLayout = QHBoxLayout() 291 self.__buttonLayout = QHBoxLayout()
281 292
282 self.__buttonGroup = QButtonGroup(self) 293 self.__buttonGroup = QButtonGroup(self)
283 self.__buttonGroup.setExclusive(True) 294 self.__buttonGroup.setExclusive(True)
284 self.__buttonGroup.buttonClicked.connect( 295 self.__buttonGroup.buttonClicked.connect(self.__selectNavigationWidget)
285 self.__selectNavigationWidget) 296
286
287 self.__buttonLayout.addStretch() 297 self.__buttonLayout.addStretch()
288 298
289 self.__openPagesButton = self.__addNavigationButton( 299 self.__openPagesButton = self.__addNavigationButton(
290 "fileMisc", self.tr("Show list of open pages")) 300 "fileMisc", self.tr("Show list of open pages")
301 )
291 self.__helpTocButton = self.__addNavigationButton( 302 self.__helpTocButton = self.__addNavigationButton(
292 "tableOfContents", self.tr("Show the table of contents")) 303 "tableOfContents", self.tr("Show the table of contents")
304 )
293 self.__helpIndexButton = self.__addNavigationButton( 305 self.__helpIndexButton = self.__addNavigationButton(
294 "helpIndex", self.tr("Show the help document index")) 306 "helpIndex", self.tr("Show the help document index")
307 )
295 self.__helpSearchButton = self.__addNavigationButton( 308 self.__helpSearchButton = self.__addNavigationButton(
296 "documentFind", self.tr("Show the help search window")) 309 "documentFind", self.tr("Show the help search window")
310 )
297 self.__bookmarksButton = self.__addNavigationButton( 311 self.__bookmarksButton = self.__addNavigationButton(
298 "bookmark22", self.tr("Show list of bookmarks")) 312 "bookmark22", self.tr("Show list of bookmarks")
299 313 )
314
300 self.__buttonLayout.addStretch() 315 self.__buttonLayout.addStretch()
301 316
302 self.__helpFilterWidget = self.__initFilterWidget() 317 self.__helpFilterWidget = self.__initFilterWidget()
303 self.__buttonLayout.addWidget(self.__helpFilterWidget) 318 self.__buttonLayout.addWidget(self.__helpFilterWidget)
304 319
305 self.__layout.addLayout(self.__buttonLayout) 320 self.__layout.addLayout(self.__buttonLayout)
306 321
307 self.__indexingProgressWidget = self.__initIndexingProgress() 322 self.__indexingProgressWidget = self.__initIndexingProgress()
308 self.__layout.addWidget(self.__indexingProgressWidget) 323 self.__layout.addWidget(self.__indexingProgressWidget)
309 self.__indexingProgressWidget.hide() 324 self.__indexingProgressWidget.hide()
310 325
311 ################################################################### 326 ###################################################################
312 327
313 self.setLayout(self.__layout) 328 self.setLayout(self.__layout)
314 329
315 self.__openPagesButton.setChecked(True) 330 self.__openPagesButton.setChecked(True)
316 331
317 self.__ui.preferencesChanged.connect(self.__populateHelpSelector) 332 self.__ui.preferencesChanged.connect(self.__populateHelpSelector)
318 333
319 self.__initActionsMenu() 334 self.__initActionsMenu()
320 335
321 if WEBENGINE_AVAILABLE: 336 if WEBENGINE_AVAILABLE:
322 self.__initQWebEngine() 337 self.__initQWebEngine()
323 self.__ui.preferencesChanged.connect(self.__initQWebEngineSettings) 338 self.__ui.preferencesChanged.connect(self.__initQWebEngineSettings)
324 339
325 self.addPage() 340 self.addPage()
326 self.__checkActionButtons() 341 self.__checkActionButtons()
327 342
328 self.__centerSplitter.setSizes([900, 150]) 343 self.__centerSplitter.setSizes([900, 150])
329 344
330 QTimer.singleShot(50, self.__lookForNewDocumentation) 345 QTimer.singleShot(50, self.__lookForNewDocumentation)
331 346
332 def __addNavigationButton(self, iconName, toolTip): 347 def __addNavigationButton(self, iconName, toolTip):
333 """ 348 """
334 Private method to create and add a navigation button. 349 Private method to create and add a navigation button.
335 350
336 @param iconName name of the icon 351 @param iconName name of the icon
337 @type str 352 @type str
338 @param toolTip tooltip to be shown 353 @param toolTip tooltip to be shown
339 @type str 354 @type str
340 @return reference to the created button 355 @return reference to the created button
344 button.setIcon(UI.PixmapCache.getIcon(iconName)) 359 button.setIcon(UI.PixmapCache.getIcon(iconName))
345 button.setToolTip(toolTip) 360 button.setToolTip(toolTip)
346 button.setCheckable(True) 361 button.setCheckable(True)
347 self.__buttonGroup.addButton(button) 362 self.__buttonGroup.addButton(button)
348 self.__buttonLayout.addWidget(button) 363 self.__buttonLayout.addWidget(button)
349 364
350 return button 365 return button
351 366
352 def __populateNavigationStack(self): 367 def __populateNavigationStack(self):
353 """ 368 """
354 Private method to populate the stack of navigation widgets. 369 Private method to populate the stack of navigation widgets.
355 """ 370 """
356 # Open Pages 371 # Open Pages
357 self.__openPagesList = OpenPagesWidget(self.__helpStack, self) 372 self.__openPagesList = OpenPagesWidget(self.__helpStack, self)
358 self.__openPagesList.currentPageChanged.connect( 373 self.__openPagesList.currentPageChanged.connect(self.__currentPageChanged)
359 self.__currentPageChanged)
360 self.__helpNavigationStack.addWidget(self.__openPagesList) 374 self.__helpNavigationStack.addWidget(self.__openPagesList)
361 375
362 # QtHelp TOC widget 376 # QtHelp TOC widget
363 self.__helpTocWidget = HelpTocWidget( 377 self.__helpTocWidget = HelpTocWidget(self.__helpEngine, internal=True)
364 self.__helpEngine, internal=True)
365 self.__helpTocWidget.escapePressed.connect(self.__activateCurrentPage) 378 self.__helpTocWidget.escapePressed.connect(self.__activateCurrentPage)
366 self.__helpTocWidget.openUrl.connect(self.openUrl) 379 self.__helpTocWidget.openUrl.connect(self.openUrl)
367 self.__helpTocWidget.newTab.connect(self.openUrlNewPage) 380 self.__helpTocWidget.newTab.connect(self.openUrlNewPage)
368 self.__helpTocWidget.newBackgroundTab.connect( 381 self.__helpTocWidget.newBackgroundTab.connect(self.openUrlNewBackgroundPage)
369 self.openUrlNewBackgroundPage)
370 self.__helpNavigationStack.addWidget(self.__helpTocWidget) 382 self.__helpNavigationStack.addWidget(self.__helpTocWidget)
371 383
372 # QtHelp Index widget 384 # QtHelp Index widget
373 self.__helpIndexWidget = HelpIndexWidget( 385 self.__helpIndexWidget = HelpIndexWidget(self.__helpEngine, internal=True)
374 self.__helpEngine, internal=True) 386 self.__helpIndexWidget.escapePressed.connect(self.__activateCurrentPage)
375 self.__helpIndexWidget.escapePressed.connect(
376 self.__activateCurrentPage)
377 self.__helpIndexWidget.openUrl.connect(self.openUrl) 387 self.__helpIndexWidget.openUrl.connect(self.openUrl)
378 self.__helpIndexWidget.newTab.connect(self.openUrlNewPage) 388 self.__helpIndexWidget.newTab.connect(self.openUrlNewPage)
379 self.__helpIndexWidget.newBackgroundTab.connect( 389 self.__helpIndexWidget.newBackgroundTab.connect(self.openUrlNewBackgroundPage)
380 self.openUrlNewBackgroundPage)
381 self.__helpNavigationStack.addWidget(self.__helpIndexWidget) 390 self.__helpNavigationStack.addWidget(self.__helpIndexWidget)
382 391
383 # QtHelp Search widget 392 # QtHelp Search widget
384 self.__indexing = False 393 self.__indexing = False
385 self.__indexingProgress = None 394 self.__indexingProgress = None
386 self.__helpSearchEngine = self.__helpEngine.searchEngine() 395 self.__helpSearchEngine = self.__helpEngine.searchEngine()
387 self.__helpSearchEngine.indexingStarted.connect( 396 self.__helpSearchEngine.indexingStarted.connect(self.__indexingStarted)
388 self.__indexingStarted) 397 self.__helpSearchEngine.indexingFinished.connect(self.__indexingFinished)
389 self.__helpSearchEngine.indexingFinished.connect( 398
390 self.__indexingFinished)
391
392 self.__helpSearchWidget = HelpSearchWidget( 399 self.__helpSearchWidget = HelpSearchWidget(
393 self.__helpSearchEngine, internal=True) 400 self.__helpSearchEngine, internal=True
394 self.__helpSearchWidget.escapePressed.connect( 401 )
395 self.__activateCurrentPage) 402 self.__helpSearchWidget.escapePressed.connect(self.__activateCurrentPage)
396 self.__helpSearchWidget.openUrl.connect(self.openUrl) 403 self.__helpSearchWidget.openUrl.connect(self.openUrl)
397 self.__helpSearchWidget.newTab.connect(self.openUrlNewPage) 404 self.__helpSearchWidget.newTab.connect(self.openUrlNewPage)
398 self.__helpSearchWidget.newBackgroundTab.connect( 405 self.__helpSearchWidget.newBackgroundTab.connect(self.openUrlNewBackgroundPage)
399 self.openUrlNewBackgroundPage)
400 self.__helpNavigationStack.addWidget(self.__helpSearchWidget) 406 self.__helpNavigationStack.addWidget(self.__helpSearchWidget)
401 407
402 # Bookmarks widget 408 # Bookmarks widget
403 self.__bookmarksList = HelpBookmarksWidget(self) 409 self.__bookmarksList = HelpBookmarksWidget(self)
404 self.__bookmarksList.escapePressed.connect(self.__activateCurrentPage) 410 self.__bookmarksList.escapePressed.connect(self.__activateCurrentPage)
405 self.__bookmarksList.openUrl.connect(self.openUrl) 411 self.__bookmarksList.openUrl.connect(self.openUrl)
406 self.__bookmarksList.newTab.connect(self.openUrlNewPage) 412 self.__bookmarksList.newTab.connect(self.openUrlNewPage)
407 self.__bookmarksList.newBackgroundTab.connect( 413 self.__bookmarksList.newBackgroundTab.connect(self.openUrlNewBackgroundPage)
408 self.openUrlNewBackgroundPage)
409 self.__helpNavigationStack.addWidget(self.__bookmarksList) 414 self.__helpNavigationStack.addWidget(self.__bookmarksList)
410 415
411 @pyqtSlot(QAbstractButton) 416 @pyqtSlot(QAbstractButton)
412 def __selectNavigationWidget(self, button): 417 def __selectNavigationWidget(self, button):
413 """ 418 """
414 Private slot to select the navigation widget. 419 Private slot to select the navigation widget.
415 420
416 @param button reference to the clicked button 421 @param button reference to the clicked button
417 @type QAbstractButton 422 @type QAbstractButton
418 """ 423 """
419 if button == self.__openPagesButton: 424 if button == self.__openPagesButton:
420 self.__helpNavigationStack.setCurrentWidget( 425 self.__helpNavigationStack.setCurrentWidget(self.__openPagesList)
421 self.__openPagesList)
422 elif button == self.__helpTocButton: 426 elif button == self.__helpTocButton:
423 self.__helpNavigationStack.setCurrentWidget( 427 self.__helpNavigationStack.setCurrentWidget(self.__helpTocWidget)
424 self.__helpTocWidget)
425 elif button == self.__helpIndexButton: 428 elif button == self.__helpIndexButton:
426 self.__helpNavigationStack.setCurrentWidget( 429 self.__helpNavigationStack.setCurrentWidget(self.__helpIndexWidget)
427 self.__helpIndexWidget)
428 elif button == self.__helpSearchButton: 430 elif button == self.__helpSearchButton:
429 self.__helpNavigationStack.setCurrentWidget( 431 self.__helpNavigationStack.setCurrentWidget(self.__helpSearchWidget)
430 self.__helpSearchWidget)
431 elif button == self.__bookmarksButton: 432 elif button == self.__bookmarksButton:
432 self.__helpNavigationStack.setCurrentWidget( 433 self.__helpNavigationStack.setCurrentWidget(self.__bookmarksList)
433 self.__bookmarksList) 434
434
435 def __populateHelpSelector(self): 435 def __populateHelpSelector(self):
436 """ 436 """
437 Private method to populate the help selection combo box. 437 Private method to populate the help selection combo box.
438 """ 438 """
439 self.__helpSelector.clear() 439 self.__helpSelector.clear()
440 440
441 self.__helpSelector.addItem("", "") 441 self.__helpSelector.addItem("", "")
442 442
443 for key, topic in [ 443 for key, topic in [
444 ("EricDocDir", self.tr("eric API Documentation")), 444 ("EricDocDir", self.tr("eric API Documentation")),
445 ("PythonDocDir", self.tr("Python 3 Documentation")), 445 ("PythonDocDir", self.tr("Python 3 Documentation")),
446 ("Qt5DocDir", self.tr("Qt5 Documentation")), 446 ("Qt5DocDir", self.tr("Qt5 Documentation")),
447 ("Qt6DocDir", self.tr("Qt6 Documentation")), 447 ("Qt6DocDir", self.tr("Qt6 Documentation")),
451 ("PySide6DocDir", self.tr("PySide6 Documentation")), 451 ("PySide6DocDir", self.tr("PySide6 Documentation")),
452 ]: 452 ]:
453 urlStr = Preferences.getHelp(key) 453 urlStr = Preferences.getHelp(key)
454 if urlStr: 454 if urlStr:
455 self.__helpSelector.addItem(topic, urlStr) 455 self.__helpSelector.addItem(topic, urlStr)
456 456
457 @pyqtSlot() 457 @pyqtSlot()
458 def __helpTopicSelected(self): 458 def __helpTopicSelected(self):
459 """ 459 """
460 Private slot handling the selection of a new help topic. 460 Private slot handling the selection of a new help topic.
461 """ 461 """
463 if urlStr: 463 if urlStr:
464 url = QUrl(urlStr) 464 url = QUrl(urlStr)
465 self.openUrl(url) 465 self.openUrl(url)
466 else: 466 else:
467 self.openUrl(QUrl("about:blank")) 467 self.openUrl(QUrl("about:blank"))
468 468
469 def activate(self, searchWord=None, url=None): 469 def activate(self, searchWord=None, url=None):
470 """ 470 """
471 Public method to activate the widget and search for a given word. 471 Public method to activate the widget and search for a given word.
472 472
473 @param searchWord word to search for (defaults to None) 473 @param searchWord word to search for (defaults to None)
474 @type str (optional) 474 @type str (optional)
475 @param url URL to show in a new page 475 @param url URL to show in a new page
476 @type QUrl 476 @type QUrl
477 """ 477 """
483 self.openUrlNewPage(url) 483 self.openUrlNewPage(url)
484 else: 484 else:
485 cv = self.currentViewer() 485 cv = self.currentViewer()
486 if cv: 486 if cv:
487 cv.setFocus(Qt.FocusReason.OtherFocusReason) 487 cv.setFocus(Qt.FocusReason.OtherFocusReason)
488 488
489 if searchWord: 489 if searchWord:
490 self.searchQtHelp(searchWord) 490 self.searchQtHelp(searchWord)
491 491
492 def shutdown(self): 492 def shutdown(self):
493 """ 493 """
494 Public method to perform shut down actions. 494 Public method to perform shut down actions.
495 """ 495 """
496 self.__helpSearchEngine.cancelIndexing() 496 self.__helpSearchEngine.cancelIndexing()
497 self.__helpSearchEngine.cancelSearching() 497 self.__helpSearchEngine.cancelSearching()
498 498
499 self.__helpInstaller.stop() 499 self.__helpInstaller.stop()
500 500
501 @pyqtSlot() 501 @pyqtSlot()
502 def __openFile(self): 502 def __openFile(self):
503 """ 503 """
504 Private slot to open a local help file (*.html). 504 Private slot to open a local help file (*.html).
505 """ 505 """
506 htmlFile = EricFileDialog.getOpenFileName( 506 htmlFile = EricFileDialog.getOpenFileName(
507 self, 507 self,
508 self.tr("Open HTML File"), 508 self.tr("Open HTML File"),
509 "", 509 "",
510 self.tr("HTML Files (*.htm *.html);;All Files (*)") 510 self.tr("HTML Files (*.htm *.html);;All Files (*)"),
511 ) 511 )
512 if htmlFile: 512 if htmlFile:
513 self.currentViewer().setLink(QUrl.fromLocalFile(htmlFile)) 513 self.currentViewer().setLink(QUrl.fromLocalFile(htmlFile))
514 514
515 @pyqtSlot() 515 @pyqtSlot()
516 def __addNewPage(self): 516 def __addNewPage(self):
517 """ 517 """
518 Private slot to add a new empty page. 518 Private slot to add a new empty page.
519 """ 519 """
520 urlStr = self.__helpSelector.currentData() 520 urlStr = self.__helpSelector.currentData()
521 url = QUrl(urlStr) if bool(urlStr) else None 521 url = QUrl(urlStr) if bool(urlStr) else None
522 self.addPage(url=url) 522 self.addPage(url=url)
523 523
524 def addPage(self, url=None, background=False): 524 def addPage(self, url=None, background=False):
525 """ 525 """
526 Public method to add a new help page with the given URL. 526 Public method to add a new help page with the given URL.
527 527
528 @param url requested URL (defaults to QUrl("about:blank")) 528 @param url requested URL (defaults to QUrl("about:blank"))
529 @type QUrl (optional) 529 @type QUrl (optional)
530 @param background flag indicating to open the page in the background 530 @param background flag indicating to open the page in the background
531 (defaults to False) 531 (defaults to False)
532 @type bool (optional) 532 @type bool (optional)
533 @return reference to the created page 533 @return reference to the created page
534 @rtype HelpViewerImpl 534 @rtype HelpViewerImpl
535 """ 535 """
536 if url is None: 536 if url is None:
537 url = QUrl("about:blank") 537 url = QUrl("about:blank")
538 538
539 viewer, viewerType = self.__newViewer() 539 viewer, viewerType = self.__newViewer()
540 viewer.setLink(url) 540 viewer.setLink(url)
541 541
542 cv = self.currentViewer() 542 cv = self.currentViewer()
543 if background and bool(cv): 543 if background and bool(cv):
544 index = self.__helpStack.indexOf(cv) + 1 544 index = self.__helpStack.indexOf(cv) + 1
545 self.__helpStack.insertWidget(index, viewer) 545 self.__helpStack.insertWidget(index, viewer)
546 self.__openPagesList.insertPage( 546 self.__openPagesList.insertPage(index, viewer, background=background)
547 index, viewer, background=background)
548 cv.setFocus(Qt.FocusReason.OtherFocusReason) 547 cv.setFocus(Qt.FocusReason.OtherFocusReason)
549 else: 548 else:
550 self.__helpStack.addWidget(viewer) 549 self.__helpStack.addWidget(viewer)
551 self.__openPagesList.addPage(viewer, background=background) 550 self.__openPagesList.addPage(viewer, background=background)
552 viewer.setFocus(Qt.FocusReason.OtherFocusReason) 551 viewer.setFocus(Qt.FocusReason.OtherFocusReason)
553 self.__searchWidget.attachTextEdit(viewer, editType=viewerType) 552 self.__searchWidget.attachTextEdit(viewer, editType=viewerType)
554 553
555 return viewer 554 return viewer
556 555
557 @pyqtSlot(QUrl) 556 @pyqtSlot(QUrl)
558 def openUrl(self, url): 557 def openUrl(self, url):
559 """ 558 """
560 Public slot to load a URL in the current page. 559 Public slot to load a URL in the current page.
561 560
562 @param url URL to be opened 561 @param url URL to be opened
563 @type QUrl 562 @type QUrl
564 """ 563 """
565 cv = self.currentViewer() 564 cv = self.currentViewer()
566 if cv: 565 if cv:
567 cv.setLink(url) 566 cv.setLink(url)
568 cv.setFocus(Qt.FocusReason.OtherFocusReason) 567 cv.setFocus(Qt.FocusReason.OtherFocusReason)
569 568
570 @pyqtSlot(QUrl) 569 @pyqtSlot(QUrl)
571 def openUrlNewPage(self, url): 570 def openUrlNewPage(self, url):
572 """ 571 """
573 Public slot to load a URL in a new page. 572 Public slot to load a URL in a new page.
574 573
575 @param url URL to be opened 574 @param url URL to be opened
576 @type QUrl 575 @type QUrl
577 """ 576 """
578 self.addPage(url=url) 577 self.addPage(url=url)
579 578
580 @pyqtSlot(QUrl) 579 @pyqtSlot(QUrl)
581 def openUrlNewBackgroundPage(self, url): 580 def openUrlNewBackgroundPage(self, url):
582 """ 581 """
583 Public slot to load a URL in a new background page. 582 Public slot to load a URL in a new background page.
584 583
585 @param url URL to be opened 584 @param url URL to be opened
586 @type QUrl 585 @type QUrl
587 """ 586 """
588 self.addPage(url=url, background=True) 587 self.addPage(url=url, background=True)
589 588
590 @pyqtSlot() 589 @pyqtSlot()
591 def closeCurrentPage(self): 590 def closeCurrentPage(self):
592 """ 591 """
593 Public slot to close the current page. 592 Public slot to close the current page.
594 """ 593 """
595 self.__openPagesList.closeCurrentPage() 594 self.__openPagesList.closeCurrentPage()
596 595
597 @pyqtSlot() 596 @pyqtSlot()
598 def closeOtherPages(self): 597 def closeOtherPages(self):
599 """ 598 """
600 Public slot to close all other pages. 599 Public slot to close all other pages.
601 """ 600 """
602 self.__openPagesList.closeOtherPages() 601 self.__openPagesList.closeOtherPages()
603 602
604 @pyqtSlot() 603 @pyqtSlot()
605 def closeAllPages(self): 604 def closeAllPages(self):
606 """ 605 """
607 Public slot to close all pages. 606 Public slot to close all pages.
608 """ 607 """
609 self.__openPagesList.closeAllPages() 608 self.__openPagesList.closeAllPages()
610 609
611 @pyqtSlot() 610 @pyqtSlot()
612 def __activateCurrentPage(self): 611 def __activateCurrentPage(self):
613 """ 612 """
614 Private slot to activate the current page. 613 Private slot to activate the current page.
615 """ 614 """
616 cv = self.currentViewer() 615 cv = self.currentViewer()
617 if cv: 616 if cv:
618 cv.setFocus() 617 cv.setFocus()
619 618
620 def __newViewer(self): 619 def __newViewer(self):
621 """ 620 """
622 Private method to create a new help viewer. 621 Private method to create a new help viewer.
623 622
624 @return tuple containing the reference to the created help viewer 623 @return tuple containing the reference to the created help viewer
625 object and its type 624 object and its type
626 @rtype tuple of (HelpViewerImpl, EricTextEditType) 625 @rtype tuple of (HelpViewerImpl, EricTextEditType)
627 """ 626 """
628 if WEBENGINE_AVAILABLE: 627 if WEBENGINE_AVAILABLE:
629 from .HelpViewerImplQWE import HelpViewerImplQWE 628 from .HelpViewerImplQWE import HelpViewerImplQWE
629
630 viewer = HelpViewerImplQWE(self.__helpEngine, self) 630 viewer = HelpViewerImplQWE(self.__helpEngine, self)
631 viewerType = EricTextEditType.QWEBENGINEVIEW 631 viewerType = EricTextEditType.QWEBENGINEVIEW
632 else: 632 else:
633 from .HelpViewerImplQTB import HelpViewerImplQTB 633 from .HelpViewerImplQTB import HelpViewerImplQTB
634
634 viewer = HelpViewerImplQTB(self.__helpEngine, self) 635 viewer = HelpViewerImplQTB(self.__helpEngine, self)
635 viewerType = EricTextEditType.QTEXTBROWSER 636 viewerType = EricTextEditType.QTEXTBROWSER
636 637
637 viewer.zoomChanged.connect(self.__checkActionButtons) 638 viewer.zoomChanged.connect(self.__checkActionButtons)
638 639
639 return viewer, viewerType 640 return viewer, viewerType
640 641
641 def currentViewer(self): 642 def currentViewer(self):
642 """ 643 """
643 Public method to get the active viewer. 644 Public method to get the active viewer.
644 645
645 @return reference to the active help viewer 646 @return reference to the active help viewer
646 @rtype HelpViewerImpl 647 @rtype HelpViewerImpl
647 """ 648 """
648 return self.__helpStack.currentWidget() 649 return self.__helpStack.currentWidget()
649 650
650 def bookmarkPage(self, title, url): 651 def bookmarkPage(self, title, url):
651 """ 652 """
652 Public method to bookmark a page with the given data. 653 Public method to bookmark a page with the given data.
653 654
654 @param title title of the page 655 @param title title of the page
655 @type str 656 @type str
656 @param url URL of the page 657 @param url URL of the page
657 @type QUrl 658 @type QUrl
658 """ 659 """
659 self.__bookmarksList.addBookmark(title, url) 660 self.__bookmarksList.addBookmark(title, url)
660 661
661 ####################################################################### 662 #######################################################################
662 ## QtHelp related code below 663 ## QtHelp related code below
663 ####################################################################### 664 #######################################################################
664 665
665 def __initHelpEngine(self): 666 def __initHelpEngine(self):
666 """ 667 """
667 Private method to initialize the QtHelp related stuff. 668 Private method to initialize the QtHelp related stuff.
668 """ 669 """
669 self.__helpEngine = QHelpEngine( 670 self.__helpEngine = QHelpEngine(self.__getQtHelpCollectionFileName(), self)
670 self.__getQtHelpCollectionFileName(),
671 self)
672 self.__helpEngine.setReadOnly(False) 671 self.__helpEngine.setReadOnly(False)
673 self.__helpEngine.setUsesFilterEngine(True) 672 self.__helpEngine.setUsesFilterEngine(True)
674 673
675 self.__helpEngine.warning.connect(self.__warning) 674 self.__helpEngine.warning.connect(self.__warning)
676 675
677 self.__helpEngine.setupData() 676 self.__helpEngine.setupData()
678 self.__removeOldDocumentation() 677 self.__removeOldDocumentation()
679 678
680 def __getQtHelpCollectionFileName(self): 679 def __getQtHelpCollectionFileName(self):
681 """ 680 """
682 Private method to determine the name of the QtHelp collection file. 681 Private method to determine the name of the QtHelp collection file.
683 682
684 @return path of the QtHelp collection file 683 @return path of the QtHelp collection file
685 @rtype str 684 @rtype str
686 """ 685 """
687 qthelpDir = os.path.join(Utilities.getConfigDir(), "qthelp") 686 qthelpDir = os.path.join(Utilities.getConfigDir(), "qthelp")
688 if not os.path.exists(qthelpDir): 687 if not os.path.exists(qthelpDir):
689 os.makedirs(qthelpDir) 688 os.makedirs(qthelpDir)
690 return os.path.join(qthelpDir, "eric7help.qhc") 689 return os.path.join(qthelpDir, "eric7help.qhc")
691 690
692 @pyqtSlot(str) 691 @pyqtSlot(str)
693 def __warning(self, msg): 692 def __warning(self, msg):
694 """ 693 """
695 Private slot handling warnings of the help engine. 694 Private slot handling warnings of the help engine.
696 695
697 @param msg message sent by the help engine 696 @param msg message sent by the help engine
698 @type str 697 @type str
699 """ 698 """
700 EricMessageBox.warning( 699 EricMessageBox.warning(self, self.tr("Help Engine"), msg)
701 self, 700
702 self.tr("Help Engine"), msg)
703
704 @pyqtSlot() 701 @pyqtSlot()
705 def __removeOldDocumentation(self): 702 def __removeOldDocumentation(self):
706 """ 703 """
707 Private slot to remove non-existing documentation from the help engine. 704 Private slot to remove non-existing documentation from the help engine.
708 """ 705 """
709 for namespace in self.__helpEngine.registeredDocumentations(): 706 for namespace in self.__helpEngine.registeredDocumentations():
710 docFile = self.__helpEngine.documentationFileName(namespace) 707 docFile = self.__helpEngine.documentationFileName(namespace)
711 if not os.path.exists(docFile): 708 if not os.path.exists(docFile):
712 self.__helpEngine.unregisterDocumentation(namespace) 709 self.__helpEngine.unregisterDocumentation(namespace)
713 710
714 @pyqtSlot() 711 @pyqtSlot()
715 def __lookForNewDocumentation(self): 712 def __lookForNewDocumentation(self):
716 """ 713 """
717 Private slot to look for new documentation to be loaded into the 714 Private slot to look for new documentation to be loaded into the
718 help database. 715 help database.
719 """ 716 """
720 from WebBrowser.QtHelp.HelpDocsInstaller import HelpDocsInstaller 717 from WebBrowser.QtHelp.HelpDocsInstaller import HelpDocsInstaller
721 self.__helpInstaller = HelpDocsInstaller( 718
722 self.__helpEngine.collectionFile()) 719 self.__helpInstaller = HelpDocsInstaller(self.__helpEngine.collectionFile())
723 self.__helpInstaller.errorMessage.connect( 720 self.__helpInstaller.errorMessage.connect(self.__showInstallationError)
724 self.__showInstallationError)
725 self.__helpInstaller.docsInstalled.connect(self.__docsInstalled) 721 self.__helpInstaller.docsInstalled.connect(self.__docsInstalled)
726 722
727 self.__ui.statusBar().showMessage( 723 self.__ui.statusBar().showMessage(self.tr("Looking for Documentation..."))
728 self.tr("Looking for Documentation..."))
729 self.__helpInstaller.installDocs() 724 self.__helpInstaller.installDocs()
730 725
731 @pyqtSlot(str) 726 @pyqtSlot(str)
732 def __showInstallationError(self, message): 727 def __showInstallationError(self, message):
733 """ 728 """
734 Private slot to show installation errors. 729 Private slot to show installation errors.
735 730
736 @param message message to be shown 731 @param message message to be shown
737 @type str 732 @type str
738 """ 733 """
739 EricMessageBox.warning( 734 EricMessageBox.warning(self, self.tr("eric Help Viewer"), message)
740 self, 735
741 self.tr("eric Help Viewer"),
742 message)
743
744 @pyqtSlot(bool) 736 @pyqtSlot(bool)
745 def __docsInstalled(self, installed): 737 def __docsInstalled(self, installed):
746 """ 738 """
747 Private slot handling the end of documentation installation. 739 Private slot handling the end of documentation installation.
748 740
749 @param installed flag indicating that documents were installed 741 @param installed flag indicating that documents were installed
750 @type bool 742 @type bool
751 """ 743 """
752 self.__ui.statusBar().clearMessage() 744 self.__ui.statusBar().clearMessage()
753 self.__helpEngine.setupData() 745 self.__helpEngine.setupData()
754 746
755 ####################################################################### 747 #######################################################################
756 ## Actions Menu related methods 748 ## Actions Menu related methods
757 ####################################################################### 749 #######################################################################
758 750
759 def __initActionsMenu(self): 751 def __initActionsMenu(self):
760 """ 752 """
761 Private method to initialize the actions menu. 753 Private method to initialize the actions menu.
762 """ 754 """
763 self.__actionsMenu = QMenu() 755 self.__actionsMenu = QMenu()
764 self.__actionsMenu.setToolTipsVisible(True) 756 self.__actionsMenu.setToolTipsVisible(True)
765 757
766 self.__actionsMenu.addAction( 758 self.__actionsMenu.addAction(
767 self.tr("Manage QtHelp Documents"), 759 self.tr("Manage QtHelp Documents"), self.__manageQtHelpDocuments
768 self.__manageQtHelpDocuments) 760 )
769 self.__actionsMenu.addAction( 761 self.__actionsMenu.addAction(
770 self.tr("Reindex Documentation"), 762 self.tr("Reindex Documentation"),
771 self.__helpSearchEngine.reindexDocumentation) 763 self.__helpSearchEngine.reindexDocumentation,
764 )
772 self.__actionsMenu.addSeparator() 765 self.__actionsMenu.addSeparator()
773 self.__actionsMenu.addAction( 766 self.__actionsMenu.addAction(
774 self.tr("Configure Help Documentation"), 767 self.tr("Configure Help Documentation"), self.__configureHelpDocumentation
775 self.__configureHelpDocumentation) 768 )
776 769
777 self.__actionsButton.setMenu(self.__actionsMenu) 770 self.__actionsButton.setMenu(self.__actionsMenu)
778 771
779 @pyqtSlot() 772 @pyqtSlot()
780 def __manageQtHelpDocuments(self): 773 def __manageQtHelpDocuments(self):
781 """ 774 """
782 Private slot to manage the QtHelp documentation database. 775 Private slot to manage the QtHelp documentation database.
783 """ 776 """
784 from WebBrowser.QtHelp.QtHelpDocumentationConfigurationDialog import ( 777 from WebBrowser.QtHelp.QtHelpDocumentationConfigurationDialog import (
785 QtHelpDocumentationConfigurationDialog 778 QtHelpDocumentationConfigurationDialog,
786 ) 779 )
787 dlg = QtHelpDocumentationConfigurationDialog( 780
788 self.__helpEngine, self) 781 dlg = QtHelpDocumentationConfigurationDialog(self.__helpEngine, self)
789 dlg.exec() 782 dlg.exec()
790 783
791 @pyqtSlot() 784 @pyqtSlot()
792 def __configureHelpDocumentation(self): 785 def __configureHelpDocumentation(self):
793 """ 786 """
794 Private slot to open the Help Documentation configuration page. 787 Private slot to open the Help Documentation configuration page.
795 """ 788 """
796 self.__ui.showPreferences("helpDocumentationPage") 789 self.__ui.showPreferences("helpDocumentationPage")
797 790
798 ####################################################################### 791 #######################################################################
799 ## Navigation related methods below 792 ## Navigation related methods below
800 ####################################################################### 793 #######################################################################
801 794
802 @pyqtSlot() 795 @pyqtSlot()
803 def __backward(self): 796 def __backward(self):
804 """ 797 """
805 Private slot to move one page backward. 798 Private slot to move one page backward.
806 """ 799 """
807 cv = self.currentViewer() 800 cv = self.currentViewer()
808 if cv: 801 if cv:
809 cv.backward() 802 cv.backward()
810 803
811 @pyqtSlot() 804 @pyqtSlot()
812 def __forward(self): 805 def __forward(self):
813 """ 806 """
814 Private slot to move one page foreward. 807 Private slot to move one page foreward.
815 """ 808 """
816 cv = self.currentViewer() 809 cv = self.currentViewer()
817 if cv: 810 if cv:
818 cv.forward() 811 cv.forward()
819 812
820 @pyqtSlot() 813 @pyqtSlot()
821 def __reload(self): 814 def __reload(self):
822 """ 815 """
823 Private slot to reload the current page. 816 Private slot to reload the current page.
824 """ 817 """
825 cv = self.currentViewer() 818 cv = self.currentViewer()
826 if cv: 819 if cv:
827 cv.reload() 820 cv.reload()
828 821
829 def __showBackMenu(self): 822 def __showBackMenu(self):
830 """ 823 """
831 Private slot showing the backward navigation menu. 824 Private slot showing the backward navigation menu.
832 """ 825 """
833 cv = self.currentViewer() 826 cv = self.currentViewer()
834 if cv: 827 if cv:
835 self.__backMenu.clear() 828 self.__backMenu.clear()
836 backwardHistoryCount = min(cv.backwardHistoryCount(), 829 backwardHistoryCount = min(
837 HelpViewerWidget.MaxHistoryItems) 830 cv.backwardHistoryCount(), HelpViewerWidget.MaxHistoryItems
838 831 )
832
839 for index in range(1, backwardHistoryCount + 1): 833 for index in range(1, backwardHistoryCount + 1):
840 act = QAction(self) 834 act = QAction(self)
841 act.setData(-index) 835 act.setData(-index)
842 act.setText(cv.historyTitle(-index)) 836 act.setText(cv.historyTitle(-index))
843 self.__backMenu.addAction(act) 837 self.__backMenu.addAction(act)
844 838
845 self.__backMenu.addSeparator() 839 self.__backMenu.addSeparator()
846 self.__backMenu.addAction(self.tr("Clear History"), 840 self.__backMenu.addAction(self.tr("Clear History"), self.__clearHistory)
847 self.__clearHistory) 841
848
849 def __showForwardMenu(self): 842 def __showForwardMenu(self):
850 """ 843 """
851 Private slot showing the forward navigation menu. 844 Private slot showing the forward navigation menu.
852 """ 845 """
853 cv = self.currentViewer() 846 cv = self.currentViewer()
854 if cv: 847 if cv:
855 self.__forwardMenu.clear() 848 self.__forwardMenu.clear()
856 forwardHistoryCount = min(cv.forwardHistoryCount(), 849 forwardHistoryCount = min(
857 HelpViewerWidget.MaxHistoryItems) 850 cv.forwardHistoryCount(), HelpViewerWidget.MaxHistoryItems
858 851 )
852
859 for index in range(1, forwardHistoryCount + 1): 853 for index in range(1, forwardHistoryCount + 1):
860 act = QAction(self) 854 act = QAction(self)
861 act.setData(index) 855 act.setData(index)
862 act.setText(cv.historyTitle(index)) 856 act.setText(cv.historyTitle(index))
863 self.__forwardMenu.addAction(act) 857 self.__forwardMenu.addAction(act)
864 858
865 self.__forwardMenu.addSeparator() 859 self.__forwardMenu.addSeparator()
866 self.__forwardMenu.addAction(self.tr("Clear History"), 860 self.__forwardMenu.addAction(self.tr("Clear History"), self.__clearHistory)
867 self.__clearHistory) 861
868
869 def __navigationMenuActionTriggered(self, act): 862 def __navigationMenuActionTriggered(self, act):
870 """ 863 """
871 Private slot to go to the selected page. 864 Private slot to go to the selected page.
872 865
873 @param act reference to the action selected in the navigation menu 866 @param act reference to the action selected in the navigation menu
874 @type QAction 867 @type QAction
875 """ 868 """
876 cv = self.currentViewer() 869 cv = self.currentViewer()
877 if cv: 870 if cv:
878 index = act.data() 871 index = act.data()
879 if index is not None: 872 if index is not None:
880 cv.gotoHistory(index) 873 cv.gotoHistory(index)
881 874
882 def __clearHistory(self): 875 def __clearHistory(self):
883 """ 876 """
884 Private slot to clear the history of the current viewer. 877 Private slot to clear the history of the current viewer.
885 """ 878 """
886 cv = self.currentViewer() 879 cv = self.currentViewer()
887 if cv: 880 if cv:
888 cv.clearHistory() 881 cv.clearHistory()
889 self.__checkActionButtons() 882 self.__checkActionButtons()
890 883
891 ####################################################################### 884 #######################################################################
892 ## Page navigation related methods below 885 ## Page navigation related methods below
893 ####################################################################### 886 #######################################################################
894 887
895 @pyqtSlot() 888 @pyqtSlot()
896 def __checkActionButtons(self): 889 def __checkActionButtons(self):
897 """ 890 """
898 Private slot to set the enabled state of the action buttons. 891 Private slot to set the enabled state of the action buttons.
899 """ 892 """
906 else: 899 else:
907 self.__backwardButton.setEnabled(False) 900 self.__backwardButton.setEnabled(False)
908 self.__forwardButton.setEnabled(False) 901 self.__forwardButton.setEnabled(False)
909 self.__zoomInButton.setEnabled(False) 902 self.__zoomInButton.setEnabled(False)
910 self.__zoomOutButton.setEnabled(False) 903 self.__zoomOutButton.setEnabled(False)
911 904
912 @pyqtSlot() 905 @pyqtSlot()
913 def __currentPageChanged(self): 906 def __currentPageChanged(self):
914 """ 907 """
915 Private slot handling the selection of another page. 908 Private slot handling the selection of another page.
916 """ 909 """
919 if cv: 912 if cv:
920 self.__searchWidget.attachTextEdit( 913 self.__searchWidget.attachTextEdit(
921 cv, 914 cv,
922 editType=( 915 editType=(
923 EricTextEditType.QWEBENGINEVIEW 916 EricTextEditType.QWEBENGINEVIEW
924 if WEBENGINE_AVAILABLE else 917 if WEBENGINE_AVAILABLE
925 EricTextEditType.QTEXTBROWSER 918 else EricTextEditType.QTEXTBROWSER
926 ) 919 ),
927 ) 920 )
928 cv.setFocus(Qt.FocusReason.OtherFocusReason) 921 cv.setFocus(Qt.FocusReason.OtherFocusReason)
929 922
930 ####################################################################### 923 #######################################################################
931 ## Zoom related methods below 924 ## Zoom related methods below
932 ####################################################################### 925 #######################################################################
933 926
934 @pyqtSlot() 927 @pyqtSlot()
935 def __zoomIn(self): 928 def __zoomIn(self):
936 """ 929 """
937 Private slot to zoom in. 930 Private slot to zoom in.
938 """ 931 """
939 cv = self.currentViewer() 932 cv = self.currentViewer()
940 if cv: 933 if cv:
941 cv.scaleUp() 934 cv.scaleUp()
942 935
943 @pyqtSlot() 936 @pyqtSlot()
944 def __zoomOut(self): 937 def __zoomOut(self):
945 """ 938 """
946 Private slot to zoom out. 939 Private slot to zoom out.
947 """ 940 """
948 cv = self.currentViewer() 941 cv = self.currentViewer()
949 if cv: 942 if cv:
950 cv.scaleDown() 943 cv.scaleDown()
951 944
952 @pyqtSlot() 945 @pyqtSlot()
953 def __zoomReset(self): 946 def __zoomReset(self):
954 """ 947 """
955 Private slot to reset the zoom level. 948 Private slot to reset the zoom level.
956 """ 949 """
957 cv = self.currentViewer() 950 cv = self.currentViewer()
958 if cv: 951 if cv:
959 cv.resetScale() 952 cv.resetScale()
960 953
961 ####################################################################### 954 #######################################################################
962 ## QtHelp Search related methods below 955 ## QtHelp Search related methods below
963 ####################################################################### 956 #######################################################################
964 957
965 def __initIndexingProgress(self): 958 def __initIndexingProgress(self):
966 """ 959 """
967 Private method to initialize the help documents indexing progress 960 Private method to initialize the help documents indexing progress
968 widget. 961 widget.
969 962
970 @return reference to the generated widget 963 @return reference to the generated widget
971 @rtype QWidget 964 @rtype QWidget
972 """ 965 """
973 progressWidget = QWidget(self) 966 progressWidget = QWidget(self)
974 layout = QHBoxLayout(progressWidget) 967 layout = QHBoxLayout(progressWidget)
975 layout.setContentsMargins(0, 0, 0, 0) 968 layout.setContentsMargins(0, 0, 0, 0)
976 969
977 label = QLabel(self.tr("Updating search index")) 970 label = QLabel(self.tr("Updating search index"))
978 layout.addWidget(label) 971 layout.addWidget(label)
979 972
980 progressBar = QProgressBar() 973 progressBar = QProgressBar()
981 progressBar.setRange(0, 0) 974 progressBar.setRange(0, 0)
982 progressBar.setTextVisible(False) 975 progressBar.setTextVisible(False)
983 progressBar.setFixedHeight(16) 976 progressBar.setFixedHeight(16)
984 layout.addWidget(progressBar) 977 layout.addWidget(progressBar)
985 978
986 return progressWidget 979 return progressWidget
987 980
988 @pyqtSlot() 981 @pyqtSlot()
989 def __indexingStarted(self): 982 def __indexingStarted(self):
990 """ 983 """
991 Private slot handling the start of the indexing process. 984 Private slot handling the start of the indexing process.
992 """ 985 """
993 self.__indexing = True 986 self.__indexing = True
994 self.__indexingProgressWidget.show() 987 self.__indexingProgressWidget.show()
995 988
996 @pyqtSlot() 989 @pyqtSlot()
997 def __indexingFinished(self): 990 def __indexingFinished(self):
998 """ 991 """
999 Private slot handling the end of the indexing process. 992 Private slot handling the end of the indexing process.
1000 """ 993 """
1001 self.__indexingProgressWidget.hide() 994 self.__indexingProgressWidget.hide()
1002 self.__indexing = False 995 self.__indexing = False
1003 996
1004 @pyqtSlot(str) 997 @pyqtSlot(str)
1005 def searchQtHelp(self, searchExpression): 998 def searchQtHelp(self, searchExpression):
1006 """ 999 """
1007 Public slot to search for a given search expression. 1000 Public slot to search for a given search expression.
1008 1001
1009 @param searchExpression expression to search for 1002 @param searchExpression expression to search for
1010 @type str 1003 @type str
1011 """ 1004 """
1012 if searchExpression: 1005 if searchExpression:
1013 if self.__indexing: 1006 if self.__indexing:
1014 # Try again a second later 1007 # Try again a second later
1015 QTimer.singleShot( 1008 QTimer.singleShot(1000, lambda: self.searchQtHelp(searchExpression))
1016 1000,
1017 lambda: self.searchQtHelp(searchExpression)
1018 )
1019 else: 1009 else:
1020 self.__helpSearchButton.setChecked(True) 1010 self.__helpSearchButton.setChecked(True)
1021 self.__helpSearchEngine.search(searchExpression) 1011 self.__helpSearchEngine.search(searchExpression)
1022 1012
1023 ####################################################################### 1013 #######################################################################
1024 ## QtHelp filter related methods below 1014 ## QtHelp filter related methods below
1025 ####################################################################### 1015 #######################################################################
1026 1016
1027 def __initFilterWidget(self): 1017 def __initFilterWidget(self):
1028 """ 1018 """
1029 Private method to initialize the filter selection widget. 1019 Private method to initialize the filter selection widget.
1030 1020
1031 @return reference to the generated widget 1021 @return reference to the generated widget
1032 @rtype QWidget 1022 @rtype QWidget
1033 """ 1023 """
1034 filterWidget = QWidget() 1024 filterWidget = QWidget()
1035 layout = QHBoxLayout(filterWidget) 1025 layout = QHBoxLayout(filterWidget)
1036 layout.setContentsMargins(0, 0, 0, 0) 1026 layout.setContentsMargins(0, 0, 0, 0)
1037 1027
1038 label = QLabel(self.tr("Filtered by: ")) 1028 label = QLabel(self.tr("Filtered by: "))
1039 layout.addWidget(label) 1029 layout.addWidget(label)
1040 1030
1041 self.__helpFilterCombo = QComboBox() 1031 self.__helpFilterCombo = QComboBox()
1042 comboWidth = QFontMetrics(QFont()).horizontalAdvance( 1032 comboWidth = QFontMetrics(QFont()).horizontalAdvance("ComboBoxWithEnoughWidth")
1043 "ComboBoxWithEnoughWidth")
1044 self.__helpFilterCombo.setMinimumWidth(comboWidth) 1033 self.__helpFilterCombo.setMinimumWidth(comboWidth)
1045 layout.addWidget(self.__helpFilterCombo) 1034 layout.addWidget(self.__helpFilterCombo)
1046 1035
1047 self.__helpEngine.setupFinished.connect( 1036 self.__helpEngine.setupFinished.connect(
1048 self.__setupFilterCombo, Qt.ConnectionType.QueuedConnection) 1037 self.__setupFilterCombo, Qt.ConnectionType.QueuedConnection
1038 )
1049 self.__helpFilterCombo.currentIndexChanged.connect( 1039 self.__helpFilterCombo.currentIndexChanged.connect(
1050 self.__filterQtHelpDocumentation) 1040 self.__filterQtHelpDocumentation
1041 )
1051 self.__helpEngine.filterEngine().filterActivated.connect( 1042 self.__helpEngine.filterEngine().filterActivated.connect(
1052 self.__currentFilterChanged) 1043 self.__currentFilterChanged
1053 1044 )
1045
1054 self.__setupFilterCombo() 1046 self.__setupFilterCombo()
1055 1047
1056 return filterWidget 1048 return filterWidget
1057 1049
1058 @pyqtSlot() 1050 @pyqtSlot()
1059 def __setupFilterCombo(self): 1051 def __setupFilterCombo(self):
1060 """ 1052 """
1061 Private slot to setup the filter combo box. 1053 Private slot to setup the filter combo box.
1062 """ 1054 """
1064 if not activeFilter: 1056 if not activeFilter:
1065 activeFilter = self.__helpEngine.filterEngine().activeFilter() 1057 activeFilter = self.__helpEngine.filterEngine().activeFilter()
1066 if not activeFilter: 1058 if not activeFilter:
1067 activeFilter = self.tr("Unfiltered") 1059 activeFilter = self.tr("Unfiltered")
1068 allFilters = self.__helpEngine.filterEngine().filters() 1060 allFilters = self.__helpEngine.filterEngine().filters()
1069 1061
1070 blocked = self.__helpFilterCombo.blockSignals(True) 1062 blocked = self.__helpFilterCombo.blockSignals(True)
1071 self.__helpFilterCombo.clear() 1063 self.__helpFilterCombo.clear()
1072 self.__helpFilterCombo.addItem(self.tr("Unfiltered")) 1064 self.__helpFilterCombo.addItem(self.tr("Unfiltered"))
1073 if allFilters: 1065 if allFilters:
1074 self.__helpFilterCombo.insertSeparator(1) 1066 self.__helpFilterCombo.insertSeparator(1)
1075 for helpFilter in sorted(allFilters): 1067 for helpFilter in sorted(allFilters):
1076 self.__helpFilterCombo.addItem(helpFilter, helpFilter) 1068 self.__helpFilterCombo.addItem(helpFilter, helpFilter)
1077 self.__helpFilterCombo.blockSignals(blocked) 1069 self.__helpFilterCombo.blockSignals(blocked)
1078 1070
1079 self.__helpFilterCombo.setCurrentText(activeFilter) 1071 self.__helpFilterCombo.setCurrentText(activeFilter)
1080 1072
1081 @pyqtSlot(int) 1073 @pyqtSlot(int)
1082 def __filterQtHelpDocumentation(self, index): 1074 def __filterQtHelpDocumentation(self, index):
1083 """ 1075 """
1084 Private slot to filter the QtHelp documentation. 1076 Private slot to filter the QtHelp documentation.
1085 1077
1086 @param index index of the selected QtHelp documentation filter 1078 @param index index of the selected QtHelp documentation filter
1087 @type int 1079 @type int
1088 """ 1080 """
1089 if self.__helpEngine: 1081 if self.__helpEngine:
1090 helpFilter = self.__helpFilterCombo.itemData(index) 1082 helpFilter = self.__helpFilterCombo.itemData(index)
1091 self.__helpEngine.filterEngine().setActiveFilter(helpFilter) 1083 self.__helpEngine.filterEngine().setActiveFilter(helpFilter)
1092 1084
1093 @pyqtSlot(str) 1085 @pyqtSlot(str)
1094 def __currentFilterChanged(self, filter_): 1086 def __currentFilterChanged(self, filter_):
1095 """ 1087 """
1096 Private slot handling a change of the active QtHelp filter. 1088 Private slot handling a change of the active QtHelp filter.
1097 1089
1098 @param filter_ filter name 1090 @param filter_ filter name
1099 @type str 1091 @type str
1100 """ 1092 """
1101 index = self.__helpFilterCombo.findData(filter_) 1093 index = self.__helpFilterCombo.findData(filter_)
1102 if index < 0: 1094 if index < 0:
1103 index = 0 1095 index = 0
1104 self.__helpFilterCombo.setCurrentIndex(index) 1096 self.__helpFilterCombo.setCurrentIndex(index)
1105 1097
1106 ####################################################################### 1098 #######################################################################
1107 ## QWebEngine related code below 1099 ## QWebEngine related code below
1108 ####################################################################### 1100 #######################################################################
1109 1101
1110 def __initQWebEngine(self): 1102 def __initQWebEngine(self):
1111 """ 1103 """
1112 Private method to initialize global QWebEngine related objects. 1104 Private method to initialize global QWebEngine related objects.
1113 """ 1105 """
1114 self.__webProfile = QWebEngineProfile.defaultProfile() 1106 self.__webProfile = QWebEngineProfile.defaultProfile()
1115 self.__webProfile.setHttpCacheType( 1107 self.__webProfile.setHttpCacheType(
1116 QWebEngineProfile.HttpCacheType.MemoryHttpCache) 1108 QWebEngineProfile.HttpCacheType.MemoryHttpCache
1109 )
1117 self.__webProfile.setHttpCacheMaximumSize(0) 1110 self.__webProfile.setHttpCacheMaximumSize(0)
1118 1111
1119 self.__initQWebEngineSettings() 1112 self.__initQWebEngineSettings()
1120 1113
1121 from WebBrowser.Network.QtHelpSchemeHandler import QtHelpSchemeHandler 1114 from WebBrowser.Network.QtHelpSchemeHandler import QtHelpSchemeHandler
1115
1122 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(self.__helpEngine) 1116 self.__qtHelpSchemeHandler = QtHelpSchemeHandler(self.__helpEngine)
1123 self.__webProfile.installUrlSchemeHandler( 1117 self.__webProfile.installUrlSchemeHandler(
1124 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler) 1118 QByteArray(b"qthelp"), self.__qtHelpSchemeHandler
1125 1119 )
1120
1126 def webProfile(self): 1121 def webProfile(self):
1127 """ 1122 """
1128 Public method to get a reference to the global web profile object. 1123 Public method to get a reference to the global web profile object.
1129 1124
1130 @return reference to the global web profile object 1125 @return reference to the global web profile object
1131 @rtype QWebEngineProfile 1126 @rtype QWebEngineProfile
1132 """ 1127 """
1133 return self.__webProfile 1128 return self.__webProfile
1134 1129
1135 def webSettings(self): 1130 def webSettings(self):
1136 """ 1131 """
1137 Public method to get the web settings of the current profile. 1132 Public method to get the web settings of the current profile.
1138 1133
1139 @return web settings of the current profile 1134 @return web settings of the current profile
1140 @rtype QWebEngineSettings 1135 @rtype QWebEngineSettings
1141 """ 1136 """
1142 return self.webProfile().settings() 1137 return self.webProfile().settings()
1143 1138
1144 def __initQWebEngineSettings(self): 1139 def __initQWebEngineSettings(self):
1145 """ 1140 """
1146 Private method to set the global web settings. 1141 Private method to set the global web settings.
1147 """ 1142 """
1148 settings = self.webSettings() 1143 settings = self.webSettings()
1149 1144
1150 settings.setFontFamily( 1145 settings.setFontFamily(
1151 QWebEngineSettings.FontFamily.StandardFont, 1146 QWebEngineSettings.FontFamily.StandardFont,
1152 Preferences.getWebBrowser("StandardFontFamily")) 1147 Preferences.getWebBrowser("StandardFontFamily"),
1148 )
1153 settings.setFontFamily( 1149 settings.setFontFamily(
1154 QWebEngineSettings.FontFamily.FixedFont, 1150 QWebEngineSettings.FontFamily.FixedFont,
1155 Preferences.getWebBrowser("FixedFontFamily")) 1151 Preferences.getWebBrowser("FixedFontFamily"),
1152 )
1156 settings.setFontFamily( 1153 settings.setFontFamily(
1157 QWebEngineSettings.FontFamily.SerifFont, 1154 QWebEngineSettings.FontFamily.SerifFont,
1158 Preferences.getWebBrowser("SerifFontFamily")) 1155 Preferences.getWebBrowser("SerifFontFamily"),
1156 )
1159 settings.setFontFamily( 1157 settings.setFontFamily(
1160 QWebEngineSettings.FontFamily.SansSerifFont, 1158 QWebEngineSettings.FontFamily.SansSerifFont,
1161 Preferences.getWebBrowser("SansSerifFontFamily")) 1159 Preferences.getWebBrowser("SansSerifFontFamily"),
1160 )
1162 settings.setFontFamily( 1161 settings.setFontFamily(
1163 QWebEngineSettings.FontFamily.CursiveFont, 1162 QWebEngineSettings.FontFamily.CursiveFont,
1164 Preferences.getWebBrowser("CursiveFontFamily")) 1163 Preferences.getWebBrowser("CursiveFontFamily"),
1164 )
1165 settings.setFontFamily( 1165 settings.setFontFamily(
1166 QWebEngineSettings.FontFamily.FantasyFont, 1166 QWebEngineSettings.FontFamily.FantasyFont,
1167 Preferences.getWebBrowser("FantasyFontFamily")) 1167 Preferences.getWebBrowser("FantasyFontFamily"),
1168 1168 )
1169
1169 settings.setFontSize( 1170 settings.setFontSize(
1170 QWebEngineSettings.FontSize.DefaultFontSize, 1171 QWebEngineSettings.FontSize.DefaultFontSize,
1171 Preferences.getWebBrowser("DefaultFontSize")) 1172 Preferences.getWebBrowser("DefaultFontSize"),
1173 )
1172 settings.setFontSize( 1174 settings.setFontSize(
1173 QWebEngineSettings.FontSize.DefaultFixedFontSize, 1175 QWebEngineSettings.FontSize.DefaultFixedFontSize,
1174 Preferences.getWebBrowser("DefaultFixedFontSize")) 1176 Preferences.getWebBrowser("DefaultFixedFontSize"),
1177 )
1175 settings.setFontSize( 1178 settings.setFontSize(
1176 QWebEngineSettings.FontSize.MinimumFontSize, 1179 QWebEngineSettings.FontSize.MinimumFontSize,
1177 Preferences.getWebBrowser("MinimumFontSize")) 1180 Preferences.getWebBrowser("MinimumFontSize"),
1181 )
1178 settings.setFontSize( 1182 settings.setFontSize(
1179 QWebEngineSettings.FontSize.MinimumLogicalFontSize, 1183 QWebEngineSettings.FontSize.MinimumLogicalFontSize,
1180 Preferences.getWebBrowser("MinimumLogicalFontSize")) 1184 Preferences.getWebBrowser("MinimumLogicalFontSize"),
1181 1185 )
1186
1182 settings.setAttribute( 1187 settings.setAttribute(
1183 QWebEngineSettings.WebAttribute.AutoLoadImages, 1188 QWebEngineSettings.WebAttribute.AutoLoadImages,
1184 Preferences.getWebBrowser("AutoLoadImages")) 1189 Preferences.getWebBrowser("AutoLoadImages"),
1185 settings.setAttribute( 1190 )
1186 QWebEngineSettings.WebAttribute.JavascriptEnabled, 1191 settings.setAttribute(QWebEngineSettings.WebAttribute.JavascriptEnabled, True)
1187 True)
1188 # JavaScript is needed for the web browser functionality 1192 # JavaScript is needed for the web browser functionality
1189 settings.setAttribute( 1193 settings.setAttribute(
1190 QWebEngineSettings.WebAttribute.JavascriptCanOpenWindows, 1194 QWebEngineSettings.WebAttribute.JavascriptCanOpenWindows,
1191 Preferences.getWebBrowser("JavaScriptCanOpenWindows")) 1195 Preferences.getWebBrowser("JavaScriptCanOpenWindows"),
1196 )
1192 settings.setAttribute( 1197 settings.setAttribute(
1193 QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard, 1198 QWebEngineSettings.WebAttribute.JavascriptCanAccessClipboard,
1194 Preferences.getWebBrowser("JavaScriptCanAccessClipboard")) 1199 Preferences.getWebBrowser("JavaScriptCanAccessClipboard"),
1195 settings.setAttribute( 1200 )
1196 QWebEngineSettings.WebAttribute.PluginsEnabled, 1201 settings.setAttribute(QWebEngineSettings.WebAttribute.PluginsEnabled, False)
1197 False) 1202
1198 1203 settings.setAttribute(
1199 settings.setAttribute( 1204 QWebEngineSettings.WebAttribute.LocalStorageEnabled, False
1200 QWebEngineSettings.WebAttribute.LocalStorageEnabled, 1205 )
1201 False)
1202 settings.setDefaultTextEncoding( 1206 settings.setDefaultTextEncoding(
1203 Preferences.getWebBrowser("DefaultTextEncoding")) 1207 Preferences.getWebBrowser("DefaultTextEncoding")
1204 1208 )
1209
1205 settings.setAttribute( 1210 settings.setAttribute(
1206 QWebEngineSettings.WebAttribute.SpatialNavigationEnabled, 1211 QWebEngineSettings.WebAttribute.SpatialNavigationEnabled,
1207 Preferences.getWebBrowser("SpatialNavigationEnabled")) 1212 Preferences.getWebBrowser("SpatialNavigationEnabled"),
1213 )
1208 settings.setAttribute( 1214 settings.setAttribute(
1209 QWebEngineSettings.WebAttribute.LinksIncludedInFocusChain, 1215 QWebEngineSettings.WebAttribute.LinksIncludedInFocusChain,
1210 Preferences.getWebBrowser("LinksIncludedInFocusChain")) 1216 Preferences.getWebBrowser("LinksIncludedInFocusChain"),
1217 )
1211 settings.setAttribute( 1218 settings.setAttribute(
1212 QWebEngineSettings.WebAttribute.LocalContentCanAccessRemoteUrls, 1219 QWebEngineSettings.WebAttribute.LocalContentCanAccessRemoteUrls,
1213 Preferences.getWebBrowser("LocalContentCanAccessRemoteUrls")) 1220 Preferences.getWebBrowser("LocalContentCanAccessRemoteUrls"),
1221 )
1214 settings.setAttribute( 1222 settings.setAttribute(
1215 QWebEngineSettings.WebAttribute.LocalContentCanAccessFileUrls, 1223 QWebEngineSettings.WebAttribute.LocalContentCanAccessFileUrls,
1216 Preferences.getWebBrowser("LocalContentCanAccessFileUrls")) 1224 Preferences.getWebBrowser("LocalContentCanAccessFileUrls"),
1225 )
1217 settings.setAttribute( 1226 settings.setAttribute(
1218 QWebEngineSettings.WebAttribute.XSSAuditingEnabled, 1227 QWebEngineSettings.WebAttribute.XSSAuditingEnabled,
1219 Preferences.getWebBrowser("XSSAuditingEnabled")) 1228 Preferences.getWebBrowser("XSSAuditingEnabled"),
1229 )
1220 settings.setAttribute( 1230 settings.setAttribute(
1221 QWebEngineSettings.WebAttribute.ScrollAnimatorEnabled, 1231 QWebEngineSettings.WebAttribute.ScrollAnimatorEnabled,
1222 Preferences.getWebBrowser("ScrollAnimatorEnabled")) 1232 Preferences.getWebBrowser("ScrollAnimatorEnabled"),
1233 )
1223 settings.setAttribute( 1234 settings.setAttribute(
1224 QWebEngineSettings.WebAttribute.ErrorPageEnabled, 1235 QWebEngineSettings.WebAttribute.ErrorPageEnabled,
1225 Preferences.getWebBrowser("ErrorPageEnabled")) 1236 Preferences.getWebBrowser("ErrorPageEnabled"),
1226 settings.setAttribute( 1237 )
1227 QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, 1238 settings.setAttribute(
1228 False) 1239 QWebEngineSettings.WebAttribute.FullScreenSupportEnabled, False
1240 )
1229 settings.setAttribute( 1241 settings.setAttribute(
1230 QWebEngineSettings.WebAttribute.ScreenCaptureEnabled, 1242 QWebEngineSettings.WebAttribute.ScreenCaptureEnabled,
1231 Preferences.getWebBrowser("ScreenCaptureEnabled")) 1243 Preferences.getWebBrowser("ScreenCaptureEnabled"),
1244 )
1232 settings.setAttribute( 1245 settings.setAttribute(
1233 QWebEngineSettings.WebAttribute.WebGLEnabled, 1246 QWebEngineSettings.WebAttribute.WebGLEnabled,
1234 Preferences.getWebBrowser("WebGLEnabled")) 1247 Preferences.getWebBrowser("WebGLEnabled"),
1248 )
1235 settings.setAttribute( 1249 settings.setAttribute(
1236 QWebEngineSettings.WebAttribute.FocusOnNavigationEnabled, 1250 QWebEngineSettings.WebAttribute.FocusOnNavigationEnabled,
1237 Preferences.getWebBrowser("FocusOnNavigationEnabled")) 1251 Preferences.getWebBrowser("FocusOnNavigationEnabled"),
1252 )
1238 settings.setAttribute( 1253 settings.setAttribute(
1239 QWebEngineSettings.WebAttribute.PrintElementBackgrounds, 1254 QWebEngineSettings.WebAttribute.PrintElementBackgrounds,
1240 Preferences.getWebBrowser("PrintElementBackgrounds")) 1255 Preferences.getWebBrowser("PrintElementBackgrounds"),
1256 )
1241 settings.setAttribute( 1257 settings.setAttribute(
1242 QWebEngineSettings.WebAttribute.AllowRunningInsecureContent, 1258 QWebEngineSettings.WebAttribute.AllowRunningInsecureContent,
1243 Preferences.getWebBrowser("AllowRunningInsecureContent")) 1259 Preferences.getWebBrowser("AllowRunningInsecureContent"),
1260 )
1244 settings.setAttribute( 1261 settings.setAttribute(
1245 QWebEngineSettings.WebAttribute.AllowGeolocationOnInsecureOrigins, 1262 QWebEngineSettings.WebAttribute.AllowGeolocationOnInsecureOrigins,
1246 Preferences.getWebBrowser("AllowGeolocationOnInsecureOrigins")) 1263 Preferences.getWebBrowser("AllowGeolocationOnInsecureOrigins"),
1247 settings.setAttribute( 1264 )
1248 QWebEngineSettings.WebAttribute 1265 settings.setAttribute(
1249 .AllowWindowActivationFromJavaScript, 1266 QWebEngineSettings.WebAttribute.AllowWindowActivationFromJavaScript,
1250 Preferences.getWebBrowser( 1267 Preferences.getWebBrowser("AllowWindowActivationFromJavaScript"),
1251 "AllowWindowActivationFromJavaScript")) 1268 )
1252 settings.setAttribute( 1269 settings.setAttribute(
1253 QWebEngineSettings.WebAttribute.ShowScrollBars, 1270 QWebEngineSettings.WebAttribute.ShowScrollBars,
1254 Preferences.getWebBrowser("ShowScrollBars")) 1271 Preferences.getWebBrowser("ShowScrollBars"),
1272 )
1255 settings.setAttribute( 1273 settings.setAttribute(
1256 QWebEngineSettings.WebAttribute.PlaybackRequiresUserGesture, 1274 QWebEngineSettings.WebAttribute.PlaybackRequiresUserGesture,
1257 Preferences.getWebBrowser( 1275 Preferences.getWebBrowser("PlaybackRequiresUserGesture"),
1258 "PlaybackRequiresUserGesture")) 1276 )
1259 settings.setAttribute( 1277 settings.setAttribute(
1260 QWebEngineSettings.WebAttribute.JavascriptCanPaste, 1278 QWebEngineSettings.WebAttribute.JavascriptCanPaste,
1261 Preferences.getWebBrowser( 1279 Preferences.getWebBrowser("JavaScriptCanPaste"),
1262 "JavaScriptCanPaste")) 1280 )
1263 settings.setAttribute( 1281 settings.setAttribute(
1264 QWebEngineSettings.WebAttribute.WebRTCPublicInterfacesOnly, 1282 QWebEngineSettings.WebAttribute.WebRTCPublicInterfacesOnly, False
1265 False) 1283 )
1266 settings.setAttribute( 1284 settings.setAttribute(QWebEngineSettings.WebAttribute.DnsPrefetchEnabled, False)
1267 QWebEngineSettings.WebAttribute.DnsPrefetchEnabled,
1268 False)
1269 settings.setAttribute( 1285 settings.setAttribute(
1270 QWebEngineSettings.WebAttribute.PdfViewerEnabled, 1286 QWebEngineSettings.WebAttribute.PdfViewerEnabled,
1271 Preferences.getWebBrowser( 1287 Preferences.getWebBrowser("PdfViewerEnabled"),
1272 "PdfViewerEnabled")) 1288 )
1273 1289
1274 ####################################################################### 1290 #######################################################################
1275 ## Search widget related methods below 1291 ## Search widget related methods below
1276 ####################################################################### 1292 #######################################################################
1277 1293
1278 @pyqtSlot() 1294 @pyqtSlot()
1279 def __searchWidgetClosed(self): 1295 def __searchWidgetClosed(self):
1280 """ 1296 """
1281 Private slot to handle the closing of the search widget. 1297 Private slot to handle the closing of the search widget.
1282 """ 1298 """
1283 self.__searchButton.setChecked(False) 1299 self.__searchButton.setChecked(False)
1284 1300
1285 @pyqtSlot(bool) 1301 @pyqtSlot(bool)
1286 def showHideSearch(self, visible): 1302 def showHideSearch(self, visible):
1287 """ 1303 """
1288 Public slot to show or hide the search widget. 1304 Public slot to show or hide the search widget.
1289 1305
1290 @param visible flag indicating to show or hide the search widget 1306 @param visible flag indicating to show or hide the search widget
1291 @type bool 1307 @type bool
1292 """ 1308 """
1293 self.__searchWidget.setVisible(visible) 1309 self.__searchWidget.setVisible(visible)
1294 if visible: 1310 if visible:
1295 self.__searchWidget.activate() 1311 self.__searchWidget.activate()
1296 else: 1312 else:
1297 self.__searchWidget.deactivate() 1313 self.__searchWidget.deactivate()
1298 1314
1299 @pyqtSlot() 1315 @pyqtSlot()
1300 def searchPrev(self): 1316 def searchPrev(self):
1301 """ 1317 """
1302 Public slot to find the previous occurrence of the current search term. 1318 Public slot to find the previous occurrence of the current search term.
1303 """ 1319 """
1304 self.__searchWidget.findPrev() 1320 self.__searchWidget.findPrev()
1305 1321
1306 @pyqtSlot() 1322 @pyqtSlot()
1307 def searchNext(self): 1323 def searchNext(self):
1308 """ 1324 """
1309 Public slot to find the next occurrence of the current search term. 1325 Public slot to find the next occurrence of the current search term.
1310 """ 1326 """
1311 self.__searchWidget.findNext() 1327 self.__searchWidget.findNext()
1312 1328
1313 ####################################################################### 1329 #######################################################################
1314 ## Utility methods below 1330 ## Utility methods below
1315 ####################################################################### 1331 #######################################################################
1316 1332
1317 def openPagesCount(self): 1333 def openPagesCount(self):
1318 """ 1334 """
1319 Public method to get the count of open pages. 1335 Public method to get the count of open pages.
1320 1336
1321 @return count of open pages 1337 @return count of open pages
1322 @rtype int 1338 @rtype int
1323 """ 1339 """
1324 return self.__helpStack.count() 1340 return self.__helpStack.count()
1325 1341
1326 @classmethod 1342 @classmethod
1327 def emptyDocument(cls): 1343 def emptyDocument(cls):
1328 """ 1344 """
1329 Class method to get the HTML code for an empty page. 1345 Class method to get the HTML code for an empty page.
1330 1346
1331 @return HTML code for an empty page. 1347 @return HTML code for an empty page.
1332 @rtype str 1348 @rtype str
1333 """ 1349 """
1334 if ericApp().usesDarkPalette(): 1350 if ericApp().usesDarkPalette():
1335 return cls.EmpytDocument_Dark 1351 return cls.EmpytDocument_Dark

eric ide

mercurial