72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
|
from tkinter import *
|
||
|
from tkinter import filedialog
|
||
|
from pathlib import Path
|
||
|
from util import Util
|
||
|
from functools import partial
|
||
|
from image import ImageWindow
|
||
|
|
||
|
|
||
|
class App:
|
||
|
def __init__(self, root):
|
||
|
super().__init__()
|
||
|
self.selected_folder = ""
|
||
|
self.found_images = []
|
||
|
self.timer = 0
|
||
|
self.title = Label(root, text="Drawing Training")
|
||
|
self.title.pack()
|
||
|
|
||
|
self.folder_selector = Button(root, text="Select a folder", command=self.select_folder)
|
||
|
self.folder_selector.pack()
|
||
|
|
||
|
self.folder_name = Label(root, text="Folder : " + self.selected_folder)
|
||
|
self.folder_name.pack()
|
||
|
|
||
|
self.images_len = Label(root, text="Found : " + str(len(self.found_images)))
|
||
|
self.images_len.pack()
|
||
|
|
||
|
self.button_frame = Frame(root)
|
||
|
self.button_frame.pack(fill=X)
|
||
|
|
||
|
timers = [30, 45, 60, 120, 300, 600]
|
||
|
self.buttons = []
|
||
|
i = 0
|
||
|
for i in timers:
|
||
|
t = i
|
||
|
new_button = Button(self.button_frame, text=Util.format_seconds(t),
|
||
|
command=partial(self.set_timer_in_seconds, t))
|
||
|
# new_button.pack(side="left")
|
||
|
self.buttons.append(new_button)
|
||
|
self.button_frame.columnconfigure(i, weight=1)
|
||
|
new_button.grid(row=0, column=i, sticky=W + E)
|
||
|
i += 1
|
||
|
|
||
|
self.launch_button = Button(root, text="Let's draw!", command=self.lets_draw, state="disabled")
|
||
|
self.launch_button.pack(side="bottom")
|
||
|
self.image_window = ImageWindow(root)
|
||
|
|
||
|
def lets_draw(self):
|
||
|
self.image_window.lets_draw(self.found_images, self.timer)
|
||
|
|
||
|
def select_folder(self):
|
||
|
self.selected_folder = filedialog.askdirectory()
|
||
|
self.found_images = list(
|
||
|
p.resolve() for p in Path(self.selected_folder).glob("**/*") if p.suffix in {".jpg", ".gif", ".png"})
|
||
|
self.folder_name.config(text="Folder : " + self.selected_folder)
|
||
|
self.images_len.config(text="Found : " + str(len(self.found_images)))
|
||
|
self.check_lets_draw()
|
||
|
|
||
|
def check_lets_draw(self):
|
||
|
if self.selected_folder != "" and len(self.found_images) > 0 and self.timer != 0:
|
||
|
self.launch_button.config(state="normal")
|
||
|
else:
|
||
|
self.launch_button.config(state="disabled")
|
||
|
|
||
|
def set_timer_in_seconds(self, user_data):
|
||
|
self.timer = user_data
|
||
|
for button in self.buttons:
|
||
|
if button['text'] == Util.format_seconds(self.timer):
|
||
|
button.config(bg="blue")
|
||
|
else:
|
||
|
button.config(bg="gray85")
|
||
|
self.check_lets_draw()
|