def setLayerStyle(self, layer): Log.debug("agTankTopicManager setLayerStyle " + os.path.join(self.path(), "rules.qml")) #_path = os.path.join(self.path(), "../") # if not _path in QgsApplication.svgPaths(): # QgsApplication.setDefaultSvgPaths(QgsApplication.svgPaths() + [_path]) self.loadStyle(layer, os.path.join(self.path(), "rules.qml"))
def __init__(self, tbl, row, param, default=None): super(tlTableParamSpinBox, self).__init__(tbl, row, param, default) try: self.min = param['min'] self.max = param['max'] self.int = param['interval'] self.units = param['units'] try: self.step = param['step'] except: self.step = "1" self.control = QtGui.QSpinBox(self.tbl) self.control.setMinimum(int(self.min) - 1) # Qt Bug Min is actual > not >= self.control.setMaximum(int(self.max)) self.control.setSingleStep(int(self.step)) # ??? self.control.setToolTip(self.tooltip) self.control.setSuffix('\x0A' + self.units) self.control.setStyleSheet("padding: 4px") self.control.valueChanged.connect(self.setValue) self._setControl(40) self.control.setValue(int(self.default)) # self.control.valueChanged.connect(self.setDirty) except Exception as e: Log.debug('Error loading parameter widget ' + str(e)) return pass
def register(): Log.debug("File Register") icons = os.path.join(os.path.dirname(__file__), 'icons') if not icons in QgsApplication.svgPaths(): QgsApplication.setDefaultSvgPaths(QgsApplication.svgPaths() + [icons]) pass
def featureUpdated(self,tlayer,feat): try: Log.debug("Feature Updated") self.dockWidget.setWindowTitle(feat['match']) #Log.debug(self.relay.checkState()) #Log.debug(feat['payload']) except Exception as e: Log.debug(str(e))
def _applied(self, client, status = True, msg = None): if status == False: Log.progress("Unable to update device settings - restoring") self._rebuild() else: Log.progress("Configuration updated") Log.debug("Updating Devices") self._topicManager._requestDevices(self._updateBroker) pass
def _rebuild(self,mqtt =None, status = True, msg = None): if not status: Log.progress("There was an error reading the device configurations for this broker: " +str(msg)); return try: topic = self._broker.topic(self._feature['topic']) self._params = topic['params'] self._pTable = agParameterTable(self._tabs.tblParams, self._params) # self._tabs.btnApply.setEnabled(False) except Exception as e: Log.debug("Error loading Configuration tab " + str(e))
def featureUpdated(self, tlayer, feat): try: Log.debug("Feature Updated") self.symbol.setPixmap(ActiveLayerSymbolPixmap(self._layer, feat)) self.dockWidget.setWindowTitle(feat['match']) #Log.debug(self.relay.checkState()) #Log.debug(feat['payload']) if str(self.relay.checkState()) != feat['payload']: self.relay.setChecked(feat['payload'] == "2") except Exception as e: Log.debug(str(e))
def _updateBroker(self,mqtt, status = True, msg = None): Log.debug("_updateBroker! " + str(status)) if not status: Log.warn(msg) return self._topicManager.setDevices(agDeviceList(msg.payload)) self._broker.setTopics(self._topicManager.getTopics()) self._broker.setDirty(True) Brokers.instance().update(self._broker) Brokers.instance().sync(True) Log.debug("Broker updated")
def featureUpdated(self,tlayer,feat): try: Log.debug("Feature Updated") self.symbol.setPixmap(ActiveLayerSymbolPixmap(self._layer,feat)) self.dockWidget.setWindowTitle(feat['match']) #Log.debug(self.relay.checkState()) #Log.debug(feat['payload']) if str(self.relay.checkState()) != feat['payload']: self.relay.setChecked(feat['payload'] == "2") except Exception as e: Log.debug(str(e))
def reload_classx(class_obj): module_name = class_obj.__module__ module = sys.modules[module_name] Log.debug("Reloading modules") for modile_pycfile in get_modules(module): os.remove(os.path.join(os.path.dirname(module.__file__), modile_pycfile)) pycfile = module.__file__ modulepath = pycfile.replace(".pyc", ".py") code = open(modulepath, 'rU').read() compile(code, module_name, "exec") module = reload(module) return getattr(module, class_obj.__name__)
def initGui(self): # Tree Widget test Log.debug("Sample Plugin init") self.iface.newProjectCreated.connect( lambda: TopicManagerFactory.register({'name':"Sample TM",'class':sampleTopicManager}) # Add more as required ) QgsProject.instance().readProject.connect( lambda: TopicManagerFactory.register({'name':"Sample TM",'class':sampleTopicManager}) # Add more as required )
def featureUpdated(self,tlayer,feat): try: # do what you need here. Draw it yourself if required! super(MyFeatureDock,self).featureUpdated(tlayer,feat) Log.debug("MyFeatureDock - featureUpdated: " + str(feat['payload'])) layer = tlayer.layer() fieldId = layer.dataProvider().fieldNameIndex("context") layer.startEditing() layer.changeAttributeValue(feat.id(), fieldId, "fubar") layer.commitChanges() except Exception as e: Log.debug("Error on MyFeatureDock - featureUpdated: " + str(e)) pass
def _lambda(self, x): try: l = self.device.find('Lambda').text # perform regex for paramaters!!! f = eval("lambda " + l) if 'function' in str(type(f)): return f(x) else: return x except TypeError as e: Log.debug('Type Error ' + str(e)) return x except Exception as e: Log.debug(e) return x
def __init__(self, xml): self.devices = {} if xml[0] == '<': Log.debug('Parsing XML from string') self.root = ETree.fromstring(xml) else: try: tree = ETree.parse(xml) self.root = tree.getroot() except Exception as e: Log.debug("Unable to open/parse XML file: " + str(e)) for device in self.root.iter('Device'): _id = device.get('nid') self.devices[_id] = agDevice(device)
def reload_class(class_obj): module_name = class_obj.__module__ module = sys.modules[module_name] Log.debug("Reloading modules") for module_pycfile in get_modules(module): os.remove(os.path.join(os.path.dirname(module.__file__), module_pycfile)) # pycfile = module.__file__ pycfile = module_pycfile modulepath = pycfile.replace(".pyc", ".py") _module_name = pycfile.replace(".py*", "") print "importing " + os.path.join(os.path.dirname(module.__file__), modulepath) code = open(os.path.join(os.path.dirname(module.__file__), modulepath), 'rU').read() compile(code, _module_name, "exec") _module = sys.modules[_module_name] _module = reload(_module) return getattr(module, class_obj.__name__)
def __init__(self, tbl, row, param, default=None): super(tlTableParamCheckBox, self).__init__(tbl, row, param, default) try: self.control = QtGui.QCheckBox(self.tbl) self.control.setToolTip(self.tooltip) self.control.setStyleSheet("padding: 4px") self.control.stateChanged.connect(self.setValue) self.control.setTristate(False); self._setControl(40) self.control.setChecked(self.default == 'On') except Exception as e: Log.debug('Error loading parameter widget ' + str(e)) return pass
def setLabelFormatter(self, layer): # remove topicType try: palyr = QgsPalLayerSettings() palyr.readFromLayer(layer) palyr.enabled = True palyr.fontBold = True # palyr.dataDefinedProperty(QgsPalLayerSettings.DataDefinedProperties.shapeBlendMode) palyr.shapeDraw = True palyr.shapeTransparency = 0 palyr.shapeType = QgsPalLayerSettings.ShapeRectangle palyr.textColor = QColor(255,255,255) # white palyr.placement = QgsPalLayerSettings.OverPoint palyr.quadOffset = QgsPalLayerSettings.QuadrantBelow palyr.multilineAlign = QgsPalLayerSettings.MultiCenter palyr.yOffset = 0.01 palyr.fieldName = '$format_label' palyr.writeToLayer(layer) Log.debug("Palyr Settings updated") except Exception as e: Log.debug("Error setting Label Format " + str(e))
def register(): topicManagers = [] package = TelemetryLayer.topicmanagers for package in get_subpackages(TelemetryLayer.topicmanagers): path = os.path.join(os.path.dirname(TelemetryLayer.topicmanagers.__file__), package) if path not in sys.path: sys.path.append(path) module = None meta = {} Log.debug("Loading topic manager " + package) try: if sys.modules[package]: module = __import__(package) meta = module.classFactory(Settings.getIface()) meta['class'] = reload_class(meta['class']) except AttributeError: pass except Exception as e: if "'" + package + "'" != str(e): Log.debug("Error loading topic manager " + str(e) + ' ' + package) finally: if module is None: module = __import__(package) meta = module.classFactory(Settings.getIface()) meta['id'] = package topicManagers.append(meta) Log.debug("Done") return topicManagers
def __init__(self, tableWidget, params): super(agParameterTable, self).__init__() _params = params self._params =[] tblParam = tableWidget tblParam.horizontalHeader().setVisible(False) tblParam.verticalHeader().setVisible(False) tblParam.clearContents() tblParam.setRowCount(0) tblParam.setShowGrid(True) tblParam.setColumnCount(2) if _params is None or len(_params) == 0: return # Create a table of controls preset with existing values if required try: for param in _params: if 'value' in param: default = param['value'] else: default = param['default'] if param['widget'] == 'slider': self._params.append(tlTableParamSlider(tblParam, tblParam.rowCount(), param, default)) if param['widget'] == 'select': self._params.append(tlTableParamCombo(tblParam, tblParam.rowCount(), param, default)) if param['widget'] == 'spinbox': self._params.append(tlTableParamSpinBox(tblParam, tblParam.rowCount(), param, default)) if param['widget'] == 'checkbox': self._params.append(tlTableParamCheckBox(tblParam, tblParam.rowCount(), param, default)) except KeyError as e: Log.warn("Error parsing configuration parameters " + str(e)) exc_type, exc_value, exc_traceback = sys.exc_info() Log.debug(repr(traceback.format_exception(exc_type, exc_value, exc_traceback)))
def _apply(self): _client = None try: params = {"topic":self._feature['topic']} for key,val in self._pTable: params[key] = val payload = json.dumps(params) request = "agsense/request/set" Log.progress("Updating configuration") _client = tlMqttSingleShot(self, self._broker, request, ["agsense/response/set"], payload, 0, #qos self._applied) _client.run() except Exception as e: Log.debug("Error setting parameter " + str(e)) if _client: _client.kill()
def setLayerStyle(self, layer): if not self.path(tlGenericTopicManager) in QgsApplication.svgPaths(): QgsApplication.setDefaultSvgPaths(QgsApplication.svgPaths() + [self.path(tlGenericTopicManager)]) Log.debug("Loading QML " +os.path.join(self.path(tlGenericTopicManager), "rules.qml")) rules = os.path.join(self.path(tlGenericTopicManager), "rules.qml") self.loadStyle(layer, rules)
def setLayerStyle(self, layer): Log.debug("agTopicManager setLayerStyle " + self.path() + "/agsense.qml") self.loadStyle(layer, os.path.join(self.path(), "agsense.qml"))
def setLayerStyle(self, layer): Log.debug("agTankTopicManager setLayerStyle " + os.path.join(self.path(), "rules.qml")) # _path = os.path.join(self.path(), "../") # if not _path in QgsApplication.svgPaths(): # QgsApplication.setDefaultSvgPaths(QgsApplication.svgPaths() + [_path]) self.loadStyle(layer, os.path.join(self.path(), "rules.qml"))
def register(): if not QgsExpression.isFunctionName("$sample_format_label"): # check to make sure these are not already registered path = os.path.join(os.path.dirname(__file__), 'qgsfuncs.py') Log.debug(path) imp.load_source('qgsfuncs', path)