Skip to content

Commit

Permalink
closes chriskiehl#147 - support function reference in default arg; fi…
Browse files Browse the repository at this point in the history
…xed nargs behavior in textfields
  • Loading branch information
chriskiehl committed Apr 18, 2016
1 parent e9a6afe commit f886428
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion gooey/python_bindings/argparse_to_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,23 @@ def as_json(action, widget, required):
'nargs': action.nargs or '',
'commands': action.option_strings,
'choices': action.choices or [],
'default': action.default
'default': clean_default(widget, action.default)
}
}

def clean_default(widget_type, default):
'''
Attemps to safely coalesce the default value down to
a valid JSON type.
See: Issue #147.
function references supplied as arguments to the
`default` parameter in Argparse cause errors in Gooey.
'''
if widget_type != 'CheckBox':
return default.__name__ if callable(default) else default
# checkboxes must be handled differently, as they
# must be forced down to a boolean value
return default if isinstance(default, bool) else False


0 comments on commit f886428

Please sign in to comment.