Skip to content

Commit

Permalink
Merge pull request #9 from molssi-seamm/dev
Browse files Browse the repository at this point in the history
Improved handling of choices for parameters, in support of Web GUI.
  • Loading branch information
seamm authored Oct 21, 2023
2 parents 94f4513 + 7614473 commit 8c81f6c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

2023.10.21: Improved handling of choices
* When editing the choices for a parameter, the entryfield now accepts the choices
separated by spaces. If a choice has spaces or other special characters they can be
protected with quotes or backslash in the normal fashion for shell arguments.

2023.7.10: Bugfix handling parameters with 0+ values

* The default was not correctly handled for control parameters with 0+ arguments,
Expand Down
7 changes: 6 additions & 1 deletion control_parameters_step/control_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,17 @@ def create_parser(self):
else:
name = dest
nargs = nargs_values[data["nargs"]]

# Compatibility for old flowcharts
if isinstance(data["choices"], str):
data["choices"] = json.loads(data["choices"])

choices = data["choices"]
if choices == "":
choices = None
else:
# choices is a string representation of a list
choices = json.loads(choices.replace("'", '"'))
# choices = json.loads(choices.replace("'", '"'))
if len(choices) == 0:
choices = None

Expand Down
19 changes: 17 additions & 2 deletions control_parameters_step/tk_control_parameters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

"""The graphical part of a Control Parameters step"""
import json
import shlex

import seamm
from seamm_util import ureg, Q_, units_class # noqa: F401
Expand Down Expand Up @@ -129,6 +131,7 @@ def create_dialog(self):
self["variables"] = sw.ScrolledColumns(
frame,
columns=[
"",
"",
"Name",
"Type",
Expand Down Expand Up @@ -241,6 +244,15 @@ def edit(self):

P = self.node.parameters
self._variables = P["variables"].value

# Turn choices into simple strings
for data in self._variables.values():
# Compatibility for old flowcharts
if isinstance(data["choices"], str):
data["choices"] = json.loads(data["choices"])

data["choices"] = shlex.join(data["choices"])

self.reset_dialog()
self.reset_table()

Expand Down Expand Up @@ -281,8 +293,11 @@ def handle_dialog(self, result):
# Shortcut for parameters
P = self.node.parameters

# Get the values for all the widgets.
# Get the values for all the widgets, fixing up choices
for data in self._variables.values():
data["choices"] = shlex.split(data["choices"])
P["variables"].value = self._variables

self._variables = None

for key in P:
Expand Down Expand Up @@ -314,7 +329,7 @@ def add_variable(self):
self._new["nargs"].set("a single value")
self._new["overwrite"].set("No")
self._new["default"].set("")
self._new["choices"].set("[]")
self._new["choices"].set("")
self._new["help"].set("")

self._new_variable_dialog.activate(geometry="centerscreenfirst")
Expand Down

0 comments on commit 8c81f6c

Please sign in to comment.