Skip to main content

PYPI package with better toggle buttons

Project description

GitHub last commit GitHub license<space><space> Documentation Status PyPI PyPI - Python Version

Short Overview.

ipywidgets_toggle_buttons is a simple python package(py>=3.6) with more toggle buttons for ipywidgets

Installation via pip:

pip install ipywidgets_toggle_buttons

Long Overview.

This python package consists of other ToggleButtons classes

  • ToggleButtonsAutoSize - To adjust buttons size to show full their’s description

  • MultiToggleButtons - To select a few options at once with usual ToggleButtons interface

  • ToggleButtonsWithHide - ToggleButtonsAutoSize + Hidden options

  • MultiToggleButtonsWithHide - MultiToggleButtons + Hidden options

All of them will adjust size of buttons if options are modified.
Also they have usual interfaces to work with values and options

Simple Usage examples

ToggleButtonsAutoSize

Create and show this widget

from ipywidgets_toggle_buttons import ToggleButtonsAutoSize
wid = ToggleButtonsAutoSize(options=[str(i) for i in range(10)])
wid  # OR wid.box_widget
images/toggle_buttons_auto_size_1.JPG
print(wid.value)  # "0"
print(wid.options)  # ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')
print(wid.layout.width)  # '100%'
wid.options = list(wid.options) + ["ajhfkaghnkandjgnakdn"]
images/toggle_buttons_auto_size_2.JPG

MultiToggleButtons

Create and show this widget

from ipywidgets_toggle_buttons import MultiToggleButtons
wid = MultiToggleButtons(
    options=[str(i) for i in range(10)],
    max_chosen_values=2,
)
wid  # OR wid.box_widget
images/multi_toggle_buttons_1.JPG
def on_value_change(_):
    print("pew")

wid.observe(on_value_change, 'value')
print(wid.value)  # ()
wid.value = ["2", "8"]  # "pew"
images/multi_toggle_buttons_2.JPG

ToggleButtonsWithHide

Create and show this widget

from ipywidgets_toggle_buttons import ToggleButtonsWithHide
wid = ToggleButtonsWithHide(
    value="0",
    options_visible=[str(i) for i in range(10)],
    options_hidden=[str(i) for i in range(5, 15)],
)
wid  # OR wid.box_widget
images/toggle_buttons_with_hide_1.JPG

After pressing the button Show Hidden Options

images/toggle_buttons_with_hide_2.JPG

Select value 12

images/toggle_buttons_with_hide_3.JPG

And hide Hidden options

images/toggle_buttons_with_hide_4.JPG
print(wid.value)  # "12"
wid.options_visible = [str(i) for i in range(2)]
wid.options_hidden = [f"another {i}" for i in range(2)]
images/toggle_buttons_with_hide_5.JPG

MultiToggleButtonsWithHide

Create and show this widget

from ipywidgets_toggle_buttons import MultiToggleButtonsWithHide
wid = MultiToggleButtonsWithHide(
    options_visible=[str(i) for i in range(10)],
    options_hidden=[str(i) for i in range(5, 15)],
    max_chosen_values=4,
)
wid  # OR wid.box_widget
images/multi_toggle_buttons_with_hide_1.JPG

After pressing the button Show Hidden Options

images/multi_toggle_buttons_with_hide_2.JPG

Select a few options and hide all Hidden options

images/multi_toggle_buttons_with_hide_3.JPG
print(wid.value)  # ('1', '9', '11', '13')
print(wid.options_hidden)  # ('10', '11', '12', '13', '14')

If at any moment you want to change the options then it can be done like shown below

wid.options_visible = [str(i) for i in range(2)]
wid.options_hidden = [f"another {i}" for i in range(2)]

Advanced Usage examples

How to add this widgets into the Box, HBox, VBox

from ipywidget import Box

wid = AnyToggleButton(
    ...,
    func_to_get_option_width=func_new_width
)

wid_box = Box([])

def func_new_width(iter_options):

    int_max_width = 0
    for option in iter_options:
        cur_but_width = 8 * len(option)
        if cur_but_width > int_max_width:
            int_max_width = cur_but_width
    return int_max_width

How to adjust buttons width differently

During the initialization of any widget pass additional argument func_to_get_option_width with function which accepts itterator over options and returns 1 integer with width to use for this buttons

def func_new_width(iter_options):

    int_max_width = 0
    for option in iter_options:
        cur_but_width = 8 * len(option)
        if cur_but_width > int_max_width:
            int_max_width = cur_but_width
    return int_max_width

wid = AnyToggleButton(
    ...,
    func_to_get_option_width=func_new_width
)

How to access all options of the widget

Use attribute .widget to get full control over shown widget

wid = AnyToggleButton(...)
wid.widget

Contacts

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ipywidgets_toggle_buttons-0.1.7.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

ipywidgets_toggle_buttons-0.1.7-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file ipywidgets_toggle_buttons-0.1.7.tar.gz.

File metadata

File hashes

Hashes for ipywidgets_toggle_buttons-0.1.7.tar.gz
Algorithm Hash digest
SHA256 758ba9939571c64f61b97c3f86b1e3ec0d3dead03fc5811c6db1c6da347b7f41
MD5 3c3268468684e7b2c05fe3c3e11c0f71
BLAKE2b-256 19f88e87a6280003ec5544995a3bf1ee22ebdc9e970b5401d3fcd7d3041bb831

See more details on using hashes here.

File details

Details for the file ipywidgets_toggle_buttons-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for ipywidgets_toggle_buttons-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 6fdac81567fb4211410d4115b14041f6f84cd115b4774b6ef47dde58c8bee9fb
MD5 af1f2813ac8984a72eb6fbb571910d21
BLAKE2b-256 aade24028681af2c776f9ebc070eb9c8748d16467a19aca60bf5251ca65e370c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page