Skip to main content

Multi-interface Morse translator (CLI, API, GUI)

Project description

Morse-Translator

Python 3.8+ MIT License FastAPI

نسخه فارسی سند النسخة العربية من المستند Version française du document

A compact, feature-rich Morse Code ⇄ Text translator with CLI, GUI, and REST API. Bidirectional conversions for letters, numbers, and common punctuation with built-in validation.


📸 Screenshots


🚀 Features

  • Text ↔ Morse: bidirectional conversion for A–Z, 0–9, and common punctuation
  • Validation: checks Morse syntax (allowed: ., -, /, space; max 6 chars per token)
  • Interactive CLI: menu-driven experience via main.py
  • Desktop GUI: responsive customtkinter-based UI with text/Morse input fields and toggle switch
  • REST API: FastAPI with versioned routes (/v1) and interactive docs at /docs
  • Installable package: global morse command after pip install -e .
  • CLI flags: single-shot conversions (-t, -m, -vm, -ui)

📦 Installation

  1. Clone and create virtual environment:
git clone https://github.com/amirhossein77-98/Morse-Translator.git
cd Morse-Translator
python3 -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. Install dependencies:
pip install -e .

Installs the project in development mode with the global morse CLI entry point.

Alternative environments:

  • pipenv: pipenv install --dev && pipenv shell
  • poetry: poetry install && poetry shell
  • uv: uv sync (if initialized with uv)

🖥 Usage

Direct run

Interactive menu:

python3 main.py

CLI args

All flags are mutually exclusive. Use / (space-slash-space) to separate words in Morse.

Text to Morse:

python3 main.py -t "Hello World"
morse -t "Hello World"  # After pip install -e .

Morse to Text:

python3 main.py -m ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."

Validate Morse:

python3 main.py -vm ".... . .-.. .-.. ---"

GUI

Launch the responsive customtkinter GUI:

python3 main.py -ui
morse -ui  # After pip install -e .

Features:

  • Toggle between "Text to Morse" and "Morse to Text" via switch
  • Real-time input/output textboxes
  • Validation for Morse input
  • Responsive grid layout, centered widgets

API

Start the FastAPI server:

uvicorn api.app:app --reload

Open http://127.0.0.1:8000/docs for interactive API docs.

Example endpoints (base: /v1):

# GET
curl "http://127.0.0.1:8000/v1/text-to-morse/hello"
curl "http://127.0.0.1:8000/v1/morse-to-text/--"
curl "http://127.0.0.1:8000/v1/validate-morse/--"

# POST
curl -X POST "http://127.0.0.1:8000/v1/text-to-morse" \
  -H "Content-Type: application/json" \
  -d '{"text":"hello"}'

Response format:

{
  "original_text": "hello",
  "translated_text": ".... . .-.. .-.. ---"
}

Installable morse package

After pip install -e ., use the global morse command:

morse -t "Hello"
morse -m ".... . .-.. .-.. ---"
morse -vm "..."
morse -ui

🔧 Testing

Run unit and API tests (no server startup needed):

python3 -m unittest discover -v        # All tests
python3 -m unittest test.api_tests     # API only
python3 -m unittest test.converter_tests  # Converter only

Note: Tests use unittest and FastAPI TestClient. Ensure no stray Unicode characters in test strings.


🛠 Packaging & Contributing

Build distribution packages:

pip install build
python -m build

Creates wheels and source distributions in dist/.

Project structure:

  • core/converters.py — conversion logic & validation
  • data/morse_dataset.py — Morse/ASCII mapping
  • api/app.py — FastAPI application
  • api/routes/v1.py — versioned endpoints
  • views/ui/ctkinter_ui.py — GUI with customtkinter
  • test/ — unit and API tests

Contributing: Bug reports and PRs welcome. Please include repro steps and test cases.


📜 License

MIT License — see LICENSE 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

amirstein_morse_translator-0.3.1.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

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

amirstein_morse_translator-0.3.1-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file amirstein_morse_translator-0.3.1.tar.gz.

File metadata

File hashes

Hashes for amirstein_morse_translator-0.3.1.tar.gz
Algorithm Hash digest
SHA256 eb81e96f6fb4805077751a3b5823fbb1b55add99c9ac28b198d62f9386b55f91
MD5 6ca4e39b225e7de2d1b23bdde66e1e96
BLAKE2b-256 3069047ad9914f6fef397e7b87d25836c7b39e5049d6c01baaf05120ea5b5195

See more details on using hashes here.

File details

Details for the file amirstein_morse_translator-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for amirstein_morse_translator-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 339f000567b99375eecfdb6b229a4d5e8fd926032e7364fc14a4fe2badc5f6b1
MD5 a0f91e810650ea6108fd6eb186050b56
BLAKE2b-256 ef221e137fdf1b8ac3705a911444ee2265e4d5c110c48ed33b29343ceac6ab0d

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