cursesdict


Namecursesdict JSON
Version 0.13 PyPI version JSON
download
home_pagehttps://github.com/hansalemaos/cursesdict
Summarycreates an interactive menu system for your application or program, providing an intuitive and user-friendly interface for users to navigate and perform various actions
upload_time2023-07-02 00:28:14
maintainer
docs_urlNone
authorJohannes Fischer
requires_python
licenseMIT
keywords curses menu
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# creates an interactive menu system for your application or program, providing an intuitive and user-friendly interface for users to navigate and perform various actions

## pip install cursesdict

#### Tested against Windows 10 / Python 3.10 / Anaconda 
#### install curses from https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses


### Simplifies menu creation: 

The start_menu function abstracts away the complexities of handling user input and managing the menu structure. It provides a convenient way to define menus and associate actions with menu options.

### Customizable appearance: 

The module allows you to customize various aspects of the menu, such as the length of menu items, spacing, justification, and refresh time. This flexibility enables you to adapt the menu to your specific needs.

### Keyboard shortcuts: 

The module supports configurable keyboard shortcuts for actions like quitting the menu, selecting options, and navigating through the menu. This allows for efficient and intuitive menu navigation.

### Nested menus: 

The module supports nested menus, allowing you to create a hierarchical menu structure. This is useful for organizing and categorizing menu options in a logical manner.

### Flexibility and extensibility: 

The module is designed to be flexible and easily extensible. You can modify the menu structure, add new options, and define custom actions according to your requirements.



```python

# Important! The script can't be executed from ipython, Pycharm, the terminal, etc. 
# Open cmd.exe, activate your env, and start the script!

start_menu(
    menudict: dict,
    menu_len: int = 40,
    n_spaces_right: int = 5,
    n_spaces_left: int = 2,
    menu_len_selected: int = 40,
    n_spaces_right_selected: int = 10,
    n_spaces_left_selected: int = 4,
    rjust: bool = True,
    refresh_time: float = 0.001,
    quit_keys: tuple | list = ("",),
    enter_keys: tuple | list = ("PADENTER",),
    key_up_keys: tuple | list = ("KEY_UP",),
    key_down_keys: tuple | list = ("KEY_DOWN",),
) -> None:
    r"""
        Displays a menu using the curses library and allows the user to navigate and interact with the menu options.
        Download the Windows version of curses: https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses

        Args:
            menudict (dict): Dictionary containing the menu structure and options.
            menu_len (int, optional): Length of the menu items. Defaults to 40.
            n_spaces_right (int, optional): Number of spaces to add to the right of each menu item. Defaults to 5.
            n_spaces_left (int, optional): Number of spaces to add to the left of each menu item. Defaults to 2.
            menu_len_selected (int, optional): Length of the highlighted (selected) menu items. Defaults to 40.
            n_spaces_right_selected (int, optional): Number of spaces to add to the right of each highlighted menu item. Defaults to 10.
            n_spaces_left_selected (int, optional): Number of spaces to add to the left of each highlighted menu item. Defaults to 4.
            rjust (bool, optional): If True, right-justifies the menu items. If False, left-justifies the menu items. Defaults to True.
            refresh_time (float, optional): Refresh time for the menu display, in seconds. Defaults to 0.001.
            quit_keys (tuple or list, optional): Keys to quit the menu. Defaults to ("",).
            enter_keys (tuple or list, optional): Keys to select/enter a menu option. Defaults to ("PADENTER",).
            key_up_keys (tuple or list, optional): Keys to navigate up in the menu. Defaults to ("KEY_UP",).
            key_down_keys (tuple or list, optional): Keys to navigate down in the menu. Defaults to ("KEY_DOWN",).

        Returns:
            None

        Example:

	
```

## copy and paste example


The provided example demonstrates how to use the start_menu function to create a menu system for an imaginary school. Each menu option is associated with a specific action, such as opening a file or performing a task. Here's a breakdown of the example:

The fufu1 function is defined, which writes the given key to a file and opens it in Notepad using subprocess.Popen. This function represents the action to be performed when a menu option is selected.

The stama dictionary defines the menu structure and options. It includes nested dictionaries to create submenus and associated actions.

The start_menu function is called with the stama dictionary as the argument. This will display the menu and allow the user to navigate and interact with the options.

	
	
```python
import subprocess

from cursesdict import start_menu, menu_config


def fufu1(key):
    filetest = "c:\\testestestest.txt"
    with open(filetest, mode="w", encoding="utf-8") as f:
        f.write(str(key))
        f.write("\n")
    subprocess.Popen(f"notepad.exe {filetest}", shell=True)
    menu_config.is_active = False  # exits the menu


stama = {
    "main": {
        "menu_header": "Imaginary School - Main Menu",
        "option_0": {
            "Exercises": lambda: fufu1("Imaginary School - Main Menu - Exercises")
        },
        "option_1": {"Review": lambda: fufu1("Imaginary School - Main Menu - Review")},
        "option_2": {
            "Talk to a teacher": lambda: fufu1(
                "Imaginary School - Main Menu - Talk to a teacher"
            )
        },
        "option_3": {
            "Blackboard": lambda: fufu1("Imaginary School - Main Menu - Blackboard")
        },
        "option_4": {
            "Vocabulary Training": {
                "menu_header": "Welcome to the Vocabulary Training section:",
                "option_0": {
                    "A1": lambda: fufu1(
                        "Imaginary School - Main Menu - Vocabulary Training - A1"
                    )
                },
                "option_1": {
                    "A2": lambda: fufu1(
                        "Imaginary School - Main Menu - Vocabulary Training - A2"
                    )
                },
                "option_2": {
                    "B1-B2": lambda: fufu1(
                        "Imaginary School - Main Menu - Vocabulary Training - B1-B2"
                    )
                },
                "option_3": {
                    "C1-C2": lambda: fufu1(
                        "Imaginary School - Main Menu - Vocabulary Training - C1-C2"
                    )
                },
                "option_4": {
                    "Training for Tests": {
                        "menu_header": "Specific Test Training",
                        "option_0": {
                            "Sub Option 0": lambda: fufu1(
                                "Imaginary School - Main Menu - Vocabulary Training - Suboption 0"
                            )
                        },
                        "option_1": {
                            "Sub Option 1": lambda: fufu1(
                                "Imaginary School - Main Menu - Vocabulary Training - Suboption 1"
                            )
                        },
                        "option_2": {
                            "Sub Option 2": lambda: fufu1(
                                "Imaginary School - Main Menu - Vocabulary Training - SubOption 2"
                            )
                        },
                        "option_3": {
                            "Sub Option 3": lambda: fufu1(
                                "Imaginary School - Main Menu - Vocabulary Training - Suboption 3"
                            )
                        },
                        "option_4": {
                            "Sub Option 4": lambda: fufu1(
                                "Imaginary School - Main Menu - Vocabulary Training - Suboption 4"
                            )
                        },
                        "option_5": {
                            "Go back": ("main", "option_4", "Vocabulary Training")
                        },
                    },
                },
                "option_5": {"Go back": ("main",)},
            },
        },
    }
}
start_menu(stama)


```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/hansalemaos/cursesdict",
    "name": "cursesdict",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "curses,menu",
    "author": "Johannes Fischer",
    "author_email": "aulasparticularesdealemaosp@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0d/fa/8eb6d0e51fb4c98740f7f4046b656b5c7f4f14fa8cb2dc200bbc8f169ea6/cursesdict-0.13.tar.gz",
    "platform": null,
    "description": "\r\n# creates an interactive menu system for your application or program, providing an intuitive and user-friendly interface for users to navigate and perform various actions\r\n\r\n## pip install cursesdict\r\n\r\n#### Tested against Windows 10 / Python 3.10 / Anaconda \r\n#### install curses from https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses\r\n\r\n\r\n### Simplifies menu creation: \r\n\r\nThe start_menu function abstracts away the complexities of handling user input and managing the menu structure. It provides a convenient way to define menus and associate actions with menu options.\r\n\r\n### Customizable appearance: \r\n\r\nThe module allows you to customize various aspects of the menu, such as the length of menu items, spacing, justification, and refresh time. This flexibility enables you to adapt the menu to your specific needs.\r\n\r\n### Keyboard shortcuts: \r\n\r\nThe module supports configurable keyboard shortcuts for actions like quitting the menu, selecting options, and navigating through the menu. This allows for efficient and intuitive menu navigation.\r\n\r\n### Nested menus: \r\n\r\nThe module supports nested menus, allowing you to create a hierarchical menu structure. This is useful for organizing and categorizing menu options in a logical manner.\r\n\r\n### Flexibility and extensibility: \r\n\r\nThe module is designed to be flexible and easily extensible. You can modify the menu structure, add new options, and define custom actions according to your requirements.\r\n\r\n\r\n\r\n```python\r\n\r\n# Important! The script can't be executed from ipython, Pycharm, the terminal, etc. \r\n# Open cmd.exe, activate your env, and start the script!\r\n\r\nstart_menu(\r\n    menudict: dict,\r\n    menu_len: int = 40,\r\n    n_spaces_right: int = 5,\r\n    n_spaces_left: int = 2,\r\n    menu_len_selected: int = 40,\r\n    n_spaces_right_selected: int = 10,\r\n    n_spaces_left_selected: int = 4,\r\n    rjust: bool = True,\r\n    refresh_time: float = 0.001,\r\n    quit_keys: tuple | list = (\"\u001b\",),\r\n    enter_keys: tuple | list = (\"PADENTER\",),\r\n    key_up_keys: tuple | list = (\"KEY_UP\",),\r\n    key_down_keys: tuple | list = (\"KEY_DOWN\",),\r\n) -> None:\r\n    r\"\"\"\r\n        Displays a menu using the curses library and allows the user to navigate and interact with the menu options.\r\n        Download the Windows version of curses: https://www.lfd.uci.edu/~gohlke/pythonlibs/#curses\r\n\r\n        Args:\r\n            menudict (dict): Dictionary containing the menu structure and options.\r\n            menu_len (int, optional): Length of the menu items. Defaults to 40.\r\n            n_spaces_right (int, optional): Number of spaces to add to the right of each menu item. Defaults to 5.\r\n            n_spaces_left (int, optional): Number of spaces to add to the left of each menu item. Defaults to 2.\r\n            menu_len_selected (int, optional): Length of the highlighted (selected) menu items. Defaults to 40.\r\n            n_spaces_right_selected (int, optional): Number of spaces to add to the right of each highlighted menu item. Defaults to 10.\r\n            n_spaces_left_selected (int, optional): Number of spaces to add to the left of each highlighted menu item. Defaults to 4.\r\n            rjust (bool, optional): If True, right-justifies the menu items. If False, left-justifies the menu items. Defaults to True.\r\n            refresh_time (float, optional): Refresh time for the menu display, in seconds. Defaults to 0.001.\r\n            quit_keys (tuple or list, optional): Keys to quit the menu. Defaults to (\"\u001b\",).\r\n            enter_keys (tuple or list, optional): Keys to select/enter a menu option. Defaults to (\"PADENTER\",).\r\n            key_up_keys (tuple or list, optional): Keys to navigate up in the menu. Defaults to (\"KEY_UP\",).\r\n            key_down_keys (tuple or list, optional): Keys to navigate down in the menu. Defaults to (\"KEY_DOWN\",).\r\n\r\n        Returns:\r\n            None\r\n\r\n        Example:\r\n\r\n\t\r\n```\r\n\r\n## copy and paste example\r\n\r\n\r\nThe provided example demonstrates how to use the start_menu function to create a menu system for an imaginary school. Each menu option is associated with a specific action, such as opening a file or performing a task. Here's a breakdown of the example:\r\n\r\nThe fufu1 function is defined, which writes the given key to a file and opens it in Notepad using subprocess.Popen. This function represents the action to be performed when a menu option is selected.\r\n\r\nThe stama dictionary defines the menu structure and options. It includes nested dictionaries to create submenus and associated actions.\r\n\r\nThe start_menu function is called with the stama dictionary as the argument. This will display the menu and allow the user to navigate and interact with the options.\r\n\r\n\t\r\n\t\r\n```python\r\nimport subprocess\r\n\r\nfrom cursesdict import start_menu, menu_config\r\n\r\n\r\ndef fufu1(key):\r\n    filetest = \"c:\\\\testestestest.txt\"\r\n    with open(filetest, mode=\"w\", encoding=\"utf-8\") as f:\r\n        f.write(str(key))\r\n        f.write(\"\\n\")\r\n    subprocess.Popen(f\"notepad.exe {filetest}\", shell=True)\r\n    menu_config.is_active = False  # exits the menu\r\n\r\n\r\nstama = {\r\n    \"main\": {\r\n        \"menu_header\": \"Imaginary School - Main Menu\",\r\n        \"option_0\": {\r\n            \"Exercises\": lambda: fufu1(\"Imaginary School - Main Menu - Exercises\")\r\n        },\r\n        \"option_1\": {\"Review\": lambda: fufu1(\"Imaginary School - Main Menu - Review\")},\r\n        \"option_2\": {\r\n            \"Talk to a teacher\": lambda: fufu1(\r\n                \"Imaginary School - Main Menu - Talk to a teacher\"\r\n            )\r\n        },\r\n        \"option_3\": {\r\n            \"Blackboard\": lambda: fufu1(\"Imaginary School - Main Menu - Blackboard\")\r\n        },\r\n        \"option_4\": {\r\n            \"Vocabulary Training\": {\r\n                \"menu_header\": \"Welcome to the Vocabulary Training section:\",\r\n                \"option_0\": {\r\n                    \"A1\": lambda: fufu1(\r\n                        \"Imaginary School - Main Menu - Vocabulary Training - A1\"\r\n                    )\r\n                },\r\n                \"option_1\": {\r\n                    \"A2\": lambda: fufu1(\r\n                        \"Imaginary School - Main Menu - Vocabulary Training - A2\"\r\n                    )\r\n                },\r\n                \"option_2\": {\r\n                    \"B1-B2\": lambda: fufu1(\r\n                        \"Imaginary School - Main Menu - Vocabulary Training - B1-B2\"\r\n                    )\r\n                },\r\n                \"option_3\": {\r\n                    \"C1-C2\": lambda: fufu1(\r\n                        \"Imaginary School - Main Menu - Vocabulary Training - C1-C2\"\r\n                    )\r\n                },\r\n                \"option_4\": {\r\n                    \"Training for Tests\": {\r\n                        \"menu_header\": \"Specific Test Training\",\r\n                        \"option_0\": {\r\n                            \"Sub Option 0\": lambda: fufu1(\r\n                                \"Imaginary School - Main Menu - Vocabulary Training - Suboption 0\"\r\n                            )\r\n                        },\r\n                        \"option_1\": {\r\n                            \"Sub Option 1\": lambda: fufu1(\r\n                                \"Imaginary School - Main Menu - Vocabulary Training - Suboption 1\"\r\n                            )\r\n                        },\r\n                        \"option_2\": {\r\n                            \"Sub Option 2\": lambda: fufu1(\r\n                                \"Imaginary School - Main Menu - Vocabulary Training - SubOption 2\"\r\n                            )\r\n                        },\r\n                        \"option_3\": {\r\n                            \"Sub Option 3\": lambda: fufu1(\r\n                                \"Imaginary School - Main Menu - Vocabulary Training - Suboption 3\"\r\n                            )\r\n                        },\r\n                        \"option_4\": {\r\n                            \"Sub Option 4\": lambda: fufu1(\r\n                                \"Imaginary School - Main Menu - Vocabulary Training - Suboption 4\"\r\n                            )\r\n                        },\r\n                        \"option_5\": {\r\n                            \"Go back\": (\"main\", \"option_4\", \"Vocabulary Training\")\r\n                        },\r\n                    },\r\n                },\r\n                \"option_5\": {\"Go back\": (\"main\",)},\r\n            },\r\n        },\r\n    }\r\n}\r\nstart_menu(stama)\r\n\r\n\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "creates an interactive menu system for your application or program, providing an intuitive and user-friendly interface for users to navigate and perform various actions",
    "version": "0.13",
    "project_urls": {
        "Homepage": "https://github.com/hansalemaos/cursesdict"
    },
    "split_keywords": [
        "curses",
        "menu"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "469e7d0b2ee49478c7ab606dbc9962d1ff057d97e86332ca15c225369206efe5",
                "md5": "b8e07e934694be5e51adadd48e36e32f",
                "sha256": "a3a48a3ffd7970f5c8ab967b4eb34f54393a5cbeb2845b668b544ffff39c45a7"
            },
            "downloads": -1,
            "filename": "cursesdict-0.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b8e07e934694be5e51adadd48e36e32f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10467,
            "upload_time": "2023-07-02T00:28:12",
            "upload_time_iso_8601": "2023-07-02T00:28:12.580534Z",
            "url": "https://files.pythonhosted.org/packages/46/9e/7d0b2ee49478c7ab606dbc9962d1ff057d97e86332ca15c225369206efe5/cursesdict-0.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0dfa8eb6d0e51fb4c98740f7f4046b656b5c7f4f14fa8cb2dc200bbc8f169ea6",
                "md5": "fe9e82a2684a82cc999619f4ad71833b",
                "sha256": "70d89a8cb27307d6abc787407e598d3b6009c9258a566241047e4c69830a0cb5"
            },
            "downloads": -1,
            "filename": "cursesdict-0.13.tar.gz",
            "has_sig": false,
            "md5_digest": "fe9e82a2684a82cc999619f4ad71833b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7255,
            "upload_time": "2023-07-02T00:28:14",
            "upload_time_iso_8601": "2023-07-02T00:28:14.058971Z",
            "url": "https://files.pythonhosted.org/packages/0d/fa/8eb6d0e51fb4c98740f7f4046b656b5c7f4f14fa8cb2dc200bbc8f169ea6/cursesdict-0.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-02 00:28:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "hansalemaos",
    "github_project": "cursesdict",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [],
    "lcname": "cursesdict"
}
        
Elapsed time: 0.20039s