Skip to content

Commit

Permalink
feat(MenuWidget): add methods for directly selecting an Item
Browse files Browse the repository at this point in the history
  • Loading branch information
sassanh committed May 18, 2024
1 parent bbc6658 commit 288438f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Version 0.11.9

- feat(MenuWidget): add methods for directly selecting an `Item`

## Version 0.11.8

- fix(MenuWidget): align items with the physical buttons
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "ubo-gui"
version = "0.11.8"
version = "0.11.9"
description = "GUI sdk for Ubo Pod"
authors = ["Sassan Haradji <[email protected]>"]
license = "Apache-2.0"
Expand Down
27 changes: 19 additions & 8 deletions ubo_gui/menu/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,24 @@ def select_submenu_item(self: MenuWidget, item: SubMenuItem) -> None:
"""Select a submenu item."""
self.open_menu(item.sub_menu)

def select_item(self: MenuWidget, item: Item) -> None:
"""Select an item.
Parameters
----------
item: `Item`
The item to select
"""
if isinstance(item, ActionItem):
self.select_action_item(item)
if isinstance(item, ApplicationItem):
self.select_application_item(item)
if isinstance(item, SubMenuItem):
self.select_submenu_item(item)

def select(self: MenuWidget, index: int) -> None:
"""Select one of the items currently visible on the screen.
"""Select one of the items currently visible on the screen based on its index.
Parameters
----------
Expand All @@ -289,13 +305,8 @@ def select(self: MenuWidget, index: int) -> None:
return
current_page = cast(PageWidget, self.screen_manager.current_screen)
item = current_page.get_item(index)

if isinstance(item, ActionItem):
self.select_action_item(item)
if isinstance(item, ApplicationItem):
self.select_application_item(item)
if isinstance(item, SubMenuItem):
self.select_submenu_item(item)
if item:
self.select_item(item)

def go_back(self: MenuWidget) -> None:
"""Go back to the previous menu."""
Expand Down

0 comments on commit 288438f

Please sign in to comment.