2021-01-07 20:25:38 +01:00
|
|
|
import PIL.Image
|
|
|
|
import PIL.ImageTk
|
2021-01-07 18:35:51 +01:00
|
|
|
import tkinter as tk
|
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
from constants import PROJECT_VIEW_NAME, FONT_SM, FONT, PROJECTS_VIEW_NAME
|
2021-01-07 20:25:38 +01:00
|
|
|
from gestures.gesture_recognition import MyVideoCapture
|
2021-01-07 18:35:51 +01:00
|
|
|
from views.abstract_view import AbstractView
|
|
|
|
|
|
|
|
|
|
|
|
class ProjectView(tk.Frame, AbstractView):
|
|
|
|
|
|
|
|
def __init__(self, parent, controller, main_view_controller):
|
|
|
|
tk.Frame.__init__(self, parent)
|
|
|
|
self.token = ''
|
2021-01-07 20:25:38 +01:00
|
|
|
self.window = controller
|
|
|
|
self.main_view_controller = main_view_controller
|
|
|
|
self.delay = 20
|
|
|
|
self.vid = None
|
2021-01-07 22:13:39 +01:00
|
|
|
self.vid_canvas = None
|
2021-01-07 20:25:38 +01:00
|
|
|
self.canvas = None
|
|
|
|
self.index_label = None
|
|
|
|
self.middle_label = None
|
|
|
|
self.ring_label = None
|
|
|
|
self.pinky_label = None
|
|
|
|
self.back_button = None
|
2021-01-07 22:13:39 +01:00
|
|
|
self.bottom_frame = None
|
|
|
|
self.top_frame = None
|
2021-01-07 18:35:51 +01:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_view_name() -> str:
|
|
|
|
return PROJECT_VIEW_NAME
|
|
|
|
|
|
|
|
def start(self):
|
2021-01-07 20:25:38 +01:00
|
|
|
self.vid = MyVideoCapture()
|
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
self.top_frame = tk.Frame(self, relief=tk.RAISED, borderwidth=0)
|
|
|
|
self.top_frame.pack(fill=tk.BOTH, side=tk.TOP)
|
|
|
|
self.top_frame.columnconfigure(0, weight=2)
|
|
|
|
self.top_frame.columnconfigure(1, weight=1)
|
|
|
|
print(self.top_frame['width'])
|
|
|
|
print(self.top_frame['height'])
|
|
|
|
self.canvas = tk.Canvas(self.top_frame, width=465, height=415, bg="blue")
|
|
|
|
coord = 10, 50, 240, 210
|
|
|
|
self.canvas.create_arc(coord, start=0, extent=150, fill="red")
|
|
|
|
self.canvas.grid(row=0, column=0, sticky=tk.W, rowspan=4)
|
|
|
|
self.index_label = tk.Label(self.top_frame, font=FONT_SM)
|
|
|
|
self.index_label.grid(row=0, column=1)
|
|
|
|
self.middle_label = tk.Label(self.top_frame, font=FONT_SM)
|
|
|
|
self.middle_label.grid(row=1, column=1)
|
|
|
|
self.ring_label = tk.Label(self.top_frame, font=FONT_SM)
|
|
|
|
self.ring_label.grid(row=2, column=1)
|
|
|
|
self.pinky_label = tk.Label(self.top_frame, font=FONT_SM)
|
|
|
|
self.pinky_label.grid(row=3, column=1)
|
2021-01-07 20:25:38 +01:00
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
self.bottom_frame = tk.Frame(self, relief=tk.RAISED, borderwidth=1)
|
|
|
|
self.bottom_frame.pack(fill=tk.BOTH, side=tk.BOTTOM)
|
|
|
|
self.bottom_frame.columnconfigure(0, weight=1)
|
|
|
|
self.bottom_frame.columnconfigure(1, weight=1)
|
|
|
|
self.back_button = tk.Button(self.bottom_frame, text="Back", font=FONT,
|
|
|
|
command=lambda: self.back_to_projects_view())
|
|
|
|
self.back_button.grid(row=0, column=0, sticky=tk.SW)
|
|
|
|
self.vid_canvas = tk.Canvas(self.bottom_frame, width=self.vid.width, height=self.vid.height)
|
|
|
|
self.vid_canvas.grid(row=0, column=1, sticky=tk.E)
|
2021-01-07 20:25:38 +01:00
|
|
|
|
|
|
|
self.update()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
# Get a frame from the video source
|
|
|
|
if self.vid is not None:
|
|
|
|
fingers, frame, success = self.vid.get_frame()
|
2021-01-07 22:13:39 +01:00
|
|
|
if fingers is not None:
|
|
|
|
self.index_label['text'] = fingers['index'][0]
|
|
|
|
self.middle_label['text'] = fingers['middle'][0]
|
|
|
|
self.ring_label['text'] = fingers['ring'][0]
|
|
|
|
self.pinky_label['text'] = fingers['pinky'][0]
|
2021-01-07 20:25:38 +01:00
|
|
|
|
|
|
|
if success:
|
|
|
|
self.photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
|
2021-01-07 22:13:39 +01:00
|
|
|
self.vid_canvas.create_image(0, 0, image=self.photo, anchor=tk.NW)
|
2021-01-07 20:25:38 +01:00
|
|
|
|
|
|
|
self.window.after(self.delay, self.update)
|
|
|
|
|
|
|
|
def back_to_projects_view(self):
|
|
|
|
self.main_view_controller.show_frame(PROJECTS_VIEW_NAME)
|
|
|
|
self.vid.release()
|
2021-01-07 22:13:39 +01:00
|
|
|
self.destroy_widgets()
|
2021-01-07 20:25:38 +01:00
|
|
|
|
2021-01-07 22:13:39 +01:00
|
|
|
def destroy_widgets(self):
|
2021-01-07 20:25:38 +01:00
|
|
|
self.vid = None
|
2021-01-07 22:13:39 +01:00
|
|
|
self.top_frame.destroy()
|
2021-01-07 20:25:38 +01:00
|
|
|
self.canvas.destroy()
|
2021-01-07 22:13:39 +01:00
|
|
|
self.bottom_frame.destroy()
|
|
|
|
self.vid_canvas.destroy()
|
2021-01-07 20:25:38 +01:00
|
|
|
self.index_label.destroy()
|
|
|
|
self.middle_label.destroy()
|
|
|
|
self.ring_label.destroy()
|
|
|
|
self.pinky_label.destroy()
|
|
|
|
self.back_button.destroy()
|