You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.1 KiB

  1. from collections import namedtuple
  2. from gooey.gui.widgets import components
  3. is_required = lambda widget: widget['required']
  4. is_checkbox = lambda widget: isinstance(widget, components.CheckBox)
  5. ComponentList = namedtuple('ComponentList', 'required_args optional_args')
  6. def build_components(widget_list):
  7. '''
  8. :param widget_list: list of dicts containing widget info (name, type, etc..)
  9. :return: ComponentList
  10. Converts the Json widget information into concrete wx Widget types
  11. '''
  12. required_args, optional_args = partition(widget_list, is_required)
  13. checkbox_args, general_args = partition(map(build_widget, optional_args), is_checkbox)
  14. required_args = map(build_widget, required_args)
  15. optional_args = general_args + checkbox_args
  16. return ComponentList(required_args, optional_args)
  17. def build_widget(widget_info):
  18. widget_class = getattr(components, widget_info['type'])
  19. return widget_class(data=widget_info['data'])
  20. def partition(collection, condition):
  21. return filter(condition, collection), filter(lambda x: not condition(x), collection)