Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_rqt_plugins/button_general.py] reset button if SetBool failed #794

Merged
merged 2 commits into from
Dec 21, 2020
Merged
Changes from 1 commit
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
12 changes: 8 additions & 4 deletions jsk_rqt_plugins/src/jsk_rqt_plugins/button_general.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def setupButtons(self, yaml_file):
if service_type == SetBool:
button.setCheckable(True)
button.clicked.connect(
self.buttonCallback(button_data['service'], service_type))
self.buttonCallback(button_data['service'], service_type, button))
if self.button_type == "push":
button.setToolButtonStyle(
QtCore.Qt.ToolButtonTextUnderIcon)
Expand All @@ -216,13 +216,13 @@ def setupButtons(self, yaml_file):
self.layout.addWidget(group)
self.setLayout(self.layout)

def buttonCallback(self, service_name, service_type):
def buttonCallback(self, service_name, service_type, button):
"""
return function as callback
"""
return lambda checked: self.buttonCallbackImpl(checked, service_name, service_type)
return lambda checked: self.buttonCallbackImpl(checked, service_name, service_type, button)

def buttonCallbackImpl(self, checked, service_name, service_type=Empty):
def buttonCallbackImpl(self, checked, service_name, service_type=Empty, button=None):
srv = rospy.ServiceProxy(service_name, service_type)
try:
if service_type == SetBool:
Expand All @@ -235,8 +235,12 @@ def buttonCallbackImpl(self, checked, service_name, service_type=Empty):
self.showError(
"Succeeded to call {}, but service response is res.success=False"
.format(service_name))
if service_type == SetBool and not button is None:
button.setChecked(not checked)
except rospy.ServiceException as e:
self.showError("Failed to call %s" % service_name)
if service_type == SetBool and not button is None:
button.setChecked(not checked)

def save_settings(self, plugin_settings, instance_settings):
if self._layout_param:
Expand Down