|
29 | 29 | from typing_extensions import Unpack |
30 | 30 |
|
31 | 31 | from magicgui.application import AppRef |
| 32 | + from magicgui.type_map import TypeMap |
32 | 33 | from magicgui.widgets import Container, Widget |
33 | 34 | from magicgui.widgets.bases._container_widget import ContainerKwargs |
34 | 35 |
|
@@ -189,12 +190,18 @@ def __str__(self) -> str: |
189 | 190 | ) |
190 | 191 | ) |
191 | 192 |
|
192 | | - def to_widget(self, app: AppRef | None = None) -> Widget: |
| 193 | + def to_widget( |
| 194 | + self, |
| 195 | + app: AppRef | None = None, |
| 196 | + type_map: TypeMap | None = None, |
| 197 | + ) -> Widget: |
193 | 198 | """Create and return a widget for this object.""" |
194 | | - from magicgui.widgets import create_widget |
| 199 | + from magicgui.type_map import TypeMap |
195 | 200 |
|
196 | 201 | value = Undefined if self.default in (self.empty, TZ_EMPTY) else self.default |
197 | | - widget = create_widget( |
| 202 | + if type_map is None: |
| 203 | + type_map = TypeMap.global_instance() |
| 204 | + widget = type_map.create_widget( |
198 | 205 | name=self.name, |
199 | 206 | value=value, |
200 | 207 | annotation=self.annotation, |
@@ -287,19 +294,26 @@ def from_signature( |
287 | 294 | raise_on_unknown=raise_on_unknown, |
288 | 295 | ) |
289 | 296 |
|
290 | | - def widgets(self, app: AppRef | None = None) -> MappingProxyType: |
| 297 | + def widgets( |
| 298 | + self, |
| 299 | + app: AppRef | None = None, |
| 300 | + type_map: TypeMap | None = None, |
| 301 | + ) -> MappingProxyType: |
291 | 302 | """Return mapping from parameters to widgets for all params in Signature.""" |
292 | 303 | return MappingProxyType( |
293 | | - {n: p.to_widget(app) for n, p in self.parameters.items()} |
| 304 | + {n: p.to_widget(app, type_map=type_map) for n, p in self.parameters.items()} |
294 | 305 | ) |
295 | 306 |
|
296 | 307 | def to_container( |
297 | | - self, app: AppRef | None = None, **kwargs: Unpack[ContainerKwargs] |
| 308 | + self, |
| 309 | + app: AppRef | None = None, |
| 310 | + type_map: TypeMap | None = None, |
| 311 | + **kwargs: Unpack[ContainerKwargs], |
298 | 312 | ) -> Container: |
299 | 313 | """Return a ``magicgui.widgets.Container`` for this MagicSignature.""" |
300 | 314 | from magicgui.widgets import Container |
301 | 315 |
|
302 | | - kwargs["widgets"] = list(self.widgets(app).values()) |
| 316 | + kwargs["widgets"] = list(self.widgets(app, type_map=type_map).values()) |
303 | 317 | return Container(**kwargs) |
304 | 318 |
|
305 | 319 | def replace( # type: ignore[override] |
|
0 commit comments