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.

148 lines
4.7 KiB

11 years ago
9 years ago
11 years ago
9 years ago
Elapsed / Remaining Time on Progress Bar parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Jack McKew <jackmckew2@gmail.com> 1594344614 +1000 committer Jack McKew <jackmckew2@gmail.com> 1594346638 +1000 Elapsed / Remaining Time on Progress Bar parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246420 +1000 parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246359 +1000 Elapsed / Remaining Time on Progress Bar Elapsed / Remaining Time on Progress Bar Time Remaining Text for Progress Time remaining somewhat working Time format working Add tests and pythn 2.7 compat Incase python 2 import perf counter in func Fix flickering text and align Remove transactUI Add new decorators Update time remaining notes in README Amend tests with new arguments Remove unused import Separate into time module Move to dictionary structure options Explicitly show time text Amend tests for separate module Integration test - missing on complete tests Remove old code Elapsed / Remaining Time on Progress Bar parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246420 +1000 parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246359 +1000 Elapsed / Remaining Time on Progress Bar Elapsed / Remaining Time on Progress Bar Time Remaining Text for Progress Time remaining somewhat working Time format working Add tests and pythn 2.7 compat Incase python 2 import perf counter in func Fix flickering text and align Remove transactUI Add new decorators Update time remaining notes in README Amend tests with new arguments Remove unused import Separate into time module Move to dictionary structure options Explicitly show time text Amend tests for separate module Remove old code Pass testdata as dict instead of kwargs Merge dictionaries for defaults Test almost working Delete settings.json Revert "Test almost working" This reverts commit f17d50681cae664719f67a7e8cc0b1feaf1ac4c7. Back to working state Remove unhelpful test Update docs Working without updated test Add tests for time remaining text Elapsed / Remaining Time on Progress Bar parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Jack McKew <jackmckew2@gmail.com> 1594344614 +1000 committer Jack McKew <jackmckew2@gmail.com> 1594346638 +1000 Elapsed / Remaining Time on Progress Bar parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246420 +1000 parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246359 +1000 Elapsed / Remaining Time on Progress Bar Elapsed / Remaining Time on Progress Bar Time Remaining Text for Progress Time remaining somewhat working Time format working Add tests and pythn 2.7 compat Incase python 2 import perf counter in func Fix flickering text and align Remove transactUI Add new decorators Update time remaining notes in README Amend tests with new arguments Remove unused import Separate into time module Move to dictionary structure options Explicitly show time text Amend tests for separate module Integration test - missing on complete tests Remove old code Elapsed / Remaining Time on Progress Bar parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246420 +1000 parent 00e0f3e7c6434240ffe02522a0be2daf8c5b456c author Fizban <jackmckew2@gmail.com> 1593182730 +1000 committer Fizban <jackmckew2@gmail.com> 1593246359 +1000 Elapsed / Remaining Time on Progress Bar Elapsed / Remaining Time on Progress Bar Time Remaining Text for Progress Time remaining somewhat working Time format working Add tests and pythn 2.7 compat Incase python 2 import perf counter in func Fix flickering text and align Remove transactUI Add new decorators Update time remaining notes in README Amend tests with new arguments Remove unused import Separate into time module Move to dictionary structure options Explicitly show time text Amend tests for separate module Remove old code Pass testdata as dict instead of kwargs Merge dictionaries for defaults Test almost working Delete settings.json Revert "Test almost working" This reverts commit f17d50681cae664719f67a7e8cc0b1feaf1ac4c7. Back to working state Remove unhelpful test Update docs Working without updated test Add tests for time remaining text Remove artifact from squashing Amend artifacts Handle no progress and tidy up footer label
4 years ago
9 years ago
4 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.util.freeze import getResourcePath
  11. from gooey.util.functional import merge
  12. from . import config_generator
  13. from . import cmd_args
  14. IGNORE_COMMAND = '--ignore-gooey'
  15. # TODO: use these defaults in the decorator and migrate to a flat **kwargs
  16. # They're pulled out here for wiring up instances in the tests.
  17. # Some fiddling is needed before I can make the changes to make the swap to
  18. # `defaults` + **kwargs overrides.
  19. defaults = {
  20. 'advanced': True,
  21. 'language': 'english',
  22. 'auto_start': False, # TODO: add this to the docs. Used to be `show_config=True`
  23. 'target': None,
  24. 'program_name': None,
  25. 'program_description': None,
  26. 'default_size': (610, 530),
  27. 'use_legacy_titles': True,
  28. 'required_cols': 2,
  29. 'optional_cols': 2,
  30. 'dump_build_config': False,
  31. 'load_build_config': None,
  32. 'monospace_display': False, # TODO: add this to the docs
  33. 'image_dir': '::gooey/default',
  34. 'language_dir': getResourcePath('languages'),
  35. 'progress_regex': None, # TODO: add this to the docs
  36. 'progress_expr': None, # TODO: add this to the docs
  37. 'hide_progress_msg': False, # TODO: add this to the docs
  38. 'disable_progress_bar_animation': False,
  39. 'disable_stop_button': False,
  40. 'group_by_type': True,
  41. 'header_height': 80,
  42. 'navigation': 'SIDEBAR', # TODO: add this to the docs
  43. 'tabbed_groups': False,
  44. 'use_cmd_args': False,
  45. 'timing_options': {
  46. 'show_time_remaining': False,
  47. 'hide_time_remaining_on_complete': True
  48. }
  49. }
  50. # TODO: kwargs all the things
  51. def Gooey(f=None,
  52. advanced=True,
  53. language='english',
  54. auto_start=False, # TODO: add this to the docs. Used to be `show_config=True`
  55. target=None,
  56. program_name=None,
  57. program_description=None,
  58. default_size=(610, 530),
  59. use_legacy_titles=True,
  60. required_cols=2,
  61. optional_cols=2,
  62. dump_build_config=False,
  63. load_build_config=None,
  64. monospace_display=False, # TODO: add this to the docs
  65. image_dir='::gooey/default',
  66. language_dir=getResourcePath('languages'),
  67. progress_regex=None, # TODO: add this to the docs
  68. progress_expr=None, # TODO: add this to the docs
  69. hide_progress_msg=False, # TODO: add this to the docs
  70. disable_progress_bar_animation=False,
  71. disable_stop_button=False,
  72. group_by_type=True,
  73. header_height=80,
  74. navigation='SIDEBAR', # TODO: add this to the docs
  75. tabbed_groups=False,
  76. use_cmd_args=False,
  77. **kwargs):
  78. '''
  79. Decorator for client code's main function.
  80. Serializes argparse data to JSON for use with the Gooey front end
  81. '''
  82. params = merge(locals(), locals()['kwargs'])
  83. def build(payload):
  84. def run_gooey(self, args=None, namespace=None):
  85. # This import is delayed so it is not in the --ignore-gooey codepath.
  86. from gooey.gui import application
  87. source_path = sys.argv[0]
  88. build_spec = None
  89. if load_build_config:
  90. try:
  91. exec_dir = os.path.dirname(sys.argv[0])
  92. open_path = os.path.join(exec_dir,load_build_config)
  93. build_spec = json.load(open(open_path, "r"))
  94. except Exception as e:
  95. print('Exception loading Build Config from {0}: {1}'.format(load_build_config, e))
  96. sys.exit(1)
  97. if not build_spec:
  98. if use_cmd_args:
  99. cmd_args.parse_cmd_args(self, args)
  100. build_spec = config_generator.create_from_parser(
  101. self,
  102. source_path,
  103. payload_name=payload.__name__,
  104. **params)
  105. if dump_build_config:
  106. config_path = os.path.join(os.path.dirname(sys.argv[0]), 'gooey_config.json')
  107. print('Writing Build Config to: {}'.format(config_path))
  108. with open(config_path, 'w') as f:
  109. f.write(json.dumps(build_spec, indent=2))
  110. application.run(build_spec)
  111. def inner2(*args, **kwargs):
  112. ArgumentParser.original_parse_args = ArgumentParser.parse_args
  113. ArgumentParser.parse_args = run_gooey
  114. return payload(*args, **kwargs)
  115. inner2.__name__ = payload.__name__
  116. return inner2
  117. def run_without_gooey(func):
  118. return lambda *args, **kwargs: func(*args, **kwargs)
  119. if IGNORE_COMMAND in sys.argv:
  120. sys.argv.remove(IGNORE_COMMAND)
  121. if callable(f):
  122. return run_without_gooey(f)
  123. return run_without_gooey
  124. if callable(f):
  125. return build(f)
  126. return build
  127. if __name__ == '__main__':
  128. pass