wx.ComboBox SetValue() automatically selects values from the list.

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

wx.ComboBox SetValue() automatically selects values from the list.

Sungjune
Hi,

When I call wx.ComboBox.SetValue() with a string, it selects one from its predefined list if my string PARTIALLY matches with one of the predefined strings:

>>>
self.MyComboBox = wx.ComboBox(self, -1, choices=['10','20'], style=wx.CB_DROPDOWN)
...

self.MyComboBox.SetValue('1')
<<<

Then the combobox displays '10' rather than '1'. However if I set '1.' for example, then it displays '1.'.  

Is this feature designed?

Reply | Threaded
Open this post in threaded view
|

Re: wx.ComboBox SetValue() automatically selects values from the list.

Nathan McCorkle


On Monday, February 2, 2015 at 8:59:25 AM UTC-8, sungjune.lee wrote:
Then the combobox displays '10' rather than '1'. However if I set '1.' for
example, then it displays '1.'.  

Is this feature designed? 

I could be wrong, but I think that is the intention. My first thought is to make the ComboBox READ-ONLY with the style CB_READONLY then see if you don't get that behaviour.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.ComboBox SetValue() automatically selects values from the list.

Sungjune
Thanks for the reply.

But my intention was to allow users to choose any numbers. Actual problem goes like this:

- User enters number '1' in the combobox
- Program reads the user input and save the number '1'  in a file.
- Later when user run the program again, he will see '10' instead of '1' because python will try

   MyComboBox.SetValue('1')

- But if he choose '1.' instead then he will see '1.'

Reply | Threaded
Open this post in threaded view
|

Re: wx.ComboBox SetValue() automatically selects values from the list.

Rufus V. Smith
Are you sure the "10" being displayed is a result of your SetValue?  It may be just
left over from the button setup when the run starts because you say the "10" appears
the next time the user runs the program.  And "10" is index 0 of your choices.

Or are you looking at the field before the screen has a chance to update, perhaps?
Reply | Threaded
Open this post in threaded view
|

Re: wx.ComboBox SetValue() automatically selects values from the list.

Sungjune
I've tested with following piece of code:

==============================
class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.combobox = wx.ComboBox(self, wx.ID_ANY, '',
            choices=['10','20','30'], style=wx.CB_DROPDOWN)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.combobox, 0, 0, 0)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

        self.combobox.SetValue('1')

if __name__ == "__main__":
    gettext.install("app")

    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame = MyFrame(None, wx.ID_ANY, "")
    app.SetTopWindow(frame)
    frame.Show()
    app.MainLoop()
=====================

Interesting thing is that in my Lunux machine it shows '1' but in my Windows it shows '10'. Both have the same version of wx (2.8.12.1).
Reply | Threaded
Open this post in threaded view
|

Re: wx.ComboBox SetValue() automatically selects values from the list.

Nathan McCorkle


On Tuesday, February 3, 2015 at 5:47:23 PM UTC-8, sungjune.lee wrote:
I've tested with following piece of code:

==============================
class MyFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.combobox = wx.ComboBox(self, wx.ID_ANY, '',
            choices=['10','20','30'], style=wx.CB_DROPDOWN)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.combobox, 0, 0, 0)
        self.SetSizer(sizer)
        sizer.Fit(self)
        self.Layout()

        self.combobox.SetValue('1')


A simple workaround would be:
# make sure the index returned is at least 0
if self.combobox.FindString('1')>=0:
    self.combobox.SetValue('1')  

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: wx.ComboBox SetValue() automatically selects values from the list.

Sungjune
For those who may suffer from the same issue, my quick and dirty fix is adding a space character at the end.

==========

self.MyComboBox.SetValue(str(some_integer_value) + " ")

==========