-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
116 lines (81 loc) · 4.97 KB
/
ui.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
import platformdirs
import os
import tkinter as tk
from tkinter import StringVar, OptionMenu, Label, Entry, Button
from settings import load_settings, save_settings
# Function to create the PyTinker GUI for settings
def create_settings_gui(config_file,app_name):
settings = load_settings(config_file,app_name)
root = tk.Tk()
root.title(settings["fake_app_name"])
openai_key_var = StringVar(value=settings["openai_key"])
ocr_option_var = StringVar(value=settings["ocr_option"])
start_keybinding_var = StringVar(value=settings["keybinding_to_start_typing"])
fake_app_name_var = StringVar(value=settings["fake_app_name"])
stop_keybinding_var = StringVar(value=settings["keybinding_to_stop_typing"])
screenshot_keybinding_var = StringVar(value=settings["keybinding_to_take_screenshot"])
sent_image_to_chat_gpt_keybinding_var = StringVar(value=settings["keybinding_to_sent_image_to_chat_gpt"])
type_clipboard_contents_keybinding_var= StringVar(value=settings["keybinding_to_type_clipboard_contents"])
type_delay_lower_bound_var =StringVar(value=settings["type_delay_lower_bound"])
type_delay_upper_bound_var =StringVar(value=settings["type_delay_upper_bound"])
# OpenAI Key
Label(root, text="OpenAI Key").grid(row=0, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=openai_key_var).grid(row=0, column=1, padx=10, pady=5)
# OCR Option
Label(root, text="OCR Option").grid(row=1, column=0, padx=10, pady=5, sticky="w")
ocr_menu = OptionMenu(root, ocr_option_var, "openai_vision","tesseract" )
ocr_menu.grid(row=1, column=1, padx=10, pady=5)
ocr_menu.config(state='disabled')
# Keybinding to Take Screenshot
Label(root, text="Keybinding to Take Screenshot").grid(row=2, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=screenshot_keybinding_var).grid(row=2, column=1, padx=10, pady=5)
Label(root, text="Keybinding to sent image to openai").grid(row=3, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=sent_image_to_chat_gpt_keybinding_var).grid(row=3, column=1, padx=10, pady=5)
# Keybinding to Start Typing
Label(root, text="Keybinding to Start Typing").grid(row=4, column=0, padx=10, pady=5, sticky="w")
start_keybinding_entey= Entry(root, textvariable=start_keybinding_var)
start_keybinding_entey.grid(row=4, column=1, padx=10, pady=5)
start_keybinding_entey.config(state='disabled')
# Keybinding to Stop Typing
Label(root, text="Keybinding to Stop Typing").grid(row=5, column=0, padx=10, pady=5, sticky="w")
stop_keybinding_entry = Entry(root, textvariable=stop_keybinding_var)
stop_keybinding_entry.grid(row=5, column=1, padx=10, pady=5)
stop_keybinding_entry.config(state='disabled')
Label(root, text="Keybinding to type from cilpboard").grid(row=6, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=type_clipboard_contents_keybinding_var).grid(row=6, column=1, padx=10, pady=5)
Label(root, text="typing delay upper bound").grid(row=7, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=type_delay_upper_bound_var).grid(row=7, column=1, padx=10, pady=5)
Label(root, text="typing delay lower bound").grid(row=8, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=type_delay_lower_bound_var).grid(row=8, column=1, padx=10, pady=5)
Label(root, text="fake app name").grid(row=9, column=0, padx=10, pady=5, sticky="w")
Entry(root, textvariable=fake_app_name_var).grid(row=9, column=1, padx=10, pady=5)
# Save Button
def save():
settings = {
"openai_key": openai_key_var.get(),
"ocr_option": ocr_option_var.get(),
"keybinding_to_start_typing": start_keybinding_var.get(),
"keybinding_to_stop_typing": stop_keybinding_var.get(),
"keybinding_to_take_screenshot": screenshot_keybinding_var.get(),
"keybinding_to_sent_image_to_chat_gpt": sent_image_to_chat_gpt_keybinding_var.get(),
"keybinding_to_type_clipboard_contents": type_clipboard_contents_keybinding_var.get(),
"type_delay_lower_bound": type_delay_lower_bound_var.get(),
"type_delay_upper_bound": type_delay_upper_bound_var.get(),
"fake_app_name":fake_app_name_var.get(),
}
save_settings(config_file, settings)
root.destroy()
warning_lbl = Label(root, text="please relaunch app after saving for changes to take effect")
warning_lbl.grid(row=10, column=0, columnspan=2, pady=10)
warning_lbl.config(fg="red")
Button(root, text="Save", command=save).grid(row=11, column=0, columnspan=2, pady=10)
root.mainloop()
# Example usage
if __name__ == "__main__":
app_auther = "vaisaskh"
app_name = "aihelper"
fake_app_name = app_name
config_dir = platformdirs.user_config_dir(app_name,app_auther)
config_file = os.path.join(config_dir,"settings.ini")
print(config_file)
create_settings_gui(config_file,app_name)