11import os
22
33from python_qt_binding import loadUi
4- from python_qt_binding .QtCore import QSize
4+ from python_qt_binding .QtCore import QMutex , QSize , QTimer
55from python_qt_binding .QtWidgets import QGridLayout
66from python_qt_binding .QtWidgets import QPushButton
77from python_qt_binding .QtWidgets import QWidget
@@ -32,7 +32,8 @@ def __init__(self, ui_file, controller):
3232 # Extend the widget with all attributes and children from UI file
3333 loadUi (ui_file , self )
3434
35- self .refresh_button .clicked .connect (self ._update_possible_gaits )
35+ self ._update_gaits_mutex = QMutex ()
36+ self ._start_possible_gaits_refresh_timer ()
3637
3738 self ._create_buttons ()
3839 self ._update_possible_gaits ()
@@ -325,7 +326,13 @@ def _rejected_cb(self):
325326 def _current_gait_cb (self , gait_name ):
326327 self .gait_label .setText (gait_name )
327328
329+ def _start_possible_gaits_refresh_timer (self ):
330+ self ._gaits_timer = QTimer (self )
331+ self ._gaits_timer .timeout .connect (self ._update_possible_gaits )
332+ self ._gaits_timer .start (500 )
333+
328334 def _update_possible_gaits (self ):
335+ self ._update_gaits_mutex .lock ()
329336 self .frame .setEnabled (False )
330337 self .frame .verticalScrollBar ().setEnabled (False )
331338 possible_gaits = self ._controller .get_possible_gaits ()
@@ -343,6 +350,7 @@ def _update_possible_gaits(self):
343350 button .setEnabled (False )
344351 self .frame .setEnabled (True )
345352 self .frame .verticalScrollBar ().setEnabled (True )
353+ self ._update_gaits_mutex .unlock ()
346354
347355 def create_button (self , name , callback = None , image_path = None , size = (128 , 160 ), always_enabled = False ):
348356 """Create a push button which the mock input device can register.
0 commit comments