|
From: Kevin A. <al...@se...> - 2002-02-19 22:07:53
|
The cvs version of PythonCardPrototype is using direct subclasses of
wxPython controls, so you can use the client data methods if you want to
give that a try.
In general, I would say you are better off creating a second dictionary that
uses the values as keys and the keys as values, assuming the values are
unique, which they probably are if you're displaying them in a Choice
component. I suppose there is a good reason that the descriptions are not
already being used as the keys? How big are the dictionaries?
The brute force method of finding a key based on value looks like this:
>>> d = {1:'one', 2:'two', 3:'three', 4:'four'}
>>> def getKeyByValue(d, value):
... for k in d.items():
... if k[1] == value:
... return k[0]
... return None
...
>>> getKeyByValue(d, 'four')
4
There is probably a clever lambda or iterator that would do a better job,
but that function gets the job done. Is this what you needed?
ka
> -----Original Message-----
> From: pyt...@li...
> [mailto:pyt...@li...]On Behalf Of Andy
> Todd
> Sent: Tuesday, February 19, 2002 3:50 AM
> To: Pythoncard-Users
> Subject: [Pythoncard-users] Brain Fade
>
>
> Evening all,
>
> Its late, but I can't find any examples of what I want to do anywhere.
> This is a fairly frequent occurrence in the world of relational
> databases and I've been scratching my head trying to figure out how to
> represent it in PythonCard.
>
> Enough teasing, I have a table which contains keys and descriptions and
> I want to display the available descriptions in a 'choice' widget. Which
> is fairly easy. But when the user selects an element in the choice
> widget I want my code to know the corresponding key value. Is there any
> way to associate multiple items (say tuples?) with a choice widget?
>
> At the moment I'm returning the key-description pairs into a dictionary,
> so of course it would be nice to just get the key from the description
> value but I don't know of a way to do this in ordinary Python, unless I
> am being more of an idiot than usual.
>
> I don't think I can associate multiple values with each item in
> PythonCard (or wxPython for that matter) so I probably need to do this
> in my program.
>
> But, and this is a big but, I don't want to have to iterate through all
> of the available key-description pairs to find the key I'm looking for
> based on the value from the choice widget.
>
> Any suggestions?
>
> Regards,
> Andy
> --
> -----------------------------------------------------------------------
> From the desk of Andrew J Todd esq.
> Smiggins Hole 2010 - Unleash the Mongrel
>
>
> _______________________________________________
> Pythoncard-users mailing list
> Pyt...@li...
> https://lists.sourceforge.net/lists/listinfo/pythoncard-users
>
|