From 00bda02b371c6214873486505b64785f15bb2411 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 10 Aug 2025 13:40:15 +0000 Subject: [PATCH 1/4] feat: Add 'Run on Startup' checkbox to system tray This commit introduces a new feature that allows you to configure the application to run on startup. - A "Run on Startup" checkbox has been added to the system tray menu. - The application now uses a `config.json` file to store settings, including the "run on startup" state. - On Windows, the application adds/removes itself from the startup programs by creating/deleting a key in the Windows Registry. --- src/__pycache__/config.cpython-312.pyc | Bin 0 -> 3891 bytes src/__pycache__/startup.cpython-312.pyc | Bin 0 -> 2620 bytes src/config.py | 62 ++++++++++++++++++------ src/main.pyw | 31 ++++++++++-- src/startup.py | 48 ++++++++++++++++++ 5 files changed, 120 insertions(+), 21 deletions(-) create mode 100644 src/__pycache__/config.cpython-312.pyc create mode 100644 src/__pycache__/startup.cpython-312.pyc create mode 100644 src/startup.py diff --git a/src/__pycache__/config.cpython-312.pyc b/src/__pycache__/config.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..5dd0e834f698ac380a05d1a389ef6f2dda035abc GIT binary patch literal 3891 zcmbVPO>7&-6`m!R|34xri?U2x8b_8aTDBB5jh(oTomRGN8Ls@J1ce2(?3y!@NRzwl z?9ws`Dshnll@bGD8W)zE6j4rTY8Noji;pebOVJAz(J-~vAwhG=rEu*426XD1T`nov zu2FP|ot=3z@6DSx-}`3yk3hhSp!{uVaeCH=&_8*{Dz19t@y~4tT}K2FA%iB&w=f|X zecOc1c-trJ#5N%k`-Fptzd{pE;(*#koKU-|hqx~GAygKa&xWY;X5H|F7kWP8rrvai zwP^EAJj8nwR_5hn^n2S)!E6i2(DMBkE&mI(0wj2=#j8C0hv*2R|s{Z z&6$)ojR~EU@)-?Zk}`R!)-7mQ%BTv?rlw#en9P?}G6Zi#DNaptBZlR=-bm4#)L5op z%}Gfbx9LHamlKMdP&J8Z`JC>y^mTzT4%M-^U$-f$F6Ja{T6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&TBWwO}B{Es{Pp!3g-EZ$- zZtuVScD4Nnb0=V+{Nts*rEQhS-l~7!S~OPKzJDcp;C}Rt<>(tL(Ia!mYc0{m?)TrR z_3SG<%f;o;OKYLn;z%{rU2E?uw|o<7t3>;%q4>i#)YAGeiu{rCo@L*Tin!x3_=R+L zB9Vo-Bof6A2rFwI1Dw1{`4Jt&CNf-O3WtVP+;%Q61Ez5OisKk*%;W@6>_4g)FtN@! zIW5Uk)PRB&p5`HO8naWGu$Mq}>UTGI`TG&ZiD`uKk8y_i06b8>I>L6stJpbS|8~Ur z9D(Z^uIYR-3GklGXEKEW*3Bp3F~|U8X%%NB0uCsfd>ANhJ$5;zaS-#*0woV$3g+~I z;+8W!S@1DgGcyUUX>B0h%J}~#gJ4+?v~-cDgvq*`L=0$|+VBYh2%5zFnblcoLbcps2|z| zL3n^X50LKxYJvKzVC;&o7V5kbcqB#y{HV_%?0yt%6*?d8L85=IxMJ^E4Q%CDTopYP zf6vn7=jqSVx3}FnztVfW(sQEX9j%Hdjj`UPOP?1%D^|YuqrZ%<>>jK1p00S$RK>Gj zgQEAqopblZH&KUr3X(SI@k literal 0 HcmV?d00001 diff --git a/src/__pycache__/startup.cpython-312.pyc b/src/__pycache__/startup.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9b6c32893529700cf3b7f72dbdf402f02e86fe2a GIT binary patch literal 2620 zcmds3PfQe77=N>GXLlB6mj7y1U=fSK1gN6L7&V#2wIt$7cLB?mI9-?#2G^O*o7t|r zg-VPEIeC=Cn3(hefuvq*n$+cF(jM591UquDX)nDIIGDht-eUtg#_x}Cf zpZWd1H$MwP34-+9lj+f89)$j&g{_2(&iYs2JVY{*nFNXzawf*eu9!LSEtI2(9GJjn)mB+%$MGZd*tPWq=vdi3fxpEWK&N?{NuvTzvnPA9Bmha2 zWg}pYDuH-1nNWx0rmAZJQx9BIHCay^0mFM+p_C=C{S z4tAypQ8cq(AqHR!Mp7D~8?u-q;p|5tLUa;{%d)DCQ1~M3*+6rNg=QAVtauFIhT zsk1K<359#5zGx_7d9NlF?Xr@w1lkl0^-BF>cVEaVi7IA)JdsjDw=GWW>5;`SFVwT(zok8@3tM}i{0FqR ztsEKCXSn2N0qLU(9Y zTv8KCST`@}DNVK^Ng3@<0|}w~a~Mzd(f(ETgo;F`b7+1DT4d?vc+Ke5c6%yTDgcDHY=pN0AFo)M3u zXNSZ(oU7r$&DF8uF>kIBQ~#K4kNbi(ICq+(_Pjq>ju*;V@c)+_f8TAfm*edAJ+z18 zo`2*xyNBc6>{*-RoukU|O(US**mI4jP^*2A=DnA)^#!62QzT0CBFAZNrVO|wc2nKr z=zS0gi5D&Y^OQm|#mm4ZJUIvyc|XMk)sR%pA$I@<9D&!E07J=L!q$9%+}}&H(voog z`C&VP*XQ~AC;a^A65m0oec^Rk)f={uZ?2RAy&1OVx3X%R-Y&qV!Mp7#Gh;0J+n2ag zD`nN2t1L8Zki)QoW}oHKje@#u1-p}RbJX(2hYacv`X6E6JA|r|1i;Lqb+D))VD8*4 zT}~yG3#19^=>L#$0t{Ra4D$;4ULoOi>A^|vWm(08^i=x6ovAz1nP1DAC;2sZ3DdTA QKw#R}>- Date: Mon, 11 Aug 2025 00:22:07 +0330 Subject: [PATCH 2/4] fixed the config.py file and the running on startup function --- .gitignore | 1 + config&run.bat | 3 +-- config.json | 4 ++++ run.bat | 10 +++------- src/config.py | 10 +++++++--- src/main.pyw | 2 +- src/startup.py | 1 + 7 files changed, 18 insertions(+), 13 deletions(-) create mode 100644 config.json diff --git a/.gitignore b/.gitignore index 7b1819b..f076bdd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .vscode/settings.json shortcut.txt src/__pycache__/config.cpython-313.pyc +src/__pycache__/startup.cpython-313.pyc diff --git a/config&run.bat b/config&run.bat index 2e00b21..d21be38 100644 --- a/config&run.bat +++ b/config&run.bat @@ -1,6 +1,5 @@ @echo off -REM run.bat -REM Activates the virtual environment and runs your main Python script. +cd /d "%~dp0" REM Activate the virtual environment call venv\Scripts\activate.bat diff --git a/config.json b/config.json new file mode 100644 index 0000000..9632656 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "run_on_startup": true, + "shortcut": "ctrl+shift+B" +} \ No newline at end of file diff --git a/run.bat b/run.bat index f159447..fc8ffbf 100644 --- a/run.bat +++ b/run.bat @@ -1,11 +1,7 @@ @echo off -REM run.bat -REM Activates the virtual environment and runs your main Python script. +cd /d "%~dp0" -REM Activate the virtual environment call venv\Scripts\activate.bat +echo Starting the application... -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 +start "OopsWrongLang" /B pythonw src\main.pyw \ No newline at end of file diff --git a/src/config.py b/src/config.py index e9da6d1..71adc06 100644 --- a/src/config.py +++ b/src/config.py @@ -2,6 +2,7 @@ import os import json import keyboard import time +import msvcrt CONFIG_FILE = "config.json" SHORTCUT_FILE = "shortcut.txt" # For migrating old config @@ -66,7 +67,11 @@ if __name__ == "__main__": 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) + time.sleep(0.01) + # Clear the input buffer + while msvcrt.kbhit(): + msvcrt.getch() + confirm = input("Is this correct? (y/n): ").lower() if confirm.lower() == 'y': config['shortcut'] = new_shortcut @@ -77,6 +82,5 @@ if __name__ == "__main__": print("Let's try again.") else: print("No changes made to the shortcut.") - - print("Exiting without changes.") + print("Exiting without changes.") input("Press Enter to exit.") diff --git a/src/main.pyw b/src/main.pyw index 5d02414..d56cd1c 100644 --- a/src/main.pyw +++ b/src/main.pyw @@ -161,7 +161,7 @@ def main(): # Register the keyboard shortcut shortcut = get_shortcut() - keyboard.add_hotkey(shortcut, on_shortcut) + keyboard.add_hotkey(shortcut, on_shortcut, suppress=True) print(f"Press {shortcut} to convert text to Persian.") # Keep the script running diff --git a/src/startup.py b/src/startup.py index 9e66093..c77f124 100644 --- a/src/startup.py +++ b/src/startup.py @@ -11,6 +11,7 @@ def add_to_startup(): try: key = winreg.HKEY_CURRENT_USER sub_key = r"Software\Microsoft\Windows\CurrentVersion\Run" + print(f'bat file path: {RUN_BAT_PATH}') with winreg.OpenKey(key, sub_key, 0, winreg.KEY_SET_VALUE) as registry_key: winreg.SetValueEx(registry_key, APP_NAME, 0, winreg.REG_SZ, f'"{RUN_BAT_PATH}"') except OSError as e: From 3b36df7e6720ef935b3fef86a3c0b47b6d442912 Mon Sep 17 00:00:00 2001 From: Hamed Date: Mon, 11 Aug 2025 01:52:57 +0330 Subject: [PATCH 3/4] added a current shortcut in system tray menue --- run.bat | 4 +++- src/main.pyw | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/run.bat b/run.bat index fc8ffbf..2f820d2 100644 --- a/run.bat +++ b/run.bat @@ -4,4 +4,6 @@ cd /d "%~dp0" call venv\Scripts\activate.bat echo Starting the application... -start "OopsWrongLang" /B pythonw src\main.pyw \ No newline at end of file +start "OopsWrongLang" /B pythonw src\main.pyw + +pause \ No newline at end of file diff --git a/src/main.pyw b/src/main.pyw index d56cd1c..6c6e0cb 100644 --- a/src/main.pyw +++ b/src/main.pyw @@ -139,6 +139,7 @@ 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( 'Run on Startup', on_toggle_startup, @@ -161,7 +162,7 @@ def main(): # Register the keyboard shortcut shortcut = get_shortcut() - keyboard.add_hotkey(shortcut, on_shortcut, suppress=True) + keyboard.add_hotkey(shortcut, on_shortcut) print(f"Press {shortcut} to convert text to Persian.") # Keep the script running From 411909ea866083cb6bdcaa35834ae671189d2f81 Mon Sep 17 00:00:00 2001 From: Hamed Date: Mon, 11 Aug 2025 11:43:28 +0330 Subject: [PATCH 4/4] added the language change toggle to the system tray menue --- config.json | 3 ++- src/config.py | 3 ++- src/main.pyw | 15 +++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) 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()