Exemplo n.º 1
0
    def expose(self, widget=None, data=None):
        if self.expose_offset == True:
            return
        else:
            self.expose_offset = True
            
        # Make the container accept the focus and pass it to the control;
        # this makes the Tab key pass focus to IE correctly.
        self.set_property('can-focus', True)
        self.connect('focus', self.on_container_focus)

        # Resize the AtlAxWin window with its container.
        self.connect('size-allocate', self.on_container_size)

        # Create an instance of IE via AtlAxWin. 
        atl.AtlAxWinInit()
        hInstance = kernel32.GetModuleHandleA(None)
        parentHwnd = self.window.handle
        self.atlAxWinHwnd = user32.CreateWindowExA(0, 'AtlAxWin', 'about:',
            win32con.WS_VISIBLE | win32con.WS_CHILD | win32con.WS_HSCROLL |
            win32con.WS_VSCROLL, 0, 0, 100, 100, parentHwnd, None, hInstance, 0) 

        # Get the IWebBrowser2 interface for the IE control.
        pBrowserUnk = POINTER(IUnknown)()
        atl.AtlAxGetControl(self.atlAxWinHwnd, byref(pBrowserUnk))

        # the wrap call queries for the default interface
        self.browser = wrap(pBrowserUnk)

        # Create a Gtk window that refers to the native AtlAxWin window.
        self.gtkAtlAxWin = gtk.gdk.window_foreign_new(long(self.atlAxWinHwnd))
Exemplo n.º 2
0
    def init_ie(self):
        # Create a DrawingArea to host IE and add it to the hbox.
        self.container = gtk.DrawingArea()
        self.main_vbox.add(self.container)
        self.container.show()
        
        # Make the container accept the focus and pass it to the control;
        # this makes the Tab key pass focus to IE correctly.
        self.container.set_property("can-focus", True)
        self.container.connect("focus", self.on_container_focus)
        
        # Resize the AtlAxWin window with its container.
        self.container.connect("size-allocate", self.on_container_size)
        
        # Create an instance of IE via AtlAxWin.
        atl.AtlAxWinInit()
        hInstance = kernel32.GetModuleHandleA(None)
        parentHwnd = self.container.window.handle
        self.atlAxWinHwnd = user32.CreateWindowExA(0, "AtlAxWin", self.home_url,
                            win32con.WS_VISIBLE | win32con.WS_CHILD |
                            win32con.WS_HSCROLL | win32con.WS_VSCROLL,
                            0, 0, 100, 100, parentHwnd, None, hInstance, 0)
        
        # Get the IWebBrowser2 interface for the IE control.
        pBrowserUnk = POINTER(IUnknown)()
        atl.AtlAxGetControl(self.atlAxWinHwnd, byref(pBrowserUnk))
        # the wrap call querys for the default interface
        self.browser = wrap(pBrowserUnk)
        
        # Create a Gtk window that refers to the native AtlAxWin window.
        self.gtkAtlAxWin = gtk.gdk.window_foreign_new(long(self.atlAxWinHwnd))

        # By default, clicking a GTK widget doesn't grab the focus away from
        # a native Win32 control.
        self.address.connect("button-press-event", self.on_widget_click)
Exemplo n.º 3
0
    def test_events(self):
        p = wrap(self.create())

        class Handler(object):
            called = 0

            def OnSomething(self, this):
                "Handles the OnSomething event"
                self.called += 1

        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomething()
        self.assertEqual(handler.called, 1)

        class Handler(object):
            called = 0

            def IMyEventInterface_OnSomething(self):
                "Handles the OnSomething event"
                self.called += 1

        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomething()
        self.assertEqual(handler.called, 1)
Exemplo n.º 4
0
    def load_app(self):

        uri = self.application
        if uri.find(":") == -1:
            # assume file
            uri = 'file://'+os.path.abspath(uri)

        #print "load_app", uri

        self.application = uri
        v = byref(VARIANT())
        self.pBrowser.Navigate(uri, v, v, v, v)

        # Show Window
        cw = c_int(self.hwnd)
        ShowWindow(cw, c_int(SW_SHOW))
        UpdateWindow(cw)


        # http://msdn.microsoft.com/en-us/library/aa752126%28VS.85%29.aspx
        wba = self.pBrowser.QueryInterface(IServiceProvider)
        wn = wrap(wba.QueryService(SID_SShellBrowser, IOleWindow))

        hwnd = c_void_p(0)
        pHnd = byref(hwnd)
        wn.GetWindow(pHnd)

        #PostMessage(pHnd.value, WM_SETFOCUS,0,0)
        SetFocus(hwnd)
Exemplo n.º 5
0
    def test_DoSomethingElse(self):
        p = wrap(self.create())

        class Handler(object):
            called = 0

            def OnSomethingElse(self):
                "Handles the OnSomething event"
                self.called += 1
                return 42

        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomethingElse()
        self.assertEqual(handler.called, 1)

        class Handler(object):
            called = 0

            def OnSomethingElse(self, this, presult):
                "Handles the OnSomething event"
                self.called += 1
                presult[0] = 42

        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomethingElse()
        self.assertEqual(handler.called, 1)
Exemplo n.º 6
0
    def _create_atlax_window(self):
        _atl.AtlAxWinInit()
        hInstance = win32api.GetModuleHandle(None)

        if self.fullscreen:
            atl_width = self.width
            atl_height = self.height
        elif not self.resizable:
            atl_width = self.width - NON_RESIZEABLE_OFFSET
            atl_height = self.height - self.scrollbar_height - NON_RESIZEABLE_OFFSET * 2
        else:
            atl_width = self.width - self.scrollbar_width
            atl_height = self.height - self.scrollbar_height - VERTICAL_SCROLLBAR_OFFSET

        self.atlhwnd = win32gui.CreateWindow(
            "AtlAxWin", "about:blank",
            win32con.WS_CHILD | win32con.WS_HSCROLL | win32con.WS_VSCROLL, 0,
            0, atl_width, atl_height, self.hwnd, None, hInstance, None)

        # COM voodoo
        pBrowserUnk = POINTER(IUnknown)()
        _atl.AtlAxGetControl(self.atlhwnd, byref(pBrowserUnk))
        self.browser = wrap(pBrowserUnk)
        self.browser.RegisterAsBrowser = True
        self.browser.AddRef()
        self.conn = GetEvents(self.browser, sink=self)
Exemplo n.º 7
0
    def __init__(self, application, appdir):
        EventSink.__init__(self)
        self.platform = 'mshtml'
        self.application = application
        self.appdir = appdir
        self.already_initialised = False
        self.workaround_ignore_first_doc_complete = False
        self.window_handler = None
        self.node_handlers = {}

        # Create an instance of IE via AtlAxWin.
        atl.AtlAxWinInit()
        hInstance = GetModuleHandle(None)

        self.hwnd = CreateWindowEx(
            0, "AtlAxWin", "about:blank",
            WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL,
            CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL,
            NULL, hInstance, NULL)

        # Get the IWebBrowser2 interface for the IE control.
        self.pBrowserUnk = POINTER(IUnknown)()
        atl.AtlAxGetControl(self.hwnd, byref(self.pBrowserUnk))
        # the wrap call querys for the default interface
        self.pBrowser = wrap(self.pBrowserUnk)
        self.pBrowser.RegisterAsBrowser = True
        self.pBrowser.AddRef()

        self.conn = mshtmlevents.GetEvents(
            self.pBrowser, sink=self, interface=SHDocVw.DWebBrowserEvents2)
Exemplo n.º 8
0
    def load_app(self):

        uri = self.application
        if uri.find(":") == -1:
            # assume file
            uri = 'file://' + os.path.abspath(uri)

        #print "load_app", uri

        self.application = uri
        v = byref(VARIANT())
        self.pBrowser.Navigate(uri, v, v, v, v)

        # Show Window
        cw = c_int(self.hwnd)
        ShowWindow(cw, c_int(SW_SHOW))
        UpdateWindow(cw)

        # http://msdn.microsoft.com/en-us/library/aa752126%28VS.85%29.aspx
        wba = self.pBrowser.QueryInterface(IServiceProvider)
        wn = wrap(wba.QueryService(SID_SShellBrowser, IOleWindow))

        hwnd = c_void_p(0)
        pHnd = byref(hwnd)
        wn.GetWindow(pHnd)

        #PostMessage(pHnd.value, WM_SETFOCUS,0,0)
        SetFocus(hwnd)
Exemplo n.º 9
0
    def _create_atlax_window(self):
        _atl.AtlAxWinInit()
        hInstance = win32api.GetModuleHandle(None)

        if self.fullscreen:
            atl_width = self.width
            atl_height = self.height
        elif not self.resizable:
            atl_width = self.width - NON_RESIZEABLE_OFFSET
            atl_height = self.height - self.scrollbar_height - NON_RESIZEABLE_OFFSET * 2
        else:
            atl_width = self.width - self.scrollbar_width
            atl_height = self.height - self.scrollbar_height - VERTICAL_SCROLLBAR_OFFSET

        self.atlhwnd = win32gui.CreateWindow("AtlAxWin", self.url,
                                      win32con.WS_CHILD | win32con.WS_HSCROLL | win32con.WS_VSCROLL,
                                      0, 0, atl_width, atl_height, self.hwnd, None, hInstance, None)

        # COM voodoo
        pBrowserUnk = POINTER(IUnknown)()
        _atl.AtlAxGetControl(self.atlhwnd, byref(pBrowserUnk))
        self.browser = wrap(pBrowserUnk)
        self.browser.RegisterAsBrowser = True
        self.browser.AddRef()
        self.conn = GetEvents(self.browser, sink=self)
Exemplo n.º 10
0
    def test_GetStackTrace(self):
        p = wrap(self.create())
        from ctypes import c_int, POINTER, pointer
        frames = (c_int * 5)()
        res = p.GetStackTrace(42, frames, 5)
##        print "RES_1", res

        frames = pointer(c_int(5))
        res = p.GetStackTrace(42, frames, 0)
Exemplo n.º 11
0
    def test_GetStackTrace(self):
        p = wrap(self.create())
        from ctypes import c_int, POINTER, pointer
        frames = (c_int * 5)()
        res = p.GetStackTrace(42, frames, 5)
        ##        print "RES_1", res

        frames = pointer(c_int(5))
        res = p.GetStackTrace(42, frames, 0)
Exemplo n.º 12
0
    def __init__(self, *args, **kwargs):
        atl.AxWindow.__init__(self, "ShockwaveFlash.ShockwaveFlash", *args, **kwargs)

        pUnk = self.GetControl()
        #get the Flash interface of the control
        pFlash = wrap(pUnk) # XXX replace 'wrap' with 'GetBestInterface'

        #receive events
        self.flashEvents = GetEvents(pFlash, self)

        #start the flash movie
        import os
        pFlash.LoadMovie(0, os.getcwd() + os.sep + "cow.swf")
        pFlash.Play()
Exemplo n.º 13
0
    def create_atlax_window(self):
        _atl.AtlAxWinInit()
        hInstance = win32api.GetModuleHandle(None)
        self.atlhwnd = win32gui.CreateWindowEx(
            0, "AtlAxWin", self.url,
            win32con.WS_CHILD | win32con.WS_HSCROLL | win32con.WS_VSCROLL, 0,
            0, self.width, self.height, self.hwnd, None, hInstance, None)

        # COM voodoo
        pBrowserUnk = POINTER(IUnknown)()
        _atl.AtlAxGetControl(self.atlhwnd, byref(pBrowserUnk))
        self.browser = wrap(pBrowserUnk)
        self.browser.RegisterAsBrowser = True
        self.browser.AddRef()
Exemplo n.º 14
0
    def _create_atlax_window(self):
        _atl.AtlAxWinInit()
        hInstance = win32api.GetModuleHandle(None)
        self.atlhwnd = win32gui.CreateWindow("AtlAxWin", self.url,
                                      win32con.WS_CHILD | win32con.WS_HSCROLL | win32con.WS_VSCROLL,
                                      0, 0, self.width, self.height,
                                      self.hwnd, None, hInstance, None)

        # COM voodoo
        pBrowserUnk = POINTER(IUnknown)()
        _atl.AtlAxGetControl(self.atlhwnd, byref(pBrowserUnk))
        self.browser = wrap(pBrowserUnk)
        self.browser.RegisterAsBrowser = True
        self.browser.AddRef()
Exemplo n.º 15
0
    def __init__(self, *args, **kwargs):
        atl.AxWindow.__init__(self, "ShockwaveFlash.ShockwaveFlash", *args,
                              **kwargs)

        pUnk = self.GetControl()
        #get the Flash interface of the control
        pFlash = wrap(pUnk)  # XXX replace 'wrap' with 'GetBestInterface'

        #receive events
        self.flashEvents = GetEvents(pFlash, self)

        #start the flash movie
        import os
        pFlash.LoadMovie(0, os.getcwd() + os.sep + "cow.swf")
        pFlash.Play()
Exemplo n.º 16
0
    def __init__(self, application, appdir, x=CW_USEDEFAULT, y=CW_USEDEFAULT, width=CW_USEDEFAULT, height=CW_USEDEFAULT):
        EventSink.__init__(self)
        self.platform = 'mshtml'
        self.application = application
        self.appdir = appdir
        self.already_initialised = False
        self.workaround_ignore_first_doc_complete = False
        self.window_handler = None
        self.node_handlers = {}

        # Create an instance of IE via AtlAxWin.
        atl.AtlAxWinInit()
        hInstance = GetModuleHandle(None)

        self.hwnd = CreateWindowEx(0,
                              "AtlAxWin",
                              "about:blank",
                              WS_OVERLAPPEDWINDOW |
                              WS_VISIBLE |
                              WS_HSCROLL | WS_VSCROLL,
                              x,          #CW_USEDEFAULT,
                              y,          #CW_USEDEFAULT,
                              width,    #CW_USEDEFAULT,
                              height,   #CW_USEDEFAULT,
                              NULL,
                              NULL,
                              hInstance,
                              NULL)

        # Get the IWebBrowser2 interface for the IE control.
        self.pBrowserUnk = POINTER(IUnknown)()
        atl.AtlAxGetControl(self.hwnd, byref(self.pBrowserUnk))
        # the wrap call querys for the default interface
        self.pBrowser = wrap(self.pBrowserUnk)
        self.pBrowser.RegisterAsBrowser = True
        self.pBrowser.AddRef()

        print dir(SHDocVw)
        print SHDocVw.IWebBrowser
        print SHDocVw.IWebBrowser2

        print dir(MSHTML)

        self.conn = mshtmlevents.GetEvents(self.pBrowser, sink=self,
                        interface=SHDocVw.DWebBrowserEvents2)

        #print "browser HWND", SetFocus(self.pBrowser.HWND)
        self.closeHandlers=[]
Exemplo n.º 17
0
    def test_events(self):
        p = wrap(self.create())
        class Handler(object):
            called = 0
            def OnSomething(self, this):
                "Handles the OnSomething event"
                self.called += 1
        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomething()
        self.assertEqual(handler.called, 1)

        class Handler(object):
            called = 0
            def IMyEventInterface_OnSomething(self):
                "Handles the OnSomething event"
                self.called += 1
        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomething()
        self.assertEqual(handler.called, 1)
Exemplo n.º 18
0
 def IDispatch_Invoke(self, this, memid, riid, lcid, wFlags, pDispParams,
                      pVarResult, pExcepInfo, puArgErr):
     #print "IDispatch_Invoke", memid, this, riid, lcid, pDispParams
     mth = self.dispmap.get(memid, None)
     if mth is None:
         return S_OK
     dp = pDispParams[0]
     #print "num args", dp.cArgs
     # DISPPARAMS contains the arguments in reverse order
     args = [dp.rgvarg[i].value for i in range(dp.cArgs)]
     #print "Event", self, memid, mth, args
     event = None
     if len(args) > 0:
         event = wrap(args[0])
     try:
         result = mth(self.sender, event, None)
     except:
         sys.stderr.write( traceback.print_exc() )
         sys.stderr.flush()
     if pVarResult:
         pVarResult[0].value = result
     return S_OK
Exemplo n.º 19
0
 def IDispatch_Invoke(self, this, memid, riid, lcid, wFlags, pDispParams,
                      pVarResult, pExcepInfo, puArgErr):
     #print "IDispatch_Invoke", memid, this, riid, lcid, pDispParams
     mth = self.dispmap.get(memid, None)
     if mth is None:
         return S_OK
     dp = pDispParams[0]
     #print "num args", dp.cArgs
     # DISPPARAMS contains the arguments in reverse order
     args = [dp.rgvarg[i].value for i in range(dp.cArgs)]
     #print "Event", self, memid, mth, args
     event = None
     if len(args) > 0:
         event = wrap(args[0])
     try:
         result = mth(self.sender, event, None)
     except:
         sys.stderr.write(traceback.print_exc())
         sys.stderr.flush()
     if pVarResult:
         pVarResult[0].value = result
     return S_OK
Exemplo n.º 20
0
    def test_DoSomethingElse(self):
        p = wrap(self.create())
        class Handler(object):
            called = 0
            def OnSomethingElse(self):
                "Handles the OnSomething event"
                self.called += 1
                return 42
        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomethingElse()
        self.assertEqual(handler.called, 1)

        class Handler(object):
            called = 0
            def OnSomethingElse(self, this, presult):
                "Handles the OnSomething event"
                self.called += 1
                presult[0] = 42
        handler = Handler()
        ev = comtypes.client.GetEvents(p, handler)
        p.DoSomethingElse()
        self.assertEqual(handler.called, 1)
Exemplo n.º 21
0
 def test_Name(self):
     p = wrap(self.create())
     self.assertEqual((p.Name, p.name, p.nAME), ("foo", ) * 3)
     p.NAME = "spam"
     self.assertEqual((p.Name, p.name, p.nAME), ("spam", ) * 3)
Exemplo n.º 22
0
 def test_MixedInOut(self):
     p = wrap(self.create())
     self.assertEqual(p.MixedInOut(1, 2), (2, 3))
Exemplo n.º 23
0
 def test_MultiInOutArgs4(self):
     p = wrap(self.create())
     res = p.MultiInOutArgs4(pb=32)
Exemplo n.º 24
0
 def test_MultiInOutArgs3(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs3(), (42, 43))
Exemplo n.º 25
0
 def test_MultiInOutArgs3(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs3(), (42, 43))
Exemplo n.º 26
0
 def test_MixedInOut(self):
     p = wrap(self.create())
     self.assertEqual(p.MixedInOut(1, 2), (2, 3))
Exemplo n.º 27
0
 def test_Name(self):
     p = wrap(self.create())
     self.assertEqual((p.Name, p.name, p.nAME), ("foo",) * 3)
     p.NAME = "spam"
     self.assertEqual((p.Name, p.name, p.nAME), ("spam",) * 3)
Exemplo n.º 28
0
 def test_MultiInOutArgs(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs(1, 2), (3, 8))
Exemplo n.º 29
0
    def __init__(self):
        # Create the main GTK window.
        self.main = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.main.set_title("Poor man's browser [TM]")
        self.main.connect("destroy", gtk.main_quit)
        self.main.set_size_request(750, 550)
        self.main.realize()
        
        # Create a VBox to house the address bar and the IE control.
        self.mainVBox = gtk.VBox()
        self.main.add(self.mainVBox)
        self.mainVBox.show()
        
        # Create the address bar.
        self.addressEntry = gtk.Entry()
        self.addressEntry.show()
        self.addressEntry.connect("key-press-event", self.on_addressEntry_key)
        self.addressLabel = gtk.Label()
        self.addressLabel.set_text_with_mnemonic("_Address: ")
        self.addressLabel.set_mnemonic_widget(self.addressEntry)
        self.addressLabel.show()
        self.goButton = gtk.Button("  Go  ")
        self.goButton.show()
        self.goButton.connect("clicked", self.on_goButton_clicked)
        self.addressHbox = gtk.HBox()
        self.addressHbox.show()
        self.addressHbox.add(self.addressLabel)
        self.addressHbox.add(self.addressEntry)
        self.addressHbox.add(self.goButton)
        self.addressHbox.set_child_packing(self.addressLabel,
                                           False, True, 2, gtk.PACK_START)
        self.addressHbox.set_child_packing(self.goButton,
                                           False, True, 0, gtk.PACK_END)
        self.mainVBox.add(self.addressHbox)
        self.mainVBox.set_child_packing(self.addressHbox,
                                        False, True, 0, gtk.PACK_START)
        
        # Create a DrawingArea to host IE and add it to the hbox.
        self.container = gtk.DrawingArea()
        self.mainVBox.add(self.container)
        self.container.show()
        
        # Make the container accept the focus and pass it to the control;
        # this makes the Tab key pass focus to IE correctly.
        self.container.set_property("can-focus", True)
        self.container.connect("focus", self.on_container_focus)
        
        # Resize the AtlAxWin window with its container.
        self.container.connect("size-allocate", self.on_container_size)
        
        # Create an instance of IE via AtlAxWin.
        atl.AtlAxWinInit()
        hInstance = kernel32.GetModuleHandleA(None)
        parentHwnd = self.container.window.handle
        self.atlAxWinHwnd = \
            user32.CreateWindowExA(0, "AtlAxWin", "http://www.pygtk.org",
                            win32con.WS_VISIBLE | win32con.WS_CHILD |
                            win32con.WS_HSCROLL | win32con.WS_VSCROLL,
                            0, 0, 100, 100, parentHwnd, None, hInstance, 0)
        
        # Get the IWebBrowser2 interface for the IE control.
        pBrowserUnk = POINTER(IUnknown)()
        atl.AtlAxGetControl(self.atlAxWinHwnd, byref(pBrowserUnk))
        # the wrap call querys for the default interface
        self.pBrowser = wrap(pBrowserUnk)
        
        # Create a Gtk window that refers to the native AtlAxWin window.
        self.gtkAtlAxWin = gtk.gdk.window_foreign_new(long(self.atlAxWinHwnd))

        # By default, clicking a GTK widget doesn't grab the focus away from
        # a native Win32 control.
        self.addressEntry.connect("button-press-event", self.on_widget_click)
Exemplo n.º 30
0
 def test_MultiInOutArgs(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs(1, 2), (3, 8))
Exemplo n.º 31
0
 def test_MultiInOutArgs4(self):
     p = wrap(self.create())
     res = p.MultiInOutArgs4(pb=32)