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.

88 lines
2.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. '''
  2. Created on Jan 24, 2014
  3. @author: Chris
  4. '''
  5. from functools import partial
  6. import wx
  7. from gooey.gui.component_factory import ComponentFactory
  8. import i18n
  9. import i18n_config
  10. import source_parser
  11. from gooey.gui.client_app import ClientApp
  12. from gooey.gui.client_app import EmptyClientApp
  13. from gooey.gui.base_window import BaseWindow
  14. from gooey.gui.advanced_config import AdvancedConfigPanel
  15. from gooey.gui.basic_config_panel import BasicConfigPanel
  16. def Gooey(f=None, advanced=True,
  17. language='english', config=True,
  18. program_name=None, program_description=None):
  19. '''
  20. Decorator for client code's main function.
  21. Entry point for the GUI generator.
  22. Scans the client code for argparse data.
  23. If found, extracts it and build the proper
  24. configuration gui window (basic or advanced).
  25. '''
  26. params = locals()
  27. def build(payload):
  28. def inner():
  29. module_path = get_caller_path()
  30. # Must be called before anything else
  31. app = wx.App(False)
  32. i18n.load(language)
  33. if config:
  34. parser = get_parser(module_path)
  35. client_app = ClientApp(parser, payload)
  36. if advanced:
  37. BodyPanel = partial(AdvancedConfigPanel, action_groups=client_app.action_groups)
  38. else:
  39. BodyPanel = BasicConfigPanel
  40. # User doesn't want to display configuration screen
  41. # Just jump straight to the run panel
  42. else:
  43. BodyPanel = BasicConfigPanel
  44. client_app = EmptyClientApp()
  45. frame = BaseWindow(BodyPanel, client_app, params)
  46. if not config:
  47. frame.ManualStart()
  48. frame.Show(True)
  49. app.MainLoop()
  50. inner.__name__ = payload.__name__
  51. return inner
  52. if callable(f):
  53. return build(f)
  54. return build
  55. def get_parser(module_path):
  56. try:
  57. return source_parser.extract_parser(module_path)
  58. except source_parser.ParserError:
  59. raise source_parser.ParserError(
  60. 'Could not locate ArgumentParser statements in Main().'
  61. '\nThis is probably my fault :( Please checkout github.com/chriskiehl/gooey to file a bug!')
  62. def get_caller_path():
  63. # utility func for decorator
  64. # gets the name of the calling script
  65. tmp_sys = __import__('sys')
  66. return tmp_sys.argv[0]
  67. if __name__ == '__main__':
  68. pass