Ejemplo n.º 1
0
    def _update_service_list(self):
        self._widget.service_tree_widget.clear()
        self._widget.service_info_text.clear()
        self._widgetitem_service_pair = {}
        service_list = self.admin_app_info.service_list

        for k in service_list.values():
            #Top service
            service_item = QTreeWidgetItem(self._widget.service_tree_widget)
            #service_item=QTreeWidgetItem()
            service_item.setText(0, k['name'])

            #set Top Level Font
            font = service_item.font(0)
            font.setPointSize(20)
            font.setBold(True)
            service_item.setFont(0, font)

            #set client item
            for l in k["client_list"]:
                client_item = QTreeWidgetItem()
                client_item.setText(0, l)
                font = client_item.font(0)
                font.setPointSize(15)
                client_item.setFont(0, font)
                service_item.addChild(client_item)

            self._widgetitem_service_pair[service_item] = k

            #self._widget.service_tree_widget.addTopLevelItem(service_item)
        pass
Ejemplo n.º 2
0
    def _on_plans(self, msg):
        if self._plans == msg.plans:
            return
        self._plans = msg.plans

        mission_tree = self._widget.findChild(QTreeWidget, "missionTreeWidget")
        mission_tree.clear()
        contigency_combo = self._widget.findChild(QComboBox, "contigencyCombo")
        contigency_combo.clear()

        for plan in sorted(self._plans, key=lambda plan: plan.name):
            item = QTreeWidgetItem([plan.name])
            for entry in plan.entries:
                contigency = entry.contigency_plan
                if len(contigency) == 0:
                    contigency = "none"
                dist = str(entry.dist) if entry.dist != 0 else ""
                subitem = QTreeWidgetItem([entry.mission, str(entry.timeout.secs), contigency, entry.path, dist])
                item.setFlags(item.flags() | Qt.ItemIsEditable)
                item.addChild(subitem)
            mission_tree.addTopLevelItem(item)
            item.setExpanded(True)
            if plan.name != "main":
                contigency_combo.addItem(plan.name)
        contigency_combo.addItem("none")

        mission_combo = self._widget.findChild(QComboBox, "missionCombo")
        mission_combo.clear()
        mission_combo.addItems(sorted(msg.available_missions))
    def loadLocation(self):
        self.startTrajectoryButton.setEnabled(False)
        self.startButton.setEnabled(False)
        self.addButton.setEnabled(False)
        self.openHandButton.setEnabled(False)
        self.closeHandButton.setEnabled(False)
        self.endButton.setEnabled(False)

        location = self.demoLocation.text()
        if os.path.isdir(location):
            locations = [os.path.join(location, f) for f in os.listdir(location) if os.path.isfile(os.path.join(location, f)) and f.split(".")[-1] == "bag"]
        else:
            locations = [location]

        if len(locations) == 0 or len(locations[0]) == 0:
            return
        
        self.keyframeCount.setText("")
        self.playbackTree.clear()
        self.zeroMarker.clear()
        self._showStatus("Parsing...")
        
        totalFrames = 0
        for location in sorted(locations):
            try:
                self.keyframeBagInterface = KeyframeBagInterface()
                parsedData = self.keyframeBagInterface.parse(location)
                objectsInScene = self.keyframeBagInterface.parseContainedObjects(location)
            except (rosbag.bag.ROSBagException, ParseException) as err:
                self._showStatus(str(err))
                rospy.logwarn("[%s] %s", location, str(err))
                self.playbackTree.clear()
                return
            totalFrames += len(parsedData)

            objectLabels = []
            for item in objectsInScene:
                label = item.label
                if objectLabels.count(label) > 0:
                    label = "{} #{}".format(label, objectLabels.count(label) + 1)
                objectLabels.append(item.label)

                if len(locations) > 1:
                    self.zeroMarker.addItem(u"{} → {}".format(label, os.path.basename(location)))
                else:
                    self.zeroMarker.addItem(label)

            items = []
            for i, keyframe in enumerate(parsedData):
                item = QTreeWidgetItem()
                title = "(#{}) ".format(i) + time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(keyframe["time"]))
                item.setText(0, title)
                # Add children
                for topic in sorted(keyframe["data"]):
                    data = keyframe["data"][topic]
                    topicItem = QTreeWidgetItem()
                    topicItem.setText(0, topic)
                    for attribute in sorted(data):
                        attributeValueItem = QTreeWidgetItem()
                        attributeValueItem.setText(0, attribute)
                        attributeValueItem.setText(1, str(data[attribute]))
                        topicItem.addChild(attributeValueItem)
                    item.addChild(topicItem)
                items.append(item)
            if len(locations) == 1:
                self.playbackTree.addTopLevelItems(items)
            else:
                item = QTreeWidgetItem()
                item.setText(0, location)
                item.addChildren(items)
                self.playbackTree.addTopLevelItem(item)
        
        if len(locations) == 1:
            self.demoName.setText(os.path.basename(locations[0]))
            self.keyframeCount.setText("{} keyframe(s) loaded".format(totalFrames))
        else:
            self.demoName.setText(os.path.basename(self.demoLocation.text()) + os.path.sep)
            self.keyframeCount.setText("{} keyframe(s) loaded from {} files".format(totalFrames, len(locations)))
        self._showStatus("Parsed {} keyframe(s).".format(totalFrames))
        self.playDemoButton.setEnabled(True)
        if self.locateObjectsBox.isChecked():
            self.zeroMarker.setEnabled(True)
    def loadLocation(self):
        self.startTrajectoryButton.setEnabled(False)
        self.startButton.setEnabled(False)
        self.addButton.setEnabled(False)
        self.openHandButton.setEnabled(False)
        self.closeHandButton.setEnabled(False)
        self.endButton.setEnabled(False)

        location = self.demoLocation.text()
        if os.path.isdir(location):
            locations = [
                os.path.join(location, f) for f in os.listdir(location)
                if os.path.isfile(os.path.join(location, f))
                and f.split(".")[-1] == "bag"
            ]
        else:
            locations = [location]

        if len(locations) == 0 or len(locations[0]) == 0:
            return

        self.keyframeCount.setText("")
        self.playbackTree.clear()
        self.zeroMarker.clear()
        self._showStatus("Parsing...")

        totalFrames = 0
        for location in sorted(locations):
            try:
                self.keyframeBagInterface = KeyframeBagInterface()
                parsedData = self.keyframeBagInterface.parse(location)
                objectsInScene = self.keyframeBagInterface.parseContainedObjects(
                    location)
            except (rosbag.bag.ROSBagException, ParseException) as err:
                self._showStatus(str(err))
                rospy.logwarn("[%s] %s", location, str(err))
                self.playbackTree.clear()
                return
            totalFrames += len(parsedData)

            objectLabels = []
            for item in objectsInScene:
                label = item.label
                if objectLabels.count(label) > 0:
                    label = "{} #{}".format(label,
                                            objectLabels.count(label) + 1)
                objectLabels.append(item.label)

                if len(locations) > 1:
                    self.zeroMarker.addItem(u"{} → {}".format(
                        label, os.path.basename(location)))
                else:
                    self.zeroMarker.addItem(label)

            items = []
            for i, keyframe in enumerate(parsedData):
                item = QTreeWidgetItem()
                title = "(#{}) ".format(i) + time.strftime(
                    '%Y-%m-%d %H:%M:%S', time.localtime(keyframe["time"]))
                item.setText(0, title)
                # Add children
                for topic in sorted(keyframe["data"]):
                    data = keyframe["data"][topic]
                    topicItem = QTreeWidgetItem()
                    topicItem.setText(0, topic)
                    for attribute in sorted(data):
                        attributeValueItem = QTreeWidgetItem()
                        attributeValueItem.setText(0, attribute)
                        attributeValueItem.setText(1, str(data[attribute]))
                        topicItem.addChild(attributeValueItem)
                    item.addChild(topicItem)
                items.append(item)
            if len(locations) == 1:
                self.playbackTree.addTopLevelItems(items)
            else:
                item = QTreeWidgetItem()
                item.setText(0, location)
                item.addChildren(items)
                self.playbackTree.addTopLevelItem(item)

        if len(locations) == 1:
            self.demoName.setText(os.path.basename(locations[0]))
            self.keyframeCount.setText(
                "{} keyframe(s) loaded".format(totalFrames))
        else:
            self.demoName.setText(
                os.path.basename(self.demoLocation.text()) + os.path.sep)
            self.keyframeCount.setText(
                "{} keyframe(s) loaded from {} files".format(
                    totalFrames, len(locations)))
        self._showStatus("Parsed {} keyframe(s).".format(totalFrames))
        self.playDemoButton.setEnabled(True)
        if self.locateObjectsBox.isChecked():
            self.zeroMarker.setEnabled(True)