Merge pull request 'VIS-47' (#12) from VIS-47 into master

Reviewed-on: #12
This commit is contained in:
Helena Gałązka 2021-01-25 17:47:06 +01:00
commit 2669185e60

View 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:
index_of_dot = basename.index('.')
basename_no_extension = basename[:index_of_dot]
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
@ -45,7 +53,7 @@ class analizePopup(QMessageBox):
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'))
@ -59,7 +67,7 @@ class analizePopup(QMessageBox):
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,7 +78,7 @@ 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()
@ -83,6 +91,7 @@ class LibraryTableButtons(QWidget):
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()
@ -107,11 +116,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 +135,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 +162,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 +191,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 +206,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()