Continued implementing the embedded help viewer widget. eric7

Thu, 07 Oct 2021 20:22:02 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 07 Oct 2021 20:22:02 +0200
branch
eric7
changeset 8679
fd172973428e
parent 8678
85a83e4e7f18
child 8680
85503ff2fce9

Continued implementing the embedded help viewer widget.

eric7.epj file | annotate | diff | comparison | revisions
eric7/HelpViewer/HelpViewerImpl.py file | annotate | diff | comparison | revisions
eric7/HelpViewer/HelpViewerImpl_qtb.py file | annotate | diff | comparison | revisions
eric7/HelpViewer/HelpViewerWidget.py file | annotate | diff | comparison | revisions
eric7/HelpViewer/OpenPagesWidget.py file | annotate | diff | comparison | revisions
--- a/eric7.epj	Wed Oct 06 20:00:29 2021 +0200
+++ b/eric7.epj	Thu Oct 07 20:22:02 2021 +0200
@@ -2281,7 +2281,10 @@
       "eric7/UI/FindLocationWidget.py",
       "eric7/JediInterface/RefactoringPreviewDialog.py",
       "eric7/HelpViewer/__init__.py",
-      "eric7/HelpViewer/HelpViewerWidget.py"
+      "eric7/HelpViewer/HelpViewerWidget.py",
+      "eric7/HelpViewer/OpenPagesWidget.py",
+      "eric7/HelpViewer/HelpViewerImpl.py",
+      "eric7/HelpViewer/HelpViewerImpl_qtb.py"
     ],
     "SPELLEXCLUDES": "Dictionaries/excludes.dic",
     "SPELLLANGUAGE": "en_US",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/HelpViewer/HelpViewerImpl.py	Thu Oct 07 20:22:02 2021 +0200
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the help viewer base class.
+"""
+
+from PyQt6.QtCore import QObject
+
+
+class HelpViewerImpl(QObject):
+    """
+    Class implementing the help viewer base class.
+    """
+    def __init__(self, parent=None):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super().__init__(parent)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/HelpViewer/HelpViewerImpl_qtb.py	Thu Oct 07 20:22:02 2021 +0200
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing the QTextBrowser based help viewer class.
+"""
+
+from PyQt6.QtWidgets import QTextBrowser
+
+from .HelpViewerImpl import HelpViewerImpl
+
+
+class HelpViewerImpl_qtb(QTextBrowser, HelpViewerImpl):
+    """
+    Class implementing the QTextBrowser based help viewer class.
+    """
+    def __init__(self, parent):
+        """
+        Constructor
+        
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super().__init__(parent)
+#        HelpViewerImpl.__init__(self)
--- a/eric7/HelpViewer/HelpViewerWidget.py	Wed Oct 06 20:00:29 2021 +0200
+++ b/eric7/HelpViewer/HelpViewerWidget.py	Thu Oct 07 20:22:02 2021 +0200
@@ -7,10 +7,17 @@
 Module implementing an embedded viewer for QtHelp and local HTML files.
 """
 
+from PyQt6.QtCore import pyqtSlot, QUrl
+from PyQt6.QtGui import QTextDocument
 from PyQt6.QtWidgets import (
-    QWidget, QVBoxLayout, QComboBox, QSizePolicy, QStackedWidget
+    QWidget, QHBoxLayout, QVBoxLayout, QComboBox, QSizePolicy, QStackedWidget,
+    QToolButton, QButtonGroup, QAbstractButton
 )
 
+import UI.PixmapCache
+
+from .OpenPagesWidget import OpenPagesWidget
+
 
 class HelpViewerWidget(QWidget):
     """
@@ -30,29 +37,90 @@
         self.__layout.setObjectName("MainLayout")
         self.__layout.setContentsMargins(0, 3, 0, 0)
         
+        ###################################################################
+        
+        self.__selectorLayout = QHBoxLayout()
+        
         self.__helpSelector = QComboBox(self)
         self.__helpSelector.setSizePolicy(
             QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
-        self.__layout.addWidget(self.__helpSelector)
+        self.__selectorLayout.addWidget(self.__helpSelector)
         self.__populateHelpSelector()
         
+        self.__openButton = QToolButton(self)
+        self.__openButton.setIcon(UI.PixmapCache.getIcon("open"))
+        self.__openButton.setToolTip(self.tr("Open a local file"))
+        self.__openButton.clicked.connect(self.__openFile)
+        self.__selectorLayout.addWidget(self.__openButton)
+        
+        self.__layout.addLayout(self.__selectorLayout)
+        
+        ###################################################################
+        
         self.__helpStack = QStackedWidget(self)
         self.__helpStack.setSizePolicy(
             QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)
         self.__layout.addWidget(self.__helpStack)
         
+        ###################################################################
+        
         self.__helpNavigationStack = QStackedWidget(self)
         self.__helpNavigationStack.setSizePolicy(
             QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Preferred)
+        self.__helpNavigationStack.setMaximumHeight(200)
         self.__layout.addWidget(self.__helpNavigationStack)
         self.__populateNavigationStack()
         
+        ###################################################################
+        
+        self.__buttonLayout = QHBoxLayout()
+        
+        self.__buttonGroup = QButtonGroup(self)
+        self.__buttonGroup.setExclusive(True)
+        self.__buttonGroup.buttonClicked.connect(
+            self.__selectNavigationWidget)
+        
+        self.__buttonLayout.addStretch()
+        
+        self.__openPagesButton = QToolButton(self)
+        self.__openPagesButton.setIcon(UI.PixmapCache.getIcon("fileMisc"))
+        self.__openPagesButton.setToolTip(self.tr("Show list of open pages"))
+        self.__openPagesButton.setCheckable(True)
+        self.__buttonGroup.addButton(self.__openPagesButton)
+        self.__buttonLayout.addWidget(self.__openPagesButton)
+        
+        self.__buttonLayout.addStretch()
+        
+        self.__layout.addLayout(self.__buttonLayout)
+        
+        ###################################################################
+        
         self.setLayout(self.__layout)
+        
+        self.__openPagesButton.setChecked(True)
+        
+        self.addPage()
     
     def __populateNavigationStack(self):
         """
         Private method to populate the stack of navigation widgets.
         """
+        self.__openPagesList = OpenPagesWidget(self.__helpStack, self)
+        self.__helpNavigationStack.addWidget(self.__openPagesList)
+        
+        # TODO: not yet implemented
+    
+    @pyqtSlot(QAbstractButton)
+    def __selectNavigationWidget(self, button):
+        """
+        Private slot to select the navigation widget.
+        
+        @param button reference to the clicked button
+        @type QAbstractButton
+        """
+        if button == self.__openPagesButton:
+            self.__helpNavigationStack.setCurrentWidget(self.__openPagesList)
+        
         # TODO: not yet implemented
     
     def __populateHelpSelector(self):
@@ -81,3 +149,29 @@
         
         if searchWord:
             self.searchQtHelp(searchWord)
+    
+    @pyqtSlot()
+    def __openFile(self):
+        """
+        Private slot to open a local help file (*.html).
+        """
+        # TODO: not yet implemented
+    
+    def addPage(self, url=QUrl("about:blank")):
+        """
+        Public method to add a new help page with the given URL.
+        
+        @param url requested URL (defaults to QUrl("about:blank"))
+        @type QUrl (optional)
+        """
+        try:
+            from .HelpViewerImpl_qwe import HelpViewerImpl_qwe
+            viewer = HelpViewerImpl_qwe(self)
+        except ImportError:
+            from .HelpViewerImpl_qtb import HelpViewerImpl_qtb
+            viewer = HelpViewerImpl_qtb(self)
+        
+        self.__helpStack.addWidget(viewer)
+        self.__openPagesList.addPage(viewer)
+        
+        viewer.setSource(url, QTextDocument.ResourceType.HtmlResource)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric7/HelpViewer/OpenPagesWidget.py	Thu Oct 07 20:22:02 2021 +0200
@@ -0,0 +1,87 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a widget showing the list of open pages.
+"""
+
+from PyQt6.QtCore import pyqtSlot
+from PyQt6.QtWidgets import (
+    QWidget, QLabel, QListWidget, QVBoxLayout, QAbstractItemView
+)
+
+
+class OpenPagesWidget(QWidget):
+    """
+    Class implementing a widget showing the list of open pages.
+    """
+    def __init__(self, stack, parent=None):
+        """
+        Constructor
+        
+        @param stack reference to the stack widget containing the open
+            help pages
+        @type QStackedWidget
+        @param parent reference to the parent widget (defaults to None)
+        @type QWidget (optional)
+        """
+        super().__init__(parent)
+        self.setObjectName("OpenPagesWidget")
+        
+        self.__layout = QVBoxLayout()
+        self.__layout.setContentsMargins(0, 0, 0, 0)
+        
+        self.__title = QLabel(self.tr("Open Pages"), self)
+        self.__layout.addWidget(self.__title)
+        
+        self.__openPagesList = QListWidget(self)
+        self.__openPagesList.setAlternatingRowColors(True)
+        self.__openPagesList.setSelectionMode(
+            QAbstractItemView.SelectionMode.ExtendedSelection)
+        self.__openPagesList.currentRowChanged.connect(
+            self.__currentRowChanged)
+        self.__layout.addWidget(self.__openPagesList)
+        
+        self.setLayout(self.__layout)
+        
+        self.__stack = stack
+        self.__stack.currentChanged.connect(self.__currentPageChanged)
+        
+        self.__defaultFont = self.__openPagesList.font()
+        self.__boldFont = self.__openPagesList.font()
+        self.__boldFont.setBold(True)
+    
+    @pyqtSlot(int)
+    def __currentPageChanged(self, index):
+        """
+        Private slot to handle a change of the shown page.
+        
+        @param index index of the current page
+        @type int
+        """
+        for row in range(self.__openPagesList.count()):
+            itm = self.__openPagesList.item(index)
+            itm.setFont(
+                self.__boldFont if row == index else self.__defaultFont
+            )
+    
+    @pyqtSlot(int)
+    def __currentRowChanged(self, row):
+        """
+        Private slot handling a change of the current row.
+        
+        @param row current row
+        @type int
+        """
+        self.__stack.setCurrentIndex(row)
+    
+    def addPage(self, viewer):
+        """
+        Public method to add a viewer page to our list.
+        
+        @param viewer DESCRIPTION
+        @type TYPE
+        """
+        # TODO: not yet implemented

eric ide

mercurial