I have a wxPython gui that is controlling some hardware. I need a button to disable while a function is running. The function also receives an argument value
let's say that I have this function that is bound to a button press:
def button_press(self, event):
in_val = self.num_in.GetValue() #grabs a value from a NumCtrl
TheThread(in_val) #initiates the thread with argument
btn = event.GetEventObject()
btn.Disable() #disables button
this function goes to the following thread class:
class TheThread(Thread):
def __init__(self, in_val):
"""Init Worker Thread Class."""
Thread.__init__(self)
self.run(in_val)
def run(self, in_val):
print val
time.sleep(5)
wx.CallAfter(Publisher.sendMessage, "ctrl")
"""
threadsafe method to call a pub.subscribe that runs a
function to re-enable button
"""
This works improperly, as the gui freezes during the function run period, and the button does not properly disable.
How do I properly inherit this argument to allow this to run properly? Maybe something involving self.start() method?