2020-07-23 00:54:14 +05:30
|
|
|
'''
|
|
|
|
Simple GUI to facilitate interaction with Fawkes.
|
|
|
|
'''
|
|
|
|
|
2020-07-12 04:42:32 +05:30
|
|
|
import threading
|
2020-07-23 02:42:27 +05:30
|
|
|
from tkinter import Tk, BOTH, StringVar, Canvas, PhotoImage, CENTER, NW
|
2020-07-22 23:01:01 +05:30
|
|
|
from tkinter.filedialog import askopenfilenames
|
|
|
|
from tkinter.ttk import Frame, Label, Button
|
2020-07-23 02:42:27 +05:30
|
|
|
from PIL import ImageTk, Image
|
2020-07-12 04:42:32 +05:30
|
|
|
|
|
|
|
import fawkes.protection
|
|
|
|
|
|
|
|
|
|
|
|
class UI(Frame):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.my_fawkes = fawkes.protection.Fawkes("high_extract", '0', 1)
|
|
|
|
self.var = StringVar()
|
2020-07-23 02:42:27 +05:30
|
|
|
self.var.set('Select images to cloak!')
|
2020-07-12 04:42:32 +05:30
|
|
|
self.img_paths = './imgs'
|
|
|
|
self.initUI()
|
|
|
|
|
|
|
|
def initUI(self):
|
2020-07-23 02:42:27 +05:30
|
|
|
self.master.title("Fawkes")
|
|
|
|
self.master.configure(bg='white')
|
2020-07-12 04:42:32 +05:30
|
|
|
self.pack(fill=BOTH, expand=1)
|
|
|
|
|
2020-07-23 02:42:27 +05:30
|
|
|
# fawkes image
|
|
|
|
canvas = Canvas(self, width=110, height=150)
|
|
|
|
orig = Image.open("fawkes_mask.jpg")
|
|
|
|
resized = orig.resize((110,150), Image.ANTIALIAS)
|
|
|
|
img = ImageTk.PhotoImage(resized)
|
|
|
|
canvas.create_image(0,0, image=img, anchor=NW)
|
|
|
|
canvas.image = img
|
|
|
|
canvas.pack()
|
|
|
|
|
|
|
|
|
|
|
|
# open button
|
2020-07-12 04:42:32 +05:30
|
|
|
btn_Open = Button(self,
|
2020-07-23 02:42:27 +05:30
|
|
|
text='Choose image(s) to cloak',
|
|
|
|
width=25,
|
2020-07-12 04:42:32 +05:30
|
|
|
command=self.select_path)
|
|
|
|
btn_Open.pack()
|
|
|
|
|
2020-07-23 02:42:27 +05:30
|
|
|
# run button
|
2020-07-12 04:42:32 +05:30
|
|
|
btn_Run = Button(self,
|
2020-07-23 02:42:27 +05:30
|
|
|
text='Cloak images',
|
|
|
|
width=25,
|
2020-07-12 04:42:32 +05:30
|
|
|
command=lambda: thread_it(self.my_fawkes.run_protection, self.img_paths))
|
|
|
|
btn_Run.pack()
|
|
|
|
|
2020-07-23 02:42:27 +05:30
|
|
|
# # save button
|
|
|
|
# btn_Save = Button(self,
|
|
|
|
# text='Save cloaked image(s)',
|
|
|
|
# width=25,
|
|
|
|
# command=self.save_images)
|
|
|
|
# btn_Save.pack()
|
|
|
|
|
|
|
|
# Progress info
|
2020-07-12 04:42:32 +05:30
|
|
|
Label_Show = Label(self,
|
|
|
|
textvariable=self.var,
|
|
|
|
font=('Arial', 13), width=50)
|
2020-07-23 02:42:27 +05:30
|
|
|
Label_Show.configure(anchor="center")
|
2020-07-12 04:42:32 +05:30
|
|
|
Label_Show.pack()
|
2020-07-23 02:42:27 +05:30
|
|
|
|
2020-07-12 04:42:32 +05:30
|
|
|
|
|
|
|
def select_path(self):
|
|
|
|
self.img_paths = askopenfilenames(filetypes=[('image', "*.gif *.jpg *.png")])
|
2020-07-23 02:42:27 +05:30
|
|
|
self.var.set('Images chosen.')
|
|
|
|
|
|
|
|
def save_images(self):
|
|
|
|
print(self.img_paths)
|
|
|
|
|
|
|
|
|
2020-07-12 04:42:32 +05:30
|
|
|
|
|
|
|
|
|
|
|
root = Tk()
|
|
|
|
root.title('window')
|
2020-07-23 02:42:27 +05:30
|
|
|
root.geometry('200x230')
|
2020-07-12 04:42:32 +05:30
|
|
|
app = UI()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2020-07-23 02:42:27 +05:30
|
|
|
root.configure(bg='white')
|
2020-07-12 04:42:32 +05:30
|
|
|
root.mainloop()
|
|
|
|
|
|
|
|
def thread_it(func, *args):
|
2020-07-23 02:42:27 +05:30
|
|
|
app.var.set('Cloaking in progress.')
|
|
|
|
t = threading.Thread(target=func, args=args)
|
|
|
|
t.setDaemon(True)
|
|
|
|
t.start()
|
|
|
|
while t.is_alive():
|
|
|
|
pass
|
|
|
|
app.var.set('Cloaking finished.')
|
|
|
|
|
|
|
|
def thread_test():
|
|
|
|
app.var.set('Cloaking in progress.')
|
|
|
|
|
|
|
|
def func(test):
|
|
|
|
print(test)
|
|
|
|
args = "testing"
|
2020-07-12 04:42:32 +05:30
|
|
|
t = threading.Thread(target=func, args=args)
|
|
|
|
t.setDaemon(True)
|
|
|
|
t.start()
|
2020-07-23 02:42:27 +05:30
|
|
|
while t.is_alive():
|
|
|
|
pass
|
|
|
|
t.sleep(1)
|
|
|
|
app.var.set('Cloaking finished.')
|
2020-07-12 04:42:32 +05:30
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-07-22 23:01:01 +05:30
|
|
|
main()
|