简体   繁体   中英

WxPython - Binding an Event to a Randomly changing value - Algorithm Required

I have a textBox on my WxPython GUI, where I am displaying a changing value (Which changes every 100 mS). I have two buttons - Button A, Button B.

Initial condition: Textbox has a value of between 2000-3000. Button A is enabled, Button B is disabled.

I need the following sequence of events to go on: The user presses the Button A. After approximately 20 seconds or some user defined time (completely variable based on the user/ type of work he is doing), the textBox value goes under less 50.

Once the textBox value goes less than 50 - Button B should be enabled.

Currently this is my following code, where I am pressing the Button A - waiting for the textBox value to less than 50. Then enable the Button B - and it is not working. The button B is not getting enabled. I tried using other means, but they are leaving to an unresponsive GUI. My Button A is - DONE, Button B is START. textBox is pressure_text_control.

def OnDone(self, event):
    self.WriteToController([0x04],'GuiMsgIn')
    self.status_text.SetLabel('PRESSURE CALIBRATION DONE \n DUMP PRESSURE')
    self.led1.SetBackgroundColour('GREY')
    self.add_pressure.Disable()
    while self.pressure_text_control.GetValue() < 50:
        wx.CallAfter(self.StartEnable, 'Enabling start button')
        #self.start.Enable()

def StartEnable(self):
    self.start.Enable()

You haven't supplied sufficient code to be able to see what is going on.
We don't know for example if self.pressure_text_control.GetValue() < 50 is in fact less than 50, given that you say the value is changing every 100mS.

If your issue is really about the fact that the GUI becomes unresponsive, then investigate wx.Timer()
See:
http://www.blog.pythonlibrary.org/2009/08/25/wxpython-using-wx-timers/

The Timer class allows you to execute code at specified intervals, which allows you to process one or more periodic events (you can declare multiple timers ), as long as they are not long or blocking processes, yet leave the GUI responsive.

mocked up as follows:

    self.timer = wx.Timer(self)
    self.Bind(wx.EVT_TIMER, self.check, self.timer)

def StartmyButton(self):
    self.start.Enable()
    self.timer.Start(100)

def check(self, event):
    "check you input here and process any results"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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