Ganesh_Gupta | 2021-05-30 15:35:33 UTC | #1
I am creating a GUI which use external Python script function with parramters for calcualtion and updating progressbar.I had used multithreading.It works fine for first run but if I change dropdown and lineedit parameter and click again on calculate button it does not respose. I have three level dropdown on basis of that we select python script for running function by using csv sheet for calcualtion. GUI image is attached [GUI image for calcuation][1]
This is My code
import sys
import os
from decimal import Decimal
import time
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QMessageBox
from pathlib import Path
from CONNECTDATABASE import*
from RB import*
from UPDATEDATABASEthread import*
import subprocess
from urllib.request import urlopen
qtCreatorFile = "SMOG_COLASCE_DEVELOPER_INTERFACE1.ui" # Enter file here.
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
class Worker(QObject):
hashed = pyqtSignal(str)
signal=pyqtSignal(int)
finished = pyqtSignal()
@pyqtSlot(str,str,str,str,str,str)
def cal_functions(self,filter,filter1,IND,OTD,Version,Year):
if filter=='RB':
if filter1 =='None':
x=ARBthread(self,IND,OTD,Version,Year)
self.hashed.emit(x)
self.finished.emit()
class Worker1(QObject) :
def __init__(self):
super().__init__()
hashed1 = pyqtSignal(str)
signal=pyqtSignal(int)
finished = pyqtSignal()
@pyqtSlot(str,str,str,str,str,str,str,str,str)
def update_database(self,hostname,port,username,password,Database_Name,IND,OTD,Version,Year):
x1=UPDATEDATABASEthread(self,hostname,port,username,password,Database_Name,IND,OTD,Version,Year)
self.hashed1.emit(x1)
self.finished.emit()
class MyWindow(QtWidgets.QMainWindow, Ui_MainWindow):
cal_requested = pyqtSignal(str,str,str,str,str,str)
data_requested= pyqtSignal(str,str,str,str,str,str,str,str,str)
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.setWindowTitle("SMoG-India COALESCE")
self.Sector.currentIndexChanged.connect(self.comboBox_sector_change)
self.SubSectorLevel1.currentIndexChanged.connect(self.comboBox_subsector_change)
self.Calculate.clicked.connect(self.calc)
self.toolButton.clicked.connect(self._open_file_dialog)
self.toolButton_2.clicked.connect(self._open_file_dialog1)
self.toolButton_3.clicked.connect(self._open_file_dialog2)
self.checkBox_2.stateChanged.connect(self.checkedcLS)
self.checkBox_3.stateChanged.connect(self.checkedcRS)
self.pushButton_3.clicked.connect(self.Database)
self.pushButton_4.clicked.connect(self.ConnectDatabase)
self.lineEdit_5.setReadOnly(True)
self.lineEdit_6.setReadOnly(True)
self.lineEdit_7.setReadOnly(True)
self.lineEdit_8.setReadOnly(True)
self.lineEdit_9.setReadOnly(True)
self.pushButton_2.clicked.connect(self.close_event)
self.pushButton.clicked.connect(self.open_tutorial)
# Create a worker object and a thread
self.worker = Worker()
self.worker_thread = QThread()
self.worker.hashed.connect(self.messagebox)
self.worker.signal.connect(self.update_progress_bar)
self.cal_requested.connect(self.worker.cal_functions)
self.worker.moveToThread(self.worker_thread)
self.worker.finished.connect(self.worker_thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.worker_thread.start()
self.worker_thread.finished.connect(self.finish)
self.worker1 = Worker1()
self.worker1_thread = QThread()
self.worker1.hashed1.connect(self.messagebox)
self.worker1.signal.connect(self.update_progress_bar)
self.worker1.moveToThread(self.worker1_thread)
self.data_requested.connect(self.worker1.update_database)
self.worker1.finished.connect(self.worker1_thread.quit)
self.worker1.finished.connect(self.worker1.deleteLater)
self.worker1_thread.finished.connect(self.worker1_thread.deleteLater)
self.worker1_thread.start()
self.worker1_thread.finished.connect(self.finish)
def calc(self):
progressBar = self.progressBar
self.Calculate.setEnabled(False)
self.SubSectorLevel1.setEnabled(False)
self.SubSectorLevel2.setEnabled(False)
self.Sector.setEnabled(False)
self.toolButton_2.setEnabled(False)
self.toolButton_3.setEnabled(False)
self.lineEdit_10.setReadOnly(True)
self.lineEdit_4.setReadOnly(True)
self.toolButton_2.setEnabled(False)
self.toolButton_3.setEnabled(False)
filter = self.SubSectorLevel1.currentText()
filter1 = self.SubSectorLevel2.currentText()
IND = self.lineEdit.text()
OTD = self.lineEdit_2.text()
Version= self.lineEdit_10.text()
Year=self.lineEdit_4.text()
self.cal_requested.emit(filter,filter1,IND,OTD,Version,Year)
``` if name == "main": global app app = QtWidgets.QApplication.instance() if app is None: app = QtWidgets.QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec_())
It will be Great if you help in this
stelaldridge11281 | 2021-06-07 15:01:08 UTC | #2
Hi Ganesh,
Create GUI Applications with Python & Qt5 by Martin Fitzpatrick — (PyQt5 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!
Did you find a solution already or it is still unsolved?