Hello,
This is a small application I generated with wxglade to illustrate
the problem I have :
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.lb = wx.ListBox(self, -1, choices=[str(el) for el in
xrange(20)])
self.lb.SetSelection(0)
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.lb, 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
self.Bind(wx.EVT_LISTBOX, self.OnEventListBox, self.lb)
def OnEventListBox(self, event):
print 'EvtListBox: %s, %s, %s, %s' % (event.GetString(),
event.IsSelection(),
event.GetSelection(),
event.GetClientData())
if __name__ == "__main__":
app = wx.PySimpleApp(0)
f = MyFrame(None, -1, "")
app.SetTopWindow(f)
f.Show()
app.MainLoop()
If I execute this application, it works. When I launch the application
and click for instance the third element of the list it prints :
EvtListBox: 3, True, 3, None
But I don't want to have a selected element at startup so I commented
the line self.lb.SetSelection(0). If I do that, when I launch the
application and select the the third element of the list it prints :
EvtListBox: 0, True, 0, None
EvtListBox: 3, True, 3, None
The first event of the listbox also trigger a selection of the first
element of the list. In my case it launches a heavy process that I
want to avoid. After the first selection it works well, I only have 1
event.
I'm using wx Python 2.8.10.1 (gtk2-unicode) with python 2.6.2 under
linux.
Thanks,
Jerome