Skip to content

Commit d803b11

Browse files
create get_widget_variant
1 parent b715080 commit d803b11

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

qt_jsonschema_form/form.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from . import widgets
66
from .defaults import compute_defaults
7-
7+
from typing import Dict, Any
88

99
def get_widget_state(schema, state=None):
1010
"""A JSON object. Either the state given in input if any, otherwise
@@ -79,17 +79,7 @@ def validate(data):
7979

8080
def create_widget(self, schema: dict, ui_schema: dict, state=None) -> widgets.SchemaWidgetMixin:
8181
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)
9383
widget_cls = self.widget_map[schema_type][widget_variant]
9484

9585
widget = widget_cls(schema, ui_schema, self)
@@ -98,3 +88,14 @@ def create_widget(self, schema: dict, ui_schema: dict, state=None) -> widgets.Sc
9888
if default_state is not None:
9989
widget.state = default_state
10090
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

Comments
 (0)