%run __init__.py
import ipywidgets as w
import traitlets as tr
from ipyautoui.constants import IMAGE_BUTTON_KWARGS
from ipyautoui.custom.buttonbars import CrudButtonBar, CrudOptions, CrudView
for maplocal to load openpath and runcmd callable, maplocal_example.py must exist with functions `openpath` and `runcmd`
EXTENDED_BUTTONBAR_CONFIG = CrudView(
images=CrudOptions(
tooltip="Add image",
tooltip_clicked="Go back to table",
button_style="info",
message="📷 <i>Adding image</i>",
),
add=CrudOptions(
tooltip="Add item",
tooltip_clicked="Go back to table",
button_style="success",
message="➕ <i>Adding data</i>",
),
edit=CrudOptions(
tooltip="Edit item",
tooltip_clicked="Go back to table",
button_style="warning",
message="✏️ <i>Editing data</i>",
),
copy=CrudOptions(
tooltip="Copy item",
tooltip_clicked="Go back to table",
button_style="primary",
message="📝 <i>Copying data</i>",
),
delete=CrudOptions(
tooltip="Delete item",
tooltip_clicked="Go back to table",
button_style="danger",
message="🗑️ <i>Deleting data</i>",
),
)
class CrudButtonBarExtended(CrudButtonBar):
fn_images = tr.Callable(default_value=lambda: print("add image"))
def __init__(self, **kwargs):
self.images = w.ToggleButton(**IMAGE_BUTTON_KWARGS)
self.images.observe(self._images, "value")
super().__init__(**kwargs | {"crud_view": EXTENDED_BUTTONBAR_CONFIG})
self.children = [
self.images,
self.add,
self.edit,
self.copy,
self.delete,
self.reload,
self.message,
]
def _images(self, onchange):
self._onclick("images")
if __name__ == "__main__":
display(CrudButtonBarExtended())
CrudButtonBarExtended(children=(ToggleButton(value=False, button_style='info', icon='image', layout=Layout(wid…