|
| 1 | +# Main usage |
| 2 | +As shown in the example, the main use of this library is as follows: |
| 3 | + |
| 4 | +```python3 |
| 5 | +from qt_jsonschema_form import WidgetBuilder |
| 6 | +builder = WidgetBuilder() |
| 7 | +form = builder.create_form(schema, ui_schema) |
| 8 | +form.show() |
| 9 | +form.widget.state = default_value |
| 10 | +``` |
| 11 | +You can then apply a method `fn(json_value)` to the JSON value each time a change |
| 12 | +is done by doing: |
| 13 | +```python3 |
| 14 | +form.widget.on_changed.connect(fn) |
| 15 | +``` |
| 16 | +and you can access to the current json value using |
| 17 | +```python3 |
| 18 | +form.widget.state |
| 19 | +```. |
| 20 | +
|
| 21 | +# Variants |
| 22 | +JSON's type is extremely vague. For example decimal (floating point) |
| 23 | +number and integral numbers have the same type. In order to decide |
| 24 | +which widget the user see, this library uses "variant". A variant is a |
| 25 | +name stating which kind of widget should be used to display a value to |
| 26 | +the user and let them change it. A variant can only be assigned to an |
| 27 | +element of an object, it is determined by the property name and the |
| 28 | +parameter ui_schema. TODO: why? |
| 29 | + |
| 30 | +Each type has the variant "enum". If this variant is used for a |
| 31 | +schema, this schema must have an "enum" property. Each element of this |
| 32 | +property will be displayed in a `QComboBox`. We now list the other |
| 33 | +variants. |
| 34 | + |
| 35 | +## Boolean |
| 36 | +The only other variant of "boolean" is "checkbox", which is |
| 37 | +implemented using a `QCheckBox` |
| 38 | + |
| 39 | +## Object |
| 40 | +The only other variant of "object" is "object", which is implemented |
| 41 | +using a `QGroupBox`. That is: its content is displayed in the same |
| 42 | +window, with elements grouped together. |
| 43 | + |
| 44 | +## Number |
| 45 | + |
| 46 | +Number has two variants: |
| 47 | +* "spin", which uses a `QDoubleSpinBox` |
| 48 | +* "text", which uses a `QLineEdit` |
| 49 | + |
| 50 | +## Integer |
| 51 | + |
| 52 | +It admits the same variants as Number, plus: |
| 53 | +* "range", which uses a `QSlider` |
| 54 | + |
| 55 | +## String |
| 56 | + |
| 57 | +Strings has the following variant: |
| 58 | +* "textarea", which uses a `QTextEdit` |
| 59 | +* "text", which uses a `QLineEdit` |
| 60 | +* "password", which uses a `TextSchemaWidget` |
| 61 | +* "filepath", which adds a button which use the open file name in the computer |
| 62 | +* "colour", which uses a `QColorButton` |
| 63 | + |
| 64 | +# Defaults |
| 65 | +When the UI is created, default values are inserted. Those values may |
| 66 | +be changed by the user for a specific json value. Those values are of |
| 67 | +the correct types; it's not guaranteed however that they satisfy all |
| 68 | +schema constraints. (Actually, since there can be conjunction, |
| 69 | +disjunction, negation of schema, and even if-then-else schema, finding |
| 70 | +such value may be actually impossible). |
| 71 | + |
| 72 | +If a schema contains a "default" value, this value is used. |
| 73 | + |
| 74 | +If a schema is an enum, its first value is used as default value. |
| 75 | + |
| 76 | +If the type of the schema is an object, then its default value is an object |
| 77 | +containing the values in "properties", and its associated default |
| 78 | +values are computed as explained in this section. |
| 79 | + |
| 80 | +If the type of the schema is a list (array whose "items" is a schema) |
| 81 | +then the default value is the empty list. |
| 82 | + |
| 83 | +If the type of the schema is a tuple (array whose "items" is an array |
| 84 | +of schema) then the default value is a tuple, whose value contains as |
| 85 | +many element as the items. Each element's default value is computed as |
| 86 | +explained in this section. |
| 87 | + |
| 88 | +The default value of Boolean is True. |
| 89 | + |
| 90 | +The default value of a string is a string containing only spaces, as |
| 91 | +short as possible, accordin to the minimal size constraint. |
| 92 | + |
| 93 | +The default value of a number is: |
| 94 | +* as close as possible to the average between the maximum and the |
| 95 | + minimum if they are set. |
| 96 | +* as close as possible to the maximum or to the minimum if only one is |
| 97 | + set |
| 98 | +* 0 otherwise. |
0 commit comments