I have tried everything to make a progress bar I created in PYQT5 move at the same time a function from another file called untitled3.gl_dump is called. However, the progress bar freezes each time the function is called through a click of a button.
Here is my code so far
import sys
import time
import untitled3
from untitled3 import gl_dump
from PyQt5.uic import loadUi
from PyQt5 import QtWidgets,QtGui
from PyQt5.QtWidgets import QDialog, QApplication,QMainWindow, QWidget, QHBoxLayout, QProgressBar,QVBoxLayout,QPushButton
from PyQt5.QtCore import QThread, pyqtSignal, QObject, pyqtSlot, QCoreApplication
class Worker(QObject):
finished = pyqtSignal()
intReady = pyqtSignal(int)
@pyqtSlot()
def proc_counter(self):
for i in range(1, 101):
time.sleep(0.5)
self.intReady.emit(i)
self.finished.emit()
class PopUpProgressB(QWidget):
def __init__(self):
super().__init__()
self.pbar = QProgressBar(self)
#self.pbar.setRange(0,0)
self.pbar.setGeometry(30, 40, 500, 75)
self.layout = QVBoxLayout()
self.layout.addWidget(self.pbar)
self.setLayout(self.layout)
self.setGeometry(300, 300, 550, 100)
self.setWindowTitle('Progress Bar')
self.obj = Worker()
self.thread = QThread()
self.obj.intReady.connect(self.on_count_changed)
self.obj.moveToThread(self.thread)
self.obj.finished.connect(self.thread.quit)
self.obj.finished.connect(self.hide) # To hide the progress bar after the progress is completed
self.thread.started.connect(self.obj.proc_counter)
def start_progress(self):
# To restart the progress every time
self.show()
self.thread.start()
def on_count_changed(self, value):
self.pbar.setValue(value)
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow,self).__init__()
loadUi("app_interface.ui",self)
self.pushButton.clicked.connect(self.gotoScreen2)
self.screen2=Screen2()
def gotoScreen2(self):
screen2=Screen2()
widget.addWidget(screen2)
widget.setCurrentWidget(screen2)
class Screen2(QDialog):
def __init__(self):
super(Screen2,self).__init__()
loadUi("GL_Dump_Curr.ui",self)
self.pushButton_2.clicked.connect(self.gotoScreen1)
self.popup=PopUpProgressB()
self.main_window_button=self.pushButton
self.btn=self.pushButton
self.main_window_button.clicked.connect(self.popup.start_progress)
self.btn.clicked.connect(untitled3.gl_dump)
def gotoScreen1(self):
mainwindow=MainWindow()
widget.addWidget(mainwindow)
widget.setCurrentWidget(mainwindow)
if __name__ == '__main__':
app = QApplication(sys.argv)
QApplication.processEvents()
widget=QtWidgets.QStackedWidget()
mainwindow=MainWindow()
widget.addWidget(mainwindow)
widget.setFixedHeight(300)
widget.setFixedHeight(400)
widget.show()
try:
sys.exit(app.exec_())
except:
print("Exiting")
for the untitled3 file the function I am using is below
import xlwings as xw
import win32com.client as win32
import time
from datetime import datetime
month=datetime.now().strftime('%B')
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.Visible = True
excel.DisplayAlerts = False
destination=rf"C:UsersRaphaelCDesktopImportant EmailsWIP Special WorkingsFY2024{month}"
def gl_dump():
data_file = rf"C:UsersRaphaelCDesktopImportant EmailsWIP Special WorkingsFY2024{month}gl transaction download-cc1.xlsx"
template_file=rf"C:UsersRaphaelCDesktopImportant EmailsWIP Special WorkingsFY2024{month}GL Dump - {month}.xlsx"
wb_template = excel.Workbooks.Open(template_file)
wb_data = excel.Workbooks.Open(data_file)
wb_template.Sheets("GL Data Jan").Range("A2:W5000").Clear()
wb_data.Sheets("Sheet1").Range("A2:W5000").Copy()
wb_template.Sheets("GL Data Jan").Paste(wb_template.Sheets("GL Data Jan").Range('A2'))
#excel.Selection.Copy(Destination=wb_template.Worksheets("GL Data Jan").Range("A2"))
#wb_template.Worksheets("GL Data Jan").Range("A2:W5000").AutoFilter(20)
wb_template.RefreshAll()
time.sleep(5)
wb_template.Save()
wb_template.Close(True)
wb_data.Close(True)
excel.Application.Quit()
return None
This is what the interface looks like
New contributor
Raph Car is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.