Browse Source

closes #147 - support function reference in default arg; fixed nargs behavior in textfields

pull/160/head
chriskiehl 8 years ago
parent
commit
f886428bef
1 changed files with 15 additions and 1 deletions
  1. 16
      gooey/python_bindings/argparse_to_json.py

16
gooey/python_bindings/argparse_to_json.py

@ -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
Loading…
Cancel
Save