[python-win32] MSHTML wrapper class and example using IWebBrowser2

Gerdus van Zyl gerdusvanzyl at gmail.com
Mon Aug 3 16:54:04 CEST 2009


very nice! I was looking at pyjd a while back but didn't like the gtk
dependency. Any posibility on porting hulahop to windows?

~Gerdus

On Mon, Aug 3, 2009 at 12:22 AM, lkcl<lkcl at lkcl.net> wrote:
>
> hi there,
>
> from about a dozen different sources i've managed to put together something
> similar to the old ctypes atl.py example.  the purpose of the exercise is to
> create a port of pyjamas-desktop to MSHTML, and to do that, i need a GDK
> window in which an IWebBrowser2 COM object is the only object, and then to
> get access to its Document.
>
> i'll be committing the code as free software in the next few days to the svn
> repository for http://pyjs.org but i wanted to point people at this example
> code in the mean time:
> http://lkcl.net/pyjamas - ie_in_gtk.py and ie_in_win.py
>
> as you can see they're a bit of a mess because i took stuff from a boat-load
> of different places and just whopped it all together until something worked
> how i wanted.
>
> now that i have the proof-of-concept, i'll be quickly moving on to encompass
> absolutely every single bit of the MSHTML DOM model and i do mean absolutely
> all of it (and including XMLHttpRequest).  the reason is that
> pyjamas-desktop relies on manipulation of the DOM model to create the widget
> set API.  currently supported is XULRunner and pywebkitgtk but win32 users
> are left out in the cold somewhat so... MSHTML-time it is.
>
> what's particularly strategically important is that the intermediate DOM
> wrapper classes, of which there are two (pyjd/hula.py and
> pyjd/pywebkitgtk.py) make the DOM look *absolutely identical* as far as the
> interface is concerned.  i'll be adding an _mshtml.py wrapper which - again
> - makes the DOM look utterly and 100% identical to the other two.
>
> just to emphasise that in a different way: with these three DOM wrapper
> modules it will be possible to write python web browser engine applications
> that will work across a ton of different platforms, whether they be Win32,
> Mac, GNU/Linux, FreeBSD or embedded devices.
>
> the wrapper class, _mshtml.py, it's worth noting, will take care of COM
> "coclass" interfaces.  one of the lairy daft messes in MSHTML.IDL is the
> melding of different COM interfaces, and you're expected to either know or
> remember what to do, typecasting objects using QueryInterface to the right
> type, before accessing the required property or function.
>
> ... i can't be bothered with that kind of crap :)
>
> so, the _mshtml.py class will take care of it, and so instead of this:
>
>   style.left = 0
>   style2 = style.QueryInterface(MSHTML.IHTMLStyle2)
>   style2.position = "absolute"
>
> you just do this:
>
>   style.left = 0
>   style.position = "absolute"
>
> ahhhh, peace of miiind :)
>
> behind the scenes, there's a coclass wrapper which inherits from the
> necessary classes (in this case, _mshtml.IHTMLStyle2, _mshtml.IHTMLStyle3
> .... etc.) and each of those classes has properties:
>
>   def _get_position(self):
>        return wrap(self.__get_instance_IHTMLStyle3().position
>   position = property(self._get_position,....)
>
>   def __get_instance_IHTMLStyle3(self):
>      return self.__instance__.QueryInterface(MSHTML.IHTMLStyle3)
>
> etc. etc.
>
> so - not blazingly efficient, but that's the price to pay for convenience.
>
> if you're interested, keep an eye on http://pyjs.org svn repository,
> pyjamas/pyjd subdirectory, over the next few days.
>
> l.
> --
> View this message in context: http://www.nabble.com/MSHTML-wrapper-class-and-example-using-IWebBrowser2-tp24782740p24782740.html
> Sent from the Python - python-win32 mailing list archive at Nabble.com.
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>


More information about the python-win32 mailing list