-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwatchdog-pop.py
More file actions
311 lines (245 loc) · 7.54 KB
/
Copy pathwatchdog-pop.py
File metadata and controls
311 lines (245 loc) · 7.54 KB
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
import tkinter as tk
import math
import time
import os
import subprocess
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
# ===== SETTINGS =====
WATCH_FOLDER = r"C:\inetpub\wwwroot\ImageUploadSite\Uploads"
PHOTOSHOP_PATH = r"C:\Program Files\Adobe\Adobe Photoshop 2022\Photoshop.exe"
# ====================
def wait_until_finished(file_path):
previous_size = -1
while True:
try:
current_size = os.path.getsize(file_path)
if current_size == previous_size:
break
previous_size = current_size
time.sleep(2)
except Exception:
time.sleep(2)
def popup_menu(file_path):
# ========================================
# WINDOW
# ========================================
root = tk.Tk()
root.title("New File Detected")
root.geometry("400x325-0+0")
root.configure(bg="#0f0f0f")
root.resizable(False, False)
def open_photoshop():
subprocess.Popen([PHOTOSHOP_PATH, file_path])
root.destroy()
def ignore():
root.destroy()
def open_location():
subprocess.Popen(['explorer', '/select,', file_path])
root.destroy()
def open_file():
subprocess.Popen(['explorer', file_path])
root.destroy()
def print_file():
os.startfile(file_path, "print")
root.destroy()
# ========================================
# TITLE LABEL
# ========================================
label = tk.Label(
root,
text=f"New file detected:\n{os.path.basename(file_path)}",
bg="#0f0f0f",
fg="#00ffcc",
font=("Consolas", 18, "bold"),
highlightbackground="#00ffcc",
highlightcolor="#00ffcc",
highlightthickness=2,
padx=10,
pady=5
)
label.pack(pady=(15, 10), anchor="w", padx=15)
# ========================================
# MAIN FRAME
# ========================================
main_frame = tk.Frame(root, bg="#0f0f0f")
main_frame.pack(fill="both", expand=True, padx=10, pady=5)
# ========================================
# BUTTON FRAME
# ========================================
button_frame = tk.Frame(main_frame, bg="#0f0f0f")
button_frame.grid(row=0, column=0, sticky="n")
# ========================================
# HOVER EFFECTS
# ========================================
def hover_in(e):
e.widget.config(
bg="#00ffcc",
fg="#000000",
bd=1,
relief="solid"
)
def hover_out(e):
e.widget.config(
bg="#0f0f0f",
fg="#ffffff",
bd=1,
relief="solid"
)
# ========================================
# BUTTON CREATOR
# ========================================
def create_button(text, cmd, row):
btn = tk.Button(
button_frame,
text=text,
command=cmd,
bg="#0f0f0f",
fg="#ffffff",
pady=1,
activebackground="#00ffcc",
activeforeground="#000000",
font=("Consolas", 13, "bold"),
width=14,
height=1,
bd=1,
relief="solid",
highlightthickness=1,
highlightbackground="#444444",
cursor="hand2"
)
btn.grid(row=row, column=0, pady=6, sticky="w")
btn.bind("<Enter>", hover_in)
btn.bind("<Leave>", hover_out)
return btn
# ========================================
# BUTTONS
# ========================================
create_button("Photoshop", open_photoshop, 0)
create_button("Print File", print_file, 1)
create_button("Explorer", open_location, 2)
create_button("Open File", open_file, 3)
create_button("Ignore", ignore, 4)
# ========================================
# GLOBE FRAME
# ========================================
globe_frame = tk.Frame(main_frame, bg="#0f0f0f")
globe_frame.grid(row=0, column=1, padx=(10, 10), sticky="n")
canvas = tk.Canvas(
globe_frame,
bg="#111111",
width=230,
height=210,
highlightthickness=1,
highlightbackground="#333333"
)
canvas.pack()
# ========================================
# GLOBE SETTINGS
# ========================================
RADIUS = 90
NODE_COUNT = 20
FPS = 24
FRAME_DELAY = int(1000 / FPS)
WIDTH = 230
HEIGHT = 210
CX = WIDTH // 2
CY = HEIGHT // 2
# ========================================
# CREATE NODES
# ========================================
nodes = []
for i in range(NODE_COUNT):
theta = math.acos(1 - 2 * (i + 0.5) / NODE_COUNT)
phi = math.pi * (1 + 5**0.5) * i
x = RADIUS * math.sin(theta) * math.cos(phi)
y = RADIUS * math.sin(theta) * math.sin(phi)
z = RADIUS * math.cos(theta)
nodes.append([x, y, z])
# ========================================
# ROTATION
# ========================================
angle = 0
def rotate_y(x, z, a):
new_x = x * math.cos(a) - z * math.sin(a)
new_z = x * math.sin(a) + z * math.cos(a)
return new_x, new_z
# ========================================
# ANIMATION
# ========================================
def animate():
nonlocal angle
canvas.delete("all")
projected = []
# ----------------------------
# PROJECT NODES
# ----------------------------
for node in nodes:
x, y, z = node
x, z = rotate_y(x, z, angle)
depth = 400 / (z + 400)
px = x * depth + CX
py = y * depth + CY
projected.append((px, py, z))
# ----------------------------
# DRAW LINES
# ----------------------------
for i in range(len(projected)):
for j in range(i + 1, len(projected)):
x1, y1, z1 = projected[i]
x2, y2, z2 = projected[j]
dist = math.sqrt(
(x1 - x2) ** 2 +
(y1 - y2) ** 2
)
if dist < 90:
canvas.create_line(
x1,
y1,
x2,
y2,
fill="#004444",
width=1
)
# ----------------------------
# DRAW NODES
# ----------------------------
for px, py, z in projected:
size = 3 + ((z + RADIUS) / (RADIUS * 2)) * 3
canvas.create_oval(
px - size,
py - size,
px + size,
py + size,
fill="#00ffcc",
outline=""
)
angle += 0.02
root.after(FRAME_DELAY, animate)
# ========================================
# START
# ========================================
animate()
root.mainloop()
class Handler(FileSystemEventHandler):
def on_created(self, event):
if event.is_directory:
return
file_path = event.src_path
print("New file detected:", file_path)
wait_until_finished(file_path)
popup_menu(file_path)
observer = Observer()
observer.schedule(
Handler(),
WATCH_FOLDER,
recursive=False
)
observer.start()
print("Watching folder:", WATCH_FOLDER)
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
observer.stop()
observer.join()