From ece0e50d5192f67b00070397c6600990e007939b Mon Sep 17 00:00:00 2001 From: VanillaHellen Date: Mon, 21 Dec 2020 18:18:47 +0100 Subject: [PATCH 1/2] added View function and a txt file to test it --- win_venv/files/input/test.txt | 1 + win_venv/main.py | 20 +++++++++----------- 2 files changed, 10 insertions(+), 11 deletions(-) create mode 100644 win_venv/files/input/test.txt diff --git a/win_venv/files/input/test.txt b/win_venv/files/input/test.txt new file mode 100644 index 0000000..0a1baa4 --- /dev/null +++ b/win_venv/files/input/test.txt @@ -0,0 +1 @@ +test txt file \ No newline at end of file diff --git a/win_venv/main.py b/win_venv/main.py index d7aeaf8..12d6135 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -16,14 +16,19 @@ def files(path): yield file class LibraryTableButtons(QWidget): - def __init__(self, parent=None): + def __init__(self, filename, parent=None): super(LibraryTableButtons,self).__init__(parent) - layout = QHBoxLayout() + def viewFile(): + os.startfile(filePath + '\\' + filename) + + layout = QHBoxLayout() layout.setContentsMargins(0,0,0,0) layout.setSpacing(0) - layout.addWidget(QPushButton('View')) + view_btn = QPushButton('View') + view_btn.clicked.connect(viewFile) + layout.addWidget(view_btn) layout.addWidget(QPushButton('Delete')) self.setLayout(layout) @@ -48,14 +53,7 @@ class LibraryTable(QTableWidget): 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()) + self.setCellWidget(index,2,LibraryTableButtons(names[index].text())) def main(): From ffdb50f07f38acdbc570da01f0377d5184b86a11 Mon Sep 17 00:00:00 2001 From: Agata Date: Mon, 21 Dec 2020 21:39:56 +0100 Subject: [PATCH 2/2] changed format of main window to class --- win_venv/main.py | 85 +++++++++++++++++++++++++----------------------- 1 file changed, 44 insertions(+), 41 deletions(-) diff --git a/win_venv/main.py b/win_venv/main.py index d7aeaf8..1c8314f 100644 --- a/win_venv/main.py +++ b/win_venv/main.py @@ -15,6 +15,7 @@ def files(path): if os.path.isfile(os.path.join(path, file)): yield file + class LibraryTableButtons(QWidget): def __init__(self, parent=None): super(LibraryTableButtons,self).__init__(parent) @@ -28,7 +29,9 @@ class LibraryTableButtons(QWidget): self.setLayout(layout) + class LibraryTable(QTableWidget): + def __init__(self, parent=None): QTableWidget.__init__(self) self.setColumnCount(3) @@ -57,51 +60,51 @@ class LibraryTable(QTableWidget): if index.isValid(): print(index.row(), index.column()) - + +class MainWindow(QMainWindow): + def __init__(self): + super().__init__() + self.initUI() + + # Show raw uploaded files + def showLibrary(self): + libTable = LibraryTable() + 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 = 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')) - - ''' - 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 - def showLibrary(): - libTable = LibraryTable() - w.setCentralWidget(libTable) - - libraryAct = QAction('&Library', w) - libraryAct.triggered.connect(showLibrary) - menuBar.addAction(libraryAct) - - # 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") - - w.show() + w = MainWindow() sys.exit(app.exec_()) + if __name__ == '__main__': main() \ No newline at end of file