Merge pull request #4 from Hamedrz004/checkbox
fixed the config.py file and the running on startup function
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
.vscode/settings.json
|
.vscode/settings.json
|
||||||
shortcut.txt
|
shortcut.txt
|
||||||
src/__pycache__/config.cpython-313.pyc
|
src/__pycache__/config.cpython-313.pyc
|
||||||
|
src/__pycache__/startup.cpython-313.pyc
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
@echo off
|
@echo off
|
||||||
REM run.bat
|
cd /d "%~dp0"
|
||||||
REM Activates the virtual environment and runs your main Python script.
|
|
||||||
|
|
||||||
REM Activate the virtual environment
|
REM Activate the virtual environment
|
||||||
call venv\Scripts\activate.bat
|
call venv\Scripts\activate.bat
|
||||||
|
|||||||
4
config.json
Normal file
4
config.json
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"run_on_startup": true,
|
||||||
|
"shortcut": "ctrl+shift+B"
|
||||||
|
}
|
||||||
10
run.bat
10
run.bat
@@ -1,11 +1,7 @@
|
|||||||
@echo off
|
@echo off
|
||||||
REM run.bat
|
cd /d "%~dp0"
|
||||||
REM Activates the virtual environment and runs your main Python script.
|
|
||||||
|
|
||||||
REM Activate the virtual environment
|
|
||||||
call venv\Scripts\activate.bat
|
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
|
||||||
start "OopsWrongLang" /B pythonw src\main.pyw
|
|
||||||
echo application is running in the background. you can close this window.
|
|
||||||
pause
|
|
||||||
@@ -2,6 +2,7 @@ import os
|
|||||||
import json
|
import json
|
||||||
import keyboard
|
import keyboard
|
||||||
import time
|
import time
|
||||||
|
import msvcrt
|
||||||
|
|
||||||
CONFIG_FILE = "config.json"
|
CONFIG_FILE = "config.json"
|
||||||
SHORTCUT_FILE = "shortcut.txt" # For migrating old config
|
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.")
|
print("Please press the key combination you want to use as a shortcut and then press ESC.")
|
||||||
new_shortcut = keyboard.read_hotkey(suppress=False)
|
new_shortcut = keyboard.read_hotkey(suppress=False)
|
||||||
print(f"You pressed: {new_shortcut}")
|
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()
|
confirm = input("Is this correct? (y/n): ").lower()
|
||||||
if confirm.lower() == 'y':
|
if confirm.lower() == 'y':
|
||||||
config['shortcut'] = new_shortcut
|
config['shortcut'] = new_shortcut
|
||||||
@@ -77,6 +82,5 @@ if __name__ == "__main__":
|
|||||||
print("Let's try again.")
|
print("Let's try again.")
|
||||||
else:
|
else:
|
||||||
print("No changes made to the shortcut.")
|
print("No changes made to the shortcut.")
|
||||||
|
print("Exiting without changes.")
|
||||||
print("Exiting without changes.")
|
|
||||||
input("Press Enter to exit.")
|
input("Press Enter to exit.")
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ def main():
|
|||||||
|
|
||||||
# Register the keyboard shortcut
|
# Register the keyboard shortcut
|
||||||
shortcut = get_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.")
|
print(f"Press {shortcut} to convert text to Persian.")
|
||||||
|
|
||||||
# Keep the script running
|
# Keep the script running
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ def add_to_startup():
|
|||||||
try:
|
try:
|
||||||
key = winreg.HKEY_CURRENT_USER
|
key = winreg.HKEY_CURRENT_USER
|
||||||
sub_key = r"Software\Microsoft\Windows\CurrentVersion\Run"
|
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:
|
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}"')
|
winreg.SetValueEx(registry_key, APP_NAME, 0, winreg.REG_SZ, f'"{RUN_BAT_PATH}"')
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user