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.4 KiB

  1. import os
  2. import sys
  3. import argparse_to_json
  4. from gooey.gui.windows import layouts
  5. from gooey.python_bindings import source_parser
  6. def create_from_parser(parser, source_path, **kwargs):
  7. show_config = kwargs.get('show_config', False)
  8. run_cmd = 'python {}'.format(source_path)
  9. build_spec = {
  10. 'language': kwargs.get('language', 'english'),
  11. 'target': run_cmd,
  12. 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
  13. 'program_description': kwargs.get('program_description', ''),
  14. 'show_config': show_config,
  15. 'show_advanced': kwargs.get('show_advanced', True),
  16. 'default_size': kwargs.get('default_size', (610, 530)),
  17. 'requireds_cols': kwargs.get('required_cols', 1),
  18. 'optionals_cols': kwargs.get('optional_cols', 3),
  19. 'manual_start': False
  20. }
  21. if show_config:
  22. build_spec['program_description'] = parser.description or build_spec['program_description']
  23. layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items()
  24. build_spec.update(layout_data)
  25. else:
  26. build_spec['manual_start'] = True
  27. return build_spec
  28. def has_argparse(module_path):
  29. return any(['.parse_args(' in line.lower() for line in f.readlines()])