VIS-47 #12

Merged
s416067 merged 4 commits from VIS-47 into master 2021-01-25 17:47:09 +01:00
Showing only changes of commit b94304aa6e - Show all commits

View File

@ -6,7 +6,7 @@ from datetime import datetime
import time
from PyQt5 import QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon, QPixmap, QMovie
from PyQt5.QtGui import QIcon, QPixmap
from PyQt5.QtCore import *
scriptPath = os.path.dirname(os.path.realpath(__file__))
@ -23,9 +23,17 @@ def files(path):
yield os.path.join(subdir, file)
def save_input(oldpath):
# make timestampt the filename, so it wouln't overwrite
# add timestamp to the filename, so it wouln't overwrite but the user still knows which file's which
timestamp = str(int(time.time()))
filename = timestamp + '.' + oldpath.split('.')[-1]
basename = os.path.basename(oldpath)
try:
basename.index('.')
basename_no_extension = basename[:basename.index('.')]
extension = basename[index_of_dot:]
except ValueError:
basename_no_extension = basename
extension = ''
filename = basename_no_extension + '_' + timestamp + extension
newpath = inputFilePath + '\\' + filename
shutil.copy(oldpath, newpath)
return newpath
@ -40,26 +48,8 @@ class deletePopup(QMessageBox):
self.setStandardButtons(self.Yes | self.No)
class analizePopup(QMessageBox):
def __init__(self, parent=None):
super(analizePopup, self).__init__(parent)
self.setStyleSheet("QLabel{min-width: 100px; max-width: 100px; qproperty-alignment: AlignCenter;}");
self.setWindowIcon(QIcon(scriptPath + os.path.sep + 'static/v_logo.jpg'))
self.setText("Analizing file...")
self.setWindowTitle("File analysis")
# create Label
self.setIconPixmap(QPixmap(scriptPath + os.path.sep + 'static/loading.gif'))
icon_label = self.findChild(QLabel, "qt_msgboxex_icon_label")
movie = QMovie(scriptPath + os.path.sep + 'static/loading.gif')
# avoid garbage collector
setattr(self, 'icon_label', movie)
icon_label.setMovie(movie)
movie.start()
self.setStandardButtons(self.Cancel)
class LibraryTableButtons(QWidget):
def __init__(self, file, table, type, parent=None):
def __init__(self, file, table, type, mainWindow, parent=None):
super(LibraryTableButtons,self).__init__(parent)
def viewFile():
@ -70,20 +60,15 @@ class LibraryTableButtons(QWidget):
ret = self.exPopup.exec()
if ret == self.exPopup.Yes:
os.remove(file)
table.fillTable(type)
table.fillTable(type, mainWindow)
def analyzeFile():
self.exPopup = analizePopup()
#cmd = "py detect.py --source {} --view-img".format(str(file))
#popen = subprocess.Popen(cmd, cwd="../yolov5/", stdout=subprocess.PIPE)
cancel = self.exPopup.exec()
if cancel == self.exPopup.Cancel:
#popen.terminate()
pass
#popen.wait()
self.exPopup.close()
cmd = "py detect.py --source {} --view-img".format(str(file))
popen = subprocess.Popen(cmd, cwd="../yolov5/", stdout=subprocess.PIPE)
popen.wait()
# todo: display gif/spinning wheel
mainWindow.showVisualisation(file)
layout = QHBoxLayout()
layout.setContentsMargins(0,0,0,0)
@ -107,11 +92,11 @@ class LibraryTableButtons(QWidget):
class LibraryTable(QTableWidget):
def __init__(self, type, singleFilePath = None, parent = None):
def __init__(self, type, mainWindow, singleFilePath = None, parent = None):
QTableWidget.__init__(self)
self.fillTable(type, singleFilePath)
self.fillTable(type, mainWindow, singleFilePath)
def fillTable(self, type, singleFilePath = None):
def fillTable(self, type, mainWindow, singleFilePath = None):
self.setColumnCount(3)
if singleFilePath != None:
@ -126,7 +111,7 @@ class LibraryTable(QTableWidget):
self.setItem(0,0,QTableWidgetItem(str(datetime.fromtimestamp(os.path.getmtime(singleFilePath)))))
self.setItem(0,1,QTableWidgetItem(str(os.path.basename(singleFilePath))))
self.setCellWidget(0,2,LibraryTableButtons(singleFilePath, self, type))
self.setCellWidget(0,2,LibraryTableButtons(singleFilePath, self, type, mainWindow))
else:
@ -153,7 +138,7 @@ class LibraryTable(QTableWidget):
for index, date in enumerate(dates):
self.setItem(index,0,date)
self.setItem(index,1,names[index])
self.setCellWidget(index,2,LibraryTableButtons(names[index].text(), self, type))
self.setCellWidget(index,2,LibraryTableButtons(names[index].text(), self, type, mainWindow))
class formatHelp(QLabel):
@ -182,12 +167,12 @@ class MainWindow(QMainWindow):
# Show raw uploaded files
def showInputLibrary(self):
libTable = LibraryTable(LIB_RAW)
libTable = LibraryTable(LIB_RAW, self)
self.setCentralWidget(libTable)
# Show visualisations
def showVisualisationsLibrary(self):
libTable = LibraryTable(LIB_VIS)
libTable = LibraryTable(LIB_VIS, self)
self.setCentralWidget(libTable)
def showUploadFile(self):
@ -197,13 +182,18 @@ class MainWindow(QMainWindow):
if dialog.exec_():
file_path = dialog.selectedFiles()[0] # ['C:/Users/agatha/Desktop/SYI/VisionScore/win_venv/requirements.txt']
newPath = save_input(file_path)
singleFileTable = LibraryTable(LIB_RAW, newPath)
singleFileTable = LibraryTable(LIB_RAW, self, newPath)
self.setCentralWidget(singleFileTable)
def showVisualisation(self, path):
singleFileTable = LibraryTable(LIB_VIS, self, path)
self.setCentralWidget(singleFileTable)
def initUI(self):
self.setGeometry(0, 0, 600, 400)
self.setWindowTitle('VisionScore')
self.setWindowIcon(QIcon(scriptPath + os.path.sep + 'static/v_logo.jpg'))
scriptDir = os.path.dirname(os.path.realpath(__file__))
self.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
# File menu
menuBar = self.menuBar()