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.

91 lines
2.5 KiB

11 years ago
9 years ago
11 years ago
9 years ago
9 years ago
9 years ago
11 years ago
  1. '''
  2. Created on Jan 24, 2014
  3. @author: Chris
  4. TODO: this
  5. '''
  6. import json
  7. import os
  8. import sys
  9. from argparse import ArgumentParser
  10. from gooey.gui import application
  11. from gooey.gui.util.freeze import get_resource_path
  12. from . import config_generator
  13. IGNORE_COMMAND = '--ignore-gooey'
  14. def Gooey(f=None,
  15. advanced=True,
  16. language='english',
  17. auto_start=False, # TODO: add this to the docs. Used to be `show_config=True`
  18. program_name=None,
  19. program_description=None,
  20. default_size=(610, 530),
  21. required_cols=2,
  22. optional_cols=2,
  23. dump_build_config=False,
  24. load_build_config=None,
  25. monospace_display=False,
  26. image_dir='default',
  27. language_dir=get_resource_path('languages'),
  28. progress_regex=None,
  29. progress_expr=None,
  30. disable_progress_bar_animation=False,
  31. disable_stop_button=False,
  32. group_by_type=True):
  33. '''
  34. Decorator for client code's main function.
  35. Serializes argparse data to JSON for use with the Gooey front end
  36. '''
  37. params = locals()
  38. def build(payload):
  39. def run_gooey(self, args=None, namespace=None):
  40. source_path = sys.argv[0]
  41. build_spec = None
  42. if load_build_config:
  43. try:
  44. build_spec = json.load(open(load_build_config, "r"))
  45. except Exception, e:
  46. print( 'Exception loading Build Config from {0}: {1}'.format(load_build_config, e))
  47. sys.exit(1)
  48. if not build_spec:
  49. build_spec = config_generator.create_from_parser(self, source_path, payload_name=payload.__name__, **params)
  50. if dump_build_config:
  51. config_path = os.path.join(os.getcwd(), 'gooey_config.json')
  52. print 'Writing Build Config to: {}'.format(config_path)
  53. with open(config_path, 'w') as f:
  54. f.write(json.dumps(build_spec, indent=2))
  55. application.run(build_spec)
  56. def inner2(*args, **kwargs):
  57. ArgumentParser.original_parse_args = ArgumentParser.parse_args
  58. ArgumentParser.parse_args = run_gooey
  59. return payload(*args, **kwargs)
  60. inner2.__name__ = payload.__name__
  61. return inner2
  62. def run_without_gooey(func):
  63. return lambda: func()
  64. if IGNORE_COMMAND in sys.argv:
  65. sys.argv.remove(IGNORE_COMMAND)
  66. if callable(f):
  67. return run_without_gooey(f)
  68. return run_without_gooey
  69. if callable(f):
  70. return build(f)
  71. return build
  72. if __name__ == '__main__':
  73. pass