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.

62 lines
2.2 KiB

8 years ago
9 years ago
8 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. basic_config = {
  7. 'widgets': [{
  8. 'type': 'CommandField',
  9. 'required': True,
  10. 'data': {
  11. 'display_name': 'Enter Commands',
  12. 'help': 'Enter command line arguments',
  13. 'nargs': '',
  14. 'commands': '',
  15. 'choices': [],
  16. 'default': None,
  17. }
  18. }],
  19. }
  20. def create_from_parser(parser, source_path, **kwargs):
  21. auto_start = kwargs.get('auto_start', False)
  22. if hasattr(sys, 'frozen'):
  23. run_cmd = quote(source_path)
  24. else:
  25. run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))
  26. build_spec = {
  27. 'language': kwargs.get('language', 'english'),
  28. 'target': run_cmd,
  29. 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
  30. 'program_description': kwargs.get('program_description', ''),
  31. 'auto_start': kwargs.get('auto_start', False),
  32. 'show_advanced': kwargs.get('advanced', True),
  33. 'default_size': kwargs.get('default_size', (610, 530)),
  34. 'num_required_cols': kwargs.get('required_cols', 1),
  35. 'num_optional_cols': kwargs.get('optional_cols', 3),
  36. 'manual_start': False,
  37. 'layout_type': 'flat',
  38. 'monospace_display': kwargs.get('monospace_display', False),
  39. 'image_dir': kwargs.get('image_dir'),
  40. 'language_dir': kwargs.get('language_dir'),
  41. 'progress_regex': kwargs.get('progress_regex'),
  42. 'progress_expr': kwargs.get('progress_expr'),
  43. 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
  44. 'disable_stop_button': kwargs.get('disable_stop_button'),
  45. 'group_by_type': kwargs.get('group_by_type', True)
  46. }
  47. if not auto_start:
  48. build_spec['program_description'] = parser.description or build_spec['program_description']
  49. layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else basic_config.items()
  50. build_spec.update(layout_data)
  51. return build_spec