Merge branch 'master' into VIS-24
This commit is contained in:
commit
ebba0059e2
BIN
win_venv/files/output/test.pdf
Normal file
BIN
win_venv/files/output/test.pdf
Normal file
Binary file not shown.
@ -1,7 +1,9 @@
|
|||||||
#import tkinter as tk
|
#import tkinter as tk
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import shutil
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
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 QIcon, QPixmap
|
||||||
@ -15,6 +17,16 @@ def files(path):
|
|||||||
if os.path.isfile(os.path.join(path, file)):
|
if os.path.isfile(os.path.join(path, file)):
|
||||||
yield file
|
yield file
|
||||||
|
|
||||||
|
|
||||||
|
def save_input(oldpath):
|
||||||
|
# make timestampt the filename, so it wouln't overwrite
|
||||||
|
timestamp = str(int(time.time()))
|
||||||
|
filename = timestamp + '.' + oldpath.split('.')[-1]
|
||||||
|
newpath = filePath + '\\' + filename
|
||||||
|
shutil.copy(oldpath, newpath)
|
||||||
|
return newpath
|
||||||
|
|
||||||
|
|
||||||
class LibraryTableButtons(QWidget):
|
class LibraryTableButtons(QWidget):
|
||||||
def __init__(self, filename, parent=None):
|
def __init__(self, filename, parent=None):
|
||||||
super(LibraryTableButtons,self).__init__(parent)
|
super(LibraryTableButtons,self).__init__(parent)
|
||||||
@ -39,7 +51,9 @@ class LibraryTableButtons(QWidget):
|
|||||||
|
|
||||||
self.setLayout(layout)
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
|
||||||
class LibraryTable(QTableWidget):
|
class LibraryTable(QTableWidget):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QTableWidget.__init__(self)
|
QTableWidget.__init__(self)
|
||||||
self.setColumnCount(3)
|
self.setColumnCount(3)
|
||||||
@ -62,50 +76,63 @@ class LibraryTable(QTableWidget):
|
|||||||
self.setCellWidget(index,2,LibraryTableButtons(names[index].text()))
|
self.setCellWidget(index,2,LibraryTableButtons(names[index].text()))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
class MainWindow(QMainWindow):
|
||||||
app = QApplication(sys.argv)
|
|
||||||
|
|
||||||
#w = QWidget()
|
def __init__(self):
|
||||||
w = QMainWindow()
|
super().__init__()
|
||||||
w.setGeometry(0, 0, 600, 400)
|
self.initUI()
|
||||||
w.setWindowTitle('VisionScore')
|
|
||||||
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
|
||||||
w.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
|
|
||||||
|
|
||||||
'''
|
|
||||||
label = QLabel()
|
|
||||||
pixmap = QPixmap(scriptDir + os.path.sep + 'static/visionscore_logo.jpg')
|
|
||||||
label.setPixmap(pixmap)
|
|
||||||
label.resize(pixmap.width(), pixmap.height())
|
|
||||||
label.setAlignment(QtCore.Qt.AlignTop)
|
|
||||||
w.setCentralWidget(label)
|
|
||||||
'''
|
|
||||||
# Toolbar
|
|
||||||
menuBar = w.menuBar()
|
|
||||||
homeMenu = QMenu("&Home", w)
|
|
||||||
menuBar.addMenu(homeMenu)
|
|
||||||
homeMenu.addAction("Load new file")
|
|
||||||
|
|
||||||
# Show raw uploaded files
|
# Show raw uploaded files
|
||||||
def showLibrary():
|
def showLibrary(self):
|
||||||
libTable = LibraryTable()
|
libTable = LibraryTable()
|
||||||
w.setCentralWidget(libTable)
|
self.setCentralWidget(libTable)
|
||||||
|
|
||||||
libraryAct = QAction('&Library', w)
|
def showUploadFile(self):
|
||||||
libraryAct.triggered.connect(showLibrary)
|
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)
|
||||||
|
|
||||||
|
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'))
|
||||||
|
|
||||||
|
# Toolbar
|
||||||
|
menuBar = self.menuBar()
|
||||||
|
homeMenu = QMenu("&Home", self)
|
||||||
|
menuBar.addMenu(homeMenu)
|
||||||
|
|
||||||
|
# Upload file
|
||||||
|
uploadAct = QAction('&Upload new file', self)
|
||||||
|
uploadAct.triggered.connect(self.showUploadFile)
|
||||||
|
homeMenu.addAction(uploadAct)
|
||||||
|
|
||||||
|
libraryAct = QAction('&Library', self)
|
||||||
|
libraryAct.triggered.connect(self.showLibrary)
|
||||||
menuBar.addAction(libraryAct)
|
menuBar.addAction(libraryAct)
|
||||||
|
|
||||||
# Exit app
|
# Exit app
|
||||||
exitAct = QAction('&Exit', w)
|
exitAct = QAction('&Exit', self)
|
||||||
exitAct.setShortcut('Ctrl+Q')
|
exitAct.setShortcut('Ctrl+Q')
|
||||||
exitAct.setStatusTip('Exit')
|
exitAct.setStatusTip('Exit')
|
||||||
exitAct.triggered.connect(app.quit)
|
exitAct.triggered.connect(qApp.quit)
|
||||||
homeMenu.addAction(exitAct)
|
homeMenu.addAction(exitAct)
|
||||||
|
|
||||||
helpMenu = menuBar.addMenu("&Help")
|
helpMenu = menuBar.addMenu("&Help")
|
||||||
|
|
||||||
w.show()
|
self.show()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
w = MainWindow()
|
||||||
sys.exit(app.exec_())
|
sys.exit(app.exec_())
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
40
win_venv/tests.py
Normal file
40
win_venv/tests.py
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
import unittest
|
||||||
|
from main import *
|
||||||
|
from unittest.mock import Mock
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# test saving file
|
||||||
|
class savingFileTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_text_file(self):
|
||||||
|
print('Testing save_input method \n')
|
||||||
|
old_file_content = 'testing\n\n\nmore testing'
|
||||||
|
with open('test.txt', 'w') as file:
|
||||||
|
file.write(old_file_content)
|
||||||
|
|
||||||
|
script_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
test_file_path = script_path + '\\test.txt'
|
||||||
|
newpath = save_input(test_file_path)
|
||||||
|
|
||||||
|
new_file_content = ''
|
||||||
|
with open(newpath, 'r') as new_file:
|
||||||
|
for line in new_file:
|
||||||
|
new_file_content += line
|
||||||
|
|
||||||
|
self.assertEqual(old_file_content, new_file_content)
|
||||||
|
|
||||||
|
|
||||||
|
# test using mock checking if a file with analysis had been generated
|
||||||
|
class generetingOutputFile(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_output_file(self):
|
||||||
|
|
||||||
|
print('Moock testing outputfile')
|
||||||
|
m = Mock()
|
||||||
|
m.output_file_path = scriptPath + '\\files\\output\\test.pdf'
|
||||||
|
|
||||||
|
assert Path(m.output_file_path).is_file()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main()
|
Loading…
Reference in New Issue
Block a user