Compare commits

..

25 Commits

Author SHA1 Message Date
179ee054a4 Merge pull request 'VIS-50' (#15) from VIS-50 into master
Reviewed-on: #15
2021-02-01 17:36:39 +01:00
511c873d60 Merge pull request 'added txt' (#14) from tests into master
Reviewed-on: #14
2021-02-01 17:36:07 +01:00
VanillaHellen
17194ad19b help fix 2021-02-01 17:35:26 +01:00
VanillaHellen
5a91ec638e added homepage 2021-02-01 17:30:30 +01:00
VanillaHellen
315bf28e63 added txt 2021-02-01 16:12:33 +01:00
cc1d42e4cd Merge pull request 'tests' (#13) from tests into master
Reviewed-on: #13
2021-01-27 14:09:10 +01:00
VanillaHellen
2bb6e3fda1 fix 2021-01-27 14:08:25 +01:00
VanillaHellen
3885dee017 added test for deleting file 2021-01-27 14:07:25 +01:00
2669185e60 Merge pull request 'VIS-47' (#12) from VIS-47 into master
Reviewed-on: #12
2021-01-25 17:47:06 +01:00
VanillaHellen
980b323a1d final cleanup 2021-01-25 17:37:24 +01:00
VanillaHellen
c4d6e9fd66 changes 2021-01-25 17:35:09 +01:00
VanillaHellen
418548cf65 fix 2021-01-25 17:33:58 +01:00
VanillaHellen
b94304aa6e changes 2021-01-25 17:33:20 +01:00
6cb77df335 cos tam sie srogo zepsulo 2021-01-25 17:20:29 +01:00
bcf7808cba Merge branch 'VIS-31' 2021-01-25 17:12:20 +01:00
c1663bb9e7 Merge pull request 'VIS-47' (#11) from VIS-47 into master
Reviewed-on: #11
2021-01-25 17:01:34 +01:00
0a204e6f74 added analize popup 2021-01-25 17:00:50 +01:00
VanillaHellen
002f2ae2b3 removed pass since its redundant now 2021-01-25 16:57:35 +01:00
VanillaHellen
e5b595a86d uncommented stuff 2021-01-25 16:52:04 +01:00
VanillaHellen
0864afb2b7 added post-vis table, fixed help, removed test input/output files 2021-01-25 16:50:27 +01:00
7a74c39e14 Merge pull request 'VIS-48' (#10) from VIS-48 into master
Reviewed-on: #10
2021-01-25 16:26:53 +01:00
VanillaHellen
681f434386 now adding timestamp 2021-01-25 16:25:31 +01:00
VanillaHellen
5ecd3cc79c Merge branch 'master' of https://git.wmi.amu.edu.pl/s406917/VisionScore into VIS-48 2021-01-25 15:47:35 +01:00
VanillaHellen
5e24b10198 Merge remote-tracking branch 'origin/master' into VIS-40-VIS-41 2021-01-18 16:23:11 +01:00
VanillaHellen
3156842621 Merge branch 'master' of https://git.wmi.amu.edu.pl/s406917/VisionScore into VIS-40-VIS-41 2021-01-18 16:14:22 +01:00
8 changed files with 116 additions and 24 deletions

View File

@ -1 +0,0 @@
test txt file

Binary file not shown.

View File

@ -6,7 +6,7 @@ from datetime import datetime
import time import time
from PyQt5 import QtCore from PyQt5 import QtCore
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from PyQt5.QtGui import QIcon, QPixmap from PyQt5.QtGui import *
from PyQt5.QtCore import * from PyQt5.QtCore import *
scriptPath = os.path.dirname(os.path.realpath(__file__)) scriptPath = os.path.dirname(os.path.realpath(__file__))
@ -17,15 +17,33 @@ LIB_RAW = 0
LIB_VIS = 1 LIB_VIS = 1
stylesheet = """
MainWindow {
background: qlineargradient(x1:0 y1:0, x2:1 y2:0, stop:0 rgba(255,218,113,1), stop:0.5 rgba(215,137,255,1), stop:1 rgba(105,126,255,1));
}
"""
def files(path): def files(path):
for subdir, dirs, files_list in os.walk(path): for subdir, dirs, files_list in os.walk(path):
for file in files_list: for file in files_list:
yield os.path.join(subdir, file) yield os.path.join(subdir, file)
def delete_file(file):
os.remove(file)
def save_input(oldpath): 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())) 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 newpath = inputFilePath + '\\' + filename
shutil.copy(oldpath, newpath) shutil.copy(oldpath, newpath)
return newpath return newpath
@ -40,8 +58,26 @@ class deletePopup(QMessageBox):
self.setStandardButtons(self.Yes | self.No) 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("Analyzing 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): 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) super(LibraryTableButtons,self).__init__(parent)
def viewFile(): def viewFile():
@ -51,16 +87,22 @@ class LibraryTableButtons(QWidget):
self.exPopup = deletePopup() self.exPopup = deletePopup()
ret = self.exPopup.exec() ret = self.exPopup.exec()
if ret == self.exPopup.Yes: if ret == self.exPopup.Yes:
os.remove(file) delete_file(file)
table.fillTable(type) table.fillTable(type, mainWindow)
def analyzeFile(): def analyzeFile():
cmd = "py detect.py --source {} --view-img".format(str(file)) self.exPopup = analizePopup()
popen = subprocess.Popen(cmd, cwd="../yolov5/", stdout=subprocess.PIPE) #cmd = "py detect.py --source {} --view-img".format(str(file))
popen.wait() #popen = subprocess.Popen(cmd, cwd="../yolov5/", stdout=subprocess.PIPE)
# todo: display gif/spinning wheel cancel = self.exPopup.exec()
if cancel == self.exPopup.Cancel:
#popen.terminate()
pass 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 = QHBoxLayout()
layout.setContentsMargins(0,0,0,0) layout.setContentsMargins(0,0,0,0)
@ -84,11 +126,11 @@ class LibraryTableButtons(QWidget):
class LibraryTable(QTableWidget): class LibraryTable(QTableWidget):
def __init__(self, type, singleFilePath = None, parent = None): def __init__(self, type, mainWindow, singleFilePath = None, parent = None):
QTableWidget.__init__(self) 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) self.setColumnCount(3)
if singleFilePath != None: if singleFilePath != None:
@ -103,7 +145,7 @@ class LibraryTable(QTableWidget):
self.setItem(0,0,QTableWidgetItem(str(datetime.fromtimestamp(os.path.getmtime(singleFilePath))))) self.setItem(0,0,QTableWidgetItem(str(datetime.fromtimestamp(os.path.getmtime(singleFilePath)))))
self.setItem(0,1,QTableWidgetItem(str(os.path.basename(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: else:
@ -130,17 +172,17 @@ class LibraryTable(QTableWidget):
for index, date in enumerate(dates): for index, date in enumerate(dates):
self.setItem(index,0,date) self.setItem(index,0,date)
self.setItem(index,1,names[index]) 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): class formatHelp(QLabel):
def __init__(self, parent=None): def __init__(self, parent=None):
QLabel.__init__(self) QLabel.__init__(self)
with open('static/help.txt', 'r', encoding='utf-8') as file: with open(scriptPath + os.path.sep + 'static/help.txt', 'r', encoding='utf-8') as file:
help_text = file.read().replace('\n', '') help_text = file.read().replace('\n', '')
self.setText(help_text) self.setText(help_text)
self.setStyleSheet("padding-left: 20px; padding-right: 20px; padding-top: 10px; padding-bottom: 10px; font-size:32px;") self.setStyleSheet("padding-left: 20px; padding-right: 20px; padding-top: 10px; padding-bottom: 10px; font-size:32px; background-color: white;")
self.adjustSize() self.adjustSize()
@ -157,14 +199,33 @@ class MainWindow(QMainWindow):
label = formatHelp() label = formatHelp()
self.setCentralWidget(label) self.setCentralWidget(label)
def showHomepage(self):
# Upload file button + instructions on homepage
label = QLabel('Welcome to VisionScore! Use the button below to upload a file and start analyzing it. If you need further help, please click the "help" item in the menu above.', self)
label.setFont(QFont('Arial', 14))
label.setStyleSheet('color: white;')
label.adjustSize()
label.move(200,200)
shadow = QGraphicsDropShadowEffect()
shadow.setBlurRadius(10)
shadow.setOffset(2)
label.setGraphicsEffect(shadow)
button = QPushButton('Upload file', self)
button.setToolTip('This is an example button')
button.move(850,270)
button.setFixedSize(220, 50)
button.clicked.connect(self.showUploadFile)
# Show raw uploaded files # Show raw uploaded files
def showInputLibrary(self): def showInputLibrary(self):
libTable = LibraryTable(LIB_RAW) libTable = LibraryTable(LIB_RAW, self)
self.setCentralWidget(libTable) self.setCentralWidget(libTable)
# Show visualisations # Show visualisations
def showVisualisationsLibrary(self): def showVisualisationsLibrary(self):
libTable = LibraryTable(LIB_VIS) libTable = LibraryTable(LIB_VIS, self)
self.setCentralWidget(libTable) self.setCentralWidget(libTable)
def showUploadFile(self): def showUploadFile(self):
@ -174,7 +235,11 @@ class MainWindow(QMainWindow):
if dialog.exec_(): if dialog.exec_():
file_path = dialog.selectedFiles()[0] # ['C:/Users/agatha/Desktop/SYI/VisionScore/win_venv/requirements.txt'] file_path = dialog.selectedFiles()[0] # ['C:/Users/agatha/Desktop/SYI/VisionScore/win_venv/requirements.txt']
newPath = save_input(file_path) 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) self.setCentralWidget(singleFileTable)
def initUI(self): def initUI(self):
@ -182,6 +247,7 @@ class MainWindow(QMainWindow):
self.setWindowTitle('VisionScore') self.setWindowTitle('VisionScore')
scriptDir = os.path.dirname(os.path.realpath(__file__)) scriptDir = os.path.dirname(os.path.realpath(__file__))
self.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg')) self.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
self.showHomepage()
# File menu # File menu
menuBar = self.menuBar() menuBar = self.menuBar()
@ -224,6 +290,7 @@ class MainWindow(QMainWindow):
def main(): def main():
app = QApplication(sys.argv) app = QApplication(sys.argv)
app.setStyleSheet(stylesheet)
w = MainWindow() w = MainWindow()
sys.exit(app.exec_()) sys.exit(app.exec_())

BIN
win_venv/static/loading.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

4
win_venv/test.txt Normal file
View File

@ -0,0 +1,4 @@
testing
more testing

View File

@ -22,6 +22,7 @@ class savingFileTest(unittest.TestCase):
new_file_content += line new_file_content += line
self.assertEqual(old_file_content, new_file_content) self.assertEqual(old_file_content, new_file_content)
os.remove(newpath)
# test using mock checking if a file with analysis had been generated # test using mock checking if a file with analysis had been generated
@ -29,12 +30,33 @@ class generetingOutputFile(unittest.TestCase):
def test_output_file(self): def test_output_file(self):
print('Moock testing outputfile') print('Mock testing outputfile')
m = Mock() m = Mock()
m.output_file_path = scriptPath + '\\files\\output\\test.pdf' m.output_file_path = scriptPath + '\\files\\output\\test.pdf'
assert Path(m.output_file_path).is_file() assert Path(m.output_file_path).is_file()
# test deleting input file
class testDeleteFile(unittest.TestCase):
def test_delete_file(self):
print('Testing deleting the file')
new_file = inputFilePath + os.path.sep + 'new_file.txt'
with open(new_file, 'w') as file:
file.write('teeeest')
with open(new_file) as f:
content = f.read()
assert os.path.exists(new_file)
self.assertEqual(content, 'teeeest')
delete_file(new_file)
self.assertFalse(os.path.exists(new_file))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()