import sys
import time
from PyQt5.QtWidgets import QApplication, QWidget, QDialog, QVBoxLayout, QPushButton, QLabel, QProgressBar
from PyQt5.QtCore import Qt, QThread, pyqtSignal

class LoadDataThread(QThread):
    progress = pyqtSignal(int)

    def run(self):
        for i in range(101):
            time.sleep(0.01)  # 模拟数据加载过程
            self.progress.emit(i)

class LoadingDialog(QDialog):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        vbox = QVBoxLayout()
        
        self.label = QLabel("加载数据中，请稍后...", self)
        self.progressBar = QProgressBar(self)
        
        vbox.addWidget(self.label)
        vbox.addWidget(self.progressBar)
        
        self.setLayout(vbox)
        self.setWindowTitle('数据查询')
        self.setWindowFlags(Qt.Window | Qt.WindowTitleHint | Qt.CustomizeWindowHint)
        self.setModal(True)

    def updateProgress(self, value):
        self.progressBar.setValue(value)

class LoadingDataWidget(QWidget):
    def __init__(self):
        super().__init__()

    def loadData(self):
        self.loadingDialog = LoadingDialog()
        
        # 创建和启动数据加载线程
        self.loadThread = LoadDataThread()
        self.loadThread.progress.connect(self.loadingDialog.updateProgress)
        self.loadThread.finished.connect(self.onLoadingFinished)
        
        self.loadThread.start()
        self.loadingDialog.exec_()

    def onLoadingFinished(self):
        self.loadingDialog.accept()

if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = LoadingDataWidget()
    sys.exit(app.exec_())
