Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. add a progress bar before opening a window
Forum Updated to NodeBB v4.3 + New Features

add a progress bar before opening a window

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 247 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sof4Rou
    wrote on last edited by sof4Rou
    #1

    I have a pyqt project where there is a large file processing, when I click on a button (Browse Folder) that will open a window containing treeviews that present the hierarchy of files, the window remains white for a few seconds, so here, I want to display a progress bar (like the loading one), is it possible to do it? if not, please suggest me any other idea.
    Here is my code :

    class StartWindow(QDialog):
        def __init__(self, parent=None):
            super().__init__(parent)
            self.setWindowTitle('Open ODL File or Folder')
            self.setWindowIcon(QIcon('assets/acls_icon.png'))
            self.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint)
            self.resize(600, 400)
        
            main_layout = QHBoxLayout(self)
            buttons_layout = QVBoxLayout()
            self.choose_file_button = QPushButton('Browse File', self)
      
            self.choose_file_button.clicked.connect(self.choose_file)
            buttons_layout.addWidget(self.choose_file_button)
            
            self.choose_folder_button = QPushButton('Browse 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_folder(self):
            folder_path = QFileDialog.getExistingDirectory(self, "Open Folder Containing ODL Files")
            if folder_path:
                self.open_folder_view(folder_path)
    
    
        def open_folder_view(self, folder_path):
            folder_window = QDialog()
            folder_window.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint)
            folder_window.setWindowTitle('ODL Files Tree View')
            folder_window.resize(800, 600)
            folder_window.show()
    
            processed_files = set() 
            all_groups = set()
            self.folder_path = folder_path
            for root, dirs, files in os.walk(folder_path):
                for filename in files:
                    if (filename.endswith(".odl")) and ('acl' in filename.lower() or 'acls' in filename.lower()) and filename not in processed_files:
                        file_path = os.path.join(root, filename)
                        parser = ODLParser(file_path)
                        file_groups, _ = get_headers_and_rights(parser.data_model)
                        all_groups.update(file_groups)
                        tree_view = self.create_tree_view(parser)
                        scroll_layout.addWidget(tree_view)
                        processed_files.add(filename)
                    
                    elif (filename.endswith(".odl")) and not ('acl' in filename.lower() or 'acls' in filename.lower()) and filename not in processed_files:
                        file_path = os.path.join(root, filename)
                        with open(file_path, 'r', encoding='utf-8') as file:
                            content = file.read()
                            if "acl" in content.lower() and "{" in content.lower():
                                parser = ODLParser2(file_path)
                                file_groups, _ = get_headers_and_rights(parser.data_model)
                                all_groups.update(file_groups)
                                tree_view = self.create_tree_view(parser)
                                scroll_layout.addWidget(tree_view)
                                processed_files.add(filename)
                        
            valid_groups = [group for group in all_groups if group is not None]
            self.group_combobox.addItems(sorted(valid_groups))
            self.group_combobox.setCurrentIndex(0) 
            self.group_combobox.currentTextChanged.connect(self.on_group_combobox_changed)
            QTimer.singleShot(0, lambda: self.on_group_combobox_changed(self.group_combobox.currentText()))
            self.scroll_area.setWidget(scroll_widget)
            layout.addWidget(self.scroll_area)
    
            folder_window.exec_()
    
    JonBJ 1 Reply Last reply
    0
    • S sof4Rou

      I have a pyqt project where there is a large file processing, when I click on a button (Browse Folder) that will open a window containing treeviews that present the hierarchy of files, the window remains white for a few seconds, so here, I want to display a progress bar (like the loading one), is it possible to do it? if not, please suggest me any other idea.
      Here is my code :

      class StartWindow(QDialog):
          def __init__(self, parent=None):
              super().__init__(parent)
              self.setWindowTitle('Open ODL File or Folder')
              self.setWindowIcon(QIcon('assets/acls_icon.png'))
              self.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint)
              self.resize(600, 400)
          
              main_layout = QHBoxLayout(self)
              buttons_layout = QVBoxLayout()
              self.choose_file_button = QPushButton('Browse File', self)
        
              self.choose_file_button.clicked.connect(self.choose_file)
              buttons_layout.addWidget(self.choose_file_button)
              
              self.choose_folder_button = QPushButton('Browse 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_folder(self):
              folder_path = QFileDialog.getExistingDirectory(self, "Open Folder Containing ODL Files")
              if folder_path:
                  self.open_folder_view(folder_path)
      
      
          def open_folder_view(self, folder_path):
              folder_window = QDialog()
              folder_window.setWindowFlags(self.windowFlags() | Qt.WindowMinimizeButtonHint | Qt.WindowMaximizeButtonHint)
              folder_window.setWindowTitle('ODL Files Tree View')
              folder_window.resize(800, 600)
              folder_window.show()
      
              processed_files = set() 
              all_groups = set()
              self.folder_path = folder_path
              for root, dirs, files in os.walk(folder_path):
                  for filename in files:
                      if (filename.endswith(".odl")) and ('acl' in filename.lower() or 'acls' in filename.lower()) and filename not in processed_files:
                          file_path = os.path.join(root, filename)
                          parser = ODLParser(file_path)
                          file_groups, _ = get_headers_and_rights(parser.data_model)
                          all_groups.update(file_groups)
                          tree_view = self.create_tree_view(parser)
                          scroll_layout.addWidget(tree_view)
                          processed_files.add(filename)
                      
                      elif (filename.endswith(".odl")) and not ('acl' in filename.lower() or 'acls' in filename.lower()) and filename not in processed_files:
                          file_path = os.path.join(root, filename)
                          with open(file_path, 'r', encoding='utf-8') as file:
                              content = file.read()
                              if "acl" in content.lower() and "{" in content.lower():
                                  parser = ODLParser2(file_path)
                                  file_groups, _ = get_headers_and_rights(parser.data_model)
                                  all_groups.update(file_groups)
                                  tree_view = self.create_tree_view(parser)
                                  scroll_layout.addWidget(tree_view)
                                  processed_files.add(filename)
                          
              valid_groups = [group for group in all_groups if group is not None]
              self.group_combobox.addItems(sorted(valid_groups))
              self.group_combobox.setCurrentIndex(0) 
              self.group_combobox.currentTextChanged.connect(self.on_group_combobox_changed)
              QTimer.singleShot(0, lambda: self.on_group_combobox_changed(self.group_combobox.currentText()))
              self.scroll_area.setWidget(scroll_widget)
              layout.addWidget(self.scroll_area)
      
              folder_window.exec_()
      
      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @sof4Rou
      See https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QProgressBar.html and https://doc.qt.io/qtforpython-6/PySide6/QtWidgets/QProgressDialog.html.

      You could also probably avoid the "white window"/non-responsive GUI if you split your for root, dirs, files in os.walk(folder_path) and/or for filename in files loop(s) so that it did one/a few elements at a time on a QTimer.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved