changed format of main window to class

This commit is contained in:
Agata 2020-12-21 21:39:56 +01:00
parent 3862848a7e
commit ffdb50f07f

View File

@ -15,6 +15,7 @@ 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
class LibraryTableButtons(QWidget): class LibraryTableButtons(QWidget):
def __init__(self, parent=None): def __init__(self, parent=None):
super(LibraryTableButtons,self).__init__(parent) super(LibraryTableButtons,self).__init__(parent)
@ -28,7 +29,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)
@ -58,50 +61,50 @@ class LibraryTable(QTableWidget):
print(index.row(), index.column()) print(index.row(), index.column())
def main(): class MainWindow(QMainWindow):
app = QApplication(sys.argv) def __init__(self):
super().__init__()
self.initUI()
#w = QWidget() # Show raw uploaded files
w = QMainWindow() def showLibrary(self):
w.setGeometry(0, 0, 600, 400) libTable = LibraryTable()
w.setWindowTitle('VisionScore') self.setCentralWidget(libTable)
def initUI(self):
self.setGeometry(0, 0, 600, 400)
self.setWindowTitle('VisionScore')
scriptDir = os.path.dirname(os.path.realpath(__file__)) scriptDir = os.path.dirname(os.path.realpath(__file__))
w.setWindowIcon(QIcon(scriptDir + os.path.sep + 'static/v_logo.jpg')) self.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 # Toolbar
menuBar = w.menuBar() menuBar = self.menuBar()
homeMenu = QMenu("&Home", w) homeMenu = QMenu("&Home", self)
menuBar.addMenu(homeMenu) menuBar.addMenu(homeMenu)
homeMenu.addAction("Load new file") homeMenu.addAction("Load new file")
# Show raw uploaded files libraryAct = QAction('&Library', self)
def showLibrary(): libraryAct.triggered.connect(self.showLibrary)
libTable = LibraryTable()
w.setCentralWidget(libTable)
libraryAct = QAction('&Library', w)
libraryAct.triggered.connect(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()