eric7/WebBrowser/QtHelp/HelpTopicDialog.py

Thu, 30 Dec 2021 11:17:58 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 30 Dec 2021 11:17:58 +0100
branch
eric7
changeset 8881
54e42bc2437a
parent 8685
b0669ce1066d
permissions
-rw-r--r--

Updated copyright for 2022.

# -*- coding: utf-8 -*-

# Copyright (c) 2009 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing a dialog to select a help topic to display.
"""

from PyQt6.QtCore import Qt
from PyQt6.QtHelp import QHelpLink
from PyQt6.QtWidgets import QDialog, QListWidgetItem

from .Ui_HelpTopicDialog import Ui_HelpTopicDialog


class HelpTopicDialog(QDialog, Ui_HelpTopicDialog):
    """
    Class implementing a dialog to select a help topic to display.
    """
    def __init__(self, parent, helpKeyword, documents):
        """
        Constructor
        
        @param parent reference to the parent widget
        @type QWidget
        @param helpKeyword keyword for the link set
        @type str
        @param documents list of help document link data structures
        @type list of QHelpLink
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.label.setText(self.tr("Choose a &topic for <b>{0}</b>:")
                           .format(helpKeyword))
        
        for document in documents:
            itm = QListWidgetItem(document.title, self.topicsList)
            itm.setData(Qt.ItemDataRole.UserRole, document.url)
        if self.topicsList.count() > 0:
            self.topicsList.setCurrentRow(0)
        self.topicsList.setFocus()
        
        self.topicsList.itemActivated.connect(self.accept)
    
    def document(self):
        """
        Public method to retrieve the selected help topic.
        
        @return help document link for the selected help topic
        @rtype QHelpLink
        """
        document = QHelpLink()
        
        itm = self.topicsList.currentItem()
        if itm is not None:
            document.title = itm.text()
            document.url = itm.data(Qt.ItemDataRole.UserRole)
        
        return document

eric ide

mercurial