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()
    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()
Esempio n. 3
0
    def _connect(self):
        try:
            if not self._connected:
                if not self._attempts < self.kMaxAttempts:
                    if not self._resetTimer.isActive():
                        Log.progress(Settings.getMeta("name") + ": Max connection attempts reached - waiting " + str(self.kResetTimer) + " seconds before retrying" )
                        self._resetTimer.start(self.kResetTimer*1000)  # 1 minute parameterise
                    return
                if self._attempts > 0 and (time.time() - pow(2,self._attempts +1)) < self._attemped:
                        return
                Log.debug("Trying to connect")
                self._attemped = time.time()
                result = self.mqttc.connect(str(self._host), int(self._port),int( self._keepAlive), 1)
                self._connected = result == mqtt.MQTT_ERR_SUCCESS # paho
#                self._connected = result == mqtt.MOSQ_ERR_SUCCESS # mosquitto
                if not self._connected:
                    self._attempts += 1
                    Log.progress(mqtt.connack_string(connResult))
                    self.mqttConnectionError.emit(self, mqtt.connack_string(connResult))
 
        except Exception as e:
            msg = 'MQTT: ' + str(e)

            self.mqttConnectionError.emit(self, msg)
            #Log.progress(msg)
            Log.debug(msg)
            #exc_type, exc_value, exc_traceback = sys.exc_info()
            #Log.debug(repr(traceback.format_exception(exc_type, exc_value,
             #                                         exc_traceback)))
            self._attempts += 1
            self._connected = False
Esempio n. 4
0
    def _connect(self):
        try:
            if not self._connected:
                if not self._attempts < self.kMaxAttempts:
                    if not self._resetTimer.isActive():
                        Log.progress(
                            Settings.getMeta("name") +
                            ": Max connection attempts reached - waiting " +
                            str(self.kResetTimer) + " seconds before retrying")
                        self._resetTimer.start(self.kResetTimer *
                                               1000)  # 1 minute parameterise
                    return
                if self._attempts > 0 and (time.time() - pow(
                        2, self._attempts + 1)) < self._attemped:
                    return
                Log.debug("Trying to connect")
                self._attemped = time.time()
                result = self.mqttc.connect(str(self._host), int(self._port),
                                            int(self._keepAlive), 1)
                self._connected = result == mqtt.MQTT_ERR_SUCCESS  # paho
                #                self._connected = result == mqtt.MOSQ_ERR_SUCCESS # mosquitto
                if not self._connected:
                    self._attempts += 1
                    Log.progress(mqtt.connack_string(connResult))
                    self.mqttConnectionError.emit(
                        self, mqtt.connack_string(connResult))

        except Exception as e:
            msg = 'MQTT: ' + str(e)

            self.mqttConnectionError.emit(self, msg)
            #Log.progress(msg)
            Log.debug(msg)
            #exc_type, exc_value, exc_traceback = sys.exc_info()
            #Log.debug(repr(traceback.format_exception(exc_type, exc_value,
            #                                         exc_traceback)))
            self._attempts += 1
            self._connected = False
    def __init__(self, creator):
        Log.debug('init Layer Manager')
        super(layerManager, self).__init__()
        self._creator = creator
        self._iface = creator.iface
        self._plugin_dir = creator.plugin_dir
        self.disableDialog = False
        self.actions = {}
        self.menuName = Settings.getMeta('name')
        self._tLayers = {}
        layerManager._rebuildingLegend = False

        layers = layerManager.getLayers()
        if len(layers) > 0:  # Existing layers
            for layer in layers:
                if self.initLayer(layer) is None:
                    self.removeLayer(layer, True)

        self._disable_enter_attribute_values_dialog_global_default = QSettings().value(
            "/qgis/digitizing/disable_enter_attribute_values_dialog")

        self.actions['config'] = QAction(QIcon(":/plugins/telemetrylayer/icon.png"), u"Configure",
                                         self._iface.legendInterface())

        self.actions['pause'] = QAction(
            QIcon(":/plugins/telemetrylayer/icon.png"),
            "Pause", self._iface.legendInterface())

        self.actions['resume'] = QAction(
            QIcon(":/plugins/telemetrylayer/icon.png"),
            "Resume", self._iface.legendInterface())

        self._iface.legendInterface().addLegendLayerAction(self.actions['resume'], self.menuName, u"id1",
                                                           QgsMapLayer.VectorLayer, False)
        self._iface.legendInterface().addLegendLayerAction(self.actions['config'], self.menuName, u"id1",
                                                           QgsMapLayer.VectorLayer, False)
        self._iface.legendInterface().addLegendLayerAction(self.actions['pause'], self.menuName, u"id1",
                                                           QgsMapLayer.VectorLayer, False)

        # self.actions['resume'].setEnabled(False)

        QgsMapLayerRegistry.instance().layerWillBeRemoved.connect(
            self.layerWillBeRemoved)  # change to when layer is loaded also!

        self._iface.legendInterface().currentLayerChanged.connect(
            self.currentLayerChanged)  # change to when layer is loaded also!
        self._iface.mapCanvas().renderStarting.connect(self.renderStarting)

        QgsProject.instance().readProject.connect(self.readProject)
        QgsProject.instance().readMapLayer.connect(self.readMapLayer)

        QgsProject.instance().layerLoaded.connect(self.layerLoaded)

        mw = self._iface.mainWindow()
        self.lgd = mw.findChild(QTreeView, "theLayerTreeView")
        self.lgd.clicked.connect(self.legendPressed)
        self.lgd.doubleClicked.connect(self.legendDblClicked)
        self._iface.legendInterface().groupRelationsChanged.connect(self.legendRelationsChanged)

        for layer in layers:
            layer.triggerRepaint()

        layerManager._this = self
Esempio n. 6
0
    def __init__(self, creator):
        Log.debug('init Layer Manager')
        super(layerManager, self).__init__()
        self._creator = creator
        self._iface = creator.iface
        self._plugin_dir = creator.plugin_dir
        self.disableDialog = False
        self.actions = {}
        self.menuName = Settings.getMeta('name')
        self._tLayers = {}
        self._featureDocks = {}
        layerManager._rebuildingLegend = False
        QgsProject.instance().readProject.connect(self._showFeatureDocks)
        #        QgsProject.instance().writeProject.connect(self.tearDownDocks)
        QgsProject.instance().writeMapLayer.connect(self._writeMapLayer)

        layers = layerManager.getLayers()
        if len(layers) > 0:  # Existing layers
            for layer in layers:
                if self.initLayer(layer) is None:
                    self.removeLayer(layer, True)

        self._disable_enter_attribute_values_dialog_global_default = QSettings(
        ).value("/qgis/digitizing/disable_enter_attribute_values_dialog")

        self.actions['config'] = QAction(
            QIcon(":/plugins/telemetrylayer/icon.png"), u"Configure",
            self._iface.legendInterface())

        self.actions['pause'] = QAction(
            QIcon(":/plugins/telemetrylayer/icon.png"), "Pause",
            self._iface.legendInterface())

        self.actions['resume'] = QAction(
            QIcon(":/plugins/telemetrylayer/icon.png"), "Resume",
            self._iface.legendInterface())

        self._iface.legendInterface().addLegendLayerAction(
            self.actions['resume'], self.menuName, u"id1",
            QgsMapLayer.VectorLayer, False)
        self._iface.legendInterface().addLegendLayerAction(
            self.actions['config'], self.menuName, u"id1",
            QgsMapLayer.VectorLayer, False)
        self._iface.legendInterface().addLegendLayerAction(
            self.actions['pause'], self.menuName, u"id1",
            QgsMapLayer.VectorLayer, False)

        # self.actions['resume'].setEnabled(False)

        QgsMapLayerRegistry.instance().layerWillBeRemoved.connect(
            self.layerWillBeRemoved)  # change to when layer is loaded also!

        self._iface.legendInterface().currentLayerChanged.connect(
            self.currentLayerChanged)  # change to when layer is loaded also!
        self._iface.mapCanvas().renderStarting.connect(self.renderStarting)

        QgsProject.instance().readProject.connect(self.readProject)
        QgsProject.instance().readMapLayer.connect(self.readMapLayer)

        QgsProject.instance().layerLoaded.connect(self.layerLoaded)

        mw = self._iface.mainWindow()
        self.lgd = mw.findChild(QTreeView, "theLayerTreeView")
        self.lgd.clicked.connect(self.legendPressed)
        self.lgd.doubleClicked.connect(self.legendDblClicked)
        self._iface.legendInterface().groupRelationsChanged.connect(
            self.legendRelationsChanged)

        for layer in layers:
            layer.triggerRepaint()

        layerManager._this = self
Esempio n. 7
0
 def _help(self):
     webbrowser.open(Settings.getMeta('helpURL'))
 def freshInstall(self):
     version = Settings.get('version')
     current = Settings.getMeta('version')
     return current != version
    def about(self):

        webbrowser.open(Settings.getMeta("homepage"))
 def freshInstall(self):
     version = Settings.get('version')
     current = Settings.getMeta('version')
     return current != version
    def about(self):

        webbrowser.open(Settings.getMeta("homepage"))
Esempio n. 12
0
 def _help(self):
     webbrowser.open(Settings.getMeta('helpURL'))