def _rightclick_menu(self, event):
        menu = QMenu()
        text_action = QAction(self.tr('View Text'), menu)
        menu.addAction(text_action)
        raw_action = QAction(self.tr('View Raw'), menu)
        menu.addAction(raw_action)

        action = menu.exec_(event.globalPos())

        if action == raw_action or action == text_action:
            selected = self.messages_tree.selectedIndexes()
            selected_type = selected[1].data()

            if selected_type[-2:] == '[]':
                selected_type = selected_type[:-2]
            browsetext = None
            try:
                if self._mode == rosmsg.MODE_MSG:
                    browsetext = rosmsg.get_msg_text(selected_type,
                                                     action == raw_action)
                elif self._mode == rosmsg.MODE_SRV:
                    browsetext = rosmsg.get_srv_text(selected_type,
                                                     action == raw_action)
                else:
                    raise
            except rosmsg.ROSMsgException, e:
                QMessageBox.warning(
                    self, self.tr('Warning'),
                    self.
                    tr('The selected item component does not have text to view.'
                       ))
            if browsetext is not None:
                self._browsers.append(TextBrowseDialog(browsetext))
                self._browsers[-1].show()
 def _show_browsers(self):
     rowlist = []
     for current in self.table_view.selectionModel().selectedIndexes():
         rowlist.append(self._proxy_model.mapToSource(current).row())
     browsetext = self._model.get_selected_text(rowlist)
     if browsetext is not None:
         self._browsers.append(TextBrowseDialog(browsetext, self._rospack))
         self._browsers[-1].show()
    def _rightclick_menu(self, event):
        """
        :type event: QEvent
        """

        # QTreeview.selectedIndexes() returns 0 when no node is selected.
        # This can happen when after booting no left-click has been made yet
        # (ie. looks like right-click doesn't count). These lines are the
        # workaround for that problem.
        selected = self._messages_tree.selectedIndexes()
        if len(selected) == 0:
            return

        menu = QMenu()
        text_action = QAction(self.tr('View Text'), menu)
        menu.addAction(text_action)
        raw_action = QAction(self.tr('View Raw'), menu)
        menu.addAction(raw_action)
        remove_action = QAction(self.tr('Remove message'), menu)
        menu.addAction(remove_action)

        action = menu.exec_(event.globalPos())

        if action == raw_action or action == text_action:
            rospy.logdebug('_rightclick_menu selected={}'.format(selected))
            selected_type = selected[1].data()

            if selected_type[-2:] == '[]':
                selected_type = selected_type[:-2]
            browsetext = None
            try:
                if (self._mode == rosmsg.MODE_MSG
                        or self._mode == rosaction.MODE_ACTION):
                    browsetext = rosmsg.get_msg_text(selected_type,
                                                     action == raw_action)
                elif self._mode == rosmsg.MODE_SRV:
                    browsetext = rosmsg.get_srv_text(selected_type,
                                                     action == raw_action)

                else:
                    raise
            except rosmsg.ROSMsgException as e:
                QMessageBox.warning(
                    self, self.tr('Warning'),
                    self.tr('The selected item component ' +
                            'does not have text to view.'))
            if browsetext is not None:
                self._browsers.append(
                    TextBrowseDialog(browsetext, self._rospack))
                self._browsers[-1].show()

        if action == remove_action:
            self._messages_tree.model().removeRow(selected[0].row())
Beispiel #4
0
    def _rightclick_menu(self, event):
        """
        :type event: QEvent
        """
        # QTreeview.selectedIndexes() returns 0 when no node is selected.
        # This can happen when after booting no left-click has been made yet
        # (ie. looks like right-click doesn't count). These lines are the
        # workaround for that problem.
        selected = self._messages_tree.selectedIndexes()
        if len(selected) == 0:
            return

        menu = QMenu()
        text_action = QAction(self.tr('View Text'), menu)
        menu.addAction(text_action)
        remove_action = QAction(self.tr('Remove message'), menu)
        menu.addAction(remove_action)

        action = menu.exec_(event.globalPos())

        if action == text_action:
            self._logger.debug('_rightclick_menu selected={}'.format(selected))
            selected_type = selected[1].data()

            # We strip any array information for loading the python classes
            selected_type_bare = selected_type
            if selected_type_bare.find('[') >= 0:
                selected_type_bare = selected_type_bare[:selected_type_bare.
                                                        find('[')]
            # We use the number of '/' to determine of the selected type is a msg, action, srv,
            # or primitive type.
            # NOTE (mlautman - 2/4/19) this heuristic seems brittle and should be removed
            selected_type_bare_tokens_len = len(selected_type_bare.split('/'))

            # We only want the base class so we transform eg. pkg1/my_srv/Request -> pkg1/my_srv
            if selected_type_bare_tokens_len > 2:
                selected_type_bare = "/".join(
                    selected_type_bare.split('/')[:2])

            browsetext = None

            # If the type does not have '/'s then we treat it as a primitive type
            if selected_type_bare_tokens_len == 1:
                browsetext = selected_type

            # if the type has a single '/' then we treat it as a msg type
            elif selected_type_bare_tokens_len == 2:
                msg_class = get_message_class(selected_type_bare)
                browsetext = get_message_text_from_class(msg_class)

            # If the type has two '/'s then we treat it as a srv or action type
            elif selected_type_bare_tokens_len == 3:
                if self._mode == message_helpers.SRV_MODE:
                    msg_class = get_service_class(selected_type_bare)
                    browsetext = get_service_text_from_class(msg_class)

                elif self._mode == message_helpers.ACTION_MODE:
                    msg_class = get_action_class(selected_type_bare)
                    browsetext = get_action_text_from_class(msg_class)

                else:
                    self._logger.warn("Unrecognized value for self._mode: {} "
                                      "for selected_type: {}".format(
                                          self._mode, selected_type))
            else:
                self._logger.warn(
                    "Invalid selected_type: {}".format(selected_type))

            if browsetext is not None:
                self._browsers.append(TextBrowseDialog(browsetext))
                self._browsers[-1].show()

        if action == remove_action:
            self._messages_tree.model().removeRow(selected[0].row())