Skip to content

Commit

Permalink
Rename main_menu to menu
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Fleming committed Sep 16, 2024
1 parent f33d2d0 commit 4ead38b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
10 changes: 5 additions & 5 deletions examples/commands.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
},
{
Expand Down Expand Up @@ -344,7 +344,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.main_menu.add_menu(\"🌈 MY CUSTOM MENU 🎌\")"
"t = app.menu.add_menu(\"🌈 MY CUSTOM MENU 🎌\")"
]
},
{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -423,7 +423,7 @@
"metadata": {},
"outputs": [],
"source": [
"t = app.main_menu.list_attributes(depth=3)"
"t = app.menu.list_attributes(depth=3)"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion ipylab/jupyterfrontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions ipylab/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 4ead38b

Please sign in to comment.