Skip to content

Commit

Permalink
Merge branch 'main' of github.com:maxfordham/ipyautoui into main
Browse files Browse the repository at this point in the history
  • Loading branch information
jgunstone committed Mar 24, 2023
2 parents 62d2025 + 03b8980 commit 04a83dd
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions src/ipyautoui/autowidgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# extension: .py
# format_name: light
# format_version: '1.5'
# jupytext_version: 1.14.0
# jupytext_version: 1.14.5
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
Expand All @@ -27,7 +27,11 @@
import ipywidgets as w
import traitlets as tr
from copy import deepcopy
from ipyautoui.custom import modelrun, markdown_widget, filechooser #, fileupload #<- `fileupload` causes circular import
from ipyautoui.custom import (
modelrun,
markdown_widget,
filechooser,
) # , fileupload #<- `fileupload` causes circular import
from ipyautoui._utils import remove_non_present_kwargs
from datetime import datetime
import functools
Expand Down Expand Up @@ -73,6 +77,22 @@ class Nullable(w.HBox):
"""class to allow widgets to be nullable. The widget that is extended is accessed
using `self.widget`"""

disabled = tr.Bool(default_value=False)

@tr.observe("disabled")
def observe_disabled(self, on_change):
"""If disabled, ensure that the widget is disabled and the button is also."""
if self.disabled:
if self.widget.value is not None:
self.bn.value = False
else:
self.bn.value = True
self.bn.disabled = True
self.widget.disabled = True
else:
self.bn.disabled = False
self.widget.disabled = False

def __init__(self, widget_type, schema, *args, **kwargs):
self.schema = schema
self.caller = create_widget_caller(schema)
Expand All @@ -95,6 +115,7 @@ def __init__(self, widget_type, schema, *args, **kwargs):
super().__init__([self.bn, self.widget, self.show_none])
self._init_controls()
self.value = value
self._set_disabled()

def _init_trait(self):
# NOTE: see test for add_traits that demos usage -@jovyan at 7/18/2022, 12:11:39 PM
Expand Down Expand Up @@ -145,6 +166,11 @@ def _toggle_none(self, onchange):
self.show_none.layout.display = "None"
self.value = self.widget.value

def _set_disabled(self):
"""If disabled in schema, set to value defined."""
if "disabled" in self.schema:
self.disabled = self.schema["disabled"]


def nullable(fn, **kwargs):
"""extend a simple widget to allow None
Expand Down Expand Up @@ -457,8 +483,8 @@ def __init__(self, schema):
schema, calling=markdown_widget.MarkdownWidget
)
super().__init__(**self.caller)


# class AutoUploadPaths(fileupload.FilesUploadToDir):
# def __init__(self, schema):
# from ipyautoui.custom import modelrun, markdown_widget, filechooser, fileupload
Expand All @@ -473,3 +499,6 @@ def __init__(self, schema):
import doctest

doctest.testmod()
# -


0 comments on commit 04a83dd

Please sign in to comment.