browser.py :  » Windows » Venster » venster-0.72 » venster » lib » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » Venster 
Venster » venster 0.72 » venster » lib » browser.py
from venster.windows import *
from venster.atl import *
from venster.ole import *
from venster import wtl
from venster.lib import dispatch

from ctypes import *

from ctypes.com import IUnknown,STDMETHOD,HRESULT,GUID,COMObject
from ctypes.com.ole import IOleInPlaceActiveObject,IOleInPlaceUIWindow
from ctypes.com.automation import IDispatch,VARIANT
from ctypes.com.connectionpoints import dispinterface_EventReceiver

class IDocHostUIHandler(IUnknown):
    _iid_ = GUID("{BD3F23C0-D43E-11CF-893B-00AA00BDCE1A}")

##CTYPES, maybe the following 2 ifaces should be in ctypes?
class IOleCommandTarget(IUnknown):
    _iid_ = GUID("{B722BCCB-4E68-101B-A2BC-00AA00404770}")

class IOleInPlaceFrame(IUnknown):
    _iid_ = GUID("{00000116-0000-0000-C000-000000000046}")

##CTYPES, change default behaviour for addreffing iface pointers on
##methods that are not implemented on python side so that __del__ does
IDocHostUIHandler._methods_ = IUnknown._methods_ + [
    STDMETHOD(HRESULT, "ShowContextMenu", DWORD, DWORD, DWORD, DWORD),
    STDMETHOD(HRESULT, "GetHostInfo", DWORD), #TODO wrap DOCHOSTUIINFO struct
    STDMETHOD(HRESULT, "ShowUI", DWORD, DWORD, DWORD, DWORD, DWORD),
    STDMETHOD(HRESULT, "HideUI"),
    STDMETHOD(HRESULT, "UpdateUI"),
    STDMETHOD(HRESULT, "EnableModeless", BOOL),
    STDMETHOD(HRESULT, "OnDocWindowActivate", BOOL),
    STDMETHOD(HRESULT, "OnFrameWindowActivate", BOOL),
    STDMETHOD(HRESULT, "ResizeBorder", DWORD, DWORD, BOOL),
    STDMETHOD(HRESULT, "TranslateAccelerator", POINTER(MSG), POINTER(GUID), DWORD),
    STDMETHOD(HRESULT, "GetOptionKeyPath", DWORD, DWORD),
    STDMETHOD(HRESULT, "GetDropTarget", DWORD, DWORD),
    STDMETHOD(HRESULT, "GetExternal", POINTER(POINTER(IDispatch))),
    STDMETHOD(HRESULT, "TranslateUrl", DWORD, DWORD, DWORD),
    STDMETHOD(HRESULT, "FilterDataObject", WORD, DWORD),
    ]

class ICustomDoc(IUnknown):
    _iid_ = GUID("{3050F3F0-98B5-11CF-BB82-00AA00BDCE0B}")

ICustomDoc._methods_ = IUnknown._methods_ + [
    STDMETHOD(HRESULT, "SetUIHandler", POINTER(IDocHostUIHandler))
    ]
    
from ie6_gen import DWebBrowserEvents2,IWebBrowser2

class Browser(AxWindow, dispinterface_EventReceiver):
    """Internet Explorer as ActiveX Control"""    
    _window_style_ = AxWindow._window_style_ | WS_HSCROLL | WS_VSCROLL

    _com_interfaces_ = [DWebBrowserEvents2]

    def __init__(self, url = "about:blank", *args, **kwargs):
        kwargs['ctrlId'] = url #if url is passed to axwindow, IE control is launched
        AxWindow.__init__(self, *args, **kwargs)
        dispinterface_EventReceiver.__init__(self)

        pUnk = self.GetControl() #IUnknown of IE
        pOle = POINTER(IOleInPlaceActiveObject)() #automation object
        pUnk.QueryInterface(byref(IOleInPlaceActiveObject._iid_), byref(pOle))        
        self.pOle = pOle

        self.pBrowser = POINTER(IWebBrowser2)() #the interface to IE
        pUnk.QueryInterface(byref(IWebBrowser2._iid_), byref(self.pBrowser))

        self.connectInfo = self.connect(pUnk) #receive callbacks from IE
            
        #makes accelerator keys work in IE:
        wtl.GetMessageLoop().AddFilter(self.PreTranslateMessage)

        
    
    def dispose(self):
        self.disconnect(self.connectInfo)
        wtl.GetMessageLoop().RemoveFilter(self.PreTranslateMessage)
        del self.pOle
        del self.pBrowser
        del self.connectInfo
        
    def Navigate(self, url):
         v = VARIANT()
         self.pBrowser.Navigate(url, byref(v), byref(v), byref(v), byref(v))

    #filter needed to make 'del' and other accel keys work
    #within IE control. @see http://www.microsoft.com/mind/0499/faq/faq0499.asp
    #insert into wtl ptl loop
    def PreTranslateMessage(self, msg):
        #here any keyboard message from the app passes:
        if msg.message >= WM_KEYFIRST and  msg.message <= WM_KEYLAST:
            #now we see if the control which sends these msgs is a child of
            #this axwindow (for instance input control embedded in html page)
            parent = msg.hWnd
            while parent:
                parent = GetParent(int(parent))
                if parent == self.handle:
                    #yes its a child of mine
                    if self.pOle.TranslateAccelerator(byref(msg)) == 0:
                        #translation has happened
                        return 1



www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.