• Diff for "rqt/Tutorials/To show error or exception message to the users"
Differences between revisions 13 and 14
Revision 13 as of 2013-04-17 18:55:58
Size: 3890
Editor: IsaacSaito
Comment:
Revision 14 as of 2013-04-17 19:04:16
Size: 997
Editor: IsaacSaito
Comment: To squash unncessary intermediate commits
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
## title = To show error or exception message to users ## title = /To show error or exception message to users
Line 25: Line 25:
<<TOC(3)>>
Line 27: Line 26:
=== Motivation ===
GUI should better notify errors and progress to users to some extent, and GUI developers should NOT expect users to pay attention to terminals where they can easily print error messages to. Therefore it is '''recommended''' for all `rqt` plugins to indicate those on GUI.
<<TableOfContents(4)>>
Line 30: Line 28:
This tutorial shows a way to do it by using a component in [[rqt_py_common]] pkg. Here we look at [[rqt_topic v 0.2.16|https://github.com/ros-visualization/rqt_common_plugins/tree/d9cc43a58322e410d72fca4d0db698ee52ee78be/rqt_topic]] plugin as an example.

=== Steps to implement ===
==== Instantiate `PluginContainerWidget` ====

([[http://ros.org/doc/groovy/api/rqt_py_common/html/classrqt__py__common_1_1plugin__container__widget_1_1PluginContainerWidget.html|its API doc]]), taking the plugin's main widget ([[https://raw.github.com/ros-visualization/rqt_common_plugins/d9cc43a58322e410d72fca4d0db698ee52ee78be/rqt_topic/src/rqt_topic/topic.py|Full code]] is available).

{{{
#!python block=plugin_py
class Topic(Plugin):
    def __init__(self, context):
        :
        self._widget = TopicWidget(self)
        :
        self.mainwidget = PluginContainerWidget(self._widget, True, False)
}}}

Looking at its constructor:

<<CodeRef(plugin_py,6,6)>>

Both 2nd and 3rd arguments are boolean. 3rd turns on message pane, 4th is for progress bar.

/!\ progress bar isn't implemented as of March 2013.

==== Create `Signal`s in plugin's widget class ====
/!\ From here only message pane will be discussed. That of progress bar that isn't implemented as of March 2013 will be added once it's implemented. Sorry for the inconvenience.

The widget class is the one that's passed to `PluginContainerWidget`.

In `TopicWidget` ([[https://raw.github.com/ros-visualization/rqt_common_plugins/d9cc43a58322e410d72fca4d0db698ee52ee78be/rqt_topic/src/rqt_topic/topic_widget.py|Full code]]),

{{{
#!python block=widget_py
from python_qt_binding.QtCore import Qt, QTimer, Signal, Slot
:
class TopicWidget(QWidget):
    :
    sig_sysmsg = Signal(str)

    def __init__(self, plugin=None, selected_topics=None,
                 select_topic_type=SELECT_BY_NAME):
    :
    def _kick_refresh_topics(self):
        """
        Calling internally self.refresh_topics method.
        Reason of existence is to catch possible exception raised from
        refresh_topics method that can be used as a callback.
        """
        try:
            self.refresh_topics()
        except Exception as e:
            self.sig_sysmsg.emit(e.message)
}}}

What needs to be added:

<<CodeRef(widget_py,3,3)>>

Note that under current implementation of `PluginContainerWidget`, the name of the `Signal` variable MUST BE '''sig_sysmsg'''.

==== Emit signal wherever necessary ====
<<CodeRef(widget_py,16,19)>>
The string that's passed to `emit` will be shown in message pane.

(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

To show error or exception message to users

Description: Shows error/warning msgs or progress bar on GUI by using a component in rqt_py_common pkg

Tutorial Level: INTERMEDIATE

Contents

Wiki: rqt/Tutorials/To show error or exception message to the users (last edited 2013-04-17 19:46:45 by IsaacSaito)