I am trying to get the value emitted by Class Qthread's signal without using the function
I am calling alert box when the user chooses to exit and press [X] button on GUI so I called this alert box by the means of threading to ensure that my GUI doesn't freeze.
Below is the code for that:
class ABC:
def __init__(self):
self.close = CloseThread() # Creating instance of QThread Class
........
........
........
def closeEvent(self, event):
button = self.close.CloseResult
self.close.start()
if button == 1:
event.accept()
else:
event.ignore()
class CloseThread(QThread):
"""Threading class which is emitting the return value according to the choice
of the user(When the message appears, if the user chooses
'Ok' then return value is 1 and if the user chooses
'Cancel'return value is 2)"""
CloseResult = QtCore.pyqtSignal(object)
def __init__(self):
QThread.__init__(self)
def close(self):
button = win32api.MessageBox(0, 'Do you want to Exit?', 'Message')
self.CloseResult.emit(button)
def run(self):
self.close()
I know I can get the emitted value by self.close.CloseResult.connect(self.fn_name)
instead of using self.close.CloseResult
but I don't want to call another function because here I am extending the scope of closeEvent
function so I don't want to call another function.(Actually by calling another function things aren't working out as they are supposed to)
Note: By using
self.close.CLoseResult
I am getting an object so is there any way to access this object's value or not?
So is there any way I can get emitted value just in a variable without having to call any other function?