P1sec / pycrate

A Python library to ease the development of encoders and decoders for various protocols and file formats; contains ASN.1 and CSN.1 compilers.
GNU Lesser General Public License v2.1
382 stars 132 forks source link

Question: Reasonable approach to constructing an editor #104

Open andyvan-trabus opened 4 years ago

andyvan-trabus commented 4 years ago

I have written an editor using PyCrate and PySimpleGUI that works well for editing existing fields in an object. It uses get_val_paths() to go through a message and construct a PySimpleGUI TreeData. This works well, and didn't take too long to implement.

However, it only allows changing fields that already exist. I'd like to extend this to allow changing a Choice, generating some minimal/default value for that choice, and then allowing the user to modify the newly created sub-fields.

Any suggestions on how to do this? My first thought is that I can borrow some of the get_proto code, but that seems a fair amount of work.

I've attached a screenshot showing the editor I have working now.

Screenshot from 2020-09-08 17-27-11

p1-bmu commented 4 years ago

When you set a value for a constructed type (CHOICE, SEQUENCE, SET) from scratch, you need to know all exact sub-components values. When working with such a graphical editor, it should propose a default values for all sub-components, that can be then edited further.

To initialize a value for a constructed type, you would need to go through all mandatory sub-components, assigning one default value in accordance with any existing constraint (value, size, content...) for each. What I would do myself is creating a common method to all ASN.1 types (e.g. set_default_val()): for classes defined in _asnobjbasic.py, _asnobjstr.py, _asnobjconstruct.py and eventually _asnobjext.py. In this way, calling such a method for a constructed object would just call it recursively to all its components. This is still quite a lot of work, as defining default values could be cumbersome for some ASN.1 objects and constraints.

p1-bmu commented 2 years ago

Sorry, I am coming back to this too. Did you implement something ? Feel free to open a PR. Otherwise we can just close the issue