From 31c79a36fc06c095a75ce74e6aeebf095aa260f1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 9 Aug 2025 22:17:15 +0000 Subject: [PATCH 1/3] feat: Implement interactive shortcut selection This commit enhances your experience for setting a keyboard shortcut. Instead of typing the shortcut as a string, you are now prompted to press the desired key combination directly. The `src/config.py` module has been updated to: - Use `keyboard.read_hotkey()` to capture the key combination you press. - Display the captured shortcut for confirmation. - Save the shortcut only after you confirm it is correct. This provides a more intuitive and less error-prone way for you to configure your preferred shortcut. --- run.bat | 2 +- src/config.py | 26 ++++++++++++++++++++++++++ src/main.pyw | 8 +++++--- 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/config.py diff --git a/run.bat b/run.bat index f159447..3cb2435 100644 --- a/run.bat +++ b/run.bat @@ -6,6 +6,6 @@ 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 +start "OopsWrongLang" /B python 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/config.py b/src/config.py new file mode 100644 index 0000000..1095932 --- /dev/null +++ b/src/config.py @@ -0,0 +1,26 @@ +import os +import keyboard + +CONFIG_FILE = "shortcut.txt" + +def get_shortcut(): + """ + Retrieves the shortcut from the config file. + If the file doesn't exist, it prompts the user to create one by pressing the desired keys. + """ + if not os.path.exists(CONFIG_FILE): + print("It seems this is the first time you are running the application.") + while True: + print("Please press the key combination you want to use as a shortcut and then press ESC.") + shortcut = keyboard.read_hotkey(suppress=False) + print(f"You pressed: {shortcut}") + confirm = input("Is this correct? (y/n): ").lower() + if confirm == 'y': + with open(CONFIG_FILE, "w") as f: + f.write(shortcut) + return shortcut + else: + print("Let's try again.") + else: + with open(CONFIG_FILE, "r") as f: + return f.read().strip() diff --git a/src/main.pyw b/src/main.pyw index 1f66100..9304ea4 100644 --- a/src/main.pyw +++ b/src/main.pyw @@ -8,6 +8,7 @@ import threading import pystray from PIL import Image import re +from config import get_shortcut def convert_en_characters(input_str): """ @@ -136,9 +137,10 @@ def main(): 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.") + # Register the keyboard shortcut + shortcut = get_shortcut() + keyboard.add_hotkey(shortcut, on_shortcut) + print(f"Press {shortcut} to convert text to Persian.") # Keep the script running keyboard.wait() From 43ac0b1e3b683f2030605766ab15e45fb3c68405 Mon Sep 17 00:00:00 2001 From: Hamed Date: Sun, 10 Aug 2025 10:35:45 +0330 Subject: [PATCH 2/3] fixed cinfig.py to allow for changing the shortcut after the first run --- src/config.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/config.py b/src/config.py index 1095932..e45ef77 100644 --- a/src/config.py +++ b/src/config.py @@ -24,3 +24,26 @@ def get_shortcut(): else: with open(CONFIG_FILE, "r") as f: return f.read().strip() + +if __name__ == "__main__": + shortcut = get_shortcut() + print(f"Your shortcut is set to: {shortcut}") + print("You can now use this shortcut in the application.") + print('do you want to change the shortcut? (y/n): ', end='') + if input().lower() == 'y': + while True: + print("Please press the key combination you want to use as a shortcut and then press ESC.") + new_shortcut = keyboard.read_hotkey(suppress=False) + print(f"You pressed: {new_shortcut}") + confirm = input("Is this correct? (y/n): ").lower() + if confirm.lower() == 'y': + with open(CONFIG_FILE, "w") as f: + f.write(new_shortcut) + print("Shortcut updated successfully.") + break + else: + print("Let's try again.") + else: + print("No changes made to the shortcut.") + print("Exiting without changes.") + input("Press Enter to exit.") \ No newline at end of file From 25ef29be4b2beb3871b04c23b9d5ebf6f1506ee5 Mon Sep 17 00:00:00 2001 From: Hamed Date: Sun, 10 Aug 2025 11:01:34 +0330 Subject: [PATCH 3/3] fixed run.bat and created config&run.bat for easy configuration. --- config&run.bat | 20 ++++++++++++++++++++ run.bat | 2 +- src/config.py | 5 ++++- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 config&run.bat diff --git a/config&run.bat b/config&run.bat new file mode 100644 index 0000000..2e00b21 --- /dev/null +++ b/config&run.bat @@ -0,0 +1,20 @@ +@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 the config script +python src\config.py +REM Check if the activation was successful +if errorlevel 1 ( + echo Failed to activate the virtual environment. + pause + exit /b 1 +) + +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/run.bat b/run.bat index 3cb2435..f159447 100644 --- a/run.bat +++ b/run.bat @@ -6,6 +6,6 @@ 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 python src\main.pyw +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/config.py b/src/config.py index e45ef77..72051be 100644 --- a/src/config.py +++ b/src/config.py @@ -1,6 +1,6 @@ import os import keyboard - +import time CONFIG_FILE = "shortcut.txt" def get_shortcut(): @@ -32,9 +32,11 @@ if __name__ == "__main__": print('do you want to change the shortcut? (y/n): ', end='') if input().lower() == 'y': while True: + time.sleep(0.2) print("Please press the key combination you want to use as a shortcut and then press ESC.") new_shortcut = keyboard.read_hotkey(suppress=False) print(f"You pressed: {new_shortcut}") + time.sleep(0.5) confirm = input("Is this correct? (y/n): ").lower() if confirm.lower() == 'y': with open(CONFIG_FILE, "w") as f: @@ -43,6 +45,7 @@ if __name__ == "__main__": break else: print("Let's try again.") + else: print("No changes made to the shortcut.") print("Exiting without changes.")