2

I have a Main GUI class, and I am attempting to open another window, I am using QWidget to inherit from. The window that opens is just a progress bar and there is a QThread timer in another class in the Python file it uses to do a simpple countdown.

But my issue is that when I open the GuiProgressBar Window, none of the controls in the window show on the form for some reason.

This is from within my main GUI Class:

def TestOpenProgressWindow(self):
    myProgressBar = TimerThread.GuiProgressBar()
    myProgressBar.show()
    time.sleep(3)
    myProgressBar.StopProgressBar()
    myProgressBar.hide()

This is the code from within my GUIProgressBar class:

class WorkerThread(QThread):
    changeValue = Signal(int)
    finished = Signal()

    def __init__(self):
        super().__init__()
        self.runs = False
        self.count = -1
        return

    def run(self):
        count = 0
        while self.runs and (0 <= count < 10):
            time.sleep(0.5)
            count = count + 1
            self.changeValue.emit(count)
        self.finished.emit()

    def startThread(self):
        self.runs = True
        self.count = 0
        self.start()

    def stopThread(self):
        self.runs = False
        self.count = -1
        self.exit()


class GuiProgressBar(QWidget):
    def __init__(self):
        super().__init__()
        self.btnStop = None
        self.btnStart = None
        self.label1 = None
        self.w1 = None
        self.barThread = WorkerThread()
        self.barThread.finished.connect(self.threadStopped)
        self.barThread.changeValue.connect(self.UpdateProgressBar)
        self.hprogress1 = None
        self.gui()
        self.StartProgressBar()

    def gui(self):
        self.w1 = self
        self.w1.setAutoFillBackground(True)
        self.w1.setWindowTitle("")
        self.w1.resize(320, 170)
        self.w1.setCursor(Qt.ArrowCursor)
        self.w1.setToolTip("")
        self.label1 = QLabel(self.w1)
        self.label1.setText("Please wait while the BigQuery queries are run")
        self.label1.move(20, 20)
        self.label1.resize(290, 22)
        self.label1.setCursor(Qt.ArrowCursor)
        self.label1.setToolTip("")
        self.hprogress1 = QProgressBar(self.w1)
        self.hprogress1.setMinimum(0)
        self.hprogress1.setMaximum(100)
        self.hprogress1.setValue(0)
        self.hprogress1.setOrientation(Qt.Horizontal)
        self.hprogress1.move(20, 50)
        self.hprogress1.resize(270, 22)
        self.hprogress1.setCursor(Qt.ArrowCursor)
        self.hprogress1.setToolTip("")
        self.btnStart = QToolButton(self.w1)
        self.btnStart.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.btnStart.setText("Start")
        self.btnStart.move(20, 90)
        self.btnStart.resize(90, 22)
        self.btnStart.setCursor(Qt.ArrowCursor)
        self.btnStart.setToolTip("")
        self.btnStart.clicked.connect(self.StartProgressBar)
        self.btnStop = QToolButton(self.w1)
        self.btnStop.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.btnStop.setText("Stop")
        self.btnStop.move(110, 90)
        self.btnStop.resize(90, 22)
        self.btnStop.setCursor(Qt.ArrowCursor)
        self.btnStop.setToolTip("")
        self.btnStop.clicked.connect(self.StopProgressBar)
        return self.w1

    def StartProgressBar(self):
        if not self.barThread.isRunning():
            print("Thread Started")
            self.barThread.startThread()
        else:
            print("Thread is already running")

    def StopProgressBar(self):
        if not self.barThread.isRunning():
            print("No thread is running")
        else:
            print("HERE")
            self.barThread.stopThread()
            print(self.barThread.isRunning())

    def threadStopped(self):
        print("Thread Stopped")

    def UpdateProgressBar(self, value):
        self.hprogress1.setValue(value)

# if __name__ == '__main__':
#    app = QApplication(sys.argv)
#    aw = GuiProgressBar()
#    aw.show()
#    sys.exit(app.exec())

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.