show module members in a DropDown List

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

show module members in a DropDown List

Timmie
Administrator
Dear ETS users,
how can I show the members of a module in a selection drop-down list?

Let me illustrate further what I aim at:

For example:
1) I have an array and would like to provide different numpy functions
such as numpy.sum, numpy.mean, numpy.std
    I would like to have a dropdown list, wherein the user could select
the name of the function to be applied.
2) I define a set of constants in the constants.py file. I would like to
offer the user the possibilty to select among these via a dropdown list.
The contents of the dropdown list should be generated automatically from
the contents of the module or a subset thereof.

How do recommend to solve such a problem?
With a manually created dictionary that is shown as a dropdown?
funcs_to_apply = {'Sum' : np.sum, 'Mean' : np.mean}

Are there any example for such a widget?

Best regards,
Timmie

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Solved: Re: show module members in a DropDown List

Timmie
Administrator
> How do recommend to solve such a problem?
I created a dictionary of functions with:

###
import inspect

memb = inspect.getmembers(mymodule)
memb_dic = {}
# get module specific function names (exclude imports and doc)
for item in memb[5:]:
    memb_dic.update({item[0] : item[1]})

Then I used the dictionary to create a Enum in my Traits class:

functionselector = Enum(memb_dic.keys())

Hope that helps in future.

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev