mr-menu


Namemr-menu JSON
Version 0.1 PyPI version JSON
download
home_pageNone
SummaryComplex and simple nested menus
upload_time2024-09-17 01:08:02
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT License Copyright (c) 2024 Soumyo Deep Gupta Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords d33p0st mr-menu menu nested-menu complex-menu
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Unit Tests](https://github.com/d33p0st/mr-menu/actions/workflows/test.yml/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/test.yml)
[![codecov](https://codecov.io/github/d33p0st/mr-menu/graph/badge.svg?token=NF0LC6QWPX)](https://codecov.io/github/d33p0st/mr-menu)
[![CD(PYPI)](https://github.com/d33p0st/mr-menu/actions/workflows/pypi.yml/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/pypi.yml)
# Overview

`mr-menu` helps create Menus and sub-Menus all at once and helps managing them easily. `mr-menu` can easily execute menu and sub-menus and their conditional functions all-together.

Using `mr-menu`, you can create a `Tree` of Menus and add functionalities for each menu item. `mr-menu` can execute those functionalities and return results gracefully.

## Table of Contents

- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [Issues](#issues)
- [Pull Requests](#pull-requests)

## Features

- **_Nested Tree of Menu and Sub-Menus_**: Single Menu can have multiple sub-menus and further sub-sub-menus and so on.

- **_In-built Execution of defined functions_**: You can define functions for each menu item and `mr-menu` will execute them based on which option the user chooses.

## Installation

Execute in Terminal:

```bash
pip install mr-menu
```

## Usage

> Example Test Case: Suppose you want to create a simple menu which will contain two items - Add two nums and Sub two nums.

- **`Simple Menu`**

  - import the `Menu` class.

    ```python
    from mr-menu.simple import Menu
    ```

  - create functions/class methods for Add and Sub

    ```python
    def add_two():
        num1 = int(input("Enter num 1: "))
        num2 = int(input("Enter num 2: "))
        return num1 + num2
    
    def sub_two():
        num1 = int(input("Enter num 1: "))
        num2 = int(input("Enter num 2: "))
        return num1 - num2
    ```

  - Create `Menu` class object

    ```python
    menu = Menu(
        identifier="main", # unique menu identifier.
        menu={1: "Add two nums", 2: "Sub two nums"}, # menu in dict form
        functions={1: add_two, 2: sub_two}, # function dict with callable functions mapped to menu
    )
    ```

  - Handle the menu and it's functions.

    ```python
    result = menu.handler(
        prompt="Enter choice: ", # to be shown to the user.
        return_execution_result=True,
        *args, # see docstring
        **kwargs, # see docstring
    )

    # the above code will ask the user for input with the 
    # prompt and if it is "1", it will ask for two nums and 
    # return (True, output).
    # Similarly, if "2" is selected, it will return (True, output) again.
    # if execution fails, it will return (False, None)
    ```

> Now, Let us take an example where the first menu has two options -> Add, Sub and one extra option -> `More options` which expands into another menu, say, `Multiply` and `divide`.

- **`Tree of Menus and submenus`**

  - import `MenuBuilder` classs

    ```python
    from mr-menu.generator import MenuBuilder
    ```

  - create functions for `Add`, `Sub`, `Multiply` and `divide`

    ```python
    def add():
        num1 = int(input("enter num 1: "))
        num2 = int(input("enter num 2: "))
        return num1 + num2
    
    def sub():
        num1 = int(input("enter num 1: "))
        num2 = int(input("enter num 2: "))
        return num1 - num2
    
    def mult():
        num1 = int(input("enter num 1: "))
        num2 = int(input("enter num 2: "))
        return num1*num2
    
    def div():
        num1 = int(input("enter num 1: "))
        num2 = int(input("enter num 2: "))
        return num1/num2 if num2 != 0 else 0
    ```

  - create `MenuBuilder` class object

    ```python
    builder = MenuBuilder()
    ```

  - Add the first menu (main menu)

    ```python
    builder.add(
        identifier="main", # Unique identifier for this particular menu
        menu={1: "Add two nums", 2: "Sub two nums", 3: "More Options"}, # menu in dict form
        functions={1: add, 2: sub, 3: None}, # functions for all the options except the one that expands a new menu (3rd)
        go_back_index=None, # It is recommended to keep this
        # None, as a new (4th) option will be automatically
        # created and handled that facilitates going back to the main menu.
    )
    ```

  - Add the sub-menu

    ```python
    builder.add_submenu(
        parent_identifier="main", # parent menu is "main",
        parent_menu_index=3, # the index key where the menu is supposed to expand. i.e., 3 (More options)
        submenu_identifier="main-submenu-1", # the unique identifier for this sub-menu,
        submenu={1: "Multiply two nums", 2: "Divide two nums"}, # submenu in dict form.
        go_back_index=None, # again, keep this None, here a 3rd
        # option will be automatically created that helps to
        # go back to the main menu.
        replace_if_exist=True, # this means if the submenu already exists, replace the old one with this current one.
    )
    ```

  - Handle the menu and submenu

    If the user chooses option 1 (Add two nums), the `handler` will ask for two inputs and return the sum of the numbers. But when the user chooses 3rd option in the main menu, The new sub-menu will be displayed. The user can then choose `Multiply` and `Divide`.

    ```python
    result = builder.handler(
        prompt="Enter your choice:", # the prompt that asks to choose an option.
        post_execution_label="The Task executed Successfully", # after a task finishes, this will be printed.
        return_execution_result=True, # returns the result in tuple form with two values - tuple[bool, Any],,
        # where bool represents execute status and Any is the result.
    )
    ```

## Issues

Please submit any issues found [here](https://github.com/d33p0st/mr-menu/issues).

## Pull Requests

Pull Requests are welcome and encouraged. Find it [here](https://github.com/d33p0st/mr-menu/pulls)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mr-menu",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": "Soumyo Deep Gupta <deep.main.ac@gmail.com>",
    "keywords": "d33p0st, mr-menu, menu, nested-menu, complex-menu",
    "author": null,
    "author_email": "Soumyo Deep Gupta <deep.main.ac@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/96/9a/26e22d379dd4a5de4760b7f20b044f93a841861b166ffd32c5e30368f33b/mr_menu-0.1.tar.gz",
    "platform": null,
    "description": "[![Unit Tests](https://github.com/d33p0st/mr-menu/actions/workflows/test.yml/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/test.yml)\n[![codecov](https://codecov.io/github/d33p0st/mr-menu/graph/badge.svg?token=NF0LC6QWPX)](https://codecov.io/github/d33p0st/mr-menu)\n[![CD(PYPI)](https://github.com/d33p0st/mr-menu/actions/workflows/pypi.yml/badge.svg)](https://github.com/d33p0st/mr-menu/actions/workflows/pypi.yml)\n# Overview\n\n`mr-menu` helps create Menus and sub-Menus all at once and helps managing them easily. `mr-menu` can easily execute menu and sub-menus and their conditional functions all-together.\n\nUsing `mr-menu`, you can create a `Tree` of Menus and add functionalities for each menu item. `mr-menu` can execute those functionalities and return results gracefully.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n- [Issues](#issues)\n- [Pull Requests](#pull-requests)\n\n## Features\n\n- **_Nested Tree of Menu and Sub-Menus_**: Single Menu can have multiple sub-menus and further sub-sub-menus and so on.\n\n- **_In-built Execution of defined functions_**: You can define functions for each menu item and `mr-menu` will execute them based on which option the user chooses.\n\n## Installation\n\nExecute in Terminal:\n\n```bash\npip install mr-menu\n```\n\n## Usage\n\n> Example Test Case: Suppose you want to create a simple menu which will contain two items - Add two nums and Sub two nums.\n\n- **`Simple Menu`**\n\n  - import the `Menu` class.\n\n    ```python\n    from mr-menu.simple import Menu\n    ```\n\n  - create functions/class methods for Add and Sub\n\n    ```python\n    def add_two():\n        num1 = int(input(\"Enter num 1: \"))\n        num2 = int(input(\"Enter num 2: \"))\n        return num1 + num2\n    \n    def sub_two():\n        num1 = int(input(\"Enter num 1: \"))\n        num2 = int(input(\"Enter num 2: \"))\n        return num1 - num2\n    ```\n\n  - Create `Menu` class object\n\n    ```python\n    menu = Menu(\n        identifier=\"main\", # unique menu identifier.\n        menu={1: \"Add two nums\", 2: \"Sub two nums\"}, # menu in dict form\n        functions={1: add_two, 2: sub_two}, # function dict with callable functions mapped to menu\n    )\n    ```\n\n  - Handle the menu and it's functions.\n\n    ```python\n    result = menu.handler(\n        prompt=\"Enter choice: \", # to be shown to the user.\n        return_execution_result=True,\n        *args, # see docstring\n        **kwargs, # see docstring\n    )\n\n    # the above code will ask the user for input with the \n    # prompt and if it is \"1\", it will ask for two nums and \n    # return (True, output).\n    # Similarly, if \"2\" is selected, it will return (True, output) again.\n    # if execution fails, it will return (False, None)\n    ```\n\n> Now, Let us take an example where the first menu has two options -> Add, Sub and one extra option -> `More options` which expands into another menu, say, `Multiply` and `divide`.\n\n- **`Tree of Menus and submenus`**\n\n  - import `MenuBuilder` classs\n\n    ```python\n    from mr-menu.generator import MenuBuilder\n    ```\n\n  - create functions for `Add`, `Sub`, `Multiply` and `divide`\n\n    ```python\n    def add():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1 + num2\n    \n    def sub():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1 - num2\n    \n    def mult():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1*num2\n    \n    def div():\n        num1 = int(input(\"enter num 1: \"))\n        num2 = int(input(\"enter num 2: \"))\n        return num1/num2 if num2 != 0 else 0\n    ```\n\n  - create `MenuBuilder` class object\n\n    ```python\n    builder = MenuBuilder()\n    ```\n\n  - Add the first menu (main menu)\n\n    ```python\n    builder.add(\n        identifier=\"main\", # Unique identifier for this particular menu\n        menu={1: \"Add two nums\", 2: \"Sub two nums\", 3: \"More Options\"}, # menu in dict form\n        functions={1: add, 2: sub, 3: None}, # functions for all the options except the one that expands a new menu (3rd)\n        go_back_index=None, # It is recommended to keep this\n        # None, as a new (4th) option will be automatically\n        # created and handled that facilitates going back to the main menu.\n    )\n    ```\n\n  - Add the sub-menu\n\n    ```python\n    builder.add_submenu(\n        parent_identifier=\"main\", # parent menu is \"main\",\n        parent_menu_index=3, # the index key where the menu is supposed to expand. i.e., 3 (More options)\n        submenu_identifier=\"main-submenu-1\", # the unique identifier for this sub-menu,\n        submenu={1: \"Multiply two nums\", 2: \"Divide two nums\"}, # submenu in dict form.\n        go_back_index=None, # again, keep this None, here a 3rd\n        # option will be automatically created that helps to\n        # go back to the main menu.\n        replace_if_exist=True, # this means if the submenu already exists, replace the old one with this current one.\n    )\n    ```\n\n  - Handle the menu and submenu\n\n    If the user chooses option 1 (Add two nums), the `handler` will ask for two inputs and return the sum of the numbers. But when the user chooses 3rd option in the main menu, The new sub-menu will be displayed. The user can then choose `Multiply` and `Divide`.\n\n    ```python\n    result = builder.handler(\n        prompt=\"Enter your choice:\", # the prompt that asks to choose an option.\n        post_execution_label=\"The Task executed Successfully\", # after a task finishes, this will be printed.\n        return_execution_result=True, # returns the result in tuple form with two values - tuple[bool, Any],,\n        # where bool represents execute status and Any is the result.\n    )\n    ```\n\n## Issues\n\nPlease submit any issues found [here](https://github.com/d33p0st/mr-menu/issues).\n\n## Pull Requests\n\nPull Requests are welcome and encouraged. Find it [here](https://github.com/d33p0st/mr-menu/pulls)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Soumyo Deep Gupta  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Complex and simple nested menus",
    "version": "0.1",
    "project_urls": {
        "GitHub": "https://github.com/d33p0st/mr-menu",
        "Issues": "https://github.com/d33p0st/mr-menu/issues",
        "Pull Requests": "https://github.com/d33p0st/mr-menu/pulls"
    },
    "split_keywords": [
        "d33p0st",
        " mr-menu",
        " menu",
        " nested-menu",
        " complex-menu"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "60dd19e4d9f7f5401f60b150237ed89c716712f687397ff39c840c80fdb5ef1f",
                "md5": "2dca1f78e1742573bd38b3872f109b62",
                "sha256": "f90ed33e93380aee669a2d1a7f1fb583c0b76d61ab93fca0074f721e76b49bb9"
            },
            "downloads": -1,
            "filename": "mr_menu-0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2dca1f78e1742573bd38b3872f109b62",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12304,
            "upload_time": "2024-09-17T01:08:00",
            "upload_time_iso_8601": "2024-09-17T01:08:00.702189Z",
            "url": "https://files.pythonhosted.org/packages/60/dd/19e4d9f7f5401f60b150237ed89c716712f687397ff39c840c80fdb5ef1f/mr_menu-0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "969a26e22d379dd4a5de4760b7f20b044f93a841861b166ffd32c5e30368f33b",
                "md5": "71334d4a6975eca815eefc2ab9cc6ac8",
                "sha256": "fde8b4256921472c6497f658411b587d3d6bc1bac2a4108874f7e10959fdd163"
            },
            "downloads": -1,
            "filename": "mr_menu-0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "71334d4a6975eca815eefc2ab9cc6ac8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 11218,
            "upload_time": "2024-09-17T01:08:02",
            "upload_time_iso_8601": "2024-09-17T01:08:02.542479Z",
            "url": "https://files.pythonhosted.org/packages/96/9a/26e22d379dd4a5de4760b7f20b044f93a841861b166ffd32c5e30368f33b/mr_menu-0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-17 01:08:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "d33p0st",
    "github_project": "mr-menu",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "mr-menu"
}
        
Elapsed time: 0.39860s