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

9 years ago
  1. import os
  2. import sys
  3. from gooey.gui.windows import layouts
  4. from gooey.python_bindings import argparse_to_json
  5. from gooey.gui.util.quoting import quote
  6. def create_from_parser(parser, source_path, **kwargs):
  7. show_config = kwargs.get('show_config', False)
  8. if hasattr(sys, 'frozen'):
  9. run_cmd = quote(source_path)
  10. else:
  11. run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))
  12. build_spec = {
  13. 'language': kwargs.get('language', 'english'),
  14. 'target': run_cmd,
  15. 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
  16. 'program_description': kwargs.get('program_description', ''),
  17. 'show_config': show_config,
  18. 'show_advanced': kwargs.get('show_advanced', True),
  19. 'default_size': kwargs.get('default_size', (610, 530)),
  20. 'num_required_cols': kwargs.get('required_cols', 1),
  21. 'num_optional_cols': kwargs.get('optional_cols', 3),
  22. 'manual_start': False,
  23. 'layout_type': 'column',
  24. 'monospace_display': kwargs.get('monospace_display', False),
  25. 'image_dir': kwargs.get('image_dir'),
  26. 'language_dir': kwargs.get('language_dir'),
  27. 'progress_regex': kwargs.get('progress_regex'),
  28. 'progress_expr': kwargs.get('progress_expr'),
  29. 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
  30. 'disable_stop_button': kwargs.get('disable_stop_button'),
  31. }
  32. if show_config:
  33. build_spec['program_description'] = parser.description or build_spec['program_description']
  34. layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items()
  35. build_spec.update(layout_data)
  36. else:
  37. build_spec['manual_start'] = True
  38. return build_spec