Ask Your Question
0

Using ROS message and python to update text input field in kivy GUI

asked 2014-06-25 04:41:21 -0500

Hozer gravatar image

updated 2014-06-25 04:45:02 -0500

I try to design a GUI to handle stepper motors via ROS, kivy and python. You can find a minimal version of the GUI below. Actually I want to use a ROS message to update a kivy text input field (read only). In the minimal example, pressing the button should transfer the data of the first input field over a local ROS node to the second input field. Actually it seems, that the Callback within the rospy.Subscriber() doesn't enter the Test class.

Thank You for any suggestions!

main.py

import kivy
kivy.require('1.7.2')

import rospy
from std_msgs.msg import String

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout

class Test(BoxLayout):
    text_is = 'text before button press'

    def Pub(self):
        publish = self.ids.test_text_pub.text
        try:
            ROSNode.new_text_is.publish(publish)
        except rospy.ROSInterruptException: pass

class ROSNode(Widget):

    def Callback(publish):
        print(publish.data) #check if Callback has been called
        test.text_is = publish.data

    new_text_is = rospy.Publisher('new_text_is', String, queue_size=10)
    rospy.Subscriber('new_text_is', String, Callback)

    rospy.init_node('talker', anonymous=True)

class TestApp(App):

    def build(self):
        return Test()

if __name__ == '__main__':
    TestApp().run()

test.kv

#:kivy 1.0

<test>:
    BoxLayout:
        orientation: 'vertical'

        Button:
            id: test_button
            text: 'publish'
            on_press: root.Pub()

        TextInput:
            id: test_text_pub
            text: 'text after button press'

        TextInput:
            id: test_text_sub
            text: root.text_is
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2016-01-16 03:23:23 -0500

Pototo gravatar image

Hi,

You can use this file as an example to help you:

https://github.com/RoboEvangelist/br_...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2014-06-25 04:41:21 -0500

Seen: 1,562 times

Last updated: Jan 16 '16