2020-12-14 14:28:42 +01:00
|
|
|
#import tkinter as tk
|
|
|
|
import sys
|
|
|
|
import os
|
2020-12-21 22:42:37 +01:00
|
|
|
import shutil
|
2020-12-21 17:40:37 +01:00
|
|
|
from datetime import datetime
|
2020-12-21 22:42:37 +01:00
|
|
|
import time
|
2020-12-14 15:38:18 +01:00
|
|
|
from PyQt5 import QtCore
|
2020-12-21 17:40:37 +01:00
|
|
|
from PyQt5.QtWidgets import *
|
2020-12-14 15:38:18 +01:00
|
|
|
from PyQt5.QtGui import QIcon, QPixmap
|
2020-12-21 17:40:37 +01:00
|
|
|
from PyQt5.QtCore import *
|
2020-12-14 15:38:18 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
scriptPath = os.path.dirname(os.path.realpath(__file__))
|
2021-01-04 12:47:36 +01:00
|
|
|
inputFilePath = scriptPath + '\\files\\input'
|
|
|
|
outputFilePath = scriptPath + '\\files\\output'
|
|
|
|
|
|
|
|
LIB_RAW = 0
|
|
|
|
LIB_VIS = 1
|
2020-12-14 14:28:42 +01:00
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
def files(path):
|
|
|
|
for file in os.listdir(path):
|
|
|
|
if os.path.isfile(os.path.join(path, file)):
|
|
|
|
yield file
|
|
|
|
|
2020-12-21 22:42:37 +01:00
|
|
|
def save_input(oldpath):
|
|
|
|
# make timestampt the filename, so it wouln't overwrite
|
|
|
|
timestamp = str(int(time.time()))
|
|
|
|
filename = timestamp + '.' + oldpath.split('.')[-1]
|
2021-01-04 12:58:04 +01:00
|
|
|
newpath = inputFilePath + '\\' + filename
|
2020-12-21 22:42:37 +01:00
|
|
|
shutil.copy(oldpath, newpath)
|
2020-12-21 23:10:17 +01:00
|
|
|
return newpath
|
2021-01-11 10:24:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class deletePopup(QMessageBox):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(deletePopup, self).__init__(parent)
|
|
|
|
self.setText("Are you sure you want to delete the file?")
|
|
|
|
self.setIcon(self.Warning)
|
|
|
|
self.setWindowTitle("Confirm deletion")
|
|
|
|
self.setStandardButtons(self.Yes | self.No)
|
2020-12-21 22:42:37 +01:00
|
|
|
|
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
class LibraryTableButtons(QWidget):
|
2021-01-11 16:22:46 +01:00
|
|
|
def __init__(self, file, table, type, parent=None):
|
2020-12-21 17:40:37 +01:00
|
|
|
super(LibraryTableButtons,self).__init__(parent)
|
|
|
|
|
2020-12-21 18:18:47 +01:00
|
|
|
def viewFile():
|
2021-01-04 12:47:36 +01:00
|
|
|
os.startfile(file)
|
2020-12-21 18:18:47 +01:00
|
|
|
|
2021-01-04 12:22:19 +01:00
|
|
|
def deleteFile():
|
2021-01-04 12:23:17 +01:00
|
|
|
self.exPopup = deletePopup()
|
2021-01-04 12:47:36 +01:00
|
|
|
ret = self.exPopup.exec()
|
|
|
|
if ret == self.exPopup.Yes:
|
|
|
|
os.remove(file)
|
2021-01-11 16:22:46 +01:00
|
|
|
table.fillTable(type)
|
2021-01-18 16:13:52 +01:00
|
|
|
|
|
|
|
def analizeFile():
|
|
|
|
# todo: run script detect.py --source ../files/input/file.mp4
|
|
|
|
pass
|
2021-01-04 12:22:19 +01:00
|
|
|
|
2020-12-21 18:18:47 +01:00
|
|
|
layout = QHBoxLayout()
|
2020-12-21 17:40:37 +01:00
|
|
|
layout.setContentsMargins(0,0,0,0)
|
|
|
|
layout.setSpacing(0)
|
2021-01-18 16:13:52 +01:00
|
|
|
|
|
|
|
if type == LIB_RAW:
|
|
|
|
analize_btn = QPushButton('Analize')
|
|
|
|
analize_btn.clicked.connect(analizeFile)
|
|
|
|
layout.addWidget(analize_btn)
|
2020-12-21 17:40:37 +01:00
|
|
|
|
2020-12-21 18:18:47 +01:00
|
|
|
view_btn = QPushButton('View')
|
|
|
|
view_btn.clicked.connect(viewFile)
|
|
|
|
layout.addWidget(view_btn)
|
2021-01-04 12:22:19 +01:00
|
|
|
|
|
|
|
delete_btn = QPushButton('Delete')
|
|
|
|
delete_btn.clicked.connect(deleteFile)
|
|
|
|
layout.addWidget(delete_btn)
|
2020-12-21 17:40:37 +01:00
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
class LibraryTable(QTableWidget):
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2021-01-04 12:47:36 +01:00
|
|
|
def __init__(self, type, parent=None):
|
2020-12-21 17:40:37 +01:00
|
|
|
QTableWidget.__init__(self)
|
2021-01-11 16:22:46 +01:00
|
|
|
self.fillTable(type)
|
|
|
|
|
|
|
|
def fillTable(self, type):
|
2020-12-21 17:40:37 +01:00
|
|
|
self.setColumnCount(3)
|
2021-01-04 12:47:36 +01:00
|
|
|
|
|
|
|
if type == LIB_RAW:
|
|
|
|
self.setHorizontalHeaderLabels(['Upload date', 'Filename', 'Options'])
|
|
|
|
filePath = inputFilePath
|
|
|
|
else:
|
|
|
|
self.setHorizontalHeaderLabels(['Creation date', 'Filename', 'Options'])
|
|
|
|
filePath = outputFilePath
|
2021-01-11 16:22:46 +01:00
|
|
|
|
2021-01-04 12:58:04 +01:00
|
|
|
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.Stretch)
|
2020-12-21 17:40:37 +01:00
|
|
|
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
|
|
|
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
|
|
|
|
|
|
|
dates = []
|
|
|
|
names = []
|
|
|
|
for index, file in enumerate(files(filePath)):
|
|
|
|
dates.append(QTableWidgetItem(str(datetime.fromtimestamp(os.path.getmtime(filePath + '/' + file)))))
|
|
|
|
names.append(QTableWidgetItem(str(file)))
|
|
|
|
|
|
|
|
self.setRowCount(len(dates))
|
|
|
|
|
|
|
|
for index, date in enumerate(dates):
|
|
|
|
self.setItem(index,0,date)
|
|
|
|
self.setItem(index,1,names[index])
|
2021-01-11 16:22:46 +01:00
|
|
|
self.setCellWidget(index,2,LibraryTableButtons(filePath + '\\' + names[index].text(), self, type))
|
2020-12-21 17:40:37 +01:00
|
|
|
|
2020-12-14 14:28:42 +01:00
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
class formatHelp(QLabel):
|
|
|
|
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
QLabel.__init__(self)
|
|
|
|
help_text = '''
|
|
|
|
VisionScore to program służący do generowania analizy nagrań lub zdjęć z meczów piłkarskich.
|
|
|
|
|
|
|
|
By wygenerować taką analizę, należy postępować według następujących kroków:
|
|
|
|
|
|
|
|
1. Wgraj plik z plikiem do przeanalizowania
|
|
|
|
File -> Upload new file
|
|
|
|
2. Po wgraniu pliku pojawi się on w
|
|
|
|
Library -> Input files
|
|
|
|
# 3. By wygenerować analizę należy kliknąć przycisk
|
|
|
|
Analyze
|
|
|
|
znajdujący się obok wgranego pliku. Analizę można wygenerować także do uprzednio wgranych plików.
|
|
|
|
4. Po wygenerowaniu, analiza znajdować się będzie w
|
|
|
|
Library -> Vizusalizations
|
|
|
|
możesz tam także zobaczyć wszystkie poprzednio wygenerowane analizy.
|
|
|
|
|
|
|
|
Każdy plik źródłowy lub wygenerowaną analizę możesz w każdym momencie podejrzeć klikając
|
|
|
|
View
|
|
|
|
obok pliku znajdującego się w bibliotekach. Plik możesz też w każdym momencie usunąć klikając
|
|
|
|
Delete
|
|
|
|
obok odpowiedniego pliku.
|
|
|
|
|
|
|
|
|
|
|
|
Zakończ działanie aplikacji klikąc
|
|
|
|
File -> Exit
|
|
|
|
używając skrótu klawiszowego Ctrl+Q lub bo prostu zamykając okienko aplikacji.
|
|
|
|
|
|
|
|
|
|
|
|
Kontakt: mikbed@st.amu.edu.pl
|
|
|
|
'''
|
|
|
|
self.setText(help_text)
|
|
|
|
self.adjustSize()
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
class MainWindow(QMainWindow):
|
2020-12-21 17:40:37 +01:00
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.initUI()
|
2021-01-11 10:24:05 +01:00
|
|
|
|
|
|
|
# todo: split in multiply labels for richer formatting
|
|
|
|
# Show Help tab
|
|
|
|
def showHelp(self):
|
|
|
|
label = formatHelp()
|
|
|
|
self.setCentralWidget(label)
|
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
# Show raw uploaded files
|
2021-01-04 12:47:36 +01:00
|
|
|
def showInputLibrary(self):
|
2021-01-11 16:24:30 +01:00
|
|
|
libTable = LibraryTable(LIB_RAW)
|
|
|
|
self.setCentralWidget(libTable)
|
2021-01-04 12:47:36 +01:00
|
|
|
|
|
|
|
# Show visualisations
|
|
|
|
def showVisualisationsLibrary(self):
|
2021-01-11 16:24:30 +01:00
|
|
|
libTable = LibraryTable(LIB_VIS)
|
|
|
|
self.setCentralWidget(libTable)
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-21 22:42:37 +01:00
|
|
|
def showUploadFile(self):
|
|
|
|
dialog = QFileDialog(self)
|
|
|
|
dialog.setFileMode(QFileDialog.AnyFile)
|
|
|
|
dialog.setFilter(QDir.Files)
|
|
|
|
if dialog.exec_():
|
|
|
|
file_path = dialog.selectedFiles()[0] # ['C:/Users/agatha/Desktop/SYI/VisionScore/win_venv/requirements.txt']
|
|
|
|
save_input(file_path)
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
def initUI(self):
|
|
|
|
self.setGeometry(0, 0, 600, 400)
|
|
|
|
self.setWindowTitle('VisionScore')
|
|
|
|
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
self.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
|
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
# File menu
|
2020-12-21 21:39:56 +01:00
|
|
|
menuBar = self.menuBar()
|
2021-01-11 10:24:05 +01:00
|
|
|
fileMenu = QMenu("&File", self)
|
|
|
|
menuBar.addMenu(fileMenu)
|
2020-12-21 22:42:37 +01:00
|
|
|
|
|
|
|
# Upload file
|
|
|
|
uploadAct = QAction('&Upload new file', self)
|
|
|
|
uploadAct.triggered.connect(self.showUploadFile)
|
2021-01-11 10:24:05 +01:00
|
|
|
fileMenu.addAction(uploadAct)
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
# Exit app
|
|
|
|
exitAct = QAction('&Exit', self)
|
|
|
|
exitAct.setShortcut('Ctrl+Q')
|
|
|
|
exitAct.setStatusTip('Exit')
|
|
|
|
exitAct.triggered.connect(qApp.quit)
|
|
|
|
fileMenu.addAction(exitAct)
|
|
|
|
|
|
|
|
# Library menu
|
2021-01-04 12:47:36 +01:00
|
|
|
libraryMenu = QMenu("&Library", self)
|
|
|
|
menuBar.addMenu(libraryMenu)
|
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
# Input files
|
2021-01-04 12:47:36 +01:00
|
|
|
inputAct = QAction('&Input files', self)
|
|
|
|
inputAct.triggered.connect(self.showInputLibrary)
|
|
|
|
libraryMenu.addAction(inputAct)
|
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
# Visualisations
|
2021-01-04 12:47:36 +01:00
|
|
|
visAct = QAction('&Visualisations', self)
|
|
|
|
visAct.triggered.connect(self.showVisualisationsLibrary)
|
|
|
|
libraryMenu.addAction(visAct)
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2021-01-11 10:24:05 +01:00
|
|
|
# Help
|
|
|
|
helpAct = QAction('&Help', self)
|
|
|
|
helpAct.triggered.connect(self.showHelp)
|
|
|
|
menuBar.addAction(helpAct)
|
2020-12-21 21:39:56 +01:00
|
|
|
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
|
|
|
w = MainWindow()
|
2020-12-14 14:28:42 +01:00
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-14 14:28:42 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|