Ask Your Question
0

How to write a simple Python Qt dialog on ROS Service?

asked 2013-07-26 03:23:02 -0500

msieber gravatar image

I want to write a ROS Service that receives a Question and then shows a Qt Pop-up Dialog with the Question and a yes or no Button. The service should return the Answer as a Boolean. I have it with wx but since it is depreciated in ROS, I want to use Qt now. This is how it looked like with wx:

    rospy.init_node('dialog_server')
    s = rospy.Service('dialog', Dialog, self.handle_dialog)
    rospy.spin()
    def handle_dialog(self, req):
        ex = wx.App()
        dial = wx.MessageDialog(None, req.message, 'Question',
                        wx.YES_NO | wx.ICON_QUESTION)
        ret = dial.ShowModal()
        if ret == wx.ID_YES:
                answer = True
        else:
                answer = False
        return DialogResponse(answer)

I tried simply replacing wx with the equivalent qt (like wx.MessageDialog -> QtGui.QMessageBox.question) but it's not working because ros is another Thread. Error: "It is not safe to use pixmaps outside the GUI thread". I am not familiar with Qt, rqt python_qt_binding and plug-ins at all.

What do I need to achieve this? Do I have to use Slots and Signals between GUI and ROS, or even write it as a plug-in? How should it look like?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2013-07-26 06:36:56 -0500

130s gravatar image

ROS does _NOT_ deprecates wx (, which is technically impossible because wx is externally hosted from ROS). ROS does so for some particular wx-based toolssuite rx. That said you are free to continue using your own wx-based program. Advantage of doing so especially in your case would be that you don't have to rewrite anything. If you decide to continue using wx, you can look at the source of rx tools.

For the particular error you mention about, I can't tell why it happens without looking at your Qt code.

And yes, if you choose to write in Qt, using its standard architecture like slot-signal is a good idea. If you extend it to rqt plugin, you get more benefits as described. This tutorial has a link to sample source of rqt plugin.

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

1 follower

Stats

Asked: 2013-07-26 03:23:02 -0500

Seen: 498 times

Last updated: Jul 26 '13