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.10.tar.gz (26.2 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.10-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: cedbox-0.1.10.tar.gz
  • Upload date:
  • Size: 26.2 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.10.tar.gz
Algorithm Hash digest
SHA256 fa5baf9b9b875086a3b071558cdb107360140532c62bd7e7cb492f3273f95ad0
MD5 1058194e8007d8f9d6912d0a518ab76f
BLAKE2b-256 9ed1174b5723048ee3086051a7b98e881bc1c7916b059f38e80ae9ead799f3fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for cedbox-0.1.10.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.10-py3-none-any.whl.

File metadata

  • Download URL: cedbox-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.10-py3-none-any.whl
Algorithm Hash digest
SHA256 23602e6ffcd09ea31bb91b555e2b8a1a3f9552368db7809ab4d11b9959bbf988
MD5 61f14efccb92d7654339a49fafdb1775
BLAKE2b-256 744e357a833dfd07b66e39d2ea2f05eb6343945ad723e2cd6aa78c58c42d162e

See more details on using hashes here.

Provenance

The following attestation bundles were made for cedbox-0.1.10-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