On Sun, 14 Jun 2009 16:02:16 +0200, Alejandro Serrano <[email protected]>
wrote:
> On Domingo 14 Junio 2009 15:46:35 Phil Thompson escribió:
>> On Sun, 14 Jun 2009 15:36:29 +0200, Alejandro Serrano
<[email protected]>
>>
>> wrote:
>> > On Domingo 14 Junio 2009 14:26:38 Phil Thompson escribió:
>> >> On Sun, 14 Jun 2009 12:05:26 +0200, Alejandro Serrano
>>
>> <[email protected]>
>>
>> >> wrote:
>> >> > ...
>> >>
>> >> It's true that earlier versions of PyQt registered a lot of C++ types
>> >> that
>> >> Qt didn't register automatically, but that was an implementation
>> >> detail
>> >> and
>> >> not documented behavior. As the registration is template based it has
>> >> to
>> >> be
>> >> done from C++.
>> >>
>> >> Phil
>> >
>> > I see... The problem that I'm facing is that I am creating the
>>
>> application
>>
>> > using plug-ins, and I need them to create different widgets in the
>> > QWebPage. I
>> > have thought about two solutions, and I would like to know whether
they
>>
>> are
>>
>> > possible:
>> > 1. Create some C++ or SIP function that would register a type passed
as
>> > argument somehow. That way I would only need one C++ library. Maybe
>> > just
>> > something that would wrap qRegisterMetaType...
>>
>> Not easy - it's a template.
>>
>> > 2. Make all plug-in derive from some common class and then register
the
>> > base
>> > class. If I do that, could I use the derived classes from QWebPage?
>>
>> I've no problem with including additional C++ classes that are then
>> wrapped
>> so that particular things can be done from Python - see the various QPy
>> classes in PyQt - but somebody will have to say exactly what's needed.
>>
>> Phil
> 
> Just for reference: I'm using this tutorial http://daniel-
> albuschat.blogspot.com/2008/12/embedding-qt-widgets-into-qtwebkit.html as

> reference

Like I said before anything that needs to register a meta-type is going to
be a problem. However, it's not needed for ordinary widgets as the attached
shows.

Phil
import sys

from PyQt4 import QtCore, QtGui, QtWebKit


HTML = """
<html>
   <head>
      <title>QtWebKit Plug-in Test</title>
   </head>
   <body>
      <object type="application/x-qt-plugin" classid="MyCalendarWidget" name="calendar" height=300 width=500></object>
      <script>
         calendar.setGridVisible(true);
         calendar.setCurrentPage(1985, 5);
      </script>
   </body>
</html>
"""


class MyWebView(QtWebKit.QWebView):

    def __init__(self, parent=None):

        super(MyWebView, self).__init__(parent)

        self._page = MyWebPage(self)
        self.setPage(self._page)


class MyWebPage(QtWebKit.QWebPage):

    def __init__(self, parent=None):

        super(MyWebPage, self).__init__(parent)

        self.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True)

    def createPlugin(self, classid, url, paramNames, paramValues):

        return MyCalendarWidget(self.view())


class MyCalendarWidget(QtGui.QCalendarWidget):

    def __init__(self, parent=None):

        super(MyCalendarWidget, self).__init__(parent)

        # Just to prove that this is being used.
        self.setFirstDayOfWeek(QtCore.Qt.Monday)


app = QtGui.QApplication(sys.argv)

viewer = MyWebView()
viewer.setHtml(HTML)
viewer.show()

app.exec_()
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to