Skip to content

Commit 6c50b8d

Browse files
feat: make mu*D optional by adding mutually exclusive group in cli and gui
1 parent 1a263b4 commit 6c50b8d

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

Diff for: src/diffpy/labpdfproc/labpdfprocapp.py

+28-15
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,8 @@
1313
from diffpy.utils.parsers.loaddata import loadData
1414

1515

16-
def define_arguments():
16+
def _define_arguments():
1717
args = [
18-
{
19-
"name": ["mud"],
20-
"help": "Value of mu*D for your sample. Required.",
21-
"type": float,
22-
},
2318
{
2419
"name": ["input"],
2520
"help": (
@@ -150,20 +145,37 @@ def define_arguments():
150145
),
151146
"default": None,
152147
},
153-
{
154-
"name": ["-z", "--z-scan-file"],
155-
"help": "Path to the z-scan file to be loaded "
156-
"to determine the mu*D value.",
157-
"default": None,
158-
"widget": "FileChooser",
159-
},
160148
]
161149
return args
162150

163151

152+
def _add_mud_selection_group(p, is_gui=False):
153+
"""Current Options:
154+
1. Manually enter muD (`--mud`).
155+
2. Estimate muD from a z-scan file (`-z` or `--z-scan-file`).
156+
"""
157+
g = p.add_argument_group("Options for setting mu*D value (Required)")
158+
g = g.add_mutually_exclusive_group(required=True)
159+
g.add_argument(
160+
"--mud",
161+
type=float,
162+
help="Enter the mu*D value manually.",
163+
**({"widget": "DecimalField"} if is_gui else {}),
164+
)
165+
g.add_argument(
166+
"-z",
167+
"--z-scan-file",
168+
help="Provide the path to the z-scan file to be loaded "
169+
"to determine the mu*D value.",
170+
**({"widget": "FileChooser"} if is_gui else {}),
171+
)
172+
return p
173+
174+
164175
def get_args(override_cli_inputs=None):
165176
p = ArgumentParser()
166-
for arg in define_arguments():
177+
p = _add_mud_selection_group(p, is_gui=False)
178+
for arg in _define_arguments():
167179
kwargs = {
168180
key: value
169181
for key, value in arg.items()
@@ -177,7 +189,8 @@ def get_args(override_cli_inputs=None):
177189
@Gooey(required_cols=1, optional_cols=1, program_name="Labpdfproc GUI")
178190
def gooey_parser():
179191
p = GooeyParser()
180-
for arg in define_arguments():
192+
p = _add_mud_selection_group(p, is_gui=True)
193+
for arg in _define_arguments():
181194
kwargs = {key: value for key, value in arg.items() if key != "name"}
182195
p.add_argument(*arg["name"], **kwargs)
183196
args = p.parse_args()

0 commit comments

Comments
 (0)