From cd28d0c19a3b48be854163873a8aad993b13713e Mon Sep 17 00:00:00 2001 From: Matt Craig Date: Wed, 9 Aug 2023 12:20:32 -0600 Subject: [PATCH] Create and use a custom BoundedIntText This is used for the aperture settings fields to ensure a lower bound in the UI. --- stellarphot/settings/autowidgets.py | 11 +++++++++++ stellarphot/settings/models.py | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 stellarphot/settings/autowidgets.py diff --git a/stellarphot/settings/autowidgets.py b/stellarphot/settings/autowidgets.py new file mode 100644 index 00000000..afe016ab --- /dev/null +++ b/stellarphot/settings/autowidgets.py @@ -0,0 +1,11 @@ +# Some classes for ipyautoui that really belong there, not here + +import ipywidgets as w +from ipyautoui.autowidgets import create_widget_caller + + +class CustomBoundedIntTex(w.BoundedIntText): + def __init__(self, schema): + self.schema = schema + self.caller = create_widget_caller(schema) + super().__init__(**self.caller) diff --git a/stellarphot/settings/models.py b/stellarphot/settings/models.py index 1dada3aa..d7029165 100644 --- a/stellarphot/settings/models.py +++ b/stellarphot/settings/models.py @@ -6,6 +6,7 @@ from pydantic import BaseModel, Field +from .autowidgets import CustomBoundedIntTex class ApertureUnit(Enum): PIXEL = un.pix @@ -13,10 +14,9 @@ class ApertureUnit(Enum): class ApertureSettings(BaseModel): - radius : float - inner_annulus : float - outer_annulus : float - unit : ApertureUnit = Field(default=ApertureUnit.PIXEL, enum=[au.value for au in ApertureUnit]) + radius : conint(ge=1) = Field(autoui=CustomBoundedIntTex) + inner_annulus : conint(ge=1) = Field(autoui=CustomBoundedIntTex) + outer_annulus : conint(ge=1) = Field(autoui=CustomBoundedIntTex) class Config: use_enum_values = True