Hi everybody,

I am facing an issue when I use the PyQt.QtHelp module. I have generated
a .qhc file containing the documentation I want to embed into my soft so
users can access it directly. It is made up with .html pages.

I have joined the code in attachment. I simplified it so it can be used
in a "stand-alone" software, but it is in fact part of a bigger program.
My problem is the same in both cases anyway.

(This code is more or less the same as in the QtHelp example from Qt :
http://doc.trolltech.com/qq/qq28-qthelp.html and
http://doc.trolltech.com/qq/qq28-qthelp.zip for the example code).

When I launch my soft, and click on one of the link of the table of
content, the error message "QFSFileEngine::open: No file name specified"
is displayed, and consequently the documentation is not displayed. The
HelpBrowser.loadResources() method is called by HelpBrowser.setSource()
when a link of the table of content is double-clicked.

I have made some tests : when I connect the "linkActivated" signal to a
method calling QHelpEngine.fileData(url), and then set the returned html
into the HelpBrowser (using setHtml() method), it displays the requested
resource, but CSS and images are not loaded. The QVariant returned by
the QHelpEngine.fileData(url) method contents correct html.

The "C++ version" of this code works perfectly and I can visualize the
documentation within the software.

Do you have any idea why when the setSource() slot is called this error
occurs ? Is my code incorrect ? I could overload the setSource method
and "manually" call loadResources() for each resources contained in the
displayed html page (such as .css files and images), but if there is an
other way it would be fine.

The installed version of PyQt is the 4.6-1 and I am running an Ubuntu
9.10 karmic koala. My version of Python is 2.6.4. The error I encounter
also appears on Gentoo.

I hope these explanations are not too vague. Thanks you in advance for
any help you could provide :)

    Regards,

--
Romain BERTHOLON
r...@arxsys.fr
http://www.arxsys.fr - http://www.digital-forensic.org/



import sys

from PyQt4.QtGui import QApplication, QDockWidget, QTextBrowser, QSplitter, QTextDocument, QMainWindow
from PyQt4.QtCore import Qt, SIGNAL, QUrl, QVariant
from PyQt4.QtHelp import QHelpEngine

class Help(QMainWindow):
    def __init__(self, mainWindow):
        QMainWindow.__init__(self)

        # create help window
        helpwindow = QDockWidget(self)
        helpwindow.setFloating(False)
        helpwindow.setFeatures(QDockWidget.NoDockWidgetFeatures)

        # create QSplitter
        self.__mainWidget = QSplitter(Qt.Horizontal)

        # create helper and set it up
        self.__helper = QHelpEngine("/path/to/help.qhc", self)
        self.__helper.setupData()

        # Get the content widget and instanciate HelpBrowser (defined below).
        # The __helper.contentWidget() displays the table of content of the help
        self.__content = self.__helper.contentWidget()
        self.__helpBrowser = HelpBrowser(self.__mainWidget, self.__helper)

        # build widget
        self.__mainWidget.insertWidget(0, self.__content)
        self.__mainWidget.insertWidget(1, self.__helpBrowser)
        self.__mainWidget.setStretchFactor(1, 1)
        helpwindow.setWidget(self.__mainWidget)
        self.addDockWidget(Qt.TopDockWidgetArea, helpwindow)

        # connect the TOC to the help browser.
        self.connect(self.__helper.contentWidget(),
                     SIGNAL("linkActivated(const QUrl &)"),
                     self.__helpBrowser.setSource)

class   HelpBrowser(QTextBrowser):
        def __init__(self, parent, help_engine):
           QTextBrowser.__init__(self)
           self.__helpEngine = help_engine

        # call QHelpEngine.fileData() for 'qthelp' resources and use the
        # default implementation for all others url. 'url' param is a QUrl.
        def loadResources(self, type, url):
            if url.scheme() == "qthelp":   
                return QVariant(self.__helpEngine.fileData(url))
            return QTextBrowser.loadResources(type, url)
 
if __name__ == '__main__':
    a = QApplication(sys.argv)
    help = Help(QMainWindow)
    help.show()
    sys.exit(a.exec_())



_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to