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.

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