def save_settings(self, instance_settings): expanded_nodes = [] for index in self._enumerate_indexes(): if self._node_selector_view.isExpanded(index): grn = RqtRosGraph.get_upper_grn(index, '') if grn: expanded_nodes.append(grn) instance_settings.set_value('expanded_nodes', expanded_nodes)
def _selection_changed_slot(self, selected, deselected): """ Send "open ROS Node box" signal. ONLY IF the selected treenode is the terminal treenode. Receives args from signal QItemSelectionModel.selectionChanged. :param selected: All indexs where selected (could be multiple) :type selected: QItemSelection :type deselected: QItemSelection """ # Getting the index where user just selected. Should be single. if not selected.indexes() and not deselected.indexes(): logging.error('Nothing selected? Not ideal to reach here') return index_current = None if selected.indexes(): index_current = selected.indexes()[0] elif len(deselected.indexes()) == 1: # Setting length criteria as 1 is only a workaround, to avoid # Node boxes on right-hand side disappears when filter key doesn't # match them. # Indeed this workaround leaves another issue. Question for # permanent solution is asked here http://goo.gl/V4DT1 index_current = deselected.indexes()[0] logging.debug(' - - - index_current={}'.format(index_current)) rosnode_name_selected = RqtRosGraph.get_upper_grn(index_current, '') # If retrieved node name isn't in the list of all nodes. if rosnode_name_selected not in self._nodeitems.keys(): # De-select the selected item. self.selectionModel.select(index_current, QItemSelectionModel.Deselect) return if selected.indexes(): try: self._selection_selected(index_current, rosnode_name_selected) except Exception as e: # TODO: print to sysmsg pane err_msg = 'Connection to node={} failed:\n{}'.format( rosnode_name_selected, e) import traceback traceback.print_exc() self._signal_msg.emit(err_msg) logging.error(err_msg) elif deselected.indexes(): try: self._selection_deselected(index_current, rosnode_name_selected) except Exception as e: self._signal_msg.emit(e) logging.error(e)
def _selection_changed_slot(self, selected, deselected): """ Sends "open ROS Node box" signal ONLY IF the selected treenode is the terminal treenode. Receives args from signal QItemSelectionModel.selectionChanged. :param selected: All indexs where selected (could be multiple) :type selected: QItemSelection :type deselected: QItemSelection """ ## Getting the index where user just selected. Should be single. if not selected.indexes() and not deselected.indexes(): rospy.logerr('Nothing selected? Not ideal to reach here') return index_current = None if selected.indexes(): index_current = selected.indexes()[0] elif len(deselected.indexes()) == 1: # Setting length criteria as 1 is only a workaround, to avoid # Node boxes on right-hand side disappears when filter key doesn't # match them. # Indeed this workaround leaves another issue. Question for # permanent solution is asked here http://goo.gl/V4DT1 index_current = deselected.indexes()[0] rospy.logdebug(' - - - index_current={}'.format(index_current)) rosnode_name_selected = RqtRosGraph.get_upper_grn(index_current, '') # If retrieved node name isn't in the list of all nodes. if not rosnode_name_selected in self._nodeitems.keys(): # De-select the selected item. self.selectionModel.select(index_current, QItemSelectionModel.Deselect) return if selected.indexes(): try: self._selection_selected(index_current, rosnode_name_selected) except ROSException as e: #TODO: print to sysmsg pane err_msg = e.message + '. Connection to node=' + \ format(rosnode_name_selected) + ' failed' self._signal_msg.emit(err_msg) rospy.logerr(err_msg) elif deselected.indexes(): try: self._selection_deselected(index_current, rosnode_name_selected) except ROSException as e: rospy.logerr(e.message)
def node_deselected(self, grn): """ Deselect the index that corresponds to the given GRN. :type grn: str """ # Obtain all indices currently selected. indexes_selected = self.selectionModel.selectedIndexes() for index in indexes_selected: grn_from_selectedindex = RqtRosGraph.get_upper_grn(index, '') logging.debug(' Compare given grn={} from selected={}'.format( grn, grn_from_selectedindex)) # If GRN retrieved from selected index matches the given one. if grn == grn_from_selectedindex: # Deselect the index. self.selectionModel.select(index, QItemSelectionModel.Deselect)
def node_selected(self, grn, scroll_to=False): """ Select the index that corresponds to the given GRN. :type grn: str """ # Iterate over all of the indexes for index in self._enumerate_indexes(): grn_from_index = RqtRosGraph.get_upper_grn(index, '') logging.debug(' Compare given grn={} from selected={}'.format( grn, grn_from_index)) # If GRN retrieved from selected index matches the given one. if grn == grn_from_index: # Select the index. self.selectionModel.select(index, QItemSelectionModel.Select) if scroll_to: self._node_selector_view.scrollTo(index) break
def node_deselected(self, grn): """ Deselect the index that corresponds to the given GRN. :type grn: str """ # Obtain the corresponding index. qindex_tobe_deselected = self._item_model.get_index_from_grn(grn) logging.debug('NodeSelWidt node_deselected qindex={} data={}'.format( qindex_tobe_deselected, qindex_tobe_deselected.data(Qt.DisplayRole))) # Obtain all indices currently selected. indexes_selected = self.selectionModel.selectedIndexes() for index in indexes_selected: grn_from_selectedindex = RqtRosGraph.get_upper_grn(index, '') logging.debug(' Compare given grn={} grn from selected={}'.format( grn, grn_from_selectedindex)) # If GRN retrieved from selected index matches the given one. if grn == grn_from_selectedindex: # Deselect the index. self.selectionModel.select(index, QItemSelectionModel.Deselect)
def node_deselected(self, grn): """ Deselect the index that corresponds to the given GRN. :type grn: str """ # Obtain the corresponding index. qindex_tobe_deselected = self._item_model.get_index_from_grn(grn) rospy.logdebug('NodeSelWidt node_deselected qindex={} data={}'.format( qindex_tobe_deselected, qindex_tobe_deselected.data(Qt.DisplayRole))) # Obtain all indices currently selected. indexes_selected = self.selectionModel.selectedIndexes() for index in indexes_selected: grn_from_selectedindex = RqtRosGraph.get_upper_grn(index, '') rospy.logdebug(' Compare given grn={} grn from selected={}'.format( grn, grn_from_selectedindex)) # If GRN retrieved from selected index matches the given one. if grn == grn_from_selectedindex: # Deselect the index. self.selectionModel.select(index, QItemSelectionModel.Deselect)
def restore_settings(self, instance_settings): expanded_nodes = instance_settings.value('expanded_nodes', []) if expanded_nodes: for index in self._enumerate_indexes(): if RqtRosGraph.get_upper_grn(index, '') in expanded_nodes: self._node_selector_view.setExpanded(index, True)