maxfordham / ipyautoui Goto Github PK
View Code? Open in Web Editor NEWcreate ipywidgets user input form pydantic model or jsonschema
Home Page: https://maxfordham.github.io/ipyautoui/
create ipywidgets user input form pydantic model or jsonschema
Home Page: https://maxfordham.github.io/ipyautoui/
modelrun.py update: incorporate getters and setters similar to how they are applied in filechoose.py
from ipyautoui.demo_schemas.editable_datagrid import EditableGrid
schema = {k: v for k,v in EditableGrid.schema().items() if k!="default"}
value = [{'string': 'asdf', 'integer': 12, 'floater': 3.33, 'something_else': 1}]
EditGrid(schema, value=value, transposed=True)
EditGrid still setting to the default value
hwo to deal with: docstrings, __init__
*args and **kwargs and traitlets
generally within the ipywidget universe, arguments are just traitlets that are piped to the Javascript side of the UI where they are observed to trigger events on_change, this means they can also be edited during the lifetime of the object.
For this reason, I guess, the arguments are defined something like:
import traitlets as tr
class MyClass(tr.HasTraits):
my_arg = tr.Bool()
def __init__(self, **kwargs):
super(MyClass).__init__(*args, **kwargs)
^ kwargs then set the traitlets on instantiation.
how do others do it?
in ipycanvas it looks like something clever is happening as documentation accompanies the traitlets definitions in the source code:
i.e. the #:
lines in the code above
which then makes it into the API Documentation
the above simply documents all the traitlets attributes in the docstring. this is nice and simple, and would also make it easier to document traitlets from child classes. This isn't being used to produce API documentation though.
One annoying thing about both of these approaches is that intellisense doesn't work as because the args aren't explicitly defined in the function call.
In reacton-ipycanvas there is a generate
function that appears to read the ipycanvas package and convert the traitlets definition into function calls, thus supporting intellisense.
here is the code that drops the title and description:
ipyautoui/src/ipyautoui/autoipywidget.py
Lines 55 to 69 in 3402bf3
if a filter is applied to the datagrid, then the selected_keys
method not returning the correct row, leading to the wrong row being edited.
currently on the autodisplay from path is tested - extend to auto display data when retrieved from an API request
ipyautoui.autodisplay.DisplayFromRequest
Create AutoUi test object and other test objects (iterable, etc).
Adding EditGrid from pdttemplater
Be able to construct a button using func from ipyrun to make help button to display each buttons in a toolbar with their tooltips.
import subprocess
from IPython.display import IFrame
subprocess.Popen("pdoc src/ipyautoui/autoipywidget.py --no-browser", shell=True)
IFrame("http://localhost:8080", width=1200, height=1200)
something like this:
class UiCopyDialogue(w.VBox):
def __init__(self):
super().__init__()
self.bn_top = w.Button(icon="sort-up", layout={"width": "40px"})
self.bn_inplace = w.Button(icon="sort", layout={"width": "40px"})
self.bn_end = w.Button(icon="sort-down", layout={"width": "40px"})
self.bn_blank = w.Button(
icon="", style={"button_color": "white"}, layout={"width": "40px"}
)
self.children = [
w.HBox([self.bn_top, w.HTML("duplicate selection to beginning")]),
w.HBox([self.bn_inplace, w.HTML("duplicate selection to below current")]),
w.HBox([self.bn_end, w.HTML("duplicate selection to end")]),
w.HBox([self.bn_blank, w.HTML("select new row/col to copy to")]),
]
UiCopyDialogue()
then the save_buttonbar.ButtonBar
needs editing along with EditGrid.
aim to match UiDelete in functionality
look at TODOs in save_buttonbar
previously the HTML widgets display (even though they didn't have any control attached to them) when the docs are built using jupyter book as described in ./docs/README.txt
.
now when i build the HTML widgets aren't showing... ?
In jupyter, looking at the hlpe string shows arguments (schema, value, path, show_raw, validate_onchange, update_fdir_to_path_parent), but the Args in the docstring are different:
In [2]: AutoUi?
Init signature:
AutoUi(
schema: Union[Type[pydantic.main.BaseModel], dict],
value: dict = None,
path: pathlib.Path = None,
show_raw: bool = True,
validate_onchange=True,
update_fdir_to_path_parent=True,
**kwargs,
)
Docstring:
extends AutoObject and AutoUiCommonMethods to create an
AutoUi capable of interacting with a json file
Init docstring:
creates a widget input form from schema. datatype must be "object"
Args:
schema (dict): json schema defining widget to generate
value (dict, optional): value of json. Defaults to None.
update_map_widgets (frozenmap, optional): frozen dict of widgets to map to schema items. Defaults to None.
fdir (path, optional): fdir to work from. useful for widgets that link to files. Defaults to None.
order (list): allows user to re-specify the order for widget rows to appear by key name in self.di_widgets
insert_rows (dict): e.g. {3:w.Button()}. allows user to insert a widget into the rows. its presence
is ignored by the widget otherwise.
nested_widgets (list): e.g. [FileUploadToDir]. allows user to indicate widgets that should be show / hide
type
Returns:
AutoObject(w.VBox)
File: ~/miniconda3/envs/mapping/lib/python3.10/site-packages/ipyautoui/autoui.py
Type: MetaHasTraits
Subclasses:
Create jupytext shell script to produce all notebooks. .sh in the root
Moved save_buttonbar to custom folder. Need to add new script and fix calls in AutoUi
Currently it uses a specific column to work which is fine in the its use case within aectemplater-ui. However, this is issue generally.
ipyautoui/src/ipyautoui/custom/editgrid.py
Lines 572 to 593 in 09873a7
๐ @jgunstone we met at the Future of Jupyter Widgets workshop a few weeks ago. I'd really like to try out ipyautoui
in a project I'm working on (the notebook pieces of https://github.com/feder-observatory/stellarphot) but to do that I'd need there to be a release that can be pip installed. In addition to the auto UI functionality, I'm potentially also interested in the auto run piece. The last piece I'm eager to use is your FileChooser
wrapper.
I'm happy to help with getting a release ready if you need help, though I won't have a ton of availability until classes end on Dec 6.
I've got a lot of experience with conda-forge, so I'm happy to help with that piece of the packaging puzzle.
currenlty we have a datahandler that mirrors the changes that are happening in EditGrid... could it be more like a watcher that pushes changes?
for implementing a copy dialogue with multiple different copy types, this would require each of those types to also be represented in the datahandler...
review.
this outlines what the copy dialogue would look like but it is currently not implemented for use... (probs shouldn't have put it in the main!)
#96
create a widget that uses the widgets.FileUpload
to upload files, but then automatically saves uploaded files in a specified location.
it should also allow the user to remove uploaded files.
Create method for class GridWrapper so that "title" fields within the schema update datagrid column headers.
ipyautoui/src/ipyautoui/custom/editgrid.py
Line 265 in de7614b
If for some reason a new column is trying to be pushed via the value setter which doesn't already exist in the data frame then raise an error.
ipyautoui
aims to map provide mapping the root file directory out-the-box.
This is useful when you are running Apps on a remote server, but want to configure a way to open files and folders on the users machine.
This is unlikely to be a common use-case and for most users will be an unused feature, but for those who have access to file both through there computer and through the server, it can be quite a powerful additional feature.
moving this config into a set-up file removes hard-coding any unusual behaviour into the code.
use pydantic config settings to set up.
e.g. https://github.com/maxfordham/aectemplater/blob/main/src/aectemplater/app/env.py
save config_autoui.json
in jupyter --config-dir
When EditGrid is in transposed view - it is possible to filter on index to show / hide params.
it would be good if these filter settings got passed to the ui_add and ui_edit objects.
this should be fairly straightforward by linking the filter settings to the AutoUi order param, which can also be used for filtering.
the order param should change on change in filter using observe.
Which one to keep?
ipyautoui/src/ipyautoui/custom/editgrid.py
Lines 804 to 826 in 83caff5
ipyautoui - v0.1.2.4
ipyautoui/src/ipyautoui/custom/editgrid.py
Lines 131 to 133 in 6473fa6
AutoUi makes the incorrect assumption that the root must be an "object"
as an example, the pydantic model works fine
from typing import List, Optional
from pydantic import AnyUrl, BaseModel, Field
class Pet(BaseModel):
id: int
name: str
tag: Optional[str] = None
Pet.schema()
{'title': 'Pet',
'type': 'object',
'properties': {'id': {'title': 'Id', 'type': 'integer'},
'name': {'title': 'Name', 'type': 'string'},
'tag': {'title': 'Tag', 'type': 'string'}},
'required': ['id', 'name']}
the root is an object and it has properties.
this does not work:
class Pets(BaseModel):
__root__: List[Pet]
Pets.schema()
{'title': 'Pets',
'type': 'array',
'items': {'$ref': '#/definitions/Pet'},
'definitions': {'Pet': {'title': 'Pet',
'type': 'object',
'properties': {'id': {'title': 'Id', 'type': 'integer'},
'name': {'title': 'Name', 'type': 'string'},
'tag': {'title': 'Tag', 'type': 'string'}},
'required': ['id', 'name']}}}
as the root is an array. it should work.
need to remove code that stops displaying bx_out
ipyautoui/src/ipyautoui/autodisplay.py
Line 316 in 9d02888
i.e. delete this line:
self.children = [self.bx_bar]
we'd like to use ipyautoui
as a best-practice example for other maxfordham opensource repos
setup.py
file and replace setup.cfg
with pyproject.toml
tests
folder?versioneer.py
and any other un-needed filesrequirements.txt
file and having them as user-installed or optional dependencies for things like: ipydatagrid
, ipyfilechooser
, ... (potentially making the core it JupyterLite compatible)Referencing https://github.com/maxfordham/aectemplater/issues/192
The position of the row in the table is returned instead of the actual key.
Updating custom widgets so that they inherit ipywidget object.
in custom.edit_grid
name changes:
pydantic_model
--> schema
df
--> value
see this example:
ipyautoui/src/ipyautoui/custom/editgrid.py
Lines 732 to 767 in 030dfcd
traitlets_paths only has a pip install
create a conda-feedstock
it could be removed but is useful for defining pathlib.Path types
Create more examples to display the functionality of the package
we add a nullable
flag to the schema indicating to the AutoUi this field can be nulled -
suggest using the terminology allow_none
instead of nullable
ipyautoui/src/ipyautoui/automapschema.py
Lines 122 to 141 in bbb04b4
automapschema
https://github.com/jgunstone/ipyautoui/blob/b91c94a98014851aba21b639887c853dca002654/src/ipyautoui/automapschema.py#L357-L366
add doctests to check it is working (against normal arrays)
If there is a value and we set it to None:
Then this is set successfully:
Now setting it back by clicking the toggle button:
The default value appears but then pressing save does not set that default value:
Potential Reason
I think the issue may be that the _value traitlet hasn't updated upon clicking the toggle button and therefore is still set to None.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.