def create_from_parser(parser, source_path, **kwargs): auto_start = kwargs.get('auto_start', False) if hasattr(sys, 'frozen'): run_cmd = quote(source_path) else: run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path)) build_spec = { 'language': kwargs.get('language', 'english'), 'target': run_cmd, 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''), 'program_description': kwargs.get('program_description', ''), 'auto_start': kwargs.get('auto_start', False), 'show_advanced': kwargs.get('advanced', True), 'default_size': kwargs.get('default_size', (610, 530)), 'num_required_cols': kwargs.get('required_cols', 1), 'num_optional_cols': kwargs.get('optional_cols', 3), 'manual_start': False, 'layout_type': 'flat', 'monospace_display': kwargs.get('monospace_display', False), 'image_dir': kwargs.get('image_dir'), 'language_dir': kwargs.get('language_dir'), 'progress_regex': kwargs.get('progress_regex'), 'progress_expr': kwargs.get('progress_expr'), 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'), 'disable_stop_button': kwargs.get('disable_stop_button'), 'group_by_type': kwargs.get('group_by_type', True) } if not auto_start: build_spec['program_description'] = parser.description or build_spec[ 'program_description'] layout_data = argparse_to_json.convert( parser) if build_spec['show_advanced'] else list( layouts.basic_config.items()) build_spec.update(layout_data) return build_spec
def test_version_maps_to_checkbox(self): testcases = [ [['--version'], {}, 'TextField'], # we only remap if the action is version # i.e. we don't care about the argument name itself [['--version'], { 'action': 'store' }, 'TextField'], # should get mapped to CheckBox becuase of the action [['--version'], { 'action': 'version' }, 'CheckBox'], # ditto, even through the 'name' isn't 'version' [['--foobar'], { 'action': 'version' }, 'CheckBox'], ] for args, kwargs, expectedType in testcases: with self.subTest([args, kwargs]): parser = argparse.ArgumentParser(prog='test') parser.add_argument(*args, **kwargs) result = argparse_to_json.convert(parser, num_required_cols=2, num_optional_cols=2) contents = getin(result, ['widgets', 'test', 'contents'])[0] self.assertEqual(contents['items'][0]['type'], expectedType)
def create_from_parser(parser, source_path, **kwargs): run_cmd = kwargs.get('target') if run_cmd is None: if hasattr(sys, 'frozen'): run_cmd = quote(source_path) else: run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path)) build_spec = {**kwargs, 'target': run_cmd} if build_spec['monospace_display']: warnings.warn( 'Gooey Option `monospace_display` is a legacy option.\n' 'See the terminal_font_x options for more flexible control ' 'over Gooey\'s text formatting') build_spec['program_description'] = build_spec[ 'program_description'] or parser.description or '' layout_data = (argparse_to_json.convert(parser, **build_spec) if build_spec['advanced'] else default_layout.items()) build_spec.update(layout_data) if len(build_spec['widgets']) > 1: # there are subparsers involved build_spec['show_sidebar'] = True return build_spec
def inner(): main_module_path = get_caller_path() _, filename = os.path.split(main_module_path) cleaned_source = clean_source(main_module_path) filepath = os.path.join(TMP_DIR, filename) with open(filepath, 'w') as f: f.write(cleaned_source) run_cmd = 'python {}'.format(filepath) # Must be called before anything else app = wx.App(False) i18n.load(language) # load gui components after loading the language pack from gooey.gui.client_app import ClientApp from gooey.gui.client_app import EmptyClientApp from gooey.gui.windows.base_window import BaseWindow from gooey.gui.windows.advanced_config import AdvancedConfigPanel from gooey.gui.windows.basic_config_panel import BasicConfigPanel if show_config: parser = get_parser(main_module_path) meta = { 'target': run_cmd, 'program_name': program_name, 'program_description': program_description or parser.description, 'show_config': show_config, 'show_advanced': advanced, 'default_size': (610, 530), 'requireds_cols': 1, 'optionals_cols': 2 } client_app = ClientApp(parser, payload) build_spec = dict(meta.items() + argparse_to_json.convert(parser).items()) if advanced: BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) else: BodyPanel = BasicConfigPanel # User doesn't want to display configuration screen # Just jump straight to the run panel else: BodyPanel = BasicConfigPanel client_app = EmptyClientApp(payload) frame = BaseWindow(BodyPanel, build_spec, params) if not show_config: frame.ManualStart() frame.Show(True) app.MainLoop()
def test_suppress_is_removed_as_default_value(self): """ Issue #469 Argparse uses the literal string ==SUPPRESS== as an internal flag. When encountered in Gooey, these should be dropped and mapped to `None`. """ parser = ArgumentParser(prog='test_program') parser.add_argument("--foo", default=argparse.SUPPRESS) parser.add_argument('--version', action='version', version='1.0') result = argparse_to_json.convert(parser, required_cols=2, optional_cols=2) groups = getin(result, ['widgets', 'test_program', 'contents']) for item in groups[0]['items']: self.assertEqual(getin(item, ['data', 'default']), None)
def create_from_parser(parser, source_path, **kwargs): show_config = kwargs.get('show_config', False) if hasattr(sys, 'frozen'): run_cmd = quote(source_path) else: run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path)) build_spec = { 'language': kwargs.get('language', 'english'), 'target': run_cmd, 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''), 'program_description': kwargs.get('program_description', ''), 'show_config': show_config, 'show_advanced': kwargs.get('advanced', True), 'default_size': kwargs.get('default_size', (610, 530)), 'num_required_cols': kwargs.get('required_cols', 1), 'num_optional_cols': kwargs.get('optional_cols', 3), 'manual_start': False, 'layout_type': 'flat', 'monospace_display': kwargs.get('monospace_display', False), 'image_dir': kwargs.get('image_dir'), 'language_dir': kwargs.get('language_dir'), 'progress_regex': kwargs.get('progress_regex'), 'progress_expr': kwargs.get('progress_expr'), 'progress_consume_line': kwargs.get('progress_consume_line'), 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'), 'disable_stop_button': kwargs.get('disable_stop_button'), } if show_config: build_spec['program_description'] = parser.description or build_spec['program_description'] layout_data = argparse_to_json.convert(parser) if build_spec['show_advanced'] else layouts.basic_config.items() build_spec.update(layout_data) else: build_spec['manual_start'] = True return build_spec
def create_from_parser(parser, source_path, **kwargs): run_cmd = kwargs.get('target') if run_cmd is None: if hasattr(sys, 'frozen'): run_cmd = quote(source_path) else: run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path)) build_spec = { 'language': kwargs.get('language', 'english'), 'target': run_cmd, # when running with a custom target, there is no need to inject # --ignore-gooey into the CLI args 'suppress_gooey_flag': kwargs.get('suppress_gooey_flag') or False, 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''), 'program_description': kwargs.get('program_description') or '', 'sidebar_title': kwargs.get('sidebar_title', 'Actions'), 'default_size': kwargs.get('default_size', (610, 530)), 'auto_start': kwargs.get('auto_start', False), 'show_advanced': kwargs.get('advanced', True), 'run_validators': kwargs.get('run_validators', True), 'encoding': kwargs.get('encoding', 'utf-8'), 'show_stop_warning': kwargs.get('show_stop_warning', True), 'show_success_modal': kwargs.get('show_success_modal', True), 'show_failure_modal': kwargs.get('show_failure_modal', True), 'force_stop_is_error': kwargs.get('force_stop_is_error', True), 'poll_external_updates': kwargs.get('poll_external_updates', False), 'return_to_config': kwargs.get('return_to_config', False), 'show_restart_button': kwargs.get('show_restart_button', True), 'requires_shell': kwargs.get('requires_shell', True), 'menu': kwargs.get('menu', []), 'clear_before_run': kwargs.get('clear_before_run', False), 'fullscreen': kwargs.get('fullscreen', False), # Legacy/Backward compatibility interop 'use_legacy_titles': kwargs.get('use_legacy_titles', True), 'num_required_cols': kwargs.get('required_cols', 1), 'num_optional_cols': kwargs.get('optional_cols', 3), 'manual_start': False, 'monospace_display': kwargs.get('monospace_display', False), 'image_dir': kwargs.get('image_dir'), 'language_dir': kwargs.get('language_dir'), 'progress_regex': kwargs.get('progress_regex'), 'progress_expr': kwargs.get('progress_expr'), 'hide_progress_msg': kwargs.get('hide_progress_msg', False), 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'), 'disable_stop_button': kwargs.get('disable_stop_button'), # Layouts 'navigation': kwargs.get('navigation', constants.SIDEBAR), 'show_sidebar': kwargs.get('show_sidebar', False), 'tabbed_groups': kwargs.get('tabbed_groups', False), 'group_by_type': kwargs.get('group_by_type', True), # styles 'body_bg_color': kwargs.get('body_bg_color', '#f0f0f0'), 'header_bg_color': kwargs.get('header_bg_color', '#ffffff'), 'header_height': kwargs.get('header_height', 90), 'header_show_title': kwargs.get('header_show_title', True), 'header_show_subtitle': kwargs.get('header_show_subtitle', True), 'header_image_center': kwargs.get('header_image_center', False), 'footer_bg_color': kwargs.get('footer_bg_color', '#f0f0f0'), 'sidebar_bg_color': kwargs.get('sidebar_bg_color', '#f2f2f2'), # font family, weight, and size are determined at runtime 'terminal_panel_color': kwargs.get('terminal_panel_color', '#F0F0F0'), 'terminal_font_color': kwargs.get('terminal_font_color', '#000000'), 'terminal_font_family': kwargs.get('terminal_font_family', None), 'terminal_font_weight': kwargs.get('terminal_font_weight', None), 'terminal_font_size': kwargs.get('terminal_font_size', None), 'richtext_controls': kwargs.get('richtext_controls', False), 'error_color': kwargs.get('error_color', '#ea7878') } if build_spec['monospace_display']: warnings.warn( 'Gooey Option `monospace_display` is a legacy option.\n' 'See the terminal_font_x options for more flexible control ' 'over Gooey\'s text formatting') build_spec['program_description'] = build_spec[ 'program_description'] or parser.description or '' layout_data = (argparse_to_json.convert(parser, **build_spec) if build_spec['show_advanced'] else default_layout.items()) build_spec.update(layout_data) if len(build_spec['widgets']) > 1: # there are subparsers involved build_spec['show_sidebar'] = True return build_spec
def inner(): show_config = params['show_config'] #because nonlocal keyword doesn't exist yet :( main_module_path = get_caller_path() _, filename = os.path.split(main_module_path) cleaned_source = clean_source(main_module_path) descriptor, tmp_filepath = tempfile.mkstemp(suffix='.py') atexit.register(cleanup, descriptor, tmp_filepath) with open(tmp_filepath, 'w') as f: f.write(cleaned_source) if not has_argparse(cleaned_source): show_config = False run_cmd = 'python {}'.format(tmp_filepath) # Must be called before anything else app = wx.App(False) i18n.load(language) # load gui components after loading the language pack from gooey.gui.client_app import ClientApp from gooey.gui.client_app import EmptyClientApp from gooey.gui.windows.base_window import BaseWindow from gooey.gui.windows.advanced_config import AdvancedConfigPanel from gooey.gui.windows.basic_config_panel import BasicConfigPanel meta = { 'target': run_cmd, 'program_name': program_name, 'program_description': program_description or '', 'show_config': show_config, 'show_advanced': advanced, 'default_size': (610, 530), 'requireds_cols': 1, 'optionals_cols': 2, 'manual_start': False } if show_config: parser = get_parser(main_module_path) meta['program_description'] = parser.description or program_description client_app = ClientApp(parser, payload) if advanced: build_spec = dict(meta.items() + argparse_to_json.convert(parser).items()) BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) else: build_spec = dict(meta.items() + layouts.basic_config.items()) BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) # User doesn't want to display configuration screen # Just jump straight to the run panel else: build_spec = dict(meta.items() + layouts.basic_config.items()) build_spec['manual_start'] = True BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) client_app = EmptyClientApp(payload) frame = BaseWindow(BodyPanel, build_spec, params) if not show_config: frame.ManualStart() frame.Show(True) app.MainLoop()
def inner(): show_config = params[ 'show_config'] #because nonlocal keyword doesn't exist yet :( main_module_path = get_caller_path() _, filename = os.path.split(main_module_path) cleaned_source = clean_source(main_module_path) descriptor, tmp_filepath = tempfile.mkstemp(suffix='.py') atexit.register(cleanup, descriptor, tmp_filepath) with open(tmp_filepath, 'w') as f: f.write(cleaned_source) if not has_argparse(cleaned_source): show_config = False run_cmd = 'python {}'.format(tmp_filepath) # Must be called before anything else app = wx.App(False) i18n.load(language) # load gui components after loading the language pack from gooey.gui.client_app import ClientApp from gooey.gui.client_app import EmptyClientApp from gooey.gui.windows.base_window import BaseWindow from gooey.gui.windows.advanced_config import AdvancedConfigPanel from gooey.gui.windows.basic_config_panel import BasicConfigPanel meta = { 'target': run_cmd, 'program_name': program_name, 'program_description': program_description or '', 'show_config': show_config, 'show_advanced': advanced, 'default_size': (610, 530), 'requireds_cols': 1, 'optionals_cols': 2, 'manual_start': False } if show_config: parser = get_parser(main_module_path) meta[ 'program_description'] = parser.description or program_description client_app = ClientApp(parser, payload) if advanced: build_spec = dict(meta.items() + argparse_to_json.convert(parser).items()) BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) else: build_spec = dict(meta.items() + layouts.basic_config.items()) BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) # User doesn't want to display configuration screen # Just jump straight to the run panel else: build_spec = dict(meta.items() + layouts.basic_config.items()) build_spec['manual_start'] = True BodyPanel = partial(AdvancedConfigPanel, build_spec=build_spec) client_app = EmptyClientApp(payload) frame = BaseWindow(BodyPanel, build_spec, params) if not show_config: frame.ManualStart() frame.Show(True) app.MainLoop()
def create_from_parser(parser, source_path, **kwargs): run_cmd = kwargs.get('target') if run_cmd is None: if hasattr(sys, 'frozen'): run_cmd = quote(source_path) else: run_cmd = '{} -u {}'.format(quote(sys.executable), quote(source_path)) build_spec = { 'language': kwargs.get('language', 'english'), 'target': run_cmd, 'program_name': kwargs.get('program_name') or os.path.basename(sys.argv[0]).replace('.py', ''), 'program_description': kwargs.get('program_description') or '', 'sidebar_title': kwargs.get('sidebar_title', 'Actions'), 'default_size': kwargs.get('default_size', (610, 530)), 'auto_start': kwargs.get('auto_start', False), 'show_advanced': kwargs.get('advanced', True), 'run_validators': kwargs.get('run_validators', True), 'encoding': kwargs.get('encoding', 'utf-8'), 'show_stop_warning': kwargs.get('show_stop_warning', True), 'show_success_modal': kwargs.get('show_success_modal', True), 'force_stop_is_error': kwargs.get('force_stop_is_error', True), 'poll_external_updates':kwargs.get('poll_external_updates', False), 'return_to_config': kwargs.get('return_to_config', False), # Legacy/Backward compatibility interop 'use_legacy_titles': kwargs.get('use_legacy_titles', True), 'num_required_cols': kwargs.get('required_cols', 1), 'num_optional_cols': kwargs.get('optional_cols', 3), 'manual_start': False, 'monospace_display': kwargs.get('monospace_display', False), 'image_dir': kwargs.get('image_dir'), 'language_dir': kwargs.get('language_dir'), 'progress_regex': kwargs.get('progress_regex'), 'progress_expr': kwargs.get('progress_expr'), 'disable_progress_bar_animation': kwargs.get('disable_progress_bar_animation'), 'disable_stop_button': kwargs.get('disable_stop_button'), # Layouts 'navigation': kwargs.get('navigation', constants.SIDEBAR), 'show_sidebar': kwargs.get('show_sidebar', False), 'tabbed_groups': kwargs.get('tabbed_groups', False), 'group_by_type': kwargs.get('group_by_type', True), # styles 'body_bg_color': kwargs.get('body_bg_color', '#f0f0f0'), 'header_bg_color': kwargs.get('header_bg_color', '#ffffff'), 'header_height': kwargs.get('header_height', 90), 'header_show_title': kwargs.get('header_show_title', True), 'header_show_subtitle': kwargs.get('header_show_subtitle', True), 'header_image_center': kwargs.get('header_image_center', False), 'footer_bg_color': kwargs.get('footer_bg_color', '#f0f0f0'), 'sidebar_bg_color': kwargs.get('sidebar_bg_color', '#f2f2f2'), # font family, weight, and size are determined at runtime 'terminal_panel_color': kwargs.get('terminal_panel_color', '#F0F0F0'), 'terminal_font_color': kwargs.get('terminal_font_color', '#000000'), 'terminal_font_family': kwargs.get('terminal_font_family', None), 'terminal_font_weight': kwargs.get('terminal_font_weight', None), 'terminal_font_size': kwargs.get('terminal_font_size', None), 'error_color': kwargs.get('error_color', '#ea7878') } if build_spec['monospace_display']: warnings.warn('Gooey Option `monospace_display` is a legacy option.\n' 'See the terminal_font_x options for more flexible control ' 'over Gooey\'s text formatting') build_spec['program_description'] = parser.description or build_spec['program_description'] layout_data = (argparse_to_json.convert(parser, **build_spec) if build_spec['show_advanced'] else default_layout.items()) build_spec.update(layout_data) if len(build_spec['widgets']) > 1: # there are subparsers involved build_spec['show_sidebar'] = True return build_spec