I have a project that consists in displaying a datamodel using qtreeview from a folder that contains several files. I displayed a treeview of a single file but i couldn't display several treeviews one under the other of several files. here is my main.py :
import sys
from PyQt5.QtWidgets import *
from start_window import StartWindow
def main():
app = QApplication(sys.argv)
start_window = StartWindow()
start_window.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
my start_window.py where I need to implement the choose folder function to reach the goal :
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from table_view import Table
from odl_parser import ODLParser
class StartWindow(QDialog):
def __init__(self, parent=None):
super().__init__(parent)
self.setWindowTitle('Open ODL File or Folder')
self.resize(600, 400)
main_layout = QHBoxLayout(self)
self.image_label = QLabel(self)
self.image_label.setPixmap(QPixmap('ACLViewer.jpg').scaled(300, 300, Qt.KeepAspectRatio))
main_layout.addWidget(self.image_label)
buttons_layout = QVBoxLayout()
self.choose_file_button = QPushButton('Choose File', self)
self.choose_file_button.clicked.connect(self.choose_file)
buttons_layout.addWidget(self.choose_file_button)
self.choose_folder_button = QPushButton('Choose Folder', self)
self.choose_folder_button.clicked.connect(self.choose_folder)
buttons_layout.addWidget(self.choose_folder_button)
main_layout.addLayout(buttons_layout)
def choose_file(self):
file_path, _ = QFileDialog.getOpenFileName(self, "Open ODL File", "", "ODL Files (*.odl)")
if file_path:
self.open_table_view(file_path)
def choose_folder(self):
folder_path = QFileDialog.getExistingDirectory(self, "Open Folder Containing ODL Files")
if folder_path:
# code for the folder
def open_table_view(self, file_path):
parser = ODLParser(file_path)
window = Table(parser)
window.setWindowTitle('DM Parsing - ' + file_path)
window.show()
make suitable changes as needed.