added the language change toggle to the system tray menue

This commit is contained in:
2025-08-11 11:43:28 +03:30
parent 3b36df7e67
commit 411909ea86
3 changed files with 17 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
{
"run_on_startup": true,
"shortcut": "ctrl+shift+B"
"shortcut": "ctrl+shift+B",
"lang_change": true
}

View File

@@ -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':

View File

@@ -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()