Christof Ecker wrote:
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()
You might want to re-post this to the wxPython user's group just in case
you're missing a wx method. I use wxPython extensively, but I'm not
familiar with that particular widget. The link to the mail list is below:
http://wxpython.org/maillist.php
Also, there's the PAMIE project which you may or may not find useful:
http://pamie.sourceforge.net/
I personally have used the SendKeys module to automate IE, however it's
rather like black magic and kind of sucks:
http://www.rutherfurd.net/python/sendkeys/
-------------------
Mike Driscoll
Blog: http:\\blog.pythonlibrary.org
Python Extension Building Network: http:\\www.pythonlibrary.org
_______________________________________________
python-win32 mailing list
python-win32@python.org
http://mail.python.org/mailman/listinfo/python-win32