Skip to content
This repository has been archived by the owner on Dec 1, 2020. It is now read-only.

Replace the 'Refresh' button with a Timer #71

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions march_rqt_input_device/resource/input_device.ui
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,6 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refresh_button">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Refreshes the buttons with possible gaits&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from python_qt_binding import loadUi
from python_qt_binding.QtCore import QSize
from python_qt_binding.QtCore import QMutex, QSize, QTimer
from python_qt_binding.QtWidgets import QGridLayout
from python_qt_binding.QtWidgets import QPushButton
from python_qt_binding.QtWidgets import QWidget
Expand Down Expand Up @@ -32,7 +32,8 @@ def __init__(self, ui_file, controller):
# Extend the widget with all attributes and children from UI file
loadUi(ui_file, self)

self.refresh_button.clicked.connect(self._update_possible_gaits)
self._update_gaits_mutex = QMutex()
self._start_possible_gaits_refresh_timer()

self._create_buttons()
self._update_possible_gaits()
Expand Down Expand Up @@ -325,7 +326,13 @@ def _rejected_cb(self):
def _current_gait_cb(self, gait_name):
self.gait_label.setText(gait_name)

def _start_possible_gaits_refresh_timer(self):
self._gaits_timer = QTimer(self)
self._gaits_timer.timeout.connect(self._update_possible_gaits)
self._gaits_timer.start(500)

def _update_possible_gaits(self):
self._update_gaits_mutex.lock()
self.frame.setEnabled(False)
self.frame.verticalScrollBar().setEnabled(False)
possible_gaits = self._controller.get_possible_gaits()
Expand All @@ -343,6 +350,7 @@ def _update_possible_gaits(self):
button.setEnabled(False)
self.frame.setEnabled(True)
self.frame.verticalScrollBar().setEnabled(True)
self._update_gaits_mutex.unlock()

def create_button(self, name, callback=None, image_path=None, size=(128, 160), always_enabled=False):
"""Create a push button which the mock input device can register.
Expand Down