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.

158 lines
6.6 KiB

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
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
  1. import os
  2. import sys
  3. import signal
  4. import warnings
  5. import textwrap
  6. from gooey.python_bindings import argparse_to_json
  7. from gooey.gui.util.quoting import quote
  8. from gooey.python_bindings import constants
  9. from gooey.python_bindings import gooey_decorator
  10. from gooey.gui.util.functional import merge_dictionaries
  11. default_layout = {
  12. 'widgets': [{
  13. 'type': 'CommandField',
  14. 'required': True,
  15. 'data': {
  16. 'display_name': 'Enter Commands',
  17. 'help': 'Enter command line arguments',
  18. 'nargs': '',
  19. 'commands': '',
  20. 'choices': [],
  21. 'default': None,
  22. }
  23. }],
  24. }
  25. def create_from_parser(parser, source_path, **kwargs):
  26. run_cmd = kwargs.get('target')
  27. if run_cmd is None:
  28. if hasattr(sys, 'frozen'):
  29. run_cmd = quote(source_path)
  30. else:
  31. run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path))
  32. build_spec = {
  33. 'language': kwargs.get('language', 'english'),
  34. 'target': run_cmd,
  35. # when running with a custom target, there is no need to inject
  36. # --ignore-gooey into the CLI args
  37. 'suppress_gooey_flag': kwargs.get('suppress_gooey_flag') or False,
  38. 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''),
  39. 'program_description': kwargs.get('program_description') or '',
  40. 'sidebar_title': kwargs.get('sidebar_title', 'Actions'),
  41. 'default_size': kwargs.get('default_size', (610, 530)),
  42. 'auto_start': kwargs.get('auto_start', False),
  43. 'show_advanced': kwargs.get('advanced', True),
  44. 'run_validators': kwargs.get('run_validators', True),
  45. 'encoding': kwargs.get('encoding', 'utf-8'),
  46. 'show_stop_warning': kwargs.get('show_stop_warning', True),
  47. 'show_success_modal': kwargs.get('show_success_modal', True),
  48. 'show_failure_modal': kwargs.get('show_failure_modal', True),
  49. 'force_stop_is_error': kwargs.get('force_stop_is_error', True),
  50. 'poll_external_updates':kwargs.get('poll_external_updates', False),
  51. 'return_to_config': kwargs.get('return_to_config', False),
  52. 'show_restart_button': kwargs.get('show_restart_button', True),
  53. 'requires_shell': kwargs.get('requires_shell', True),
  54. 'menu': kwargs.get('menu', []),
  55. 'clear_before_run': kwargs.get('clear_before_run', False),
  56. 'fullscreen': kwargs.get('fullscreen', False),
  57. # Legacy/Backward compatibility interop
  58. 'use_legacy_titles': kwargs.get('use_legacy_titles', True),
  59. 'num_required_cols': kwargs.get('required_cols', 1),
  60. 'num_optional_cols': kwargs.get('optional_cols', 3),
  61. 'manual_start': False,
  62. 'monospace_display': kwargs.get('monospace_display', False),
  63. 'image_dir': kwargs.get('image_dir'),
  64. 'language_dir': kwargs.get('language_dir'),
  65. 'progress_regex': kwargs.get('progress_regex'),
  66. 'progress_expr': kwargs.get('progress_expr'),
  67. 'hide_progress_msg': kwargs.get('hide_progress_msg', False),
  68. 'timing_options': merge_dictionaries(gooey_decorator.defaults.get('timing_options'),kwargs.get('timing_options')),
  69. 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'),
  70. 'disable_stop_button': kwargs.get('disable_stop_button'),
  71. 'shutdown_signal': kwargs.get('shutdown_signal', signal.SIGTERM),
  72. # Layouts
  73. 'navigation': kwargs.get('navigation', constants.SIDEBAR),
  74. 'show_sidebar': kwargs.get('show_sidebar', False),
  75. 'tabbed_groups': kwargs.get('tabbed_groups', False),
  76. 'group_by_type': kwargs.get('group_by_type', True),
  77. # styles
  78. 'body_bg_color': kwargs.get('body_bg_color', '#f0f0f0'),
  79. 'header_bg_color': kwargs.get('header_bg_color', '#ffffff'),
  80. 'header_height': kwargs.get('header_height', 90),
  81. 'header_show_title': kwargs.get('header_show_title', True),
  82. 'header_show_subtitle': kwargs.get('header_show_subtitle', True),
  83. 'header_image_center': kwargs.get('header_image_center', False),
  84. 'footer_bg_color': kwargs.get('footer_bg_color', '#f0f0f0'),
  85. 'sidebar_bg_color': kwargs.get('sidebar_bg_color', '#f2f2f2'),
  86. # font family, weight, and size are determined at runtime
  87. 'terminal_panel_color': kwargs.get('terminal_panel_color', '#F0F0F0'),
  88. 'terminal_font_color': kwargs.get('terminal_font_color', '#000000'),
  89. 'terminal_font_family': kwargs.get('terminal_font_family', None),
  90. 'terminal_font_weight': get_font_weight(kwargs),
  91. 'terminal_font_size': kwargs.get('terminal_font_size', None),
  92. 'richtext_controls': kwargs.get('richtext_controls', False),
  93. 'error_color': kwargs.get('error_color', '#ea7878')
  94. }
  95. if build_spec['monospace_display']:
  96. warnings.warn('Gooey Option `monospace_display` is a legacy option.\n'
  97. 'See the terminal_font_x options for more flexible control '
  98. 'over Gooey\'s text formatting')
  99. build_spec['program_description'] = build_spec['program_description'] or parser.description or ''
  100. layout_data = (argparse_to_json.convert(parser, **build_spec)
  101. if build_spec['show_advanced']
  102. else default_layout.items())
  103. build_spec.update(layout_data)
  104. if len(build_spec['widgets']) > 1:
  105. # there are subparsers involved
  106. build_spec['show_sidebar'] = True
  107. return build_spec
  108. def get_font_weight(kwargs):
  109. error_msg = textwrap.dedent('''
  110. Unknown font weight {}.
  111. The available weights can be found in the `constants` module.
  112. They're prefixed with "FONTWEIGHT" (e.g. `FONTWEIGHT_BOLD`)
  113. example code:
  114. ```
  115. from gooey import constants
  116. @Gooey(terminal_font_weight=constants.FONTWEIGHT_NORMAL)
  117. ```
  118. ''')
  119. weights = {
  120. constants.FONTWEIGHT_THIN,
  121. constants.FONTWEIGHT_EXTRALIGHT,
  122. constants.FONTWEIGHT_LIGHT,
  123. constants.FONTWEIGHT_NORMAL,
  124. constants.FONTWEIGHT_MEDIUM,
  125. constants.FONTWEIGHT_SEMIBOLD,
  126. constants.FONTWEIGHT_BOLD,
  127. constants.FONTWEIGHT_EXTRABOLD,
  128. constants.FONTWEIGHT_HEAVY,
  129. constants.FONTWEIGHT_EXTRAHEAVY
  130. }
  131. weight = kwargs.get('terminal_font_weight', constants.FONTWEIGHT_NORMAL)
  132. if weight not in weights:
  133. raise ValueError(error_msg.format(weight))
  134. return weight