Skip to main content

coopui

Package dedicated for holding tooling that allows a developer to interact with a user

Import the packages that will handle the cli interaction with the user

from coopui.cli.CliAtomicUserInteraction import CliAtomicUserInteraction as ui
from coopui.cli.CliMenu import CliMenu

The CliAtomicUserInteraction class allows interaction with the user with validation of the input returned, as well as ability to notify user with text


if __name__ == "__main__":
   # yes or no
   ret1 = ui.request_yes_no(prompt="Select Yes or No")

   # from a list
   lst = [x for x in 'abcdefghijklmnop']
   ret2 = ui.request_from_list(lst)

   # from a dict
   dic = {1: "Cat", 2: "Dog", 3: "Turtle", 4: "Frog"}
   ret3 = ui.request_from_dict(dic)

   # notify user
   ui.notify_user(text=f"selected yes: {ret1}")
   ui.notify_user(text=f"selected letter from list: {ret2}")
   ui.notify_user(text=f"selected animal: {ret3}")

First define a custom function to greet a user:

def greet(ui):
   ui.notify_user("Hello!")
   ret = ui.request_yes_no("Are you having a good day?")

   if ret is None:
       return

   if ret:
       ui.notify_user("Glad to hear it!")
   else:
       ui.notify_user("Im so sorry....")

Then, use the CliAtomicUserInteraction class along with the CliMenu class to provide a menu to perform the greeting

if __name__ == "__main__":
    ui = CliAtomicUserInteraction()
    menu = CliMenu(menu_header="************* My Menu *************",
                   definition={
                       "G": ("[G]reeting", lambda: greet(ui))
                   },
                   notify_user_provider=ui.notify_user
                   )

    menu.run()

A menu will return only if the result of a selection is None. Therefore, always include a definition for returning None

if __name__ == "__main__":
    ui = CliAtomicUserInteraction()
    menu = CliMenu(menu_header="************* My Menu *************",
                   definition={
                       "G": ("[G]reeting", lambda: greet(ui)),
                       "X": ("Back", None)
                   },
                   notify_user_provider=ui.notify_user
                   )

    menu.run()

Multiple menus can be chained together to define a nested menu selection.

if __name__ == "__main__":
    ui = CliAtomicUserInteraction()
    main_menu = CliMenu(menu_header="************* My Menu *************",
                   definition={
                       "G": ("[G]reeting", lambda: greet(ui)),
                       "S": ("[S]ub-menu", lambda: sub_menu.run()),
                       "X": ("E[X]it", None)
                   },
                   notify_user_provider=ui.notify_user
                   )
    sub_menu = CliMenu(menu_header="************* Sub Menu *************",
                   definition={
                       "G": ("[G]reeting", lambda: greet(ui)),
                       "X": ("X -- Back", None)
                   },
                   notify_user_provider=ui.notify_user
                   )

    main_menu.run()

Release files for coopui 0.21

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coopui 0.21
File Size Uploaded
coopui-0.21.tar.gz 11.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coopui 0.21
File Interpreter ABI Platform
coopui-0.21-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 kB

Release files / coopui-0.21.tar.gz

Download URL coopui-0.21.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cc19c693e3a072d478ccf0195dba462f257df9214ec60ceadd4f024d9eadae26
BLAKE2b-256 checksum
How to use checksums
08f73ad3cf515cf35aa13cea8459b021e3762969c98a265d70cf11d7e8b94851
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

Release files / coopui-0.21-py3-none-any.whl

Download URL coopui-0.21-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2dc1a3f11f3296bd5abd40d93a6b0db0941d41e0be68af1b6dba38c48bd555ff
BLAKE2b-256 checksum
How to use checksums
a0dcf70e63120184e57fc5475cf583281a5f3f6ae86c51bb9adcf02765733389
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.21 This release

2 release files

0.20

2 release files

0.19

2 release files

0.18

2 release files

0.17

2 release files

0.16

2 release files

0.15

2 release files

0.14

2 release files

0.13

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9

2 release files

0.8

2 release files

0.7

2 release files

0.6

2 release files

0.5

2 release files

0.4

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page