示例#1
0
    def onConnect(self, mosq, obj, rc):
        # Log.debug(self._layer.rendererV2().dump())

        self._dict = {}
        self.updateConnected(True)
        for feat in self._layer.getFeatures():
            if feat.id() < 0:
                continue
            try:
                topic = str(feat.attribute("topic"))
                qos = int(feat.attribute("qos"))

                if not qos in range(3):
                    Log.warn("Topic QoS must be beween 0 and 2")
                    continue

                if topic is not None:
                    self.subscribe(topic, qos)
                else:
                    Log.critical("Invalid topic")

            except TypeError:
                Log.debug("Error adding features from layer")
                pass

        self.triggerRepaint()
 def _field(self, topic, field, required=False, default=""):
     try:
         return topic.find(field).text
     except:
         if required:
             Log.critical("Error parsing " + self._xml + " No topic found")
         return default
示例#3
0
    def _processQueue(self):
        """
        Process incoming message queue
        """
        if not self._canRun():
            return
        
        try:
            while(not self.Q.empty()):
                msg =self.Q.get()

                if not self.topicManager().onMessage(self,msg):
                    continue

                for feat in self._layer.getFeatures():
                    topic = str(feat.attribute("topic"))
                    key = msg.topic + ':' + str(feat.id())
                    with QMutexLocker(self._mutex):
                        if key in self._dict:
                            self.updateFeature(feat, msg.topic, msg.payload)
                        elif Mosquitto.topic_matches_sub(topic, msg.topic):
                            self._dict[key] = feat.id()
                            self.updateFeature(feat, msg.topic, msg.payload)

        except Queue.Empty:
            Log.debug("Empty Queue")
            return

        except Exception as e:
            Log.critical("MQTT Client - Error updating features! " + str(e))
            
        finally:
            if self._dirty:
                self.triggerRepaint()
示例#4
0
 def sync(self, load=True):
     try:
         Settings.set(self.kBrokerList,json.dumps(self._brokers))
     except Exception as e:
         Log.critical(e)
     if load:
         self.load()
示例#5
0
 def sync(self, load=True):
     try:
         Settings.set(self.kBrokerList, json.dumps(self._brokers))
     except Exception as e:
         Log.critical(e)
     if load:
         self.load()
示例#6
0
    def onConnect(self, mosq, obj, rc):
        # Log.debug(self._layer.rendererV2().dump())

        self._dict = {}
        self.updateConnected(True)
        for feat in self._layer.getFeatures():
            if feat.id() < 0:
                continue
            try:
                topic = str(feat.attribute("topic"))
                qos = int(feat.attribute("qos"))
            
                if not qos in range(3):
                    Log.warn("Topic QoS must be beween 0 and 2")
                    continue
    
                if topic is not None:
                    self.subscribe(topic, qos)
                else:
                    Log.critical("Invalid topic")
                   
            except TypeError:
                Log.debug("Error adding features from layer")
                pass
                
        self.triggerRepaint()
示例#7
0
    def _processQueue(self):
        """
        Process incoming message queue
        """
        if not self._canRun():
            return

        try:
            while (not self.Q.empty()):
                msg = self.Q.get()

                if not self.topicManager().onMessage(self, msg):
                    continue

                for feat in self._layer.getFeatures():
                    topic = str(feat.attribute("topic"))
                    key = msg.topic + ':' + str(feat.id())
                    with QMutexLocker(self._mutex):
                        if key in self._dict:
                            self.updateFeature(feat, msg.topic, msg.payload)
                        elif Mosquitto.topic_matches_sub(topic, msg.topic):
                            self._dict[key] = feat.id()
                            self.updateFeature(feat, msg.topic, msg.payload)

        except Queue.Empty:
            Log.debug("Empty Queue")
            return

        except Exception as e:
            Log.critical("MQTT Client - Error updating features! " + str(e))

        finally:
            if self._dirty:
                self.triggerRepaint()
    def initGui(self):

        # Create action that will start plugin configuration
        self.aboutA = QAction(
            QIcon(":/plugins/" + self.plugin_basename + "/icons/agsense.png"),
            "About", self.iface.mainWindow())  # Replace or Add About
        # connect the action to the run method
        self.aboutA.triggered.connect(self.about)

        self.configureA = QAction(
            QIcon(":/plugins/" + self.plugin_basename + "/icons/icon.png"),
            "Configure", self.iface.mainWindow())  # Replace or Add About
        # connect the action to the run method
        self.configureA.triggered.connect(self.configure)

        # From New Memory Layer plugin
        lMenuTitle = 'New Telemetry Layer...'

        self.newLayerA = QAction(
            QIcon(":/plugins/" + self.plugin_basename + "/icons/icon.png"),
            lMenuTitle, self.iface.mainWindow())
        QObject.connect(self.newLayerA, SIGNAL("triggered()"),
                        self.createLayer)
        self.iface.newLayerMenu().addAction(self.newLayerA)  # API >= 1.9
        self.iface.registerMainWindowAction(self.newLayerA, "Shift+Ctrl+T")

        try:
            Log.debug("Loading Layer Manager")
            self.layerManager = layerManager(self)
            Log.debug("Layer Manager Loaded")
            self.telemetryLayer = TelemetryLayer(self)
            Log.debug(Settings.getMeta("name") + ": Loaded")
            self.iface.projectRead.connect(self.layerManager.rebuildLegend)
            self.iface.newProjectCreated.connect(
                self.layerManager.rebuildLegend)
            Brokers.instance().brokersLoaded.connect(
                self.layerManager.brokersLoaded)

            #Log.debug(TelemetryLayer.instance()._layerManager.getTLayers(False).iteritems())
        except Exception as e:
            Log.critical(
                Settings.getMeta("name") +
                ": There was a problem loading the layer manager")
            exc_type, exc_value, exc_traceback = sys.exc_info()
            Log.debug(
                repr(
                    traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)))

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.aboutA)
        self.iface.addToolBarIcon(self.configureA)
        self.iface.addPluginToMenu(u"&Telemetry Layer", self.aboutA)
        self.iface.addPluginToMenu(u"&Telemetry Layer", self.configureA)
        self.installed = True

        mw = self.iface.mainWindow()
示例#9
0
 def exportFile(self):
     if not self._dirty:
         return
     try:
         with open(self._file(), 'w') as f:
             json.dump(f)
         self._dirty = False
         if load:
             self.load()
     except Exception as e:
         Log.critical(e)
示例#10
0
 def exportFile(self):
     if not self._dirty:
         return
     try:
         with open(self._file(), 'w') as f:
             json.dump(f)
         self._dirty = False
         if load:
             self.load()
     except Exception as e:
         Log.critical(e)
示例#11
0
    def _file(self):
        if self._jsonfile == self._defaultFile:
            fileName = QFileDialog.getSaveFileName(None, "Location for Brokers File",  # translate
                                                   "~/",
                                                   "*.json")
            if fileName:
                Settings.set(self.kBrokerFile, fileName)
                self._jsonfile = fileName
            else:
                Log.critical("Broker data being saved to plugin directory and will be lost on upgrade!")

        return self._jsonfile
    def initGui(self):
        # Tree Widget test
        Log.debug("initGUI")

        # Create action that will start plugin configuration
        self.aboutA = QAction(
            QIcon(":/plugins/" + self.plugin_basename + "/icons/agsense.png"),
            "About", self.iface.mainWindow())  # Replace or Add About
        # connect the action to the run method
        self.aboutA.triggered.connect(self.about)

        self.configureA = QAction(
            QIcon(":/plugins/" + self.plugin_basename + "/icons/icon.png"),
            "Configure", self.iface.mainWindow())  # Replace or Add About
        # connect the action to the run method
        self.configureA.triggered.connect(self.configure)


        # From New Memory Layer plugin
        lMenuTitle = 'New Telemetry Layer...'

        self.newLayerA = QAction(
            QIcon(":/plugins/" + self.plugin_basename + "/icons/icon.png"),
            lMenuTitle, self.iface.mainWindow())
        QObject.connect(self.newLayerA, SIGNAL("triggered()"), self.createLayer)
        self.iface.newLayerMenu().addAction(self.newLayerA)  # API >= 1.9
        self.iface.registerMainWindowAction(self.newLayerA, "Shift+Ctrl+T")

        try:
            Log.debug("Loading Layer Manager")
            self.layerManager = layerManager(self)
            Log.debug("Layer Manager Loaded")
            self.telemetryLayer = TelemetryLayer(self)
            Log.debug(Settings.getMeta("name") + ": Loaded")
            self.iface.projectRead.connect(self.layerManager.rebuildLegend)
            self.iface.newProjectCreated.connect(self.layerManager.rebuildLegend)
            Brokers.instance().brokersLoaded.connect(self.layerManager.brokersLoaded)
        except Exception as e:
            Log.critical(Settings.getMeta("name") + ": There was a problem loading the layer manager")
            exc_type, exc_value, exc_traceback = sys.exc_info()
            Log.debug(repr(traceback.format_exception(exc_type, exc_value,
                                                      exc_traceback)))

        
        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.aboutA)
        self.iface.addToolBarIcon(self.configureA)
        self.iface.addPluginToMenu(u"&Telemetry Layer", self.aboutA)
        self.iface.addPluginToMenu(u"&Telemetry Layer", self.configureA)
        self.installed = True

        mw = self.iface.mainWindow()
示例#13
0
    def importFile(self, filename=None):
        try:
            if not filename:
                filename = self._jsonfile
            if os.path.exists(filename):
                return json.loads(open(filename).read())
            else:
                # no file available
                Log.debug("Broker file " + filename + " not found!")
        except Exception as e:
            Log.critical(e)

        self._dirty = False
        return ""
        pass
示例#14
0
    def importFile(self,filename = None):
        try:
            if not filename:
                filename = self._jsonfile
            if os.path.exists(filename):
                return json.loads(open(filename).read())
            else:
                # no file available
                Log.debug("Broker file " + filename + " not found!")
        except Exception as e:
            Log.critical(e)

        self._dirty = False
        return ""
        pass
示例#15
0
    def _file(self):
        if self._jsonfile == self._defaultFile:
            fileName = QFileDialog.getSaveFileName(
                None,
                "Location for Brokers File",  # translate
                "~/",
                "*.json")
            if fileName:
                Settings.set(self.kBrokerFile, fileName)
                self._jsonfile = fileName
            else:
                Log.critical(
                    "Broker data being saved to plugin directory and will be lost on upgrade!"
                )

        return self._jsonfile
    def __init__(self, iface):
        # Save reference to the QGIS interface
        super(TelemetryLayerPlugin, self).__init__(iface)
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        sys.path.append(os.path.join(self.plugin_dir, "topicmanagers"))

        self.layerManager = None
        self.installed = False
        self.configureDlg = None
        self.plugin_basename = str(os.path.basename(self.plugin_dir))
        self.state = "Init"

        # Initialise Settings and Log handlers
        try:
            Settings(self)
            Log(self)
            Log.debug("Loading Topic Managers")
            TopicManagerFactory(iface)
            Log.debug("Topic Managers Loaded")
            Brokers(os.path.join(self.plugin_dir, 'data'))
            Log.debug("Brokers Loaded")

        except Exception as e:
            Log.critical("Error on Plugin initialization " + str(e))
            exc_type, exc_value, exc_traceback = sys.exc_info()
            Log.debug(
                repr(
                    traceback.format_exception(exc_type, exc_value,
                                               exc_traceback)))

        # initialize locale
        self.translator = QTranslator()

        if QSettings().value("locale/userLocale"):
            locale = QSettings().value("locale/userLocale")[0:2]
            localePath = os.path.join(self.plugin_dir, 'i18n',
                                      'telemetrylayer_{}.qm'.format(locale))
            if os.path.exists(localePath):
                self.translator.load(localePath)

        if qVersion() > '4.3.3':
            QCoreApplication.installTranslator(self.translator)
    def __init__(self, iface):
        # Save reference to the QGIS interface
        super(TelemetryLayerPlugin, self).__init__(iface)
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        sys.path.append(os.path.join(self.plugin_dir, "topicmanagers"))
        
        self.layerManager = None
        self.installed = False
        self.configureDlg = None
        self.plugin_basename = str(os.path.basename(self.plugin_dir))
        self.state="Init"

        # Initialise Settings and Log handlers
        try:
            Settings(self)
            Log(self)
            Log.debug("Loading Topic Managers")
            TopicManagerFactory(iface)
            Log.debug("Topic Managers Loaded")
            Brokers(os.path.join(self.plugin_dir, 'data'))
            Log.debug("Brokers Loaded")


        except Exception as e:
            Log.critical("Error on Plugin initialization " + str(e))
            exc_type, exc_value, exc_traceback = sys.exc_info()
            Log.debug(repr(traceback.format_exception(exc_type, exc_value,
                                                      exc_traceback)))

        # initialize locale
        self.translator = QTranslator()

        if QSettings().value("locale/userLocale"):
            locale = QSettings().value("locale/userLocale")[0:2]
            localePath = os.path.join(self.plugin_dir, 'i18n', 'telemetrylayer_{}.qm'.format(locale))
            if os.path.exists(localePath):
                self.translator.load(localePath)

        if qVersion() > '4.3.3':
            QCoreApplication.installTranslator(self.translator)