diff --git a/config.json b/config.json index 9632656..6b90feb 100644 --- a/config.json +++ b/config.json @@ -1,4 +1,5 @@ { "run_on_startup": true, - "shortcut": "ctrl+shift+B" + "shortcut": "ctrl+shift+B", + "lang_change": true } \ No newline at end of file diff --git a/src/config.py b/src/config.py index 71adc06..3bb85a3 100644 --- a/src/config.py +++ b/src/config.py @@ -14,7 +14,7 @@ def load_config(): It also migrates the old shortcut.txt if it exists. """ if not os.path.exists(CONFIG_FILE): - config = {"run_on_startup": False, "shortcut": "ctrl+space"} + config = {"run_on_startup": False, "shortcut": "ctrl+shift+b","lang_change": True} if os.path.exists(SHORTCUT_FILE): with open(SHORTCUT_FILE, "r") as f: shortcut = f.read().strip() @@ -59,6 +59,7 @@ if __name__ == "__main__": config = load_config() print(f"Your shortcut is set to: {config.get('shortcut', 'Not set')}") print(f"Run on startup is set to: {config.get('run_on_startup', 'Not set')}") + print(f"Change language layout after transformation is set to: {config.get('lang_change', 'Not set')}") print('Do you want to change the shortcut? (y/n): ', end='') if input().lower() == 'y': diff --git a/src/main.pyw b/src/main.pyw index 6c6e0cb..33c97cb 100644 --- a/src/main.pyw +++ b/src/main.pyw @@ -122,13 +122,19 @@ def on_shortcut(): print(f"Converted text: {converted_text}") keyboard.press_and_release('ctrl+v') # Paste the converted text time.sleep(0.2) - keyboard.press_and_release('windows+space') + if load_config().get("lang_change", True): + # Change the keyboard layout to Persian + keyboard.press_and_release('windows+space') def quit_app(icon, item): icon.stop() import os os._exit(0) def setup_tray(config): + def on_toggle_lang_change(icon, item): + config["lang_change"] = not item.checked + save_config(config) + def on_toggle_startup(icon, item): config["run_on_startup"] = not item.checked save_config(config) @@ -140,6 +146,11 @@ def setup_tray(config): image = Image.open("assets/icon.png") menu = pystray.Menu( pystray.MenuItem(f'Current Shortcut: {get_shortcut()}',lambda icon, item: None), + pystray.MenuItem( + 'change keyboard language layout after transformation', + on_toggle_lang_change, + checked=lambda item: config["lang_change"] + ), pystray.MenuItem( 'Run on Startup', on_toggle_startup, @@ -166,7 +177,7 @@ def main(): print(f"Press {shortcut} to convert text to Persian.") # Keep the script running - keyboard.wait() + keyboard.wait(suppress=True) if __name__ == "__main__": main()