コード例 #1
0
    def contextMenuEvent(self, event):
        pos = None
        selection = self.selectedItems()
        if selection:
            item = selection[0]
        else:
            item = self.currentItem()
            if item is None:
                item = self.invisibleRootItem().child(0)

        if item.parent() != None and (item.parent().text(0) == "Components" or item.parent().text(0) == "Devices"):
            if item.parent().text(0) == "Components":
                containers = self.callbackObject.apps
            else:
                containers = self.callbackObject.devMgrs
            container_name = item.parent().parent().text(0)
            contref = contTrack = None
            compname = item.text(0)
            foundApp = False
            contref, contTrack, comp = self.getRefs(containers, container_name, compname)
            if contref == None:
                if item.parent().text(0) == "Components":
                    self.callbackObject.log.warn("Unable to find Application: "+container_name)
                else:
                    self.callbackObject.log.warn("Unable to find Device Manager: "+container_name)
                return
            if comp == None:
                if item.parent().text(0) == "Components":
                    self.callbackObject.log.warn("Unable to find Component ("+compname+") on Application ("+container_name+")")
                else:
                    self.callbackObject.log.warn("Unable to find Device ("+compname+") on Device Manager ("+container_name+")")
                return
            pos = self.getPos(item, item.parent())
            if pos is not None:
                menu = QMenu(self)
                startAction = menu.addAction('Start')
                if comp._get_started():
                    startAction.setEnabled(False)
                stopAction = menu.addAction('Stop')
                if not comp._get_started():
                    stopAction.setEnabled(False)
                if hasBulkio(comp.ports):
                    createBulkioMenu(menu)
                menu.popup(pos)
                retval = menu.exec_()
            if retval != None:
                resp = retval.text()
                if resp == 'Start':
                    comp.start()
                elif resp == 'Stop':
                    comp.stop()
                elif plotResponse(resp):
                    plot = createPlot(resp)
                    plot.start()
                    try:
                        comp.connect(plot)
                        contTrack['widgets'].append((comp, plot))
                    except Exception, e:
                        plot.close()
                        if 'must specify providesPortName or usesPortName' in e.__str__():
                            QMessageBox.critical(self, 'Connection failed.', 'Cannot find a matching port. Please select a specific port in the Component port list to plot', QMessageBox.Ok)
                        else:
                            QMessageBox.critical(self, 'Connection failed.', e.__str__(), QMessageBox.Ok)
                elif resp == 'Sound':
                    sound=sb.SoundSink()
                    sound.start()
                    try:
                        comp.connect(sound)
                        contTrack['widgets'].append((comp, sound))
                    except Exception, e:
                        sound.releaseObject()
                        if 'must specify providesPortName or usesPortName' in e.__str__():
                            QMessageBox.critical(self, 'Connection failed.', 'Cannot find a matching port. Please select a specific port in the Component port list to plot', QMessageBox.Ok)
                        else:
                            QMessageBox.critical(self, 'Connection failed.', e.__str__(), QMessageBox.Ok)
コード例 #2
0
         elif resp == 'Stop':
             contref.stop()
         elif plotResponse(resp):
             plot = createPlot(resp)
             plot.start()
             try:
                 contref.connect(plot)
                 contTrack['widgets'].append((contref, plot))
             except Exception, e:
                 plot.close()
                 if 'must specify providesPortName or usesPortName' in e.__str__():
                     QMessageBox.critical(self, 'Connection failed.', 'Cannot find a matching port. Please select a specific Port in the Application Port list to plot', QMessageBox.Ok)
                 else:
                     QMessageBox.critical(self, 'Connection failed.', e.__str__(), QMessageBox.Ok)
         elif resp == 'Sound':
             sound=sb.SoundSink()
             sound.start()
             try:
                 contref.connect(sound)
                 contTrack['widgets'].append((contref, sound))
             except Exception, e:
                 sound.releaseObject()
                 if 'must specify providesPortName or usesPortName' in e.__str__():
                     QMessageBox.critical(self, 'Connection failed.', 'Cannot find a matching port. Please select a specific port in the Component port list to plot', QMessageBox.Ok)
                 else:
                     QMessageBox.critical(self, 'Connection failed.', e.__str__(), QMessageBox.Ok)
 elif item.parent() != None and item.parent().text(0) == "Ports" and item.parent().parent() != None and \
   (item.parent().parent().parent().text(0) == "Components" or item.parent().parent().parent().text(0) == "Devices"):
     compname = item.parent().parent().text(0)
     container_name = item.parent().parent().parent().parent().text(0)
     portname = item.text(0)[:-7]