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

9 years ago
9 years ago
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. auto_start = kwargs.get('auto_start', False)
  8. run_cmd = kwargs.get('target')
  9. if run_cmd is None:
  10. if hasattr(sys, 'frozen'):
  11. run_cmd = quote(source_path)
  12. else:
  13. run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))
  14. build_spec = {
  15. 'language': kwargs.get('language', 'english'),
  16. 'target': run_cmd,
  17. 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
  18. 'program_description': kwargs.get('program_description', ''),
  19. 'auto_start': kwargs.get('auto_start', False),
  20. 'show_advanced': kwargs.get('advanced', True),
  21. 'default_size': kwargs.get('default_size', (610, 530)),
  22. 'num_required_cols': kwargs.get('required_cols', 1),
  23. 'num_optional_cols': kwargs.get('optional_cols', 3),
  24. 'manual_start': False,
  25. 'layout_type': 'flat',
  26. 'monospace_display': kwargs.get('monospace_display', False),
  27. 'image_dir': kwargs.get('image_dir'),
  28. 'language_dir': kwargs.get('language_dir'),
  29. 'progress_regex': kwargs.get('progress_regex'),
  30. 'progress_expr': kwargs.get('progress_expr'),
  31. 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
  32. 'disable_stop_button': kwargs.get('disable_stop_button'),
  33. 'group_by_type': kwargs.get('group_by_type', True)
  34. }
  35. if not auto_start:
  36. build_spec['program_description'] = parser.description or build_spec['program_description']
  37. layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items()
  38. build_spec.update(layout_data)
  39. return build_spec