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.

92 lines
2.4 KiB

10 years ago
9 years ago
10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
  1. '''
  2. Created on Jan 24, 2014
  3. @author: Chris
  4. TODO: this
  5. '''
  6. import sys
  7. import os
  8. import json
  9. from . import config_generator
  10. from gooey.gui import application
  11. from argparse import ArgumentParser
  12. from gooey.gui.util.freeze import get_resource_path
  13. IGNORE_COMMAND = '--ignore-gooey'
  14. def Gooey(f=None,
  15. advanced=True,
  16. language='english',
  17. 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. '''
  33. Decorator for client code's main function.
  34. Serializes argparse data to JSON for use with the Gooey front end
  35. '''
  36. params = locals()
  37. def build(payload):
  38. def run_gooey(self, args=None, namespace=None):
  39. source_path = sys.argv[0]
  40. build_spec = None
  41. if load_build_config:
  42. try:
  43. build_spec = json.load(open(load_build_config, "r"))
  44. except Exception, e:
  45. print( 'Exception loading Build Config from {0}: {1}'.format(load_build_config, e))
  46. sys.exit(1)
  47. if not build_spec:
  48. build_spec = config_generator.create_from_parser(self, source_path, payload_name=payload.__name__, **params)
  49. if dump_build_config:
  50. config_path = os.path.join(os.getcwd(), 'gooey_config.json')
  51. print 'Writing Build Config to: {}'.format(config_path)
  52. with open(config_path, 'w') as f:
  53. f.write(json.dumps(build_spec, indent=2))
  54. application.run(build_spec)
  55. def inner2(*args, **kwargs):
  56. ArgumentParser.original_parse_args = ArgumentParser.parse_args
  57. ArgumentParser.parse_args = run_gooey
  58. return payload(*args, **kwargs)
  59. inner2.__name__ = payload.__name__
  60. return inner2
  61. def run_without_gooey(func):
  62. return lambda: func()
  63. if IGNORE_COMMAND in sys.argv:
  64. sys.argv.remove(IGNORE_COMMAND)
  65. if callable(f):
  66. return run_without_gooey(f)
  67. return run_without_gooey
  68. if callable(f):
  69. return build(f)
  70. return build
  71. if __name__ == '__main__':
  72. pass