-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
148 lines (118 loc) · 6.45 KB
/
app.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
import tkinter as tk
from tkinter import ttk
from typing import Callable
from TKinterModernThemes.WidgetFrame import Widget
import TKinterModernThemes as TKMT
from controller.RecordingController import RecordingController
from controller.VideoController import VideoController
from controller.YoutubeController import YoutubeController
from managers.ControllerManager import ControllerManager
from managers.EventManager import EventManager
from managers.ViewManager import ViewManager
from managers.ViewEventManager import ViewEventManager
from library.AppEvent import AppEvent, AppEventType
from model.RecordingRepository import RecordingRepository
from view import *
from view.AnnotationEditView import AnnotationEditView
from view.TitleView import TitleView
def buttonCMD():
print("Button clicked!")
class App(TKMT.ThemedTKinterFrame):
def __init__(self, theme, mode, usecommandlineargs=True, usethemeconfigfile=True):
super().__init__("PedAnalyze: Pedestrian Behavior Annotator", theme, mode, usecommandlineargs, usethemeconfigfile)
#self.initContext()
global firstWindow
firstWindow = False # super important for popups
# Instantiating Style class
self.style = ttk.Style(self.master)
self.fontsize = 12
# Changing font-size of all the Label Widget
self.style.configure("TLabel", font=('Arial', self.fontsize))
self.style.configure("TEntry", font=('Arial', self.fontsize))
self.style.configure("TButton", font=('Arial', self.fontsize))
self.style.configure("TCheckbutton", font=('Arial', self.fontsize))
self.style.configure("TRadiobutton", font=('Arial', self.fontsize))
self.style.configure("TFrame", font=('Arial', self.fontsize))
self.style.configure("TLabelFrame", font=('Arial', self.fontsize))
self.style.configure("TCombobox", font=('Arial', self.fontsize))
self.style.configure("TLabelFrame", font=('Arial', self.fontsize))
self.style.configure("TMenubutton", font=('Arial', self.fontsize))
self.eventManager = EventManager()
self.viewEventManager = ViewEventManager(self.eventManager)
self.viewManager = ViewManager(self.eventManager, self.viewEventManager)
self.controllerManager = ControllerManager(self.eventManager)
self.recordingController = self.controllerManager.getRecordingController()
# create two widgetframes, nav and content
self.makeNav()
self.makeContent()
self.makeEditor()
# self.debugPrint()
self.eventManager.subscribe(AppEventType.newProject, self.handleNewProject)
self.eventManager.subscribe(AppEventType.requestAnnotation, self.handleNewAnnotation)
self.eventManager.subscribe(AppEventType.saveProject, self.handleSaveProject)
self.eventManager.subscribe(AppEventType.exceptions, self.handleException)
self.run()
def makeNav(self):
#TODO: call render titleview here I think
self.navFrame = self.addLabelFrame("Title View", padx=(0,0), pady=(10,0))
# self.navFrame.Button("New Project", buttonCMD)
# self.navFrame.nextCol()
# self.navFrame.Button("Save", buttonCMD)
# self.navFrame.setActiveCol(0)
# self.navFrame.Text("Recording Name")
# self.navFrame.Text("Annotation Path")
# titleView = TitleView(self.eventManager, self.recordingController)
titleView = self.viewManager.getTitleView(self.recordingController)
titleView.render(self.navFrame)
def makeContent(self):
self.contentFrame = self.addFrame("Content", padx=(0,0), pady=(0,0))
# left and right
self.leftFrame = self.contentFrame.addFrame("Left", padx=(0,0), pady=(0,0))
# self.leftFrame.Label("Left Frame")
self.contentFrame.nextCol()
self.rightFrame = self.contentFrame.addFrame("Right", padx=(0,0), pady=(0,0))
# self.rightFrame.Label("Right Frame")
def makeEditor(self):
# put video player and annotation edit on the left frame
# put recording on the right
self.videoFrame = self.leftFrame.addLabelFrame("Video View", padx=(0,0), pady=(10,0))
# self.createVideoView()
# self.videoFrame.Text("Video")
# self.leftFrame.Seperator()
self.annotationFrame = self.leftFrame.addLabelFrame("Annotation Edit View", padx=(0,0), pady=(10,0))
self.annotationEditView = self.viewManager.getAnnotationEditView(self.recordingController)
#self.context["controllers"]["recording"])
self.annotationEditView.render(self.annotationFrame)
self.recordingFrame = self.rightFrame.addFrame("Recording", padx=(0,0), pady=(10,0))
self.recordingView = self.viewManager.getRecordingView(self.recordingController)
self.recordingView.render(self.recordingFrame)
# text = self.recordingFrame.Text("Recording")
# text.pack(side=tk.TOP)
def handleNewAnnotation(self, event: AppEvent):
print("Annotation event handled")
self.annotationEditView.currentAnnotationStartFrame.set(self.videoView.startFrame.get())
self.annotationEditView.currentAnnotationEndFrame.set(self.videoView.endFrame.get())
def handleNewProject(self, event: AppEvent):
print("New project event handled")
# save current video if exists
self.createVideoView(**event.data)
def handleSaveProject(self, event: AppEvent):
print("Save project event handled")
status, message = self.recordingController.saveProject()
PopupView(message, "park", "dark")
def handleException(self, event: AppEvent):
print("Exception event handled")
if isinstance(event.data, Exception):
PopupView(str(event.data), "park", "dark")
else:
PopupView(event.data["message"], "park", "dark")
def createVideoView(self, videoURL:str, videoTitle:str, annotationPath: str):
self.recordingController.initNewRecording(videoTitle, None, annotationPath, videoURL)
print(f"Creating video view with url {videoURL} and title {videoTitle} and annotation path {annotationPath}")
if not hasattr(self, 'videoView') or self.videoView is None:
self.videoView = self.viewManager.getVideoView()
self.videoView.render(self.videoFrame, videoURL)
else:
self.videoView.updateVideo(videoURL)
if __name__ == "__main__":
App("park", "dark")