-
Notifications
You must be signed in to change notification settings - Fork 15
/
test.py
80 lines (71 loc) · 1.99 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import sys
from json import dumps
from qtpy import QtWidgets
from qt_jsonschema_form import WidgetBuilder
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
builder = WidgetBuilder()
schema = {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"type": "object",
"title": "Number fields and widgets",
"properties": {
"schema_path": {
"title": "Schema path",
"type": "string"
},
"integerRangeSteps": {
"title": "Integer range (by 10)",
"type": "integer",
"minimum": 55,
"maximum": 100,
"multipleOf": 10
},
"sky_colour": {
"type": "string"
},
"names": {
"type": "array",
"items": [
{
"type": "string",
"pattern": "[a-zA-Z]+",
"enum": [
"Jack", "Jill"
]
},
{
"type": "string",
"pattern": "[a-zA-Z]+",
"enum": [
"Alice", "Bob"
]
},
],
"additionalItems": {
"type": "number"
},
}
}
}
ui_schema = {
"schema_path": {
"ui:widget": "filepath"
},
"sky_colour": {
"ui:widget": "colour"
}
}
form = builder.create_form(schema, ui_schema)
form.widget.state = {
"schema_path": "some_file.py",
"integerRangeSteps": 60,
"sky_colour": "#8f5902",
"names": [
"Jack",
"Bob"
]
}
form.show()
form.widget.on_changed.connect(lambda d: print(dumps(d, indent=4)))
app.exec_()