From b94304aa6e419152c8fcb125a6dafc63ae46686a Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Mon, 25 Jan 2021 17:33:20 +0100 Subject: [PATCH 1/4] changes --- win_venv/main.py | 74 +++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 42 deletions(-) diff --git a/win_venv/main.py b/win_venv/main.py index bf1f47c..703f8e5 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -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() From 418548cf65bf74bc9cc4881921fdbba0a01cda59 Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Mon, 25 Jan 2021 17:33:58 +0100 Subject: [PATCH 2/4] fix --- win_venv/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/win_venv/main.py b/win_venv/main.py index 703f8e5..a60622e 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -6,7 +6,7 @@ from datetime import datetime import time from PyQt5 import QtCore from PyQt5.QtWidgets import * -from PyQt5.QtGui import QIcon, QPixmap +from PyQt5.QtGui import QIcon, QPixmap, QMovie from PyQt5.QtCore import * scriptPath = os.path.dirname(os.path.realpath(__file__)) From c4d6e9fd661cba51a3b2617d67a1cb95c1af7333 Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Mon, 25 Jan 2021 17:35:09 +0100 Subject: [PATCH 3/4] changes --- win_venv/main.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/win_venv/main.py b/win_venv/main.py index a60622e..4c99a85 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -47,6 +47,22 @@ class deletePopup(QMessageBox): self.setWindowTitle("Confirm deletion") 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, mainWindow, parent=None): @@ -63,12 +79,17 @@ class LibraryTableButtons(QWidget): table.fillTable(type, mainWindow) def analyzeFile(): - 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) + 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() + # mainWindow.showVisualisation(file) <- ALWAYS shows even if you cancel the process and we don't have time to fix that now layout = QHBoxLayout() layout.setContentsMargins(0,0,0,0) From 980b323a1d2b2e2921e9d30a5dd2fd72c1bb7ea3 Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Mon, 25 Jan 2021 17:37:24 +0100 Subject: [PATCH 4/4] final cleanup --- win_venv/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/win_venv/main.py b/win_venv/main.py index 4c99a85..7e4a1de 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -27,8 +27,8 @@ def save_input(oldpath): timestamp = str(int(time.time())) basename = os.path.basename(oldpath) try: - basename.index('.') - basename_no_extension = basename[:basename.index('.')] + index_of_dot = basename.index('.') + basename_no_extension = basename[:index_of_dot] extension = basename[index_of_dot:] except ValueError: basename_no_extension = basename @@ -47,12 +47,13 @@ class deletePopup(QMessageBox): self.setWindowTitle("Confirm deletion") 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.setText("Analyzing file...") self.setWindowTitle("File analysis") # create Label self.setIconPixmap(QPixmap(scriptPath + os.path.sep + 'static/loading.gif')) @@ -64,6 +65,7 @@ class analizePopup(QMessageBox): movie.start() self.setStandardButtons(self.Cancel) + class LibraryTableButtons(QWidget): def __init__(self, file, table, type, mainWindow, parent=None): super(LibraryTableButtons,self).__init__(parent) @@ -91,6 +93,7 @@ class LibraryTableButtons(QWidget): self.exPopup.close() # mainWindow.showVisualisation(file) <- ALWAYS shows even if you cancel the process and we don't have time to fix that now + layout = QHBoxLayout() layout.setContentsMargins(0,0,0,0) layout.setSpacing(0)