Exemplo n.º 1
0
    def __get_local_childs(self, parent=None):
        """
        Returns all childs of the topic item at the given position in the gui.

        :param parent: the model parent at the given index (not global / logical parent)
        :type parent: NodeItem
        :param sub_activated: Defines if subscriber shall be shown too.
        :returns: the child at the position row
        :rtype: AbstractItem
        """
        childs = []
        if parent is not None:
            # a specific parent has been chosen - we have to use it to display the correct connection items
            # use the seuid to determine the node and compare this to the parts in the connections item (child of this
            # item.
            seuid = parent.get_seuid()

            seuid_helper = SEUID()
            seuid_helper.identifier = seuid
            seuid_helper.set_fields()
            node = seuid_helper.node
            for child in self.get_childs():
                child_seuid = child.get_seuid()
                seuid_helper.identifier = child_seuid
                seuid_helper.set_fields()
                node_comp = seuid_helper.publisher
                # do the check on the publisher
                if node == node_comp:
                    # match.
                    childs.append(child)
                    continue

            return childs
        else:
            return self._child_items
Exemplo n.º 2
0
    def __init__(self, parent=None):
        """
        Defines the class attributes especially the root_item which later contains the list of headers e.g. for a TreeView representation.
        :param parent: the parent of the model
        :type parent: QObject
        """
        super(ROSModel, self).__init__(parent)

        self.__logger = ModelLogger()

        self._translator = QTranslator()
        # internationalize everything including the 2 plugins
        self.rp = rospkg.RosPack()
        directory = os.path.join(self.rp.get_path('arni_gui'), 'translations')
        files = find_qm_files(directory)
        translator = self.get_translator()
        # todo: make this more intelligent (should be done as soon as new languages are needed / implemented)
        print("chose translation " + files[0])
        translator.load(files[0])
        qApp.installTranslator(translator)

        self.__root_item = RootItem(self.__logger, "abstract", self)

        self.__parent = parent
        self.__model_lock = Lock()

        self.update_signal.connect(self.update_model)


        """
        IMPORTANT: Does not contain the models nodes but the logical nodes. E.g. a ConnectionItem splits up to two
        TreeConnectionItems where the identifier_dict only contains the connectionitem. This allows to push
        data into one item but to show it at two places in the Qt GUI.
        """
        self.__identifier_dict = {"root": self.__root_item}
        self.__item_delegate = SizeDelegate()

        # CAUTION: Do not change this mapping if not absolutely necessary. If you change it remember to change
        # item_filter_proxy (and maybe other classes) as well - sadly not all functions use the access function.
        self.__mapping = {
            0: 'type',
            1: 'name',
            2: 'state',
            3: 'data'
        }

        self.__last_time_error_occured = 0
        self.__logger.log("info", Time.now(), "ROSModel", "ROSModel initialization finished")

        self.__seuid_helper = SEUID()

        self.__find_host = HostLookup()

        self.__buffer_thread = BufferThread(self)
        self.__buffer_thread.start()