示例#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))
    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)
示例#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)
示例#4
0
文件: mshtml.py 项目: simbha/pyjamas
    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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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)
示例#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()
示例#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()
示例#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()
示例#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()
示例#16
0
文件: mshtml.py 项目: chopin/pyjs
    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=[]
示例#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)
示例#18
0
文件: mshtmlevents.py 项目: Afey/pyjs
 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
示例#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
示例#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)
示例#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)
示例#22
0
 def test_MixedInOut(self):
     p = wrap(self.create())
     self.assertEqual(p.MixedInOut(1, 2), (2, 3))
示例#23
0
 def test_MultiInOutArgs4(self):
     p = wrap(self.create())
     res = p.MultiInOutArgs4(pb=32)
示例#24
0
 def test_MultiInOutArgs3(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs3(), (42, 43))
示例#25
0
 def test_MultiInOutArgs3(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs3(), (42, 43))
示例#26
0
 def test_MixedInOut(self):
     p = wrap(self.create())
     self.assertEqual(p.MixedInOut(1, 2), (2, 3))
示例#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)
示例#28
0
 def test_MultiInOutArgs(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs(1, 2), (3, 8))
示例#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)
示例#30
0
 def test_MultiInOutArgs(self):
     p = wrap(self.create())
     self.assertEqual(p.MultiInOutArgs(1, 2), (3, 8))
示例#31
0
 def test_MultiInOutArgs4(self):
     p = wrap(self.create())
     res = p.MultiInOutArgs4(pb=32)