4
4
5
5
from . import widgets
6
6
from .defaults import compute_defaults
7
-
7
+ from typing import Dict , Any
8
8
9
9
def get_widget_state (schema , state = None ):
10
10
"""A JSON object. Either the state given in input if any, otherwise
@@ -79,17 +79,7 @@ def validate(data):
79
79
80
80
def create_widget (self , schema : dict , ui_schema : dict , state = None ) -> widgets .SchemaWidgetMixin :
81
81
schema_type = get_schema_type (schema )
82
-
83
- try :
84
- default_variant = self .widget_variant_modifiers [schema_type ](
85
- schema )
86
- except KeyError :
87
- default_variant = self .default_widget_variants [schema_type ]
88
-
89
- if "enum" in schema :
90
- default_variant = "enum"
91
-
92
- widget_variant = ui_schema .get ('ui:widget' , default_variant )
82
+ widget_variant = self .get_widget_variant (schema_type , schema , ui_schema )
93
83
widget_cls = self .widget_map [schema_type ][widget_variant ]
94
84
95
85
widget = widget_cls (schema , ui_schema , self )
@@ -98,3 +88,14 @@ def create_widget(self, schema: dict, ui_schema: dict, state=None) -> widgets.Sc
98
88
if default_state is not None :
99
89
widget .state = default_state
100
90
return widget
91
+
92
+ def get_widget_variant (self , schema_type : str , schema : Dict [str , Any ], ui_schema : Dict [str , Any ]) -> str :
93
+ try :
94
+ default_variant = self .widget_variant_modifiers [schema_type ](schema )
95
+ except KeyError :
96
+ default_variant = self .default_widget_variants [schema_type ]
97
+
98
+ if "enum" in schema :
99
+ default_variant = "enum"
100
+
101
+ return ui_schema .get ('ui:widget' , default_variant )
0 commit comments