-
Notifications
You must be signed in to change notification settings - Fork 0
/
Inspector.py
353 lines (290 loc) · 18 KB
/
Inspector.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
from customtkinter import *
from tkinter.colorchooser import askcolor
from tkinter import font
from datetime import datetime
from pathlib import Path
class InspectorFrame(CTkFrame):
def __init__(self, *args,
width: int = 100,
height: int = 32,
toggle=True,
options,
callback,
name,
messageIP,
**kwargs):
super().__init__(*args, width=width, height=height, **kwargs)
self.toggle = toggle
self.messageIP = messageIP
self.options = options
self.configure(fg_color="grey10")
self.w = width
self.callback = callback
#self.pack_propagate(False)
#Example with Sample Values
#{"Type": "Spinbox", "Heading": "Zoom", "Input Heading": ["X", "Y"]}
#{"Type": "Slider", "Heading": "Rotation Angle", "Min": -360, "Max": 360, "Step": 1}
self.text_box = None
self.name = name
self.widget = options["_widget"]
for option in options:
try:
val = None
print(option)
if option == "_show_type":
self.add_show_options(display_text=option, default_text=options[option])
elif option == "LOG File System Changes":
self.add_log_input(display_text="Changes in File System", default_text=options[option])
elif option == "Send Message":
self.add_message_input(display_text="Send Message")
elif type(options[option]) == int:
self.add_int_input(display_text=option, default_text=options[option], callback=lambda val=val, option=option: self.command_({option: val}))
elif type(options[option]) == str:
self.add_str_input(display_text=option, default_text=options[option], callback=lambda val=val, option=option: self.command_({option: val}))
elif type(options[option]) == tuple and type(options[option][0]) == str and type(options[option][1]) == str:
self.add_option_box(options[option], display_text=option, callback=lambda val=val, option=option: self.command_({option: val}))
elif type(options[option]) == tuple and type(options[option][0]) == bool and type(options[option][1]) == bool:
self.add_option_box_bool(options[option], display_text=option, callback=lambda val=val, option=option: self.command_({option: val}))
elif type(options[option]) == list:
print(option)
self.add_list_input(display_text=option, default_colors=options[option], callback=lambda val=val, option=option: self.command_({option: val}))
elif type(options[option]) == tuple and type(options[option][0]) == str and type(options[option][1]) == int:
self.add_option_int(font.families(), display_text=option, callback=lambda val=val, option=option: self.command_({option: val}))
else:
print(options[option])
except KeyError as e:
print(e)
def command_(self, kwargs):
self.options[list(kwargs.keys())[0]] = kwargs[list(kwargs.keys())[0]]
self.callback(kwargs)
def get_color(self, func, btn, color_btns):
color = askcolor()
if color[1] != None:
btn.configure(fg_color=color[1])
print([color_btns[0].cget("fg_color"), color_btns[1].cget("fg_color")])
func([color_btns[0].cget("fg_color"), color_btns[1].cget("fg_color")])
print(color)
def add_option_int(self, fonts, root=None, callback=None, display_text="Display Text", default_num=13, padx=(10, 20)):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w - 20, height=40*2, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, width=10, height=40 - 5, fg_color="grey10")
empty_input_frame.pack(side="right", padx=10)
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.grid(row=0, column=0, pady=5, padx=(5, 0), rowspan=2)
optionmenu = CTkOptionMenu(empty_input_frame, values=fonts, anchor="w", fg_color="#1f538d",
button_color="#14375e", button_hover_color="#1e2c40", dropdown_fg_color="gray20",
dropdown_hover_color="gray28", dropdown_text_color="gray84", text_color="#DCE4EE", width=140, dynamic_resizing=False)
optionmenu.grid(row=0, column=1, pady=5, padx=padx)
vcmd = (empty_input_frame.register(self.int_check))
int_input = CTkEntry(empty_input_frame, validate='all', validatecommand=(vcmd, '%P'), justify="center",
fg_color="#343638", border_color="#565B5E", text_color="gray84")
int_input.grid(row=1, column=1, padx=(10, 20))
int_input.insert(0, default_num)
if callback != None:
int_input.bind("<FocusOut>", lambda e: callback((optionmenu.get(), int(int_input.get()))))
optionmenu.configure(command=lambda e: callback((optionmenu.get(), int(int_input.get()))))
def add_list_input(self, default_colors, root=None, callback=None, display_text="Display Text"):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w - 20, height=40, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, width=10, height=40 - 5, fg_color="grey10")
empty_input_frame.pack(side="right", padx=10)
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.grid(row=0, column=0, pady=5, padx=(5, 0))
light_color = CTkButton(empty_input_frame, text="", width=64, height=30, hover=False, fg_color=default_colors[0], border_color="White", border_width=2, border_spacing=2)
light_color.grid(row=0, column=1, padx=(10, 10), pady=5)
dark_color = CTkButton(empty_input_frame, text="", width=64, height=30, hover=False, fg_color=default_colors[1], border_color="White", border_width=2, border_spacing=2)
dark_color.grid(row=0, column=2, padx=(0, 20), pady=5)
light_color.configure(command=lambda light_color=light_color, dark_color=dark_color: self.get_color(callback, light_color, [light_color, dark_color]))
dark_color.configure(command=lambda dark_color=dark_color, light_color=light_color: self.get_color(callback, dark_color, [light_color, dark_color]))
#if callback != None:
#light_color.configure(command=lambda: callback([light_color.cget("fg_color"), dark_color.cget("fg_color")]))
def add_int_input(self, root=None, callback=None, display_text="Display Text", default_text="", padx=(10, 20)):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w - 20, height=40, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, width=10, height=40 - 5, fg_color="grey10")
empty_input_frame.pack(side="right", padx=10)
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.grid(row=0, column=0, pady=5, padx=(5, 0))
vcmd = (empty_input_frame.register(self.int_check))
int_input = CTkEntry(empty_input_frame, validate='all', validatecommand=(vcmd, '%P'), justify="center", fg_color="#343638", border_color="#565B5E", text_color="gray84")
int_input.grid(row=0, column=1, padx=padx)
int_input.insert(0, default_text)
if callback != None:
int_input.bind("<FocusOut>", lambda e: callback(int(int_input.get())))
def add_option_box(self, options, root=None, callback=None, display_text="Display Text", padx=(10, 20), default_text=None):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w - 20, height=40, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, width=10, height=40 - 5, fg_color="grey10")
empty_input_frame.pack(side="right", padx=10)
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="grey84")
heading.grid(row=0, column=0, pady=5, padx=(5, 0))
optionmenu = CTkOptionMenu(empty_input_frame, values=options, anchor="center", fg_color="#1f538d", button_color="#14375e", button_hover_color="#1e2c40", dropdown_fg_color="gray20", dropdown_hover_color="gray28", dropdown_text_color="gray84", text_color="#DCE4EE")
optionmenu.grid(row=0, column=1, pady=5, padx=padx)
#print(f", fg_color={optionmenu.cget('fg_color')[1]}, button_color={optionmenu.cget('button_color')[1]}, button_hover_color={optionmenu.cget('button_hover_color')[1]}, dropdown_fg_color={optionmenu.cget('dropdown_fg_color')[1]}, dropdown_hover_color={optionmenu.cget('dropdown_hover_color')[1]}, dropdown_text_color={optionmenu.cget('dropdown_text_color')[1]}, text_color={optionmenu.cget('text_color')[1]}")
if default_text != None:
optionmenu.set(default_text)
if callback != None:
optionmenu.configure(command=lambda e: callback(e))
print(options)
def add_option_box_bool(self, options, root=None, callback=None, display_text="Display Text", padx=20, default_text=None):
if root == None:
root = self
print("Running add options box bool function")
input_frame = CTkFrame(root, width=self.w - 20, height=40, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, width=10, height=40 - 5, fg_color="grey10")
empty_input_frame.pack(side="right", padx=10)
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.grid(row=0, column=0, pady=5, padx=(5, 0))
optionmenu = CTkOptionMenu(empty_input_frame, values=options, anchor="center", fg_color="#1f538d", button_color="#14375e", button_hover_color="#1e2c40", dropdown_fg_color="gray20", dropdown_hover_color="gray28", dropdown_text_color="gray84", text_color="#DCE4EE")
#print(f", fg_color={optionmenu.cget('fg_color')}, button_color={optionmenu.cget('button_color')}, button_hover_color={optionmenu.cget('button_hover_color')}, dropdown_fg_color={optionmenu.cget('dropdown_fg_color')}, dropdown_hover_color={optionmenu.cget('dropdown_hover_color')}, dropdown_text_color={optionmenu.cget('dropdown_text_color')}, text_color={optionmenu.cget('text_color')}")
optionmenu.grid(row=0, column=1, pady=5, padx=padx)
if default_text != None:
optionmenu.set(default_text)
print("Starting If function")
if callback != None:
print("Running")
optionmenu.configure(command=lambda e: callback(e))
print("Ran")
print(options)
def add_str_input(self, root=None, callback=None, display_text="Display Text", default_text="", padx=(10, 20)):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w - 20, height=40, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, width=10, height=40 - 5, fg_color="grey10")
empty_input_frame.pack(side="right", padx=10)
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.grid(row=0, column=0, pady=5, padx=(5, 0))
int_input = CTkEntry(empty_input_frame, justify="center", fg_color="#343638", border_color="#565B5E", text_color="gray84")
int_input.grid(row=0, column=1, padx=padx)
int_input.insert(0, default_text)
int_input.configure(state="disabled")
if callback != None:
int_input.bind("<FocusOut>", lambda e: callback(int_input.get()))
def add_log_input(self, root=None, callback=None, display_text="Display Text", default_text="", padx=(10, 0)):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w-20, height=300, fg_color="grey10")
input_frame.pack(padx=10)
input_frame.grid_propagate(False)
input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, height=400, fg_color="grey10")
empty_input_frame.pack(padx=10, fill="x")
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.pack(pady=5)
int_input = CTkTextbox(empty_input_frame, fg_color="#343638", border_color="#565B5E", text_color="gray84")
int_input.pack(pady=5, padx=padx, fill="both", expand=True)
int_input.insert(0.0, default_text)
int_input.configure(state="disabled")
self.text_box = int_input
download_btn = CTkButton(empty_input_frame, text="Download the log file", command=lambda : self.download(self.text_box))
download_btn.pack(pady=5, padx=padx, fill="x")
def add_message_input(self, root=None, callback=None, display_text="Display Text", padx=(10, 20)):
if root == None:
root = self
input_frame = CTkFrame(root, width=self.w-20, height=200, fg_color="grey10")
input_frame.pack(padx=10, expand=True, fill="both", pady=(0, 10))
#input_frame.grid_propagate(False)
#input_frame.pack_propagate(False)
empty_input_frame = CTkFrame(input_frame, height=200, fg_color="grey10")
empty_input_frame.pack(padx=5, fill="x")
heading = CTkLabel(empty_input_frame, text=display_text.capitalize(), justify="right", text_color="gray84")
heading.pack(pady=5)
int_input = CTkTextbox(empty_input_frame, fg_color="#343638", border_color="#565B5E", text_color="gray84", height=100)
int_input.pack(pady=5, padx=padx, fill="both", expand=True)
message_btn = CTkButton(empty_input_frame, text="Send Message", command=lambda int_input=int_input: self.send_message(int_input))
message_btn.pack(pady=5, padx=padx, fill="x")
def download(self, text_box):
text = text_box.get(0.0, "end")
t = str(datetime.now().strftime('%d-%m-%Y-%H.%M.%S'))
home_dir = str(Path.home())
with open(f"{home_dir}/{self.name.decode('utf-8')} -{t}.log", "w") as f:
f.write(text)
"""
client.create_notification(
title="Log Saved Successfully",
subtitle=f"The Log has been saved in {home_dir}/{self.name.decode('utf-8')}-{t}.log",
)
"""
#askokcancel("Info", f"The Log has been saved in {home_dir}/{self.name.decode('utf-8')}-{t}.log")
def send_message(self, message):
print(message.get(0.0, "end"), self.messageIP)
self.messageIP[0].sendto(f"-----MESSAGE----- {message.get(0.0, 'end')}".encode("utf-8"), self.messageIP[1])
message.delete(0.0, "end")
def int_check(self, P):
if str.isdigit(P) or P == "":
return True
else:
return False
def disable(self, state):
if state == "off":
for child in self.winfo_children():
child = child.winfo_children()[0]
for c in child.winfo_children():
print(c)
c.configure(state="disabled")
else:
for child in self.winfo_children():
child = child.winfo_children()[0]
for c in child.winfo_children():
print(c)
c.configure(state="normal")
class InspectorWidget(CTkScrollableFrame):
def __init__(self, *args,
width: int = 100,
height: int = 32,
**kwargs):
super().__init__(*args, width=width, height=height, **kwargs)
self.chr = 0
self.w = width
self.inspect_frames = []
self.configure(fg_color="gray16")
def _toggle_menu(self, event, index, c, options):
if self.inspect_frames[index][1].toggle == True:
self.inspect_frames[index][1].toggle = False
self.inspect_frames[index][1].grid_forget()
elif self.inspect_frames[index][1].toggle == False:
self.inspect_frames[index][1].toggle = True
self.inspect_frames[index][1].grid(row=c, column=0)
def add_option(self, display_text, options, callback, messageIP):
global inspect
new_frame = CTkFrame(self, width=self.w-(2*10), height=50, fg_color="grey10")
new_frame.grid(column=0, row=self.chr, pady=(10, 0), padx=10)
new_frame.pack_propagate(False)
# Adding a new text instead of the default text with the CTKSwitch to add a bind to the text and frame only
text = CTkLabel(new_frame, text=display_text, text_color="grey84")
text.pack(side="left", padx=10)
chr = self.chr
i = None
frames = [new_frame, InspectorFrame(self, width=self.w-(2*10), toggle=False, options=options, callback=callback, name=display_text, messageIP=messageIP), display_text]
self.inspect_frames.append(frames)
index = self.inspect_frames.index(self.inspect_frames[-1])
self._toggle_menu(i, index, chr+1, options)
text.bind("<Button-1>", lambda i=i, index=index, chr=chr, options=options: self._toggle_menu(i, index, chr+1, options))
new_frame.bind("<Button-1>", lambda i=i, index=index, chr=chr, options=options: self._toggle_menu(i, index, chr+1, options))
self.chr += 2
def clear_frames(self):
self.inspect_frames[0][1].destroy()
self.inspect_frames[0][0].destroy()
self.chr = 0