subscriber in rqt plugin python
I'm writing a rqt plugin in python, but can't get the subscriber to work. I want the string from "controller/mode" to show in "lineControlMode". For some reason this doesn't happen. Hope some of you can help me.
import os
import rospkg
import rospy
from qt_gui.plugin import Plugin
from python_qt_binding import loadUi
from python_qt_binding.QtWidgets import QWidget, QGraphicsView
from std_msgs.msg import String
class MyPlugin(Plugin):
def __init__(self, context):
#PLUGIN CODE
super(MyPlugin, self).__init__(context)
# Give QObjects reasonable names
self.setObjectName('MyPlugin')
rp = rospkg.RosPack()
# Process standalone plugin command-line arguments
from argparse import ArgumentParser
parser = ArgumentParser()
# Add argument(s) to the parser.
parser.add_argument("-q", "--quiet", action="store_true",
dest="quiet",
help="Put plugin in silent mode")
args, unknowns = parser.parse_known_args(context.argv())
if not args.quiet:
print 'arguments: ', args
print 'unknowns: ', unknowns
# Create QWidget
self._widget = QWidget()
ui_file = os.path.join(rp.get_path('rqt_vortex_control_mode'), 'resource', 'MyPlugin.ui')
# Extend the widget with all attributes and children from UI file
loadUi(ui_file, self._widget)
# Give QObjects reasonable names
self._widget.setObjectName('MyPluginUi')
# Add widget to the user interface
context.add_widget(self._widget)
#MY CODE
self._widget.lineControlMode.setReadOnly(True)
self._widget.lineControlMode.setText("init")
#Subscriber
self.sub = rospy.Subscriber("/uranus_dp/controller/mode", String, self.callback)
def shutdown_plugin(self):
self.sub.unregister()
def callback(self, mode):
self._widget.lineControlMode.setText(mode)
Here is the link to my repository just in case: https://github.com/vortexntnu/rov-gui
The plugin appears to work, but when you publish to
/uranus_dp/controller/mode
the lineControlMode widget doesn't show anything?