Skip to content

Commit

Permalink
Updated JsonParamsGui updating mechanism, and added schema update fun…
Browse files Browse the repository at this point in the history
…ction.

Updated documentation to match
  • Loading branch information
rhfogh committed Feb 13, 2024
1 parent 2ca415b commit 0159031
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 79 deletions.
40 changes: 17 additions & 23 deletions doc/json_schema_gui/update_indexing.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
{
"lattice": {
"options": {
"enum": [
"cP",
"cF",
"cI",
"Cubic"
]
},
"enum": [
"cP",
"cF",
"cI",
"Cubic"
],
"value": "cI"
},
"point_groups": {
"options": {
"enum": [
"23",
"432",
"23|432"
]
},
"enum": [
"23",
"432",
"23|432"
],
"value": "23|432"
},
"space_group": {
"options": {
"enum": [
"",
"I23",
"I213",
"I432",
"I4132"
]
},
"",
"I23",
"I213",
"I432",
"I4132"
],
"value": ""
}
}
46 changes: 21 additions & 25 deletions doc/json_schema_gui/update_lattice.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,29 @@
{
"point_groups": {
"options": {
"enum": [
"23",
"432",
"23|432"
]
},
"enum": [
"23",
"432",
"23|432"
],
"value": "23|432"
},
"space_group": {
"options": {
"enum": [
"",
"P23",
"F23",
"I23",
"P213",
"I213",
"P432",
"P4232",
"F432",
"F4132",
"I432",
"P4332",
"P4132",
"I4132"
]
},
"enum": [
"",
"P23",
"F23",
"I23",
"P213",
"I213",
"P432",
"P4232",
"F432",
"F4132",
"I432",
"P4332",
"P4132",
"I4132"
],
"value": ""
}
}
26 changes: 11 additions & 15 deletions doc/json_schema_gui/update_spacegroup.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
{
"point_groups": {
"options": {
"enum": [
"23",
"432",
"23|432"
]
},
"enum": [
"23",
"432",
"23|432"
],
"value": "432"
},
"space_group": {
"options": {
"enum": [
"",
"F23",
"F432",
"F4132"
]
},
"enum": [
"",
"F23",
"F432",
"F4132"
],
"value": "F432"
}
}
9 changes: 6 additions & 3 deletions docs/source/dev/json-schema-generated-user-interface.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
:Updated:
- 20230730
- 20230927
- 20240213

After the PRs for [mxcubecore #755](https://github.com/mxcube/mxcubecore/pull/755) and [mxcubeqt #442](https://github.com/mxcube/mxcubeqt/pull/442) we have a system for code-generated interfaces that can be plugged in to both a Qt and a Web user interface. It is implemented for Qt5, and with some help it should be possible to implement a (prototype?) web interface on the same basis. After discussion with [@marcusoscarsson](https://github.com/marcus-oscarsson) the PR is now refactored to do parameter updating on the server side only, sending values back and forth as necessary through signals. The newest version is through PRs [#794 (mxcubecore)](https://github.com/mxcube/mxcubecore/pull/794) and [#453 (mxcubeqt)](https://github.com/mxcube/mxcubeqt/pull/453).
We have a system for code-generated interfaces that can be plugged in to both a Qt and a Web user interface. It is implemented for Qt5, and (as of 20240213) just about ready for testing with the web interface.

The system is used to generate parameter queries from mxcubecore (for now from the GΦL workflow). It includes a wide range of widgets; multiple nested layout fields; support for custom update functions triggered when values are edited, that can reset values of other fields or change widget colouring; field value validation; and colouring and disabling of action for invalid widgets. There are several examples of pulldown menu contents being modified depending on the values of other fields. The system is started with a `PARAMETERS_NEEDED` on signals being sent from the mxcubecore side with the JSON schemas as parameters. The UI side responds by sending a `PARAMETER_RETURN_SIGNAL` with the complete dictionary of parameter values. There is also a control parameter, that determines whether the response matches a Continue or Cancel click (closing the UI popup), or whether it is a request for a UI update. In the latter case the update is sent from the mxcubecore side with a `PARAMETER_UPDATE_SIGNAL`.
The system is used to generate parameter queries from mxcubecore (for now from the GΦL workflow). It includes a wide range of widgets; multiple nested layout fields; support for custom update functions triggered when values are edited, that can reset values of other fields, change widget colouring and pulldown enums; field value validation; and colouring and disabling of action for invalid values. There are several examples of pulldown menu contents being modified depending on the values of other fields. The system is started with a `PARAMETERS_NEEDED` on signals being sent from the mxcubecore side with the JSON schemas as parameters. The UI side responds by sending a `PARAMETER_RETURN_SIGNAL` with the complete dictionary of parameter values. There is also a control parameter, that determines whether the response matches a Continue or Cancel click (closing the UI popup), or whether it is a request for a UI update. In the latter case the update is sent from the mxcubecore side with a `PARAMETER_UPDATE_SIGNAL`.

I have done my best to follow the correct practice of using JSON schemas to specify user interfaces – but possibly with mixed success. The documentation I could find was neither as clear nor as comprehensive as is the case for Qt (where it is already hard to find what you need), and the capabilities of the proposed system go rather beyond what you see in web examples. The main documentation used has been <https://rjsf-team.github.io/react-jsonschema-form/>, <https://github.com/jsonform/jsonform/wiki>, <https://www.npmjs.com/package/react-jsonschema-form-layout>, <https://ui-schema.bemit.codes/>, <https://react-jsonschema-form.readthedocs.io/en/v1.8.1/form-customization/>. Ultimately I had to invent a certain amount, which may then be inconsistent with web libraries and best practices. Hopefully someone more familiar with JSON-schema and web practice would be able to find a more correct way of handling some of the problems. One advantage is that since this system is purely internal to MXCuBE-Qt so far it can (and will) be changed to conform to the needs of the web implementation.
The form of the JSON schemas used has been agreed between Rasmus Foghy, Jean-Baptiste FLorial, an MArcus Oscarsson. Hopefully it fits with standard practices.

The only really detailed documentation available is the Qt implementation, which serves as a worked example. The attached files show screenshots of the generated interfaces (with some examples of e.g. widget colouring); the JSON schemas that generate them can be found in the mxcubecore repository, in `mxcubecore/doc/json_schema_gui` as can the parameters returned, and some examples of the response to gui update requests.

It should be noted that the widget update machinery supports (only) the tags 'value', 'highlight' and 'enum'. Other ooptions like 'readonly', 'is_hiddden', or 'limits' could be added later, if desired.


## Implementation

Expand Down
17 changes: 4 additions & 13 deletions mxcubecore/HardwareObjects/Gphl/GphlWorkflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2765,14 +2765,8 @@ def update_lattice(self, values):
sgoptions = [""] + crystal_symmetry.space_groups_from_params()
sgvalue = space_group
result = {
"point_groups": {
"value": pgvalue,
"options": {"enum": pglist,},
},
"space_group": {
"value": sgvalue,
"options": {"enum": sgoptions,},
},
"point_groups": {"value": pgvalue, "enum": pglist,},
"space_group": {"value": sgvalue, "enum": sgoptions,},
}
#
return result
Expand All @@ -2786,10 +2780,7 @@ def update_point_groups(self, values):
)
value = ""
result = {
"space_group": {
"value": value,
"options": {"enum": sglist},
},
"space_group": {"value": value, "enum": sglist},
}
#
return result
Expand Down Expand Up @@ -2830,7 +2821,7 @@ def update_indexing_solution(self, values):
result = self.update_lattice(values1)
result["lattice"] = {
"value": lattice,
"options": {"enum":alternative_lattices[lattice]}
"enum":alternative_lattices[lattice],
}
break
else:
Expand Down

0 comments on commit 0159031

Please sign in to comment.