CheckBox and OptionBox to Python
Project description
CheckBox / OptionBox
Python class for creating list of CheckBox and OptionBox. CheckBox has the feature of being multi choice and OptionBox of simple choice.
Prerequisites
Developed and tested in Linux and Python 3.6
Installing
pip3 install ebx_checkbox
or from source:
python3 -m pip install [your_path]/ebx_checkbox/
Functions
get_CheckList
get_CheckList(str_Title, InitialLine, InitialColumn, SizeLimit, Options, ClearLine=True, Options_sets=[]):
Description: Create a list of checkBox and multiple choices, return a list of 1 (check) and 0 (uncheck) for all itens (on same order) of Options parameter
Parameter | Description |
---|---|
str_Title: | Title of the list |
InitialLine: | First line on screen where the list will br printed. |
InitialColumn: | Column on screen where the list will br printed. |
SizeLimit: | Limit (quantity) in lines that will be shown on screen, navigation is by Up and Down arrows. |
Options: | List of itens to be printed. |
ClearLine: | (True or False) Clear entire line before print?. |
Options_sets: | (Optional) List of predefined choices (mark) of 1 (Checked) or 0 (Unchecked). The list must have same len of Options, and set 1 on index that you want show checked. |
Return: List of 1 (check) and 0 (uncheck) for all itens (on same order) of Options parameter. -1 if canceled (Esc)
###Information:
- Ctrl + A To check entire list
- Ctrl + N To uncheck entire list
- Space to select item
- Arrows:
- Up: Move to the above item
- Down: Move to the item below
- Esc: Cancel selection and return -1
get_OptionList
get_OptionList (str_Title, InitialLine, InitialColumn, SizeLimit, Options, ClearLine=True, Options_Index=-1)
Description: Create a list of OptionBox and only one choice, return a list of 1 (check) and 0 (uncheck) for all itens (on same order) of Options parameter
Parameter | Description |
---|---|
str_Title: | Title of the list |
InitialLine: | First line on screen where the list will br printed |
InitialColumn: | Column on screen where the list will br printed |
SizeLimit | Limit (quantity) in lines that will be shown on screen, navigation is by Up and Down arrows |
Options: | List of itens to be printed |
ClearLine: | (True or False) Clear entire line before print? |
Options_Index: | (Optional) Index of predefined choice (mark) of 1 (Checked) or 0 (Unchecked). |
Return: List of 1 (check) and 0 (uncheck) for all itens (on same order) of Options parameter. -1 if canceled (Esc)
Information: ###Information:
- Space to select item
- Arrows:
- Up: Move to the above item
- Down: Move to the item below
- Esc: Cancel selection and return -1
Examples of use
ex_checkbox.py:
import ebx_checklist
obj_Checklist = ebx_checklist.Options()
lst_Hosts = [{'IP': '15.128.89.74', 'DC': u'asia-dc'}, {'IP': '15.128.89.75', 'DC': u'asia-dc'}, {'IP': '15.128.89.76', 'DC': u'asia-dc'},
{'IP': '15.128.89.77', 'DC': u'asia-dc'}, {'IP': '15.128.89.78', 'DC': u'asia-dc'}, {'IP': '15.128.89.79', 'DC': u'asia-dc'},
{'IP': '15.128.89.80', 'DC': u'asia-dc'}, {'IP': '15.128.89.81', 'DC': u'asia-dc'}, {'IP': '15.128.89.88', 'DC': u'asia-dc'},
{'IP': '15.128.89.89', 'DC': u'asia-dc'}, {'IP': '15.128.89.90', 'DC': u'asia-dc'}, {'IP': '15.128.89.91', 'DC': u'asia-dc'},
{'IP': '15.128.89.92', 'DC': u'asia-dc'}, {'IP': '15.128.89.93', 'DC': u'asia-dc'}, {'IP': '15.128.89.94', 'DC': u'asia-dc'},
{'IP': '15.128.89.95', 'DC': u'asia-dc'}, {'IP': '15.128.89.96', 'DC': u'asia-dc'}, {'IP': '15.128.89.97', 'DC': u'asia-dc'},
{'IP': '15.128.89.98', 'DC': u'asia-dc'}, {'IP': '15.128.89.99', 'DC': u'asia-dc'}, {'IP': '15.128.89.100', 'DC': u'asia-dc'},
{'IP': '15.128.89.101', 'DC': u'asia-dc'}, {'IP': '15.128.89.102', 'DC': u'asia-dc'}, {'IP': '15.128.89.103', 'DC': u'asia-dc'},
{'IP': '15.130.89.74', 'DC': u'eu-dc'}, {'IP': '15.130.89.75', 'DC': u'eu-dc'}, {'IP': '15.130.89.76', 'DC': u'eu-dc'},
{'IP': '15.130.89.77', 'DC': u'eu-dc'}, {'IP': '15.130.89.78', 'DC': u'eu-dc'}, {'IP': '15.130.89.79', 'DC': u'eu-dc'},
{'IP': '15.130.89.80', 'DC': u'eu-dc'}, {'IP': '15.130.89.81', 'DC': u'eu-dc'}, {'IP': '15.130.89.82', 'DC': u'eu-dc'},
{'IP': '15.130.89.83', 'DC': u'eu-dc'}, {'IP': '15.130.89.84', 'DC': u'eu-dc'}, {'IP': '15.130.89.85', 'DC': u'eu-dc'},
{'IP': '15.130.89.92', 'DC': u'eu-dc'}, {'IP': '15.130.89.93', 'DC': u'eu-dc'}, {'IP': '15.130.89.94', 'DC': u'eu-dc'},
{'IP': '15.130.89.95', 'DC': u'eu-dc'}, {'IP': '15.130.89.96', 'DC': u'eu-dc'}, {'IP': '15.130.89.97', 'DC': u'eu-dc'},
{'IP': '15.130.89.98', 'DC': u'eu-dc'}, {'IP': '15.130.89.99', 'DC': u'eu-dc'}, {'IP': '15.130.89.100', 'DC': u'eu-dc'},
{'IP': '15.130.89.101', 'DC': u'eu-dc'}, {'IP': '15.130.89.102', 'DC': u'eu-dc'}, {'IP': '15.130.89.103', 'DC': u'eu-dc'},
{'IP': '15.135.51.19', 'DC': u'america-dc'}, {'IP': '15.135.51.20', 'DC': u'america-dc'}, {'IP': '15.135.51.21', 'DC': u'america-dc'},
{'IP': '15.135.51.22', 'DC': u'america-dc'}, {'IP': '15.135.51.23', 'DC': u'america-dc'}, {'IP': '15.135.51.24', 'DC': u'america-dc'},
{'IP': '15.135.187.74', 'DC': u'america-dc'}, {'IP': '15.135.187.75', 'DC': u'america-dc'}, {'IP': '15.135.187.76', 'DC': u'america-dc'},
{'IP': '15.135.187.77', 'DC': u'america-dc'}, {'IP': '15.135.187.78', 'DC': u'america-dc'}, {'IP': '15.135.187.79', 'DC': u'america-dc'},
{'IP': '15.135.187.86', 'DC': u'america-dc'}, {'IP': '15.135.187.87', 'DC': u'america-dc'}, {'IP': '15.135.187.88', 'DC': u'america-dc'},
{'IP': '15.135.187.89', 'DC': u'america-dc'}, {'IP': '15.135.187.90', 'DC': u'america-dc'}, {'IP': '15.135.187.91', 'DC': u'america-dc'},
{'IP': '15.135.187.92', 'DC': u'america-dc'}, {'IP': '15.135.187.93', 'DC': u'america-dc'}, {'IP': '15.135.187.94', 'DC': u'america-dc'},
{'IP': '15.135.187.95', 'DC': u'america-dc'}, {'IP': '15.135.187.96', 'DC': u'america-dc'}, {'IP': '15.135.187.97', 'DC': u'america-dc'}]
lst_OptionDCs = [d['DC'] for d in {v['DC']:v for v in lst_Hosts}.values()]
print("\033c")
###################################################################################################################################
lst_DataCentersCheck = obj_Checklist.get_OptionList('DC to restart', 5, 20, 20, lst_OptionDCs, ClearLine=True, Options_Index=-1)
lst_indexes = [index for index in range(len(lst_DataCentersCheck)) if lst_DataCentersCheck[index] == 1]
lst_DataCentersFilter = [lst_OptionDCs[i] for i in lst_indexes]
lst_OptionHosts = [d['DC'] + ' - ' + d['IP'] for d in lst_Hosts if d['DC'] in lst_DataCentersFilter]
lst_HostsCheck = obj_Checklist.get_CheckList('Hosts to restart', 5, 120, 20, lst_OptionHosts, ClearLine=False, Options_sets=[])
lst_tmp_hosts = [d['IP'] for d in lst_Hosts if d['DC'] in lst_DataCentersFilter]
lst_indexes = [index for index in range(len(lst_HostsCheck)) if lst_HostsCheck[index] == 1]
lst_DataCentersFilter = [lst_tmp_hosts[i] for i in lst_indexes]
for host in lst_DataCentersFilter:
print(host)
Call python:
python3 ex_checkbox.py
DC to restart Hosts to restart
( ) - asia-dc [ ] - eu-dc - 15.130.89.74
(O) - eu-dc [ ] - eu-dc - 15.130.89.75
( ) - america-dc [ ] - eu-dc - 15.130.89.76
[X] - eu-dc - 15.130.89.77
[ ] - eu-dc - 15.130.89.78
[X] - eu-dc - 15.130.89.79
[ ] - eu-dc - 15.130.89.80
[X] - eu-dc - 15.130.89.81
[ ] - eu-dc - 15.130.89.82
[ ] - eu-dc - 15.130.89.83
[X] - eu-dc - 15.130.89.84
[ ] - eu-dc - 15.130.89.85
[X] - eu-dc - 15.130.89.92
[ ] - eu-dc - 15.130.89.93
[X] - eu-dc - 15.130.89.94
[ ] - eu-dc - 15.130.89.95
[ ] - eu-dc - 15.130.89.96
[ ] - eu-dc - 15.130.89.97
[ ] - eu-dc - 15.130.89.98
[ ] - eu-dc - 15.130.89.99
Versioning
=======================================================================================
== Log Changes:
== Date: 2021-05-13
== Author: Fausto Branco
== Version: 1.0.1
== Description: Initial Version
=================================================================================
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file ebx_checkbox-1.0.1.tar.gz
.
File metadata
- Download URL: ebx_checkbox-1.0.1.tar.gz
- Upload date:
- Size: 19.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f667c6a0e91e5e6e1057813760a7be09d861ec57185c4d1584594d410066cc75 |
|
MD5 | fed0eb5f47f5999815c37018909b2aa6 |
|
BLAKE2b-256 | 947944dd84ea86d1feafd95adec7bdfbb2dcc735b9acd5a67624cc87eb03ce25 |
File details
Details for the file ebx_checkbox-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: ebx_checkbox-1.0.1-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7f2e09ca9152ebe6ae318319d22316c2873d8de49d825aec4dbe2cf13ac7553 |
|
MD5 | 27e7744e127febfb5c14f1986d6a9a08 |
|
BLAKE2b-256 | 52a7f339fa64d53f8d679290a40e6bfb8dd3c1176d6a1e7c9634c48a2a10abeb |