Skip to main content

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

Project description

Morse-Translator

Python 3.8+ MIT License FastAPI PyPI version CI

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.1.tar.gz (14.5 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.1-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for amirstein_morse_translator-0.3.1.1.tar.gz
Algorithm Hash digest
SHA256 4e48e81b753ef70c10e6ea75d5320384ebf8bfda919c516f867668f22feea534
MD5 35daed7b99dba5a839f09f04a19bb92b
BLAKE2b-256 455d44a6ee8e3bb0f3b812396996467e3124ab4b0a9aa569b6780f0488461759

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for amirstein_morse_translator-0.3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4fe88b86760052758875d72ca76a1fed9451e892d7f4e1bd9bacc2818effb5b1
MD5 209ed93b83373d1045dc0c43999b193d
BLAKE2b-256 4a4b0128630488fa5c4524887099f39b764705ea32bb2f55360ab053d20b8ff2

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