Skip to main content

A Python utility package for data handling, input validation, Morse code processing, and audio generation/streaming

Project description

CedBox

CedBox is a Python utility package that provides various tools for Terminal User Interfaces (TUI), Morse code processing, hierarchical data handling (Yggdrasil), user input validation, and audio generation/streaming.

Features

  • TUI (Terminal User Interface): A lightweight, declarative terminal interface framework supporting:

    • Nested folder column-based menus
    • Dynamic setting/switch editing with console input validation
    • Headless/Agent execution and full schema serialization via JSON
  • Morse Code Processing: Tools for working with Morse code:

    • Convert text to Morse code
    • Represent Morse code as time units
    • Generate Morse code sequences and WAV files
  • Yggdrasil: A hierarchical tree-like data structure that extends Python's dictionary, with support for:

    • Automatic node creation
    • Loading data from DataFrames and SQL queries
    • Tree visualization
  • Input Utilities: Functions for handling user input with validation and type conversion:

    • Type-safe integer, float, choice, boolean, date, email, and file path inputs.
  • Audio Generation & Streaming: Utilities for creating WAV files or streaming audio:

    • Generate signals from sequences of durations
    • Play Morse code audio sequences directly to output devices

Installation

pip install cedbox

Usage Examples

TUI (Terminal User Interface)

CedBox includes a lightweight, hierarchical Terminal User Interface (TUI) framework that can be built programmatically, decorated, or generated directly from any Yggdrasil tree. It also supports input validation and headless execution via JSON.

Defining TUI with Builders and Decorators

import sys
from cedbox import TUI

tui = TUI(title="My TUI Application")

# Add settings with parent containers
tui.add_switch("Muted", default=True, parent="Settings/System")
tui.add_setting("Volume", default=90, parent="Settings/System")

# Add actions using parent mounting
@tui.action("Quit", "Actions")
def quit_app():
    sys.exit(0)

# Add actions using absolute path overrides
@tui.action(abs="Actions/Greet")
def greet():
    return "Hello!"

# Run interactive TUI
tui.run()

Running TUI directly from Yggdrasil Tree

from cedbox import Yggdrasil, TUI

tree = Yggdrasil()
tree["Settings"]["System"]["Muted"] = False
tree["Settings"]["System"]["Volume"] = 80

tui = TUI(tree, title="Direct Yggdrasil TUI")
tui.run()

Machine-Readable Headless JSON Mode

Any application defined using TUI can be executed headlessly without the terminal interface, making it perfect for external agents or automated scripts to interact with:

  1. Dump Menu Schema as JSON:

    python my_app.py --json-schema
    
  2. Execute Actions or Update Settings via Path:

    python my_app.py --json-exec "Settings/System/Muted" --value False
    # Output: {"status": "success", "message": "Settings/System/Muted updated directly in state", "value": false}
    

Morse Code Processing & Audio Generation

EasyMorse

The EasyMorse class provides tools for converting text to Morse code signals.

from cedbox import EasyMorse

# Create Morse code from text
morse = EasyMorse(text="SOS")
print(f"Original text: {morse.raw_text}")
print(f"Morse code: {morse.morse_code}")

# View the time sequence (1=dot, 3=dash, -1=pause between symbols)
print(f"Time sequence: {morse.morse_seq}")

EasyWav

The EasyWav class allows you to create WAV audio files from sequences of durations.

from cedbox import EasyMorse, EasyWav

morse = EasyMorse(text="SOS")
wav = EasyWav(
    sequence=morse.morse_seq,
    frequency=800,
    time_unit=100
)
wav.save('morse_sos.wav')

EasyStream

The EasyStream class allows you to stream audio directly to your output device without creating intermediate files.

from cedbox import EasyMorse, EasyStream

morse = EasyMorse(text="SOS")
stream = EasyStream(
    sequence=morse.morse_seq,
    frequency=800,
    time_unit=100
)
stream.stream()

Yggdrasil

Yggdrasil is a hierarchical tree-like data structure that extends Python's dictionary with automatic node creation.

from cedbox import Yggdrasil
import pandas as pd

# Create a new tree
tree = Yggdrasil()
tree['users']['john']['email'] = 'john@example.com'
tree['users']['john']['age'] = 30
tree.print_tree()

Creating from DataFrame / SQL

df = pd.DataFrame({
    'name': ['John', 'Jane'],
    'email': ['john@example.com', 'jane@example.com'],
    'age': [30, 28]
})
tree_from_df = Yggdrasil.from_dataframe(df)

Input Utilities

CedBox provides various functions for handling user input with validation and type conversion.

from cedbox.inputs import string_put, int_put, bool_put

name = string_put("Enter your name: ")
age = int_put("Enter your age: ", conditions=[lambda x: 0 < x < 120])
confirm = bool_put("Confirm? ")

Dependencies

  • pandas >= 2.0.0
  • sounddevice >= 0.5.2 (for audio streaming)

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

cedbox-0.1.11.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

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

cedbox-0.1.11-py3-none-any.whl (19.9 kB view details)

Uploaded Python 3

File details

Details for the file cedbox-0.1.11.tar.gz.

File metadata

  • Download URL: cedbox-0.1.11.tar.gz
  • Upload date:
  • Size: 26.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cedbox-0.1.11.tar.gz
Algorithm Hash digest
SHA256 cd4f6cb1f59657b5a5c47a471ed7fd52d526f8ec65aaaf555b5633cde1c958f5
MD5 d3bee2dfcde16d0b675eb4488ea84345
BLAKE2b-256 d5e6f5c05b986d167cd950afe6b03834be98c5b5a495552dc27d7401a9b94602

See more details on using hashes here.

Provenance

The following attestation bundles were made for cedbox-0.1.11.tar.gz:

Publisher: publish.yml on LilLordCedric/CedBox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cedbox-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: cedbox-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 19.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cedbox-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 2ca817b4faa2f60d4ebdd982785ae7d43f4e5c060e74c965df8387fc54841419
MD5 923c77d1cb8e3042655adf92c12946df
BLAKE2b-256 6a5d022af9d523299b48640375073c79454f3ecaecdf2a63df31f0978acea5e6

See more details on using hashes here.

Provenance

The following attestation bundles were made for cedbox-0.1.11-py3-none-any.whl:

Publisher: publish.yml on LilLordCedric/CedBox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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