Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am working on a python based script/tool. I would like to make use of drop down lists for several of the parameters. This is very easy to do if the lists are just plain old strings.

Does anyone know if it is possible to bind objects to this list and display a certain property? Objects will be very simple; just key-value pairs. So, I would like to display the key and be able to access the value somewhere in the ToolValidator, or better yet access the ToolValidator class from the tool script itself?

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

Since you know that you can provide a potential list of acceptable values to a tool parameter, have you ruled out using the selected value from the domain, as the key to a dictionary residing in your main script?

share|improve this answer
add comment

Mr Patterson took the words right out of my mouth.

Have your dictionary object contain a key of the same name in your drop down list.

If you're feeling adventurous, try creating a class with the default property __name__ set to the value you want to display in your drop down list. Though this is getting over complicated and not very pythonic, it might correctly bind to the drop down list and assess this default property and deliver you the functionality you want.

I say might. I have not tested this and am skewing programming idioms (I'm usually a .Net developer). If I had the time I'd join you in the 'test it and see' adventure!

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.