Ejemplo n.º 1
0
class AboutDialog(Qt.QDialog):
    """
    Simple dialog to display typical About <application> dialog.
    It will create a Dialog with the title being
    *Dialog + <app name>* and a default text combining the application
    name and version, organization name and domain.

    This behaviour can be changed by setting the dialog window title
    (:meth:`~AboutDialog.setWindowTitle`) and content
    (:meth:`~AboutDialog.setText`, :meth:`~AboutDialog.setHtml`)

    Example usage::

        from taurus.external.qt import Qt
        from taurus.qt.qtgui.help import AboutDialog

        app = Qt.QApplication([])
        app.setApplicationName("Example GUI")
        app.setApplicationVersion("1.2.3")
        app.setOrganizationName("Taurus")
        app.setOrganizationDomain("http://www.taurus-scada.org/")
        about_dialog = AboutDialog()
        pixmap = Qt.QIcon.fromTheme("folder-open").pixmap(64, 64)
        about_dialog.setPixmap(pixmap)
        about_dialog.exec_()

    """

    _Template = "<html><body><p><b>{0}</b></p>" \
                "<p>{1}</p><p>{2}</p>" \
                "<p><a href=\"{3}\">{2}</a></p>" \
                "(c) Copyright {2}"

    def __init__(self, parent=None):
        Qt.QDialog.__init__(self, parent)
        self.loadUi()
        self.text_browser.setFrameStyle(Qt.QFrame.NoFrame)
        palette = Qt.QPalette()
        palette.setColor(Qt.QPalette.Base,
                         palette.color(Qt.QPalette.Background))
        self.text_browser.setPalette(palette)
        self.logo_widget.setAlignment(Qt.Qt.AlignHCenter | Qt.Qt.AlignTop)
        name = Qt.qApp.applicationName()
        version = Qt.qApp.applicationVersion()
        org = Qt.qApp.organizationName()
        org_domain = Qt.qApp.organizationDomain()
        self.setWindowTitle("About " + Qt.qApp.applicationName())
        self.setHtml(self._Template.format(name, version, org, org_domain))

    def setText(self, text):
        """
        Sets the dialog text.

        :param text: new text
        :type text: str
        """
        self.text_browser.setText(text)

    def getHtml(self):
        """
        Gets the current dialog HTML text.

        :return: the current dialog HTML text.
        :rtype: str
        """
        return self.text_browser.toHtml()

    @Qt.Slot(str)
    def setHtml(self, html):
        """
        Sets the dialog HTML text.

        :param text: new HTML text
        :type text: str
        """
        self.text_browser.setHtml(html)

    def resetHtml(self):
        """
        Resets the dialog HTML to an empty HTML document
        """
        self.setHtml("<html><body></body></html>")

    def getSource(self):
        """
        Gets the current dialog document source.

        :return: the current dialog document source.
        :rtype: Qt.QUrl
        """
        return self.text_browser.source()

    @Qt.Slot(Qt.QUrl)
    def setSource(self, source):
        """
        Sets the dialog document source.

        :param text: new document source
        :type text: Qt.QUrl
        """
        self.text_browser.setSource(source)

    @Qt.Slot(Qt.QPixmap)
    def setPixmap(self, pixmap):
        """
        Sets the dialog pixmap

        :param text: new pixmap
        :type text: Qt.QPixmap
        """
        self.logo_widget.setPixmap(pixmap)

    def getPixmap(self):
        """
        Gets the current pixmap.

        :return: the current dialog pixmap
        :rtype: Qt.QPixmap
        """
        pixmap = self.logo_widget.pixmap()
        if pixmap is None:
            pixmap = Qt.QPixmap()
        return pixmap

    def resetPixmap(self):
        """
        Resets the dialog pixmap to a Null pixmap.
        """
        self.setPixmap(Qt.QPixmap())

    @classmethod
    def getQtDesignerPluginInfo(cls):
        from taurus.qt.qtgui.resource import getThemeIcon
        return {
            'group': 'Taurus Help',
            'icon': getThemeIcon("help"),
            'module': 'taurus.qt.qtgui.help',
            'container': False
        }

    #: This property holds the current dialog pixmap
    #:
    #: **Access functions:**
    #:
    #:     * :meth:`~AboutDialog.getPixmap`
    #:     * :meth:`~AboutDialog.setPixmap`
    #:     * :meth:`~AboutDialog.resetPixmap`
    #:
    pixmap = Qt.Property("QPixmap", getPixmap, setPixmap, resetPixmap)

    #: This property holds the current dialog HTML
    #:
    #: **Access functions:**
    #:
    #:     * :meth:`~AboutDialog.getHtml`
    #:     * :meth:`~AboutDialog.setHtml`
    #:     * :meth:`~AboutDialog.resetHtml`
    #:
    html = Qt.Property("QString", getHtml, setHtml, resetHtml)

    #: This property holds the current dialog document source
    #:
    #: **Access functions:**
    #:
    #:     * :meth:`~AboutDialog.getSource`
    #:     * :meth:`~AboutDialog.setSource`
    #:
    source = Qt.Property("QUrl", getSource, setSource)
Ejemplo n.º 2
0
class HelpPanel(Qt.QWidget):
    """
    Simple widget to display application help system. Usage::

        from taurus.external.qt import Qt
        from taurus.qt.qtgui.help import HelpPanel

        app = Qt.QApplication([])
        help_panel = HelpPanel()

        help_panel.setCollectionFile("help_file.qhc")
        help_panel.show()
        app.exec_()
    """
    def __init__(self, collection_file=None, parent=None):
        Qt.QWidget.__init__(self, parent)
        layout = Qt.QVBoxLayout(self)
        self.setLayout(layout)
        self.__help_engine = None
        if collection_file:
            self.setCollectionFile(collection_file)

    def __clear(self):
        layout = self.layout()
        while layout.count():
            layout.takeAt(0)
        self.__help_engine = None

    @Qt.Slot(str)
    def setCollectionFile(self, collection_file):
        """
        Displays the help from the specified collection file

        :param collection_file: the collection file name (.qhc)
        :type collection_file: str
        """

        self.__clear()
        if not collection_file:
            return
        help_engine = QtHelp.QHelpEngine(collection_file, self)
        if not help_engine.setupData():
            raise Exception("Help engine not available")
        layout = self.layout()
        self.__tab = tab = Qt.QTabWidget()
        self.__help_engine = help_engine
        content_widget = help_engine.contentWidget()
        index_widget = help_engine.indexWidget()
        tab.addTab(content_widget, "Contents")
        tab.addTab(index_widget, "Index")
        self.__help_browser = _HelpBrowser(help_engine, self)
        splitter = Qt.QSplitter(Qt.Qt.Horizontal)
        splitter.insertWidget(0, tab)
        splitter.insertWidget(1, self.__help_browser)
        layout.addWidget(splitter)

    def getCollectionFile(self):
        """
        Returns the name of the current collection file or empty
        string if no collection file is active

        :return: the name of the current collection file
        :rtype: str
        """
        if self.__help_engine:
            return self.__help_engine.collectionFile()
        return ""

    def resetCollectionFile(self):
        """
        Resets the collection file
        """
        self.setCollectionFile("")

    #: This property holds the current collection file name
    #:
    #: **Access functions:**
    #:
    #:     * :meth:`HelpPanel.getCollectionFile`
    #:     * :meth:`HelpPanel.setCollectionFile`
    #:     * :meth:`HelpPanel.resetCollectionFile`
    #:
    collectionFile = Qt.Property("QString", getCollectionFile,
                                 setCollectionFile, resetCollectionFile)

    @classmethod
    def getQtDesignerPluginInfo(cls):
        return {
            'group': 'Taurus Help',
            'icon': Qt.QIcon.fromTheme("help"),
            'module': 'taurus.qt.qtgui.help',
            'container': False
        }