eric7/HelpViewer/HelpViewerWidget.py

branch
eric7
changeset 8681
6285e8374d99
parent 8680
85503ff2fce9
child 8683
e8a907801549
equal deleted inserted replaced
8680:85503ff2fce9 8681:6285e8374d99
7 Module implementing an embedded viewer for QtHelp and local HTML files. 7 Module implementing an embedded viewer for QtHelp and local HTML files.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt6.QtCore import pyqtSlot, Qt, QUrl 12 from PyQt6.QtCore import pyqtSlot, QUrl
13 from PyQt6.QtGui import QAction 13 from PyQt6.QtGui import QAction
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, QHBoxLayout, QVBoxLayout, QComboBox, QSizePolicy, QStackedWidget,
17 QToolButton, QButtonGroup, QAbstractButton, QMenu 17 QToolButton, QButtonGroup, QAbstractButton, QMenu, QFrame
18 ) 18 )
19 19
20 from EricWidgets import EricFileDialog, EricMessageBox 20 from EricWidgets import EricFileDialog, EricMessageBox
21 21
22 import UI.PixmapCache 22 import UI.PixmapCache
79 79
80 self.__navButtonsLayout = QHBoxLayout() 80 self.__navButtonsLayout = QHBoxLayout()
81 81
82 self.__navButtonsLayout.addStretch() 82 self.__navButtonsLayout.addStretch()
83 83
84 # TODO: add backward button
85 self.__backwardButton = QToolButton(self) 84 self.__backwardButton = QToolButton(self)
86 self.__backwardButton.setIcon(UI.PixmapCache.getIcon("back")) 85 self.__backwardButton.setIcon(UI.PixmapCache.getIcon("back"))
87 self.__backwardButton.setToolTip(self.tr("Move one page backward")) 86 self.__backwardButton.setToolTip(self.tr("Move one page backward"))
88 self.__backwardButton.setToolButtonStyle(
89 Qt.ToolButtonStyle.ToolButtonIconOnly)
90 self.__backwardButton.setAutoRaise(True)
91 self.__backwardButton.clicked.connect(self.__backward) 87 self.__backwardButton.clicked.connect(self.__backward)
92 88
93 # TODO: add forward button
94 self.__forwardButton = QToolButton(self) 89 self.__forwardButton = QToolButton(self)
95 self.__forwardButton.setIcon(UI.PixmapCache.getIcon("forward")) 90 self.__forwardButton.setIcon(UI.PixmapCache.getIcon("forward"))
96 self.__forwardButton.setToolTip(self.tr("Move one page forward")) 91 self.__forwardButton.setToolTip(self.tr("Move one page forward"))
97 self.__forwardButton.setToolButtonStyle(
98 Qt.ToolButtonStyle.ToolButtonIconOnly)
99 self.__forwardButton.setAutoRaise(True)
100 self.__forwardButton.clicked.connect(self.__forward) 92 self.__forwardButton.clicked.connect(self.__forward)
101 93
102 self.__backForButtonLayout = QHBoxLayout() 94 self.__backForButtonLayout = QHBoxLayout()
103 self.__backForButtonLayout.setContentsMargins(0, 0, 0, 0) 95 self.__backForButtonLayout.setContentsMargins(0, 0, 0, 0)
104 self.__backForButtonLayout.setSpacing(0) 96 self.__backForButtonLayout.setSpacing(0)
105 self.__backForButtonLayout.addWidget(self.__backwardButton) 97 self.__backForButtonLayout.addWidget(self.__backwardButton)
106 self.__backForButtonLayout.addWidget(self.__forwardButton) 98 self.__backForButtonLayout.addWidget(self.__forwardButton)
107 self.__navButtonsLayout.addLayout(self.__backForButtonLayout) 99 self.__navButtonsLayout.addLayout(self.__backForButtonLayout)
108 100
109 # TODO: add reload button
110 self.__reloadButton = QToolButton(self) 101 self.__reloadButton = QToolButton(self)
111 self.__reloadButton.setIcon(UI.PixmapCache.getIcon("reload")) 102 self.__reloadButton.setIcon(UI.PixmapCache.getIcon("reload"))
112 self.__reloadButton.setToolTip(self.tr("Reload the current page")) 103 self.__reloadButton.setToolTip(self.tr("Reload the current page"))
113 self.__reloadButton.clicked.connect(self.__reload) 104 self.__reloadButton.clicked.connect(self.__reload)
114 self.__navButtonsLayout.addWidget(self.__reloadButton) 105 self.__navButtonsLayout.addWidget(self.__reloadButton)
115 106
107 self.__buttonLine1 = QFrame(self)
108 self.__buttonLine1.setFrameShape(QFrame.Shape.VLine)
109 self.__buttonLine1.setFrameShadow(QFrame.Shadow.Sunken)
110 self.__navButtonsLayout.addWidget(self.__buttonLine1)
111
116 # TODO: add zoom in button 112 # TODO: add zoom in button
113 self.__zoomInButton = QToolButton(self)
114 self.__zoomInButton.setIcon(UI.PixmapCache.getIcon("zoomIn"))
115 self.__zoomInButton.setToolTip(
116 self.tr("Zoom in on the current page"))
117 self.__zoomInButton.clicked.connect(self.__zoomIn)
118 self.__navButtonsLayout.addWidget(self.__zoomInButton)
119
117 # TODO: add zoom out button 120 # TODO: add zoom out button
121 self.__zoomOutButton = QToolButton(self)
122 self.__zoomOutButton.setIcon(UI.PixmapCache.getIcon("zoomOut"))
123 self.__zoomOutButton.setToolTip(
124 self.tr("Zoom out on the current page"))
125 self.__zoomOutButton.clicked.connect(self.__zoomOut)
126 self.__navButtonsLayout.addWidget(self.__zoomOutButton)
127
118 # TODO: add zoom reset button 128 # TODO: add zoom reset button
129 self.__zoomResetButton = QToolButton(self)
130 self.__zoomResetButton.setIcon(UI.PixmapCache.getIcon("zoomReset"))
131 self.__zoomResetButton.setToolTip(
132 self.tr("Reset the zoom level of the current page"))
133 self.__zoomResetButton.clicked.connect(self.__zoomReset)
134 self.__navButtonsLayout.addWidget(self.__zoomResetButton)
119 135
120 self.__navButtonsLayout.addStretch() 136 self.__navButtonsLayout.addStretch()
121 137
122 self.__layout.addLayout(self.__navButtonsLayout) 138 self.__layout.addLayout(self.__navButtonsLayout)
123 139
179 self.__ui.preferencesChanged.connect(self.__populateHelpSelector) 195 self.__ui.preferencesChanged.connect(self.__populateHelpSelector)
180 196
181 self.__initActionsMenu() 197 self.__initActionsMenu()
182 198
183 self.addPage() 199 self.addPage()
184 self.__checkActionButtons(0) 200 self.__checkActionButtons()
185 201
186 def __addNavigationButton(self, iconName, toolTip): 202 def __addNavigationButton(self, iconName, toolTip):
187 """ 203 """
188 Private method to create and add a navigation button. 204 Private method to create and add a navigation button.
189 205
317 from .HelpViewerImpl_qwe import HelpViewerImpl_qwe 333 from .HelpViewerImpl_qwe import HelpViewerImpl_qwe
318 viewer = HelpViewerImpl_qwe(self.__helpEngine, self) 334 viewer = HelpViewerImpl_qwe(self.__helpEngine, self)
319 except ImportError: 335 except ImportError:
320 from .HelpViewerImpl_qtb import HelpViewerImpl_qtb 336 from .HelpViewerImpl_qtb import HelpViewerImpl_qtb
321 viewer = HelpViewerImpl_qtb(self.__helpEngine, self) 337 viewer = HelpViewerImpl_qtb(self.__helpEngine, self)
338
339 viewer.zoomChanged.connect(self.__checkActionButtons)
340
322 return viewer 341 return viewer
323 342
324 def currentViewer(self): 343 def currentViewer(self):
325 """ 344 """
326 Public method to get the active viewer. 345 Public method to get the active viewer.
447 """ 466 """
448 cv = self.currentViewer() 467 cv = self.currentViewer()
449 if cv: 468 if cv:
450 cv.reload() 469 cv.reload()
451 470
452 @pyqtSlot(int) 471 @pyqtSlot()
453 def __checkActionButtons(self, row): 472 def __checkActionButtons(self):
454 """ 473 """
455 Private slot to set the enabled state of the action buttons. 474 Private slot to set the enabled state of the action buttons.
456
457 @param row index of the current page
458 @type int
459 """ 475 """
460 cv = self.currentViewer() 476 cv = self.currentViewer()
461 self.__backwardButton.setEnabled(cv and cv.isBackwardAvailable()) 477 self.__backwardButton.setEnabled(cv and cv.isBackwardAvailable())
462 self.__forwardButton.setEnabled(cv and cv.isForwardAvailable()) 478 self.__forwardButton.setEnabled(cv and cv.isForwardAvailable())
479 self.__zoomInButton.setEnabled(cv and cv.isScaleUpAvailable())
480 self.__zoomOutButton.setEnabled(cv and cv.isScaleDownAvailable())
463 481
464 def __showBackMenu(self): 482 def __showBackMenu(self):
465 """ 483 """
466 Private slot showing the backward navigation menu. 484 Private slot showing the backward navigation menu.
467 """ 485 """
468 cv = self.currentViewer() 486 cv = self.currentViewer()
469 if cv: 487 if cv:
470 self.__backMenu.clear() 488 self.__backMenu.clear()
471 backwardHistoryCount = max(cv.backwardHistoryCount(), 20) 489 backwardHistoryCount = min(cv.backwardHistoryCount(), 20)
472 # show max. 20 items 490 # show max. 20 items
473 491
474 for index in range(1, backwardHistoryCount + 1): 492 for index in range(1, backwardHistoryCount + 1):
475 act = QAction(self) 493 act = QAction(self)
476 act.setData(-index) 494 act.setData(-index)
486 Private slot showing the forward navigation menu. 504 Private slot showing the forward navigation menu.
487 """ 505 """
488 cv = self.currentViewer() 506 cv = self.currentViewer()
489 if cv: 507 if cv:
490 self.__forwardMenu.clear() 508 self.__forwardMenu.clear()
491 forwardHistoryCount = max(cv.forwardHistoryCount(), 20) 509 forwardHistoryCount = min(cv.forwardHistoryCount(), 20)
492 # show max. 20 items 510 # show max. 20 items
493 511
494 for index in range(1, forwardHistoryCount + 1): 512 for index in range(1, forwardHistoryCount + 1):
495 act = QAction(self) 513 act = QAction(self)
496 act.setData(index) 514 act.setData(index)
515 533
516 def __clearHistory(self): 534 def __clearHistory(self):
517 """ 535 """
518 Private slot to clear the history of the current viewer. 536 Private slot to clear the history of the current viewer.
519 """ 537 """
520 cb = self.__mw.currentBrowser() 538 cv = self.currentViewer()
521 if cb is not None: 539 if cv:
522 cb.history().clear() 540 cv.clearHistory()
523 self.__mw.setForwardAvailable(cb.isForwardAvailable()) 541 self.__checkActionButtons()
524 self.__mw.setBackwardAvailable(cb.isBackwardAvailable()) 542
543 #######################################################################
544 ## Zoom related methods below
545 #######################################################################
546
547 @pyqtSlot()
548 def __zoomIn(self):
549 """
550 Private slot to zoom in.
551 """
552 cv = self.currentViewer()
553 if cv:
554 cv.scaleUp()
555
556 @pyqtSlot()
557 def __zoomOut(self):
558 """
559 Private slot to zoom out.
560 """
561 cv = self.currentViewer()
562 if cv:
563 cv.scaleDown()
564
565 @pyqtSlot()
566 def __zoomReset(self):
567 """
568 Private slot to reset the zoom level.
569 """
570 cv = self.currentViewer()
571 if cv:
572 cv.resetScale()

eric ide

mercurial