2020-12-14 14:28:42 +01:00
|
|
|
#import tkinter as tk
|
|
|
|
import sys
|
|
|
|
import os
|
2020-12-21 17:40:37 +01:00
|
|
|
from datetime import datetime
|
2020-12-14 15:38:18 +01:00
|
|
|
from PyQt5 import QtCore
|
2020-12-21 17:40:37 +01:00
|
|
|
from PyQt5.QtWidgets import *
|
2020-12-14 15:38:18 +01:00
|
|
|
from PyQt5.QtGui import QIcon, QPixmap
|
2020-12-21 17:40:37 +01:00
|
|
|
from PyQt5.QtCore import *
|
2020-12-14 15:38:18 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
scriptPath = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
filePath = scriptPath + '\\files\\input'
|
2020-12-14 14:28:42 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
def files(path):
|
|
|
|
for file in os.listdir(path):
|
|
|
|
if os.path.isfile(os.path.join(path, file)):
|
|
|
|
yield file
|
|
|
|
|
|
|
|
class LibraryTableButtons(QWidget):
|
2020-12-21 18:18:47 +01:00
|
|
|
def __init__(self, filename, parent=None):
|
2020-12-21 17:40:37 +01:00
|
|
|
super(LibraryTableButtons,self).__init__(parent)
|
|
|
|
|
2020-12-21 18:18:47 +01:00
|
|
|
def viewFile():
|
|
|
|
os.startfile(filePath + '\\' + filename)
|
|
|
|
|
2021-01-04 12:22:19 +01:00
|
|
|
def deleteFile():
|
|
|
|
os.remove(filePath + '\\' + filename)
|
|
|
|
|
2020-12-21 18:18:47 +01:00
|
|
|
layout = QHBoxLayout()
|
2020-12-21 17:40:37 +01:00
|
|
|
layout.setContentsMargins(0,0,0,0)
|
|
|
|
layout.setSpacing(0)
|
|
|
|
|
2020-12-21 18:18:47 +01:00
|
|
|
view_btn = QPushButton('View')
|
|
|
|
view_btn.clicked.connect(viewFile)
|
|
|
|
layout.addWidget(view_btn)
|
2021-01-04 12:22:19 +01:00
|
|
|
|
|
|
|
delete_btn = QPushButton('Delete')
|
|
|
|
delete_btn.clicked.connect(deleteFile)
|
|
|
|
layout.addWidget(delete_btn)
|
2020-12-21 17:40:37 +01:00
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
|
|
|
class LibraryTable(QTableWidget):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
QTableWidget.__init__(self)
|
|
|
|
self.setColumnCount(3)
|
|
|
|
self.setHorizontalHeaderLabels(['Upload date', 'Filename', 'Options'])
|
|
|
|
self.horizontalHeader().setSectionResizeMode(0, QHeaderView.ResizeToContents)
|
|
|
|
self.horizontalHeader().setSectionResizeMode(1, QHeaderView.Stretch)
|
|
|
|
self.horizontalHeader().setSectionResizeMode(2, QHeaderView.ResizeToContents)
|
|
|
|
|
|
|
|
dates = []
|
|
|
|
names = []
|
|
|
|
for index, file in enumerate(files(filePath)):
|
|
|
|
dates.append(QTableWidgetItem(str(datetime.fromtimestamp(os.path.getmtime(filePath + '/' + file)))))
|
|
|
|
names.append(QTableWidgetItem(str(file)))
|
|
|
|
|
|
|
|
self.setRowCount(len(dates))
|
|
|
|
|
|
|
|
for index, date in enumerate(dates):
|
|
|
|
self.setItem(index,0,date)
|
|
|
|
self.setItem(index,1,names[index])
|
2020-12-21 18:18:47 +01:00
|
|
|
self.setCellWidget(index,2,LibraryTableButtons(names[index].text()))
|
2020-12-21 17:40:37 +01:00
|
|
|
|
|
|
|
|
2020-12-14 14:28:42 +01:00
|
|
|
def main():
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
2020-12-14 15:38:18 +01:00
|
|
|
#w = QWidget()
|
|
|
|
w = QMainWindow()
|
|
|
|
w.setGeometry(0, 0, 600, 400)
|
|
|
|
w.setWindowTitle('VisionScore')
|
|
|
|
scriptDir = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
w.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg'))
|
|
|
|
|
2020-12-21 15:13:58 +01:00
|
|
|
'''
|
2020-12-14 15:38:18 +01:00
|
|
|
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)
|
2020-12-21 15:13:58 +01:00
|
|
|
'''
|
|
|
|
# Toolbar
|
|
|
|
menuBar = w.menuBar()
|
|
|
|
homeMenu = QMenu("&Home", w)
|
|
|
|
menuBar.addMenu(homeMenu)
|
|
|
|
homeMenu.addAction("Load new file")
|
2020-12-21 17:40:37 +01:00
|
|
|
|
|
|
|
# Show raw uploaded files
|
|
|
|
def showLibrary():
|
|
|
|
libTable = LibraryTable()
|
|
|
|
w.setCentralWidget(libTable)
|
|
|
|
|
|
|
|
libraryAct = QAction('&Library', w)
|
|
|
|
libraryAct.triggered.connect(showLibrary)
|
|
|
|
menuBar.addAction(libraryAct)
|
|
|
|
|
2020-12-21 15:13:58 +01:00
|
|
|
# Exit app
|
|
|
|
exitAct = QAction('&Exit', w)
|
|
|
|
exitAct.setShortcut('Ctrl+Q')
|
|
|
|
exitAct.setStatusTip('Exit')
|
|
|
|
exitAct.triggered.connect(app.quit)
|
|
|
|
homeMenu.addAction(exitAct)
|
|
|
|
|
|
|
|
helpMenu = menuBar.addMenu("&Help")
|
2020-12-14 15:38:18 +01:00
|
|
|
|
2020-12-14 14:28:42 +01:00
|
|
|
w.show()
|
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|