Returning focus from IEHtmlWindow

Hi,

I am using the IEHtmlWindow in one of my newest applications and it works great. However, I would like to use some accelerators to a ListBox that I have next to it. The problem is that after a page has loaded in the IE window, focus just stays there. I can't get the focus to go back to the ListBox or any of my other widgets programmatically. I've tried wx.CallAfter(myWidget.SetFocus()), but that results in a traceback:

TypeError: 'NoneType' object is not callable
File "v:\PythonPackages\Development\pclip_importer\main.py", line 217, in <module>
  app.MainLoop()
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7964, in MainLoop
  wx.PyApp.MainLoop(self)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7289, in MainLoop
  return _core_.PyApp_MainLoop(*args, **kwargs)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14576, in <lambda>
  lambda event: event.callable(*event.args, **event.kw) )

Does anyone know of a way to change focus after a page has loaded? I am using wxPython 2.8.9.1, Python 2.5.2, Windows XP.

Thanks,

···

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

Mike Driscoll wrote:

Hi,

I am using the IEHtmlWindow in one of my newest applications and it works great. However, I would like to use some accelerators to a ListBox that I have next to it. The problem is that after a page has loaded in the IE window, focus just stays there. I can't get the focus to go back to the ListBox or any of my other widgets programmatically. I've tried wx.CallAfter(myWidget.SetFocus()), but that results in a traceback:

TypeError: 'NoneType' object is not callable
File "v:\PythonPackages\Development\pclip_importer\main.py", line 217, in <module>
app.MainLoop()
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7964, in MainLoop
wx.PyApp.MainLoop(self)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7289, in MainLoop
return _core_.PyApp_MainLoop(*args, **kwargs)
File "C:\Python25\Lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 14576, in <lambda>
lambda event: event.callable(*event.args, **event.kw) )

Does anyone know of a way to change focus after a page has loaded? I am using wxPython 2.8.9.1, Python 2.5.2, Windows XP.

Thanks,

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

It looks like the new version of iewin.py no longer has events to bind to. I'm not sure if that's intended or not, but it's pretty annoying. Anyway, I found a bad hack around the issue. I just disable my iewin instance and it can no longer accept focus. Of course, not I can't interact with my embedded HTMLWindow either...this will work for this hackneyed application, but I don't want to have to do this in the future.

Mike

Mike Driscoll wrote:

Hi,

I am using the IEHtmlWindow in one of my newest applications and it works great. However, I would like to use some accelerators to a ListBox that I have next to it. The problem is that after a page has loaded in the IE window, focus just stays there. I can't get the focus to go back to the ListBox or any of my other widgets programmatically. I've tried wx.CallAfter(myWidget.SetFocus()), but that results in a traceback:

The traceback is because you are passing None to CallAfter because you are calling SetFocus (None is the return value of SetFocus) instead of just passing the method itself. Try this instead:

  wx.CallAfter(myWidget.SetFocus)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Mike Driscoll wrote:

It looks like the new version of iewin.py no longer has events to bind to. I'm not sure if that's intended or not, but it's pretty annoying.

It's using the COM model of using named callbacks instead of mapping everything to wx events. See the demo for some examples. Basically whatever the ActiveX object defines as event names are looked for in the object and the eventSink object (if one is set) and if one is found it is called when the COM event happens. Things are more dynamic and flexible this way, and using the COM object is more like it would be using it in other languages or environments.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin,

Mike Driscoll wrote:

Hi,

I am using the IEHtmlWindow in one of my newest applications and it works great. However, I would like to use some accelerators to a ListBox that I have next to it. The problem is that after a page has loaded in the IE window, focus just stays there. I can't get the focus to go back to the ListBox or any of my other widgets programmatically. I've tried wx.CallAfter(myWidget.SetFocus()), but that results in a traceback:

The traceback is because you are passing None to CallAfter because you are calling SetFocus (None is the return value of SetFocus) instead of just passing the method itself. Try this instead:

    wx.CallAfter(myWidget.SetFocus)

This has no effect. The focus stays firmly in the IE window. I suppose I could continue to disable the ie window unless the user specifically select it with their mouse...

Mike

Robin Dunn wrote:

Mike Driscoll wrote:

It looks like the new version of iewin.py no longer has events to bind to. I'm not sure if that's intended or not, but it's pretty annoying.

It's using the COM model of using named callbacks instead of mapping everything to wx events. See the demo for some examples. Basically whatever the ActiveX object defines as event names are looked for in the object and the eventSink object (if one is set) and if one is found it is called when the COM event happens. Things are more dynamic and flexible this way, and using the COM object is more like it would be using it in other languages or environments.

I looked in the demo before I did anything. It's how I figured out how to embed the IEWindow to begin with. I don't see anything about binding to events explicitly in the demo, which is why I was confused. There is line 92 though:

self.ie.AddEventSink(self)

The comments above it claim that this causes the IEHtmlWindow to look for method names in my own namespace even though I didn't subclass IEHtmlWindow. Is that the correct interpretation?

Thanks,

Mike

Mike Driscoll wrote:

Robin Dunn wrote:

Mike Driscoll wrote:

It looks like the new version of iewin.py no longer has events to bind to. I'm not sure if that's intended or not, but it's pretty annoying.

It's using the COM model of using named callbacks instead of mapping everything to wx events. See the demo for some examples. Basically whatever the ActiveX object defines as event names are looked for in the object and the eventSink object (if one is set) and if one is found it is called when the COM event happens. Things are more dynamic and flexible this way, and using the COM object is more like it would be using it in other languages or environments.

I looked in the demo before I did anything. It's how I figured out how to embed the IEWindow to begin with. I don't see anything about binding to events explicitly in the demo, which is why I was confused. There is line 92 though:

self.ie.AddEventSink(self)

The comments above it claim that this causes the IEHtmlWindow to look for method names in my own namespace even though I didn't subclass IEHtmlWindow. Is that the correct interpretation?

Half of it. Look further down the file for the group of methods starting with BeforeNavigate2. These are some of the callbacks/events coming from the IWebBrowser2 interface. More info about this interface can be found on MSDN.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!