Is it possible to select an option in a wxChoice based on a string
ClientData? It works OK for numbers with SetSelection, but not with
strings... Any workarounds?
wx.Choice is derived from wx.ControlWithItems and so inherits its
methods.
Regards,
···
On Sun, 2004-08-22 at 13:51, Jorge Godoy wrote:
Hi!
Is it possible to select an option in a wxChoice based on a string
ClientData? It works OK for numbers with SetSelection, but not with
strings... Any workarounds?
Ofcourse is posible... Just iterate over the items and set the selection to the corresponding index.
like:
for index in range(choiceCtrl.GetCount()):
if choiceCtrl.GetClientData() == "some random data":
choiceCtrl.SetSelection(index)
···
On Sun, 22 Aug 2004 17:51:56 -0300, Jorge Godoy <godoy@ieee.org> wrote:
Is it possible to select an option in a wxChoice based on a string
ClientData? It works OK for numbers with SetSelection, but not with
strings... Any workarounds?
Is it possible to select an option in a wxChoice based on a string
ClientData? It works OK for numbers with SetSelection, but not with
strings... Any workarounds?
wx.Choice.SetStringSelection()
wx.Choice is derived from wx.ControlWithItems and so inherits its
methods.
It is based on the string, not on the associated ClientData value.
If I have:
String ClientData
----------------------------------
"This is the string" "Data1"
I don't want to SetStringSelection("This is the string"), but I want to
SetClientDataSelection("Data1").
On Sun, 22 Aug 2004 17:51:56 -0300, Jorge Godoy <godoy@ieee.org> wrote:
Is it possible to select an option in a wxChoice based on a string
ClientData? It works OK for numbers with SetSelection, but not with
strings... Any workarounds?
Ofcourse is posible... Just iterate over the items and set the selection
to the corresponding index.
like:
for index in range(choiceCtrl.GetCount()):
if choiceCtrl.GetClientData() == "some random data":
choiceCtrl.SetSelection(index)
This is what I am doing. I thought there could be a better and
optimized way to do that...
Are you sure you NEED a "better and optimized way to do that"?
If your first implementation works move along to other issues and return only when refactoring is NEEDED.
I've wasted countless hours searching optimisation even if it wasn't necessary. I regret that time, it could have been spent on something more important.
Don't make the mistakes I've made! It is better to have a product that needs refactoring than to have a non functional product.
···
On Mon, 23 Aug 2004 09:28:38 -0300, Jorge Godoy <godoy@ieee.org> wrote:
"Peter Damoc" <pdamoc@gmx.net> writes:
for index in range(choiceCtrl.GetCount()):
if choiceCtrl.GetClientData() == "some random data":
choiceCtrl.SetSelection(index)
This is what I am doing. I thought there could be a better and
optimized way to do that...
Are you sure you NEED a "better and optimized way to do that"?
Not for this project, but I think it is never too late to learn
something. I've seen some new stuff that made me even more interested
in wxPython 2.5... When I'm able to switch, I'll have a great
enhancement in my code, since I'll be able to cut out some things that
are now available.
If there was already something implemented that did this job, why should
I maintain my own implementation? I am sure I need *less* work.
If your first implementation works move along to other issues and return
only when refactoring is NEEDED.
Since this is the first time this became necessary, I thought it would
also be a good hour to learn how to do that the correct way. I just
made the prototype run, while I searched the docs and waited for some
answer here.
I've wasted countless hours searching optimisation even if it wasn't
necessary. I regret that time, it could have been spent on something more
important.
Don't make the mistakes I've made! It is better to have a product that
needs refactoring than to have a non functional product.
I agree with you.
But then, when do you think it is the best time to learn how to use a
feature? I think it is the first time one is exposed to it and is
needing it... You are much more experienced than I am either with
wxPython or with Python itself It is good to learn with you.
I'm not all that experienced only 8 months with both
···
On Mon, 23 Aug 2004 10:38:39 -0300, Jorge Godoy <godoy@ieee.org> wrote:
But then, when do you think it is the best time to learn how to use a
feature? I think it is the first time one is exposed to it and is
needing it... You are much more experienced than I am either with
wxPython or with Python itself It is good to learn with you.
On Mon, 23 Aug 2004 10:38:39 -0300, Jorge Godoy <godoy@ieee.org> wrote:
But then, when do you think it is the best time to learn how to use a
feature? I think it is the first time one is exposed to it and is
needing it... You are much more experienced than I am either with
wxPython or with Python itself It is good to learn with you.
I'm not all that experienced only 8 months with both
I'm into Python and wxPython for longer than that...
But, unfortunately, due to the kind of business we do here at my company
it is not possible to get a bigger dedication to them. This, I know,
makes me waste time instead of saving it.