{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "ea9dfff3-99b1-4269-a658-617f5868009e", "metadata": {}, "outputs": [], "source": [ "%run __init__.py" ] }, { "cell_type": "code", "execution_count": 2, "id": "7be455ab-fbf6-4577-a913-adb37ccebfde", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "for maplocal to load openpath and runcmd callable, maplocal_example.py must exist with functions `openpath` and `runcmd`\n" ] } ], "source": [ "import ipywidgets as w\n", "import traitlets as tr\n", "from ipyautoui.constants import IMAGE_BUTTON_KWARGS\n", "from ipyautoui.custom.buttonbars import CrudButtonBar, CrudOptions, CrudView" ] }, { "cell_type": "code", "execution_count": 3, "id": "5c7104a4-ad43-42de-b264-a408ac7f3189", "metadata": {}, "outputs": [], "source": [ "EXTENDED_BUTTONBAR_CONFIG = CrudView(\n", " images=CrudOptions(\n", " tooltip=\"Add image\",\n", " tooltip_clicked=\"Go back to table\",\n", " button_style=\"info\",\n", " message=\"📷 Adding image\",\n", " ),\n", " add=CrudOptions(\n", " tooltip=\"Add item\",\n", " tooltip_clicked=\"Go back to table\",\n", " button_style=\"success\",\n", " message=\"➕ Adding data\",\n", " ),\n", " edit=CrudOptions(\n", " tooltip=\"Edit item\",\n", " tooltip_clicked=\"Go back to table\",\n", " button_style=\"warning\",\n", " message=\"✏️ Editing data\",\n", " ),\n", " copy=CrudOptions(\n", " tooltip=\"Copy item\",\n", " tooltip_clicked=\"Go back to table\",\n", " button_style=\"primary\",\n", " message=\"📝 Copying data\",\n", " ),\n", " delete=CrudOptions(\n", " tooltip=\"Delete item\",\n", " tooltip_clicked=\"Go back to table\",\n", " button_style=\"danger\",\n", " message=\"🗑️ Deleting data\",\n", " ),\n", ")" ] }, { "cell_type": "code", "execution_count": 8, "id": "7150ceed-9f0c-469b-a0be-7409b9f3b2a1", "metadata": {}, "outputs": [], "source": [ "class CrudButtonBarExtended(CrudButtonBar):\n", " fn_images = tr.Callable(default_value=lambda: print(\"add image\"))\n", " \n", " def __init__(self, **kwargs):\n", " self.images = w.ToggleButton(**IMAGE_BUTTON_KWARGS)\n", " self.images.observe(self._images, \"value\")\n", " super().__init__(**kwargs | {\"crud_view\": EXTENDED_BUTTONBAR_CONFIG})\n", " self.children = [\n", " self.images,\n", " self.add,\n", " self.edit,\n", " self.copy,\n", " self.delete,\n", " self.reload,\n", " self.message,\n", " ]\n", "\n", " def _images(self, onchange):\n", " self._onclick(\"images\")" ] }, { "cell_type": "code", "execution_count": 9, "id": "07ee94ee-f525-4bce-b928-6437675b6e59", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "b3f3f2525ff142fb9f0e65453cf79fbd", "version_major": 2, "version_minor": 0 }, "text/plain": [ "CrudButtonBarExtended(children=(ToggleButton(value=False, button_style='info', icon='image', layout=Layout(wid…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "if __name__ == \"__main__\":\n", " display(CrudButtonBarExtended())" ] }, { "cell_type": "code", "execution_count": null, "id": "06afa3ff-9ef7-44e2-90cd-9c37f5050d4a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.5" } }, "nbformat": 4, "nbformat_minor": 5 }