diff --git a/examples/commands.ipynb b/examples/commands.ipynb index 5dd0a0b..f3a22c8 100644 --- a/examples/commands.ipynb +++ b/examples/commands.ipynb @@ -278,7 +278,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Add the command to the [command palette](https://jupyterlab.readthedocs.io/en/latest/user/commands.html#command-palette)\n" + "### Add the command to the [command palette](https://jupyterlab.readthedocs.io/en/latest/user/commands.html#command-palette)\n" ] }, { @@ -344,7 +344,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.main_menu.add_menu(\"🌈 MY CUSTOM MENU 🎌\")" + "t = app.menu.add_menu(\"🌈 MY CUSTOM MENU 🎌\")" ] }, { @@ -378,10 +378,10 @@ "outputs": [], "source": [ "async def populate_menu():\n", - " await menu.add_item(command=cmd)\n", + " await menu.add_item(command=\"help:about\")\n", " await menu.add_item(type=\"separator\")\n", " ipylab.menu.MenuConnection.new_cid()\n", - " submenu = await app.main_menu.create_menu(\"My submenu\")\n", + " submenu = await app.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", @@ -423,7 +423,7 @@ "metadata": {}, "outputs": [], "source": [ - "t = app.main_menu.list_attributes(depth=3)" + "t = app.menu.list_attributes(depth=3)" ] }, { diff --git a/ipylab/jupyterfrontend.py b/ipylab/jupyterfrontend.py index c5ecf5a..74e4ee2 100644 --- a/ipylab/jupyterfrontend.py +++ b/ipylab/jupyterfrontend.py @@ -37,7 +37,7 @@ class JupyterFrontEnd(AsyncWidgetBase): file_dialog = Instance(FileDialog, (), read_only=True) shell = Instance(Shell, (), read_only=True) session_manager = Instance(SessionManager, (), read_only=True) - main_menu = Instance(MainMenu, ()) + menu = Instance(MainMenu, ()) notification = Instance(NotificationManager, ()) @property diff --git a/ipylab/menu.py b/ipylab/menu.py index 95b1f7c..52a6f70 100644 --- a/ipylab/menu.py +++ b/ipylab/menu.py @@ -134,11 +134,12 @@ class MainMenu(AsyncWidgetBase): _all_menus: Container[tuple[MenuConnection, ...]] = TypedTuple(trait=Instance(MenuConnection)) def add_menu(self, label: str, *, update=True, rank: int = 500) -> Task[MenuConnection]: - """Add a top level menu. + """Add a top level menu to the shell. ref: https://jupyterlab.readthedocs.io/en/4.0.x/api/classes/mainmenu.MainMenu.html#addMenu """ - task = self.create_menu(label=label, rank=rank) + cid = MenuConnection.to_cid(label) + task = self._generate_menu(id=cid, label=label, cid=cid, rank=rank) async def add_menu(): menu = await task @@ -148,6 +149,7 @@ async def add_menu(): return self.to_task(self._add_to_tuple_trait("menus", add_menu())) def create_menu(self, label: str, *, rank: int = 500) -> Task[MenuConnection]: + """Make a new unique menu, likely to be used as a submenu.""" cid = MenuConnection.new_cid(label) return self._generate_menu(id=cid, label=label, cid=cid, rank=rank)