Skip to content

Amirhossein77-98/Python-Morse-Translator

Repository files navigation

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.

About

Morse-Translator is a compact Python project that converts between ASCII text and Morse code, validates Morse input, and exposes a CLI, a versioned FastAPI HTTP API, an installable Package, and a Graphical User Interface.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages