简体   繁体   English

奇怪的行为-wxPython事件

[英]Weird behavior - wxPython Events

I have this following piece of code. 我有以下这段代码。 It is working sometimes, it is not the other time. 有时它在工作,而其他时间则不在。

   def OnReset(self, event):

    self.reset_pump.Disable() # Disables the button so it is clicked
    self.WriteToController([0x30],'GuiMsgIn') # Sends the reset command
    self.flag_read.set()
    self.tr.join()
    time.sleep(2)
    start = time.time()
    self.offset_text_control.Clear()
    print "Helloin reset"
    self.gain_text_control.Clear()
    self.firmware_version_text_control.Clear()
    self.pump_rpm_text_control.Clear()
    self.pressure_text_control.Clear()
    self.last_error_text_control.Clear()
    self.error_count_text_control.Clear()
    self.pump_model_text_control.Clear()
    self.pump_serial_number_text_control.Clear()
    self.on_time_text_control.Clear()
    self.job_on_time_text_control.Clear()

    #self.MessageBox('Pump RESET going on Click OK \n')
    # Having the above step is useful
    print time.time() - start
    #self.ser.close()
    wx.CallLater(3000, self.CalledAfter, [event,])

def CalledAfter(self, event):
    self.tr = threading.Thread(target=ReadData, name="ReadThread", args=(self.ser, self.flag_read))
    self.tr.daemon = True
    self.tr.start()
    self.reset_pump.Enable()

What it does is When I click the Reset button on my GUI, it has to clear certain text fields on the GUI. 它的作用是,当我单击GUI上的Reset按钮时,它必须清除GUI上的某些文本字段。 It has to clear it, only after joining the self.tr thread. 只有在加入self.tr线程之后,才必须清除它。

Once it clears, it will execute the command wx.CallLater(3000, self.CalledAfter, [event,]). 一旦清除,它将执行命令wx.CallLater(3000,self.CalledAfter,[event,])。 Which then starts a new thread again. 然后,它将再次启动新线程。

Apparently The .Clear() command is working very at a non consistent level, it is working some time, not working the other times, and working again. 显然,.Clear()命令在一个不一致的级别上非常有效,它正在工作一段时间,而在其他时间没有工作,然后又工作。

Any idea why this might happen would be very helpful. 为什么会发生这种情况的任何想法都将非常有帮助。

There seems to be a difference in the way SetValue and Clear update the windows. SetValue和Clear更新窗口的方式似乎有所不同。 Calling SetValue("") seems to be a suitable workaround to this behavior. 调用SetValue("")似乎是解决此问题的合适方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM