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.

40 lines
1.3 KiB

  1. import itertools
  2. from gooey.gui.widgets import components2
  3. class ComponentBuilder(object):
  4. def __init__(self, build_spec):
  5. self.build_spec = build_spec
  6. _required_specs = self.build_spec.get('required', None)
  7. _optional_specs = self.build_spec.get('optional', None)
  8. self.required_args = self.build_widget(_required_specs) if _required_specs else None
  9. optionals = self.build_widget(_optional_specs) if _optional_specs else None
  10. if _optional_specs:
  11. self.flags = [widget for widget in optionals if isinstance(widget, components2.CheckBox)]
  12. self.general_options = [widget for widget in optionals if not isinstance(widget, components2.CheckBox)]
  13. else:
  14. self.flags = []
  15. self.general_options = []
  16. def build_widget(self, build_spec):
  17. assembled_widgets = []
  18. for spec in build_spec:
  19. widget_type = spec['type']
  20. properties = spec['data']
  21. Component = getattr(components2, widget_type)
  22. assembled_widgets.append(Component(data=properties))
  23. return assembled_widgets
  24. def __iter__(self):
  25. '''
  26. return an iterator for all of the contained gui
  27. '''
  28. return itertools.chain(self.required_args or [],
  29. self.flags or [],
  30. self.general_options or [])