fixed uploading file

This commit is contained in:
Agata 2020-12-21 22:42:37 +01:00
parent ec69d2df9d
commit fcb6d5f225

View File

@ -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
@ -16,6 +18,16 @@ def files(path):
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
print(oldpath)
print(newpath)
shutil.copy(oldpath, 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)
@ -60,6 +72,7 @@ class LibraryTable(QTableWidget):
class MainWindow(QMainWindow): class MainWindow(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.initUI() self.initUI()
@ -69,6 +82,14 @@ class MainWindow(QMainWindow):
libTable = LibraryTable() libTable = LibraryTable()
self.setCentralWidget(libTable) self.setCentralWidget(libTable)
def showUploadFile(self):
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): def initUI(self):
self.setGeometry(0, 0, 600, 400) self.setGeometry(0, 0, 600, 400)
self.setWindowTitle('VisionScore') self.setWindowTitle('VisionScore')
@ -79,7 +100,11 @@ class MainWindow(QMainWindow):
menuBar = self.menuBar() menuBar = self.menuBar()
homeMenu = QMenu("&Home", self) homeMenu = QMenu("&Home", self)
menuBar.addMenu(homeMenu) menuBar.addMenu(homeMenu)
homeMenu.addAction("Load new file")
# Upload file
uploadAct = QAction('&Upload new file', self)
uploadAct.triggered.connect(self.showUploadFile)
homeMenu.addAction(uploadAct)
libraryAct = QAction('&Library', self) libraryAct = QAction('&Library', self)
libraryAct.triggered.connect(self.showLibrary) libraryAct.triggered.connect(self.showLibrary)