Skip to content

Commit

Permalink
Added partial menu support. Added new feature asObject. Added 'info…
Browse files Browse the repository at this point in the history
…' to Connection.
  • Loading branch information
Alan Fleming committed Sep 9, 2024
1 parent 3c8c263 commit bcb8c7f
Show file tree
Hide file tree
Showing 19 changed files with 494 additions and 173 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ pip install -e ".[dev]"
jupyter labextension develop . --overwrite

# compile the extension
jlpm && jlpm run build
jlpm clean
jlpm && jlpm build

# pre-commit (optional)
pip install pre-commit
Expand All @@ -112,6 +113,8 @@ jlpm lint
jlpm lint:check


- Sometimes, it helps to clear cached files too by running `git clean -dfx`
from the root of the cloned repository. You will also need to redo `pip install -e ".[dev]`
```
## Related projects
Expand Down
4 changes: 2 additions & 2 deletions examples/autostart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
" tooltip=\"An error dialog will pop up when this is clicked.\\n\"\n",
" \"The dialog demonstrates the use of the `on_frontend_error` plugin.\",\n",
" )\n",
" error_button.on_click(lambda _: panel.app.execute_command(\"Not a command\"))\n",
" error_button.on_click(lambda _: panel.app.commands.execute(\"Not a command\"))\n",
" panel.children = [ipw.HTML(f\"<h3>{path}</h3> Welcome to my app.<br> kernel id: {panel.app.kernelId}\"), error_button]\n",
"\n",
" # Demonstrate usage of a plugin\n",
Expand Down Expand Up @@ -152,7 +152,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.execute_command(\"launcher:create\")"
"t = app.commands.execute(\"launcher:create\")"
]
}
],
Expand Down
163 changes: 112 additions & 51 deletions examples/commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"**Awaiting tasks in the console will block the kerenel indefinitely.**\n",
"\n",
"Note: This notebook should be run one line at a time waiting for each cell to return before running the next cell."
]
},
Expand Down Expand Up @@ -63,24 +65,6 @@
"app.commands.all_commands"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = app.commands.execute_method(\"describedBy\", \"console:inject\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t.result()"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -94,7 +78,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.execute_command(\n",
"t = app.commands.execute(\n",
" \"console:create\",\n",
" insertMode=\"split-right\",\n",
" kernelPreference={\"id\": app.kernelId},\n",
Expand All @@ -111,24 +95,6 @@
"w = t.result()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = w.list_attributes()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t.result()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -151,7 +117,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.execute_command(\"apputils:change-theme\", theme=\"JupyterLab Dark\")"
"app.commands.execute(\"apputils:change-theme\", theme=\"JupyterLab Dark\")"
]
},
{
Expand All @@ -160,7 +126,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.execute_command(\"apputils:change-theme\", theme=\"JupyterLab Light\")"
"app.commands.execute(\"apputils:change-theme\", theme=\"JupyterLab Light\")"
]
},
{
Expand Down Expand Up @@ -256,7 +222,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.execute_command(cmd, transform=ipylab.Transform.raw, isToggleable=True)"
"t = app.commands.execute(cmd, transform=ipylab.Transform.raw, isToggleable=True)"
]
},
{
Expand Down Expand Up @@ -338,8 +304,14 @@
"metadata": {},
"outputs": [],
"source": [
"pc = t.result()\n",
"t = pc.list_attributes()"
"pc = t.result()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open the command palette (CTRL + SHIFT + C) and the command should show now be visible. Look for `Swap orientation`"
]
},
{
Expand All @@ -348,15 +320,21 @@
"metadata": {},
"outputs": [],
"source": [
"result = t.result()\n",
"result"
"def show_command_pallet():\n",
" # Use a delay to the call so the command pallet remains open.\n",
" asyncio.get_running_loop().call_later(1, app.commands.execute, \"apputils:activate-command-palette\")\n",
"\n",
"\n",
"show_command_pallet()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Open the command palette (CTRL + SHIFT + C) and the command should show now be visible. Look for `Swap orientation`"
"## MainMenu\n",
"\n",
"We can add items to existing menus, but lets create a new menu."
]
},
{
Expand All @@ -365,12 +343,95 @@
"metadata": {},
"outputs": [],
"source": [
"def show_command_pallet():\n",
" # Use a delay to the call so the command pallet remains open.\n",
" asyncio.get_running_loop().call_later(1, app.execute_command, \"apputils:activate-command-palette\")\n",
"\n",
"t = app.main_menu.add_menu(\"🌈 MY CUSTOM MENU 🎌\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"See above that the new menu is now added"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"menu = t.result()\n",
"menu"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Lets populate the new menu."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"async def populate_menu():\n",
" await menu.add_item(command=cmd)\n",
" await menu.add_item(type=\"separator\")\n",
" ipylab.menu.MenuConnection.new_cid()\n",
" submenu = await app.main_menu.create_menu(\"My submenu\")\n",
" await submenu.add_item(command=\"notebook:create-console\")\n",
" await menu.add_item(submenu=submenu, type=\"submenu\")\n",
" await menu.add_item(command=\"logconsole:open\")\n",
"\n",
"show_command_pallet()"
" # Open it\n",
" await menu.execute_method(\"open\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = app.to_task(populate_menu())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t.result()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"menu.dispose()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t = app.main_menu.list_attributes(depth=3)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"t.result()"
]
},
{
Expand Down Expand Up @@ -411,7 +472,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.execute_command(\"launcher:create\")"
"app.commands.execute(\"launcher:create\")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/icons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@
},
"outputs": [],
"source": [
"asyncio.get_running_loop().call_later(1, panel.app.execute_command, \"apputils:activate-command-palette\")"
"asyncio.get_running_loop().call_later(1, panel.app.commands.execute, \"apputils:activate-command-palette\")"
]
},
{
Expand All @@ -327,7 +327,7 @@
"metadata": {},
"outputs": [],
"source": [
"panel.app.execute_command(cmd, count=1)"
"panel.app.commands.execute(cmd, count=1)"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions examples/ipytree.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"When the \"Open\" button is clicked, we call `app.execute_command` with the path to the file to open it in the JupyterLab interface."
"When the \"Open\" button is clicked, we call `app.commands.execute` with the path to the file to open it in the JupyterLab interface."
]
},
{
Expand All @@ -328,7 +328,7 @@
" for node in file_tree.selected_nodes:\n",
" filepath = node.fullpath\n",
" if filepath:\n",
" app.execute_command(\"docmanager:open\", path=filepath)\n",
" app.commands.execute(\"docmanager:open\", path=filepath)\n",
"\n",
"\n",
"open_button.on_click(on_open_clicked)"
Expand Down
4 changes: 2 additions & 2 deletions examples/sessions.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"metadata": {},
"outputs": [],
"source": [
"app.execute_command(\"console:create\", **app.current_session)"
"app.commands.execute(\"console:create\", **app.current_session)"
]
},
{
Expand All @@ -107,7 +107,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.execute_command(\"notebook:create-new\", transform=ipylab.Transform.connection)"
"t = app.commands.execute(\"notebook:create-new\", transform=ipylab.Transform.connection)"
]
},
{
Expand Down
3 changes: 2 additions & 1 deletion ipylab/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
"pack",
"pack_code",
"commands",
"menu",
]

from ipylab import commands
from ipylab import commands, menu
from ipylab.asyncwidget import pack, pack_code
from ipylab.common import Area, InsertMode, Transform
from ipylab.connection import Connection, MainAreaConnection
Expand Down
Loading

0 comments on commit bcb8c7f

Please sign in to comment.