I have a function that is ran using the Worker method. Inside this function, there can be a condition that then requires the user to input a string and that string will be used in the function. I am able to get the QInputDialog to show up, but it freezes once I start typing something and the program crashes. I have an example of what I am doing right now below:
from PySide2.QtWidgets import QApplication, QInputDialog, QMainWindow, QPushButton
from PySide2.QtCore import *
import sys, os
class Worker_Class:
class WorkerSignals():
finished = Signal()
newRecord = Signal(str)
class Worker(QRunnable):
def __init__(self, fn, *args, **kwargs):
super(Worker_Class.Worker, self).__init__()
self.fn = fn
self.args = args
self.kwargs = kwargs
self.signals = Worker_Class.WorkerSignals()
@Slot()
def run(self):
try:
self.fn(*self.args, **self.kwargs)
except:
pass
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("My App")
button = QPushButton("Press Me!")
self.setFixedSize(QSize(400, 300))
self.setCentralWidget(button)
self.threadpool = QThreadPool()
def start_worker(self):
worker = Worker_Class.Worker(get_dialog_value)
self.threadpool.start(worker)
def get_dialog_value():
text, ok = QInputDialog().getText(window, "Missing Module Partnumber", "Input Module Partnumber: ")
if ok and text:
return text
return ''
QCoreApplication.setLibraryPaths([os.getcwd() + "\\virtualenv\\Lib\\site-packages\\PyQt5\\Qt5\\plugins"])
app = QApplication(sys.argv)
window = MainWindow()
window.show()
window.start_worker()
app.exec_()