How to update a gui (python) each time the callback function is called in a subscriber node?
Hello,
I want to have several nodes send their position (x,y) to a 'visualizer' node which draws on some window/gui continuously as more data is published by the former nodes.
What I have so far (considering 1 publisher node and 1 visualizer node):
import sys
import rospy
from GITagent.msg import Position
from PyQt4.QtGui import *
from PyQt4.QtCore import *
app = QApplication(sys.argv)
w = QWidget()
def callback(data):
rospy.loginfo(rospy.get_caller_id() + "I heard %d, %d", data.x_pos, data.y_pos)
qp = QtGui.QPainter()
qp.begin()
drawPoint(data.x_pos, data.y_pos, qp)
qp.end()
def draw_xypoints(xp, yp, qp):
qp.setPen(QtCore.Qt.red)
qp.drawPoint(xp, yp)
def visualizer():
rospy.init_node('visualizer', anonymous=True)
rospy.Subscriber('mypos_xytheta', Position, callback)
rospy.spin()
if __name__ == '__main__':
w.resize(320,240)
w.setWindowTitle("1-2-3 Test")
w.show()
sys.exit(app.exec_())
visualizer()
When I run, the window pops up, but nothing else happens. Also I there is no feedback from the rospy.loginfo(). Apparently I am missing something here. (Obviously, I am not either a python or ros expert, just know some basic stuff). Any help is appreciated:).