added the language change toggle to the system tray menue
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
{
|
||||
"run_on_startup": true,
|
||||
"shortcut": "ctrl+shift+B"
|
||||
"shortcut": "ctrl+shift+B",
|
||||
"lang_change": true
|
||||
}
|
||||
@@ -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':
|
||||
|
||||
13
src/main.pyw
13
src/main.pyw
@@ -122,6 +122,8 @@ def on_shortcut():
|
||||
print(f"Converted text: {converted_text}")
|
||||
keyboard.press_and_release('ctrl+v') # Paste the converted text
|
||||
time.sleep(0.2)
|
||||
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()
|
||||
@@ -129,6 +131,10 @@ def quit_app(icon, item):
|
||||
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()
|
||||
|
||||
Reference in New Issue
Block a user