-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjexplain.py
124 lines (111 loc) · 4.65 KB
/
jexplain.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import os
import json
import time
import pyperclip
import pyautogui
import keyboard
import subprocess
import threading
from copy_modes import copy_modes
from jp_process import jp_process, jp_process_lite, chat_with, kj_process, tr_process, tr_agressive, mnemonic_process, speak
from win_focus import set_title, winfocus, clear_screen, clear_input_buffer
# Get the directory of the current script
script_dir = os.path.dirname(os.path.abspath(__file__))
config_dir = os.path.join(script_dir, 'config')
os.makedirs(config_dir, exist_ok=True)
# Path to the file storing the current copy mode
copy_mode_file = os.path.join(config_dir, 'current_copy_mode.json')
# Load the current copy mode
def load_copy_mode():
if os.path.exists(copy_mode_file):
with open(copy_mode_file, 'r') as f:
return json.load(f)['mode']
return 0 # Default to no_copy
# Save the current copy mode
def save_copy_mode(mode):
with open(copy_mode_file, 'w') as f:
json.dump({'mode': mode}, f)
# Initialize the current copy mode
current_copy_mode = load_copy_mode()
set_title("jexplain_window")
print("Ready for scanning")
def monitor_clipboard():
previous_clipboard_content = pyperclip.paste()
identifier = "[MPV]"
while True:
time.sleep(0.05) # Adjust the sleep interval as needed
current_clipboard_content = pyperclip.paste()
if current_clipboard_content != previous_clipboard_content:
if current_clipboard_content.startswith(identifier):
# Remove the identifier
processed_content = current_clipboard_content[len(identifier):].strip()
previous_clipboard_content = current_clipboard_content
pyperclip.copy(processed_content)
# Trigger Ctrl+Win+Z action
clear_screen()
copy_modes[current_copy_mode]['function']()
# winfocus("jexplain_window")
jp_process_lite()
print("\n***\n", end="")
# Start clipboard monitoring thread
clipboard_thread = threading.Thread(target=monitor_clipboard, daemon=True)
clipboard_thread.start()
while True:
time.sleep(0.05)
if keyboard.is_pressed('ctrl+win+z'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('\\'):
pass
clear_screen()
copy_modes[current_copy_mode]['function']() # Execute the current copy mode
winfocus("jexplain_window")
jp_process_lite()
print("\n***\n", end="")
elif keyboard.is_pressed('ctrl+win+-'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('-'):
pass
tr_agressive()
print("\n***\n", end="")
elif keyboard.is_pressed('ctrl+win+x'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('x'):
pass
copy_modes[current_copy_mode]['function']()
speak('ja-JP-ShioriNeural')
print("***\n", end="")
elif keyboard.is_pressed('ctrl+win+f12'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('f12'):
pass
time.sleep(0.1)
pyautogui.hotkey('ctrl', 'c')
speak('en-US-AvaNeural')
print("***\n", end="")
elif keyboard.is_pressed('ctrl+win+a'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('a'):
pass
clear_input_buffer()
chat_with(input("\nAsk a question: "))
print("\n***\n", end="")
elif keyboard.is_pressed('ctrl+win+tab'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('tab'):
pass
tr_process()
print("\n***\n", end="")
elif keyboard.is_pressed('ctrl+win+k'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('k'):
pass
kj_process()
print("\n***\n", end="")
elif keyboard.is_pressed('ctrl+win+]'):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed(']'):
pass
clear_screen()
pyautogui.hotkey('ctrl', 'c')
winfocus("jexplain_window")
mnemonic = mnemonic_process()
pyperclip.copy(mnemonic)
print("\n***\n", end="")
elif keyboard.is_pressed('ctrl+win+['):
while keyboard.is_pressed('ctrl') or keyboard.is_pressed('win') or keyboard.is_pressed('['):
pass
current_copy_mode = (current_copy_mode + 1) % len(copy_modes)
save_copy_mode(current_copy_mode)
print(f"Copy mode changed to: {copy_modes[current_copy_mode]['name']}")