-
Notifications
You must be signed in to change notification settings - Fork 0
/
PyDropper.py
257 lines (212 loc) · 6.68 KB
/
PyDropper.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
import tkinter as tk
import tkinter.ttk as ttk
import pyautogui
import keyboard
import pyperclip
import colormap
import re
import webbrowser
from pathlib import Path
import os
import sys
def get_path(relative_path):
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
last_color = '#fff'
def callback(url):
webbrowser.open_new(url)
def on_closing():
global newWindow
settings()
newWindow.destroy()
def print_value(val):
print('value: ' + str(val))
def openNewWindow():
global newWindow
global c1
newWindow = tk.Toplevel(root)
newWindow.attributes('-topmost', True)
newWindow.resizable(False, False)
newWindow.iconbitmap(get_path('settings.ico'))
newWindow.title("settings")
width = 210
height = 200
x = root.winfo_x() + 50
y = root.winfo_y() + 10
newWindow.geometry('%dx%d+%d+%d' % (width, height, x, y))
newWindow.protocol("WM_DELETE_WINDOW", on_closing)
tk.Label(newWindow,
text ="PyDropper settings").pack()
c1 = tk.Checkbutton(newWindow, text='always on top',variable=var1, onvalue=1, offvalue=0)
c1.pack()
drop_var = var2
languages = ['HEX', 'RGB']
drop = ttk.OptionMenu(newWindow, drop_var,var2.get() , *languages)
drop.pack()
link1 = tk.Label(newWindow, text="GitHub", fg="blue", cursor="hand2")
link1.pack(expand=True)
link1.bind("<Button-1>", lambda e: callback("https://github.com/Pingu1337/PyDropper"))
ok_btn = tk.Button(newWindow, text = 'Save', command = on_closing, padx=10, pady=5)
ok_btn.pack(expand=True)
def settings():
global frame
global another_frame
global btn
if (var1.get() == 1):
root.attributes('-topmost', True)
elif (var1.get() == 0):
root.attributes('-topmost', False)
if(var2.get() == 'HEX'):
width = 300
height = 50
another_frame.place(x=80,y=10)
frame.place(x=10,y=10)
btn.place(x=245, y=10)
elif(var2.get() == 'RGB'):
width = 310
height = 50
another_frame.place(x=110,y=10)
btn.place(x=270, y=10)
root.geometry('%dx%d' % (width, height))
root.update()
def getColor():
while True:
global last_color
posXY = pyautogui.position()
color = pyautogui.pixel(posXY[0], posXY[1])
win_x = root.winfo_x()
win_y = root.winfo_y()
win_w = root.winfo_width()
win_h = root.winfo_height()
win_left = win_x + win_w
win_bottom = win_y + win_h
if (posXY[1] >= win_y and posXY[1] <= win_bottom + 32):
mouse_y = True
else:
mouse_y = False
if(posXY[0] >= win_x and posXY[0] <= win_left + 10):
mouse_x = True
else:
mouse_x = False
color = re.sub('[()]', '', str(color))
color = color.split(',')
r = color[0].strip()
g = color[1].strip()
b = color[2].strip()
hexcolor = colormap.rgb2hex(int(r),int(g),int(b))
if (mouse_y and mouse_x):
hexcolor = last_color
return(hexcolor)
def getRgb():
while True:
global last_color_rgb
posXY = pyautogui.position()
color = pyautogui.pixel(posXY[0], posXY[1])
win_x = root.winfo_x()
win_y = root.winfo_y()
win_w = root.winfo_width()
win_h = root.winfo_height()
win_left = win_x + win_w
win_bottom = win_y + win_h
if (posXY[1] >= win_y and posXY[1] <= win_bottom + 32):
mouse_y = True
else:
mouse_y = False
if(posXY[0] >= win_x and posXY[0] <= win_left + 10):
mouse_x = True
else:
mouse_x = False
output = color
if (mouse_y and mouse_x):
output = last_color_rgb
return(output)
def get_complementary(c):
c = c[1:];
rgb = int(c, 16);
r = (rgb >> 16) & 0xff;
g = (rgb >> 8) & 0xff;
b = (rgb >> 0) & 0xff;
luma = 0.2126 * r + 0.7152 * g + 0.0722 * b
if (luma < 40):
return('#fff')
else:
return('#000')
def get_icon_color(c):
c = c[1:];
rgb = int(c, 16);
r = (rgb >> 16) & 0xff;
g = (rgb >> 8) & 0xff;
b = (rgb >> 0) & 0xff;
luma = 0.2126 * r + 0.7152 * g + 0.0722 * b
if (luma < 40):
return(settings_light)
else:
return(settings_dark)
root = tk.Tk()
width = 300
height = 50
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x = (screen_width/2) - (width/2)
y = (screen_height/2) - (height/2)
root.geometry('%dx%d+%d+%d' % (width, height, x, y/2))
#stored variables
var1 = tk.IntVar(value=1)
var2 = tk.StringVar(value='HEX')
root.iconbitmap(get_path('eyedropper.ico'))
settings_dark = tk.PhotoImage(file=get_path('cogwheel32.png'))
settings_light = tk.PhotoImage(file=get_path('cogwheel32light.png'))
root.resizable(False, False)
root.update()
def Draw():
global text
global txt
global frame
global another_frame
global btn
frame=tk.Frame(root,width=100,height=30,relief='solid',bd=0)
frame.place(x=10,y=10)
another_frame=tk.Frame(root,width=300,height=30,relief='solid',bd=0)
another_frame.place(x=80,y=10)
root.title('PyDropper v1.0')
text=tk.Label(frame,text='PyDropper v1.0', fg='#fff')
text.pack()
txt=tk.Label(another_frame,text="press 'c' to copy color code",fg='#fff')
txt.pack()
btn = tk.Button(root,image=settings_light,borderwidth=0, text = 'settings', command = openNewWindow, pady=10)
btn.place(x=245, y=10)
def Refresher():
global text
global txt
global another_frame
global btn
global last_color
global last_color_rgb
color = getColor()
last_color = color
inverted = get_complementary(color)
if(var2.get() == 'HEX'):
output_color = getColor()
last_color = color
if(var2.get() == 'RGB'):
output_color = getRgb()
last_color_rgb = output_color
output_color = 'rgb' + str(output_color)
text.configure(text=output_color,bg=color,fg=inverted)
txt.configure(bg=color,fg=inverted)
frame.configure(bg=color)
another_frame.configure(bg=color)
btn.configure(bg=color, image=get_icon_color(color))
root.configure(background=color)
if keyboard.is_pressed('c'):
pyperclip.copy(str(output_color))
text.configure(text='Copied!')
root.after(10, Refresher)
Draw()
settings()
Refresher()
root.mainloop()