Kirix Support Forums

Horrible focus / list selection bug

Please post all general questions, comments, bug reports, and any other wxWebConnect feedback here.

Horrible focus / list selection bug

Postby jonmmorgan on Mon Jun 20, 2011 10:23 am

Has anyone had any strange focus bugs when using wxWebControl with wxListCtrl on MS Windows?

What I find is that if I put these together, and then open a URI every time I change the list of items, one of two things happen:
1. Focus gets stolen by the HTML window, and I can no longer use keyboard navigation inside the list control.

2. The next mouse move over the list control gets turned into a mouse click or a change selection event. This is the one that is really baffling me. Basically what happens is: I click on an item. I navigate with keyboard up, even to the point where that list item is not on the screen, then when I move the mouse selection jumps back down to that entry in the list again. I have investigated, and the wxListCtrl is actually receiving a LVN_ITEMCHANGED event with the old list index, and I can't see anything in the wxWidgets code that would be triggering this event off. In a demo app I can make it behave by setting a timeout before setting the HTML. However, in my real app this solution doesn't seem to work. I include some rough Python code below. Any thoughts?

Code: Select all
import wx
import wx.wc

class TestFrame(wx.Frame):
   def __init__(self, parent=None):
      wx.Frame.__init__(self, parent)
      self.sizer = wx.BoxSizer(wx.HORIZONTAL)
      self.panel = wx.Panel(self)
      self.sizer.Add(self.panel, flag=wx.EXPAND|wx.ALL|wx.GROW, proportion=1)
      panel_sizer = wx.BoxSizer(wx.VERTICAL)
      #self.splitter = wx.SplitterWindow(self)
      self.listctrl = wx.ListCtrl(self.panel, style=wx.LC_REPORT)
      self.listctrl.InsertColumn(0, "URL - with some padding")
      self.webcontrol = wx.wc.WebControl(self.panel)
      #import displayframe
      #self.webcontrol = displayframe.DisplayFrame(self.splitter)
      #self.splitter.SplitHorizontally(self.listctrl, self.webcontrol)
      #self.webcontrol.Size = (200, 200)
      panel_sizer.Add(self.listctrl, flag=wx.EXPAND, proportion=1)
      panel_sizer.Add(self.webcontrol, flag=wx.EXPAND, proportion=1)
      self.panel.SetSizer(panel_sizer)
      #self.webcontrol.OpenURI('http://www.google.com')
      #self.sizer.Fit(self.panel)
      #panel_sizer.Fit(self.listctrl)
      self.Size = (400, 400)
      self.listctrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.item_selected)
      self.listctrl.Bind(wx.EVT_LEFT_DOWN, self.left_mouse_button_down)
      self.listctrl.Bind(wx.EVT_LIST_ITEM_FOCUSED, self.list_item_focused)
      #self.listctrl.Bind(wx.EVT_MOTION, self.evt_motion)
      self.listctrl.Bind(wx.EVT_SET_FOCUS, self.evt_focus)
      self.listctrl.Bind(wx.EVT_KILL_FOCUS, self.evt_kill_focus)
      self.webcontrol.Execute("window.open('chrome://global/content/console.xul', '', 'chrome,dialog=no,toolbar,resizable')")

      for index in range(20):
         self.listctrl.InsertStringItem(index, "Item %d" % index)

      self.timer = wx.Timer(self)
      self.Bind(wx.EVT_TIMER, self.on_timer, self.timer)

   def item_selected(self, event):
      print "Event item selection"
      index = event.GetIndex()
      print index
      self.url = "file:///d:/devel/webconnect_bpbible/generated_html2/tmp%d.html" % (index + 1)
      print "Calling OpenURI for ", self.url
      #self.timer.Start(120, oneShot=True)
      def DoOpenURI():
         self.webcontrol.OpenURI(self.url, grab_focus=False)
         #print "Calling location.replace..."
         # self.webcontrol.Execute('window.setTimeout(function() { /*alert("test");*/ window.location.replace("%s");}, 500);' % url)
         #self.webcontrol.Execute('window.location.replace("%s");' % self.url)

      wx.CallLater(200, DoOpenURI)
      """
      def DoOpenURI():
         #self.webcontrol.OpenURI(url, grab_focus=False)
         print "Calling location.replace..."
         # self.webcontrol.Execute('window.setTimeout(function() { /*alert("test");*/ window.location.replace("%s");}, 500);' % url)
         self.webcontrol.Execute('window.location.replace("%s");' % url)

      wx.CallAfter(DoOpenURI)
      """
      #self.webcontrol.ForceKillFocus()
      #self.listctrl.SetFocus()

   def on_timer(self, event):
      #self.webcontrol.OpenURI(self.url, grab_focus=False)
      def DoOpenURI():
         self.webcontrol.OpenURI(self.url, grab_focus=False)
         #print "Calling location.replace..."
         # self.webcontrol.Execute('window.setTimeout(function() { /*alert("test");*/ window.location.replace("%s");}, 500);' % url)
         #self.webcontrol.Execute('window.location.replace("%s");' % self.url)

      wx.CallAfter(DoOpenURI)

   def list_item_focused(self, event):
      print "Item focused"
      event.Skip()

   def left_mouse_button_down(self, event):
      print "Left mouse button down."
      event.Skip()

   def evt_motion(self, event):
      print "Event motion"
      event.Skip()

   def evt_focus(self, event):
      print "Event focus"
      event.Skip()

   def evt_kill_focus(self, event):
      print "Event kill focus"
      event.Skip()

if __name__ == '__main__':
   a = wx.App(0)
   wx.wc.WebControl.InitEngine(r"d:\devel\webconnect_bpbible\xulrunner")
   f = TestFrame(None)
   f.Show()
   a.MainLoop()
jonmmorgan
Registered User
 
Posts: 94
Joined: Fri May 14, 2010 9:48 am

Return to wxWebConnect Questions, Thoughts & Feedback