dropdown item ordering when populated from dictionary

Dictionaries are mapping objects so they don't have an innate "order". But you're populating your drop down box from a list which does have an order. You just have to tell it you want it in order. Try adding:
self.List.sort()

That will put it in a specific order but I'm not sure it's the order you want. Your dictionary values are text and from a text point of view you mix alpha and numeric values. '6D' is not the same as 0x6D right? Perhaps it would be better to create your dictionary with numeric values, put the values in a list, sort the list, roll that list into a new list with formatted string values.

John Purser

···

-----Original Message-----
From: Vicki Stanfield [mailto:vicki@stanfield.net]
Sent: Monday, March 29, 2004 9:53 AM
To: wxPython Users List
Subject: [wxPython-users] dropdown item ordering when populated from
dictionary

I am asking this again since I didn't get an answer the first time I asked:

I am using a dictionary to populate a wxComboBox dropdown. The order of
the items doesn't make sense to me. For the most part, they are
alphanumericly ordered, but some are out of order. The dictionary looks
like this:

#Create a dictionary to link display value and hex value of commands
self.Dict={'\x78':'78','\x65':'65','\x60':'60',
'\x4D':'4D','\x4E':'4E','\x48':'48',
'\x6D':'6D','\x10':'10','\x1D':'1D','\x5A':'5A','T1':'T1','T2':'T2','T3':'T3','\x0E':'0E','\x49':'49','\x46':'46','\x50':'50','\x52':'52','\x67':'67','\x73':'73','\x53':'53','\x18':'18','\x58':'58','\x0C':'0C','\x57':'57','\x42':'42','\x43':'43','\x59':'59','\x4F':'4F','\x72':'72','\x77':'77','\x0D':'D','\x66':'66','\x61':'61','\x56':'56','\x47':'47','\x4B':'4B','\x46':'0F','\x0B':'0B'}
self.List=self.Dict.values()

and the dropdown is created thusly:

#Create a Command Drop Down
self.combolabel = wxStaticText(self,-1,"Please select a command:")
self.combo=wxComboBox(self, 30, " ",
                      wxPoint(wxALIGN_LEFT),
                      wxDefaultSize,
                      self.Dict.values(),wxCB_DROPDOWN)
EVT_COMBOBOX(self, 30, self.CommandCallback)

How are these items supposed to be ordered? Right now they are ordered
like this:

D,4D,0C,0E,10,18,1D,5A,0B...........

--vicki

"A pessimist sees the difficulty in every opportunity; an optimist sees
the opportunity in every difficulty."
  -- Winston Churchill

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org