Skip to content

Commit

Permalink
Merge pull request #136 from maxfordham:🚑-autodisplay-issue-and-markd…
Browse files Browse the repository at this point in the history
…own_widget-warnings

🚑-autodisplay-issue-and-markdown_widget-warnings
  • Loading branch information
jgunstone authored Mar 10, 2023
2 parents 57d314f + 45c7cd2 commit 3c35c17
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 19 deletions.
48 changes: 41 additions & 7 deletions docs/autoui.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,38 +79,72 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 23,
"id": "9d70dd9d-cd5b-4b59-a5d3-32a0f184c7bf",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4b70305949f0421da5c95110b0615013",
"model_id": "247cbbe38ce6431eae93dc1b3178d3b9",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"AutoUi(children=(SaveButtonBar(children=(ToggleButton(value=False, button_style='success', disabled=True, icon…"
"AutoObject(children=(SaveButtonBar(children=(ToggleButton(value=False, button_style='success', disabled=True, …"
]
},
"execution_count": 4,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from pydantic import BaseModel, Field\n",
"from ipyautoui.custom.fileupload import AutoUploadPaths\n",
"from ipyautoui.autoipywidget import AutoObject\n",
"\n",
"class Test(BaseModel):\n",
" paths: list[pathlib.Path] = Field(autoui=\"__main__.AutoUploadPaths\")\n",
"\n",
" paths: list[pathlib.Path] = Field(autoui=\"ipyautoui.custom.fileupload.AutoUploadPaths\")\n",
" a: str\n",
"\n",
"aui = AutoUi(Test)\n",
" class Config:\n",
" schema_extra = {\n",
" 'nested_widgets': ['ipyautoui.custom.fileupload.AutoUploadPaths']\n",
" }\n",
"aui = AutoObject(Test) # , nested_widgets=[AutoUploadPaths]\n",
"aui"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "cb49c754-8660-49e4-a65e-218f71fbe920",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"{'title': 'Test',\n",
" 'type': 'object',\n",
" 'properties': {'paths': {'title': 'Paths',\n",
" 'autoui': 'ipyautoui.custom.fileupload.AutoUploadPaths',\n",
" 'type': 'array',\n",
" 'items': {'type': 'string', 'format': 'path'}},\n",
" 'a': {'title': 'A', 'type': 'string'}},\n",
" 'required': ['paths', 'a'],\n",
" 'nested_widgets': ['ipyautoui.custom.fileupload.AutoUploadPaths']}"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Test.schema()"
]
},
{
"cell_type": "markdown",
"id": "21a44310",
Expand Down
11 changes: 9 additions & 2 deletions src/ipyautoui/autodisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def _display_actions(self, change):

def __init__(
self,
*args,
display_actions,
**kwargs,
):
"""display object
Expand All @@ -350,7 +350,7 @@ def __init__(

self._init_form() # generic form only
self._init_controls()
super().__init__(*args, **kwargs)
super().__init__(display_actions=display_actions, **kwargs)
self._update_bx_bar(self.order)
self.children = [self.bx_bar, self.bx_out]

Expand Down Expand Up @@ -529,6 +529,11 @@ def value(self, value):


# -
if __name__ == "__main__":
d = DisplayFromPath(path="__init__.py")
do = DisplayObject(d)
display(do)

if __name__ == "__main__":
path = "https://catfact.ninja/fact"
ext = ".json"
Expand Down Expand Up @@ -1072,3 +1077,5 @@ def display_catfact(path):
test_display = AutoDisplay([d1, d2])
display(Markdown("### From requests: "))
display(test_display)


10 changes: 8 additions & 2 deletions src/ipyautoui/custom/fileupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,15 @@ def __init__(
from ipyautoui import AutoUi

class Test(BaseModel):
paths: list[pathlib.Path] = Field(autoui="__main__.AutoUploadPaths")
string: str
paths: list[pathlib.Path] = Field(
autoui="__main__.AutoUploadPaths",
title="A longish title about something",
description="with a rambling description as well...",
)

aui = AutoUi(Test)
value = {"string": "string", "paths": ["bdns.csv"]}
aui = AutoUi(Test, value=value, nested_widgets=[AutoUploadPaths])
display(aui)


Expand Down
29 changes: 21 additions & 8 deletions src/ipyautoui/custom/markdown_widget.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.11.5
# jupytext_version: 1.14.0
# kernelspec:
# display_name: Python 3 (ipykernel)
# language: python
Expand Down Expand Up @@ -109,13 +109,13 @@

def markdown_buttons():
"""generate markdown widget button bar"""
bn_header = w.Button(icon="fa-heading", layout=dict(BUTTON_MIN_SIZE))
bn_bold = w.Button(icon="fa-bold", layout=dict(BUTTON_MIN_SIZE))
bn_italic = w.Button(icon="fa-italic", layout=dict(BUTTON_MIN_SIZE))
bn_list = w.Button(icon="fa-list", layout=dict(BUTTON_MIN_SIZE))
bn_numbered = w.Button(icon="fa-list-ol", layout=dict(BUTTON_MIN_SIZE))
bn_image = w.Button(icon="fa-image", layout=dict(BUTTON_MIN_SIZE))
bn_link = w.Button(icon="fa-link", layout=dict(BUTTON_MIN_SIZE))
bn_header = w.Button(icon="heading", layout=dict(BUTTON_MIN_SIZE))
bn_bold = w.Button(icon="bold", layout=dict(BUTTON_MIN_SIZE))
bn_italic = w.Button(icon="italic", layout=dict(BUTTON_MIN_SIZE))
bn_list = w.Button(icon="list", layout=dict(BUTTON_MIN_SIZE))
bn_numbered = w.Button(icon="list-ol", layout=dict(BUTTON_MIN_SIZE))
bn_image = w.Button(icon="image", layout=dict(BUTTON_MIN_SIZE))
bn_link = w.Button(icon="link", layout=dict(BUTTON_MIN_SIZE))
bn_blank = w.Button(
display=True, style={"button_color": "white"}, layout=dict(BUTTON_MIN_SIZE)
)
Expand Down Expand Up @@ -222,3 +222,16 @@ def _text(self, onchange):
if __name__ == "__main__":
ui = MarkdownWidget()
display(ui)

if __name__ == "__main__":
from pydantic import BaseModel, Field
from ipyautoui import AutoUi

class Test(BaseModel):
num: int
label: str
md: str = Field("adsf", format="markdown")

display(AutoUi(Test))


0 comments on commit 3c35c17

Please sign in to comment.