Pierre Rouleau wrote:
Hi,
The wx Widget version of SingleChoiceDialog has a constructor that support the clientData argument and a method GetSelectionClientData.
In http://lists.wxwidgets.org/archive/wxPython-users/msg13900.html, Robin states that it was intentionaly left out in 2.3.1 and will get to include it later. wxPython 2.6.3.2 does not support it either. Is there plans to support GetSelectionClientData in the future version of wxPython?
It's still marked with a big "FIXME" in the code. The problem is mapping the Python list to the type that is expected by the C++ constructor, and the fact that it is expecting an array of character pointers even in the unicode build... Not too difficult really, but it would be easier to just reimplement this class in Python instead. Something like this perhaps (untested):
import wx
class SingleChoiceDialog(wx.Dialog):
def __init__(self, parent, message, caption, choices, clientData=,
style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER | wx.OK | wx.CANCEL | wx.CENTER,
pos=wx.DefaultPosition):
wx.Dialog.__init__(self, parent, -1, title=caption, pos=pos, style=style)
topSizer = wx.BoxSizer(wx.VERTICAL)
topSiser.Add(self.CreateTextSizer(message), 0, wx.ALL, 10)
self.listbox = wx.ListBox(self, -1, choices=choices, style=wx.LB_ALWAYS_SB)
self.listbox.SetSelection(0)
topSizer.Add(self.listbox, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 10)
if clientData:
for idx, data in enumerate(clientData):
self.listbox.SetClientData(idx, data)
buttonSizer = self.CreateButtonSizer(styl & self.ButtonSizerFlags, True, 10)
if len(buttonSizer.GetChildren()) > 0:
topSizer.Add(buttonSizer, 0, wx.EXPAND|wx.ALL, 10)
else:
topSizer.Add((15,15))
self.SetSizerAndFit(topSizer)
if style & wx.CENTER:
self.Center(wx.BOTH)
self.listbox.SetFocus()
self.Bind(wx.EVT_BUTTON, self.OnOk, id=wx.ID_OK)
self.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListBoxDClick, self.listbox)
def OnOk(self, evt):
self.DoChoice()
def OnListBoxDClick(self, evt):
self.DoChoice()
def DoChoice(self):
self.selection = self.listbox.GetSelection()
self.stringSelection = self.listbox.GetStringSelection()
self.clientData = self.listbox.GetClientData(self.selection)
self.EndModal(wx.ID_OK)
def SetSelection(self, sel):
self.listbox.SetSelection(sel)
def GetSelection(self):
return self.selection
def GetStringSelection(self):
return self.stringSelection
def GetSelectionClientData(self):
return self.clientData
···
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!