eric7/HelpViewer/OpenPagesWidget.py

branch
eric7
changeset 8679
fd172973428e
child 8680
85503ff2fce9
--- /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