commit 3aad8080f41312200d09d18eab942eefe0204356 Author: Hamed Date: Sun Aug 10 01:15:53 2025 +0330 Initial commit: Add main application files and setup scripts diff --git a/assets/icon.png b/assets/icon.png new file mode 100644 index 0000000..3ce4e83 Binary files /dev/null and b/assets/icon.png differ diff --git a/install.bat b/install.bat new file mode 100644 index 0000000..44fa3c7 --- /dev/null +++ b/install.bat @@ -0,0 +1,19 @@ +@echo off +REM install.bat +REM This script sets up a Python virtual environment and installs required libraries. +REM Make sure to run this script in the project directory. + +REM Create Python virtual environment +python -m venv venv + +REM Activate the virtual environment +call venv\Scripts\activate.bat + +REM Upgrade pip +pip install --upgrade pip + +REM Install required libraries from requirements.txt +pip install -r requirements.txt --no-cache-dir + +echo Environment setup complete. +pause \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..5d88c10 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,4 @@ +keyboard==0.13.5 +pyperclip==1.9.0 +pystray==0.19.5 +Pillow==11.3.0 \ No newline at end of file diff --git a/run.bat b/run.bat new file mode 100644 index 0000000..f159447 --- /dev/null +++ b/run.bat @@ -0,0 +1,11 @@ +@echo off +REM run.bat +REM Activates the virtual environment and runs your main Python script. + +REM Activate the virtual environment +call venv\Scripts\activate.bat + +REM Run your main Python script (replace main.py with your script name if different) +start "OopsWrongLang" /B pythonw src\main.pyw +echo application is running in the background. you can close this window. +pause \ No newline at end of file diff --git a/src/main.pyw b/src/main.pyw new file mode 100644 index 0000000..1f66100 --- /dev/null +++ b/src/main.pyw @@ -0,0 +1,147 @@ +# oopswronglang/main.py +# This script listens for a keyboard shortcut (Ctrl + Space) and converts the text +# from English characters to Persian characters using the `persian` library. +import keyboard +import pyperclip +import time +import threading +import pystray +from PIL import Image +import re + +def convert_en_characters(input_str): + """ + Assumes that characters written with standard persian keyboard + not windows arabic layout + :param input_str: String contains English chars + :return: New string with related characters on Persian standard keyboard + """ + mapping = { + 'q': 'ض', + 'w': 'ص', + 'e': 'ث', + 'r': 'ق', + 't': 'ف', + 'y': 'غ', + 'u': 'ع', + 'i': 'ه', + 'o': 'خ', + 'p': 'ح', + '[': 'ج', + ']': 'چ', + 'a': 'ش', + 's': 'س', + 'd': 'ی', + 'f': 'ب', + 'g': 'ل', + 'h': 'ا', + 'j': 'ت', + 'k': 'ن', + 'l': 'م', + ';': 'ک', + "'": 'گ', + 'z': 'ظ', + 'x': 'ط', + 'c': 'ز', + 'v': 'ر', + 'b': 'ذ', + 'n': 'د', + 'm': 'ئ', + ',': 'و', + '?': '؟', + '\\':'پ', + 'ض': 'q', + 'ص': 'w', + 'ث': 'e', + 'ق': 'r', + 'ف': 't', + 'غ': 'y', + 'ع': 'u', + 'ه': 'i', + 'خ': 'o', + 'ح': 'p', + 'ج': '[', + 'چ': ']', + 'ش': 'a', + 'س': 's', + 'ی': 'd', + 'ب': 'f', + 'ل': 'g', + 'ا': 'h', + 'ت': 'j', + 'ن': 'k', + 'م': 'l', + 'ک': ';', + 'گ': "'", + 'ظ': 'z', + 'ط': 'x', + 'ز': 'c', + 'ر': 'v', + 'ذ': 'b', + 'د': 'n', + 'ئ': 'm', + 'و': ',', + '؟': '?', + 'پ': '\\', + 'H':'آ', + 'آ': 'H', + 'C':'ژ', + 'ژ': 'C', + 'T':'،', + '،': 'T', + '؛':'Y', + 'Y':'؛', + } + return _multiple_replace(mapping, input_str) +def _multiple_replace(mapping, text): + """ + Internal function for replace all mapping keys for a input string + :param mapping: replacing mapping keys + :param text: user input string + :return: New string with converted mapping keys to values + """ + pattern = "|".join(map(re.escape, mapping.keys())) + return re.sub(pattern, lambda m: mapping[m.group()], str(text)) + +# Function to handle the keyboard shortcut +def on_shortcut(): + """This function is called when the shortcut is pressed.""" + orginal_text = pyperclip.paste() # Get the current clipboard content + time.sleep(0.1) + keyboard.press_and_release('ctrl+c') # Simulate pressing Ctrl+C to copy selected text + time.sleep(0.1) + text = pyperclip.paste() + # If no text is selected, do nothing + if not text or text== orginal_text: + print("No text was selected.") + return + converted_text = convert_en_characters(text) + pyperclip.copy(converted_text) + print(f"Converted text: {converted_text}") + keyboard.press_and_release('ctrl+v') # Paste the converted text + +def quit_app(icon, item): + icon.stop() + import os + os._exit(0) + +def setup_tray(): + image = Image.open("assets/icon.png") # Make sure icon.png exists in your project folder + menu = pystray.Menu(pystray.MenuItem('Quit', quit_app)) + icon = pystray.Icon("oopswronglang", image, "OopsWrongLang", menu) + icon.run() + +def main(): + # Start the tray icon in a separate thread + tray_thread = threading.Thread(target=setup_tray, daemon=True) + tray_thread.start() + + # Register the keyboard shortcut (Ctrl + Space) + keyboard.add_hotkey('ctrl+space', on_shortcut) + print("Press Ctrl + Space to convert text to Persian.") + + # Keep the script running + keyboard.wait() + +if __name__ == "__main__": + main()