Skip to main content

Simplify the creation of GUI elements in terminals and Jupyter Notebooks

Project description

EZInput

PyPI Python Version Downloads Docs License Tests Coverage Contributors GitHub stars GitHub forks DOI

EZInput is a Python library that simplifies the creation of user interfaces both in the terminal and in Jupyter notebooks. It provides a convenient way to add various types of widgets, making it easier to interact with your code and visualize results.

DISCLAIMER: the project is currently in alpha stage and will likely suffer changes in the API and functionality.

Installation

To install EZInput, you can use pip:

pip install ezinput

Usage

EZInput provides a unified interface for creating UIs in either the terminal or Jupyter notebooks. The mode is automatically determined based on the environment or can be explicitly specified using the mode argument. Thanks to the unified API, you can easily re-use your code for terminal and Jupyter notebook without having to change it.

Terminal Mode

To create a GUI in the terminal using prompt_toolkit:

from ezinput import EZInput

gui = EZInput(title="My Terminal GUI", mode="prompt")

# Add GUI elements
gui.add_check("confirm", "Do you want to proceed?", remember_value=True)
gui.add_text("name", "Enter your name:", placeholder="John Doe", remember_value=True)
gui.add_int_range("age", "Enter your age:", 18, 100, remember_value=True)
gui.add_float_range("height", "Enter your height (in meters):", 1.0, 2.5, remember_value=True)
gui.add_dropdown("color", "Choose your favorite color:", ["Red", "Blue", "Green"], remember_value=True)
gui.add_path_completer("file_path", "Enter a file path:", remember_value=True)

# Save settings
gui.save_settings()

# Restore default settings
gui.restore_default_settings()

Jupyter Notebook Mode

To create a GUI in Jupyter notebooks using ipywidgets:

from ezinput import EZInput

gui = EZInput(title="My Jupyter GUI", mode="jupyter")

# Add GUI elements
gui.add_text("text", description="Enter some text:", placeholder="Hello, world!", remember_value=True)
gui.add_int_range("int_slider", description="Choose a number:", vmin=0, vmax=10, remember_value=True)
gui.add_float_range("float_slider", description="Choose a decimal:", vmin=0.0, vmax=1.0, remember_value=True)
gui.add_check("checkbox", description="Check this box:", remember_value=True)
gui.add_dropdown("dropdown", options=["Option 1", "Option 2", "Option 3"], description="Choose an option:", remember_value=True)
gui.add_file_upload("file_upload", accept=".txt", multiple=False)

# Display the GUI
gui.show()

# Save settings
gui.save_settings()

Unified API

EZInput provides a unified API for both terminal and Jupyter notebook modes. The following methods are available:

  • add_label(tag, label): Add a label to the GUI.
  • add_text(tag, description, placeholder="", remember_value=False): Add a text input field.
  • add_text_area(tag, description, placeholder="", remember_value=False): Add a multi-line text area.
  • add_int_range(tag, description, vmin, vmax, remember_value=False): Add an integer slider or range input.
  • add_float_range(tag, description, vmin, vmax, remember_value=False): Add a float slider or range input.
  • add_check(tag, description, remember_value=False): Add a yes/no or checkbox input.
  • add_dropdown(tag, options, description="", remember_value=False): Add a dropdown menu.
  • add_path_completer(tag, description, remember_value=False): Add a file path input with autocompletion.
  • add_file_upload(tag, accept=None, multiple=False): Add a file upload widget (Jupyter only).
  • add_callback(tag, func, values, description="Run"): Add a function to be ran (if in jupyter, after the press of the generated button) that triggers a callback function.

Saving and Restoring Settings

EZInput allows you to save and restore widget values using configuration files:

# Save current settings
gui.save_settings()

# Restore default settings
gui.restore_default_settings()

Examples

Terminal Example

from ezinput import EZInput

gui = EZInput(title="Terminal Example", mode="prompt")
gui.add_text("username", "Enter your username:", remember_value=True)
gui.add_int_range("age", "Enter your age:", 18, 100, remember_value=True)
gui.save_settings()

Jupyter Notebook Example

from ezinput import EZInput

gui = EZInput(title="Jupyter Example", mode="jupyter")
gui.add_text("username", description="Enter your username:", remember_value=True)
gui.add_int_range("age", description="Enter your age:", vmin=18, vmax=100, remember_value=True)
gui.show()

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

ezinput-0.0.1.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ezinput-0.0.1-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file ezinput-0.0.1.tar.gz.

File metadata

  • Download URL: ezinput-0.0.1.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ezinput-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4b140cde82b6bf7fd0523084c866f367495c164436ed04a36460606e11dc181a
MD5 2a91b283649b970dde744aa2c33d9a6d
BLAKE2b-256 c7a11964361af371ffe974363f984fec449d3c873c0e562776084cc350dbf268

See more details on using hashes here.

File details

Details for the file ezinput-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ezinput-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for ezinput-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 54d802192d7f6b662e561583db2e435a998331ca0fc075e8fdbe82fca86f823e
MD5 8d545ee637a35e7d3b5aa2da98460e58
BLAKE2b-256 585a1c091f458d2a949949c8ec7758c794798bb264c259307476eb77fa881b0b

See more details on using hashes here.

Supported by

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