Helpviewer/HelpTopicDialog.py

Sun, 05 May 2013 18:21:40 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 05 May 2013 18:21:40 +0200
branch
5_3_x
changeset 2644
764c317915bc
parent 2302
f29e9405c851
child 2525
8b507a9a2d40
child 3034
7ce719013078
child 3163
9f50365a0870
permissions
-rw-r--r--

Prepared release 5.3.3.

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

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

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

from PyQt4.QtGui import QDialog
from PyQt4.QtCore import QUrl

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, keyword, links):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        @param keyword keyword for the link set (string)
        @param links dictionary with help topic as key (string) and
            URL as value (QUrl)
        """
        super().__init__(parent)
        self.setupUi(self)
        
        self.label.setText(self.trUtf8("Choose a &topic for <b>{0}</b>:")\
            .format(keyword))
        
        self.__links = links
        for topic in sorted(self.__links):
            self.topicsList.addItem(topic)
        if self.topicsList.count() > 0:
            self.topicsList.setCurrentRow(0)
        self.topicsList.setFocus()
        
        self.topicsList.itemActivated.connect(self.accept)
    
    def link(self):
        """
        Public method to the link of the selected topic.
        
        @return URL of the selected topic (QUrl)
        """
        itm = self.topicsList.currentItem()
        if itm is None:
            return QUrl()
        
        topic = itm.text()
        if topic == "" or topic not in self.__links:
            return QUrl()
        
        return self.__links[topic]

eric ide

mercurial