Setting SingleChoiceDialog focus

Thanks for your reply, Robin. Unfortunately this doesn't work for me, I
get the same behaviour as before. Is there something else I can try?

Thanks

Peter Butler

···

You can get a reference to the listbox and then set focus to it with
CallAfter.

  d = wx.SingleChoiceDialog(...)
  lb = d.FindWindowById(3000)
  wx.CallAfter(lb.SetFocus)
  d.ShowModal()

This one doesn't work either, unfortunately. It looks like I'll have to
create my own SingleChoiceDialog by hand.

Just for reference, here's my implementation of SingleChoiceDialog. I
hope it helps someone.

Cheers

Peter Butler

class SingleChoiceDialog(wx.Dialog):
    def __init__(self, parent, label, title, strings, style):
        self.selection = None
        self.strings = strings

        wx.Dialog.__init__(self, parent, -1, title, style=style)
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)
        
        label = wx.StaticText(self, -1, label)
        sizer.Add(label, 0, wx.EXPAND | wx.ALL, 5)

        self.list = SingleChoiceList(self, -1, style=wx.LC_SINGLE_SEL |
wx.LC_REPORT | wx.LC_NO_HEADER | wx.BORDER_SUNKEN)
        self.list.InsertColumn(0, '', width=300)
        for string in strings:
            self.list.InsertStringItem(sys.maxint, string)
        
        sizer.Add(self.list, 1, wx.EXPAND | wx.ALL, 5)

        buttonBox = wx.BoxSizer(wx.HORIZONTAL)
        btn = wx.Button(self, wx.ID_OK, "&OK")
        btn.SetDefault()
        buttonBox.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
        btn = wx.Button(self, wx.ID_CANCEL, "&Cancel")
        buttonBox.Add(btn, 0, wx.ALIGN_CENTRE|wx.ALL, 5)
        sizer.Add(buttonBox, 0, wx.ALIGN_RIGHT|wx.ALL, 5)
        
        self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.itemActivated,
self.list)
        self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.itemSelected,
self.list)
       
        self.Layout()
        self.list.Select(0)
        
    def itemSelected(self, event):
        index = event.m_itemIndex
        event.Skip()
        self.selection = self.strings[index]
        
    def itemActivated(self, event):
        index = event.m_itemIndex
        event.Skip()
        self.selection = self.strings[index]
        self.EndModal(wx.ID_OK)
        
    def GetStringSelection(self):
        return self.selection