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.

46 lines
1.6 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. #If script has been frozen execute it straight
  9. if hasattr(sys, 'frozen'):
  10. run_cmd = source_path
  11. else:
  12. run_cmd = 'python {}'.format(source_path)
  13. build_spec = {
  14. 'language': kwargs.get('language', 'english'),
  15. 'target': run_cmd,
  16. 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
  17. 'program_description': kwargs.get('program_description', ''),
  18. 'show_config': show_config,
  19. 'show_advanced': kwargs.get('show_advanced', True),
  20. 'default_size': kwargs.get('default_size', (610, 530)),
  21. 'num_required_cols': kwargs.get('required_cols', 1),
  22. 'num_optional_cols': kwargs.get('optional_cols', 3),
  23. 'manual_start': False,
  24. 'layout_type': 'column',
  25. 'monospace_display': kwargs.get('monospace_display', False)
  26. }
  27. if show_config:
  28. build_spec['program_description'] = parser.description or build_spec['program_description']
  29. layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items()
  30. build_spec.update(layout_data)
  31. else:
  32. build_spec['manual_start'] = True
  33. return build_spec
  34. def has_argparse(module_path):
  35. return any(['.parse_args(' in line.lower() for line in f.readlines()])