Converting Rqt Plugin to QWidget

asked 2016-02-21 09:53:30 -0600

rbaleksandar gravatar image

Hi!

Although rqt_robot_dashboard (class Dashboard as you can see here; I am using the cob_dashboard) itself is derived from Plugin it still uses QWidgets in its interface. The dashboard uses get_widgets() to retrieve a nested list (top-level list contains the groups of entries in the toolbar while the second-level lists contain the actual entries) of QWidget elements (from what I've seen so far it's usually recommended to use IconToolButton, QLabel or other simple widgets).

So far I have been creating my own widgets. In order for me to display something in the main view of the dashboard I am creating a toolbar entry, which - upon clicking - adds a QWidget to that view. Relatively easy to accomplish. However now I would like to reuse some of the rqt_common_plugins (rqt_graph for example) and rqt_robot_plugins (rqt_tf_tree for example) in my dashboard. The problem that I'm facing is that these plugins are either derived from Plugin or directly from QObject hence not derived from QWidget.

Is there a way to convert these things in normal QWidget without extracting bits and pieces from their original source code? These plugins actually contain QWidget (see below) however there are also various Plugin/QObject-related functions that I also have to figure out how to remap - too much work.

Here are two snippets from rqt_tf_tree (see here for complete code) and rqt_graph to give some overview:

tf_tree.py

class RosTfTree(QObject):

    _deferred_fit_in_view = Signal()

    def __init__(self, context):
        super(RosTfTree, self).__init__(context)
        self.initialized = False

        self.setObjectName('RosTfTree')

        self._current_dotcode = None

        self._widget = QWidget() // <---------This can be extracted...maybe

        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory = PygraphvizFactory()
        # generator builds rosgraph
        self.dotcode_generator = RosTfTreeDotcodeGenerator()
        self.tf2_buffer_ = tf2_ros.Buffer()
       // ...

ros_graph.py

class RosGraph(Plugin):

    _deferred_fit_in_view = Signal()

    def __init__(self, context):
        super(RosGraph, self).__init__(context)
        self.initialized = False
        self.setObjectName('RosGraph')

        self._graph = None
        self._current_dotcode = None

        self._widget = QWidget() // <---------This can be extracted...maybe

        # factory builds generic dotcode items
        self.dotcode_factory = PydotFactory()
        # self.dotcode_factory = PygraphvizFactory()
        # generator builds rosgraph
        self.dotcode_generator = RosGraphDotcodeGenerator()
       // ...

As you can see each contains self._widget which I might be able to use though I haven't finished analyzing the code to see what will break if I do that.

Has anyone done something like that? Any ideas how to do it in the most trivial and time-saving manner?

edit retag flag offensive close merge delete