[python-win32] Webbrowser control and Tab Navigation

Christof Ecker christof.ecker at googlemail.com
Mon Jun 9 12:02:19 CEST 2008


Hi all,

I am using the webbrowser control (internet explorer) as display
component in a project. Unfortunately the Tab and Enter keys do not
work, i.e. it is impossible to switch between input fields of the
displayed html-page and it is impossible to enter a newline in an
input field.

The shortened listing is below.

Can anyone help?

Christof


# file htmlwidget.py
import wx

from wx.lib.activexwrapper import MakeActiveXClass
import win32com.client.gencache
browserModule = win32com.client.gencache.EnsureModule(
    "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 1, 1)


# Flags to be used with the RefreshPage method
REFRESH_NORMAL = 0
REFRESH_IFEXPIRED = 1
REFRESH_CONTINUE = 2
REFRESH_COMPLETELY = 3


# Flags to be used with LoadUrl, Navigate, Navigate2 methods
NAV_OpenInNewWindow = 0x1
NAV_NoHistory = 0x2
NAV_NoReadFromCache = 0x4
NAV_NoWriteToCache = 0x8
NAV_AllowAutosearch = 0x10
NAV_BrowserBar = 0x20
NAV_Hyperlink = 0x40


class HtmlView(wx.Panel):
    url = None

    _needs_update = False
    def __init__(self, parent):
        wx.Panel.__init__(
            self, parent, -1,
            style=wx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON_RESIZE
            )
        ##
        # Make a new class that derives from the WebBrowser class in the
        # COM module imported above.  This class also derives from wxWindow and
        # implements the machinery needed to integrate the two worlds.
        theClass = MakeActiveXClass(browserModule.WebBrowser, eventObj=self)

        # Create an instance of that class
        self.ie = theClass(self, -1)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.ie, 1, wx.EXPAND)
        self.SetSizer(sizer)
        self.ie.offline = False


    def SetChanged(self):
        self._needs_update = True
        if self.IsShownOnScreen():
            wx.CallAfter(self.update)

    def Navigate2(self, url):
        self.ie.Navigate2(url,
Flags=NAV_NoReadFromCache|NAV_NoWriteToCache|NAV_NoHistory)


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = wx.Frame(None, -1)
    sizer = wx.BoxSizer(wx.VERTICAL)
    win1 = HtmlView(frame)
    win1.Navigate2("http://www.google.com")
    sizer.Add(win1, 1, wx.EXPAND)
    win1.Show()

    import wx.py.shell
    win = wx.py.shell.Shell(frame, -1)
    sizer.Add(win, 1, wx.EXPAND)
    frame.SetSizer(sizer)
    frame.Show(True)

    app.MainLoop()


More information about the python-win32 mailing list