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.

41 lines
1.4 KiB

9 years ago
  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. 'num_required_cols': kwargs.get('required_cols', 1),
  18. 'num_optional_cols': kwargs.get('optional_cols', 3),
  19. 'manual_start': False,
  20. 'layout_type': 'column'
  21. }
  22. if show_config:
  23. build_spec['program_description'] = parser.description or build_spec['program_description']
  24. layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items()
  25. build_spec.update(layout_data)
  26. else:
  27. build_spec['manual_start'] = True
  28. return build_spec
  29. def has_argparse(module_path):
  30. return any(['.parse_args(' in line.lower() for line in f.readlines()])