From 81033147956716981321da89b968a40345934e72 Mon Sep 17 00:00:00 2001 From: chriskiehl Date: Sat, 3 Oct 2015 14:52:59 -0400 Subject: [PATCH] Issue #103 - fixed bug where exclusive groups were being concatenated together --- gooey/python_bindings/argparse_to_json.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/gooey/python_bindings/argparse_to_json.py b/gooey/python_bindings/argparse_to_json.py index 8d0645e..b3d7386 100644 --- a/gooey/python_bindings/argparse_to_json.py +++ b/gooey/python_bindings/argparse_to_json.py @@ -13,6 +13,7 @@ from argparse import ( from collections import OrderedDict from functools import partial +from itertools import chain VALID_WIDGETS = ( 'FileChooser', @@ -56,13 +57,14 @@ def convert(parser): def process(parser, widget_dict): - mutually_exclusive_group = [ - mutex_action - for group_actions in parser._mutually_exclusive_groups - for mutex_action in group_actions._group_actions] + mutually_exclusive_groups = [ + [mutex_action for mutex_action in group_actions._group_actions] + for group_actions in parser._mutually_exclusive_groups] + + group_options = list(chain(*mutually_exclusive_groups)) base_actions = [action for action in parser._actions - if action not in mutually_exclusive_group + if action not in group_options and action.dest != 'help'] required_actions = filter(is_required, base_actions) @@ -70,7 +72,7 @@ def process(parser, widget_dict): return list(categorize(required_actions, widget_dict, required=True)) + \ list(categorize(optional_actions, widget_dict)) + \ - build_radio_group(mutually_exclusive_group) + map(build_radio_group, mutually_exclusive_groups) def categorize(actions, widget_dict, required=False): _get_widget = partial(get_widget, widgets=widget_dict) @@ -155,12 +157,12 @@ def build_radio_group(mutex_group): } for mutex_arg in mutex_group ] - return [{ + return { 'type': 'RadioGroup', 'group_name': 'Choose Option', 'required': False, 'data': options - }] + } def as_json(action, widget, required):