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
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
class LibraryTableButtons(QWidget):
|
|
|
|
def __init__(self, parent=None):
|
|
|
|
super(LibraryTableButtons,self).__init__(parent)
|
|
|
|
layout = QHBoxLayout()
|
|
|
|
|
|
|
|
layout.setContentsMargins(0,0,0,0)
|
|
|
|
layout.setSpacing(0)
|
|
|
|
|
|
|
|
layout.addWidget(QPushButton('View'))
|
|
|
|
layout.addWidget(QPushButton('Delete'))
|
|
|
|
|
|
|
|
self.setLayout(layout)
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
class LibraryTable(QTableWidget):
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
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])
|
|
|
|
self.setCellWidget(index,2,LibraryTableButtons())
|
|
|
|
|
|
|
|
def handleButtonClicked(w):
|
|
|
|
button = qApp.focusWidget()
|
|
|
|
# or button = self.sender()
|
|
|
|
index = self.table.indexAt(button.pos())
|
|
|
|
if index.isValid():
|
|
|
|
print(index.row(), index.column())
|
|
|
|
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
class MainWindow(QMainWindow):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
|
|
|
self.initUI()
|
|
|
|
|
2020-12-21 17:40:37 +01:00
|
|
|
# Show raw uploaded files
|
2020-12-21 21:39:56 +01:00
|
|
|
def showLibrary(self):
|
2020-12-21 17:40:37 +01:00
|
|
|
libTable = LibraryTable()
|
2020-12-21 21:39:56 +01:00
|
|
|
self.setCentralWidget(libTable)
|
|
|
|
|
|
|
|
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)
|
|
|
|
homeMenu.addAction("Load new file")
|
|
|
|
|
|
|
|
libraryAct = QAction('&Library', self)
|
|
|
|
libraryAct.triggered.connect(self.showLibrary)
|
|
|
|
menuBar.addAction(libraryAct)
|
|
|
|
|
|
|
|
# Exit app
|
|
|
|
exitAct = QAction('&Exit', self)
|
|
|
|
exitAct.setShortcut('Ctrl+Q')
|
|
|
|
exitAct.setStatusTip('Exit')
|
|
|
|
exitAct.triggered.connect(qApp.quit)
|
|
|
|
homeMenu.addAction(exitAct)
|
|
|
|
|
|
|
|
helpMenu = menuBar.addMenu("&Help")
|
|
|
|
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
app = QApplication(sys.argv)
|
|
|
|
|
|
|
|
w = MainWindow()
|
2020-12-14 14:28:42 +01:00
|
|
|
sys.exit(app.exec_())
|
|
|
|
|
2020-12-21 21:39:56 +01:00
|
|
|
|
2020-12-14 14:28:42 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|