-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.py
57 lines (44 loc) · 2.31 KB
/
settings.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
import os
import configparser
# Function to load settings
def load_settings(config_file,app_name):
config = configparser.ConfigParser()
config_dir=os.path.dirname(config_file)
if not os.path.exists(config_dir):
os.makedirs(config_dir)
if not os.path.exists(config_file):
config["SETTINGS"] = {
"openai_key": "",
"ocr_option": "tesseract",
"keybinding_to_start_typing": "<ctrl>+<alt>+h",
"keybinding_to_stop_typing": "<ctrl>+<alt>+i",
"keybinding_to_take_screenshot": "<ctrl>+<alt>+s",
"keybinding_to_sent_image_to_chat_gpt": "<ctrl>+<alt>+o",
"keybinding_to_type_clipboard_contents": "<ctrl>+<alt>+p",
"type_delay_upper_bound": "0.5",
"type_delay_lower_bound": "0.1",
"fake_app_name":"avg antivirus"
}
with open(config_file, 'w') as configfile:
config.write(configfile)
else:
config.read(config_file)
settings = {
"openai_key": config.get("SETTINGS", "openai_key", fallback=""),
"ocr_option": config.get("SETTINGS", "ocr_option", fallback="tesseract"),
"keybinding_to_start_typing": config.get("SETTINGS", "keybinding_to_start_typing", fallback="<ctrl>+<alt>+h"),
"keybinding_to_stop_typing": config.get("SETTINGS", "keybinding_to_stop_typing", fallback="<ctrl>+<alt>+i"),
"keybinding_to_take_screenshot": config.get("SETTINGS", "keybinding_to_take_screenshot", fallback="<ctrl>+<alt>+s"),
"keybinding_to_sent_image_to_chat_gpt": config.get("SETTINGS", "keybinding_to_sent_image_to_chat_gpt", fallback="<ctrl>+<alt>+o"),
"keybinding_to_type_clipboard_contents": config.get("SETTINGS", "keybinding_to_type_clipboard_contents", fallback="<ctrl>+<alt>+p"),
"type_delay_upper_bound": config.get("SETTINGS", "type_delay_upper_bound", fallback="0.5"),
"type_delay_lower_bound": config.get("SETTINGS", "type_delay_lower_bound", fallback="0.1"),
"fake_app_name": config.get("SETTINGS", "fake_app_name", fallback=app_name)
}
return settings
# Function to save settings
def save_settings(config_file, settings):
config = configparser.ConfigParser()
config["SETTINGS"] = settings
with open(config_file, 'w') as configfile:
config.write(configfile)