def change_i18n(self, new_lang): """Change internationalisation for the plugin. Override the system locale and then see if we can get a valid translation file for whatever locale is effectively being used. """ #os.environ["LANG"] = str(new_lang) root = os.path.abspath( os.path.join(os.path.dirname(__file__), os.pardir)) translation_path = os.path.join( root, self.name, I18N_FOLDER, self.name + "_" + str(new_lang) + ".qm") if os.path.exists(translation_path): self.translator = QTranslator() result = self.translator.load(translation_path) if not result: error( "Translation file {} for lang {} was not loaded properly," + "falling back to English".format(translation_path, new_lang)) return if qVersion() > "4.3.3": QCoreApplication.installTranslator(self.translator) else: self.translator = None warn("Translation not supported for Qt <= {}".format( qVersion())) else: if new_lang != "en": warn("Translation failed for lang {}, falling back to English". format(new_lang))
def change_i18n(self, new_lang): """Change internationalisation for the plugin. Override the system locale and then see if we can get a valid translation file for whatever locale is effectively being used. """ #os.environ["LANG"] = str(new_lang) root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir)) translation_path = os.path.join( root, self.name, I18N_FOLDER, self.name+"_" + str(new_lang) + ".qm") if os.path.exists(translation_path): self.translator = QTranslator() result = self.translator.load(translation_path) if not result: error( "Translation file {} for lang {} was not loaded properly," + "falling back to English".format(translation_path, new_lang) ) return if qVersion() > "4.3.3": QCoreApplication.installTranslator(self.translator) else: self.translator = None warn("Translation not supported for Qt <= {}".format(qVersion())) else: if new_lang != "en": warn("Translation failed for lang {}, falling back to English".format(new_lang))
def getLayerFromId(layerId): try: layer = QgsMapLayerRegistry.instance().mapLayers()[layerId] return layer except: warn("Could not get layer for id {}".format(layerId)) return None
def currentBCYearChanged(self): val = self.bcdateSpinBox.text() try: bcdate = bcdate_util.BCDate.from_str(val, strict_zeros=False) self.signalCurrentTimeUpdated.emit(val) except: warn("Invalid bc date: {}".format(val)) # how to mark as such? return
def _get_years_from_timedelta(self, td): try: return td.years except Exception, e: # FIXME v.1.7 what about offset? msg = "BC dates can only be used with year intervals, found {}".format(td) warn(msg) return 0
def show(self): idsToIgnore = set(self.getIdsAlreadyInOutTable()) allRasterIds = set(qgs.getAllLayerIds(lambda x: qgs.isRaster(x))) self.clear() try: self.populate(allRasterIds - idsToIgnore) except Exception, e: warn(e) return
def show(self): self.clear() idsToIgnore = set(self.get_ids_already_in_out_table()) allVectorIds = set(qgs.getAllLayerIds(lambda x: not qgs.isRaster(x))) try: self.populate(allVectorIds - idsToIgnore) except Exception, e: warn(e) return
def _get_years_from_timedelta(self, td): try: return td.years except Exception, e: # FIXME v.1.7 what about offset? msg = "BC dates can only be used with year intervals, found {}".format( td) warn(msg) return 0
def getLayerAttributes(layerId): try: layer = QgsMapLayerRegistry.instance().mapLayers()[layerId] fieldmap = layer.pendingFields() # TODO figure out what to do for fields with # fieldmap.fieldOrigin(idx) = QgsFields.OriginEdit/OriginExpression return fieldmap except: # OpenLayers, Raster layers don't work with this warn("Could not get attributes of layer {}".format(layerId)) return None
def vals_to_dt(vals, fmt): res = [] for val in vals: try: dt = time_util.timeval_to_datetime(val, fmt) res.append(dt) # info("{} converted to {}".format(val, dt)) except Exception, e: warn( "Unparseable value {} in layer {} ignored. Cause {}" .format(val, self.layer.name(), e)) pass
def vals_to_dt(vals, fmt): res = [] for val in vals: try: dt = timeval_to_datetime(val, fmt) res.append(dt) # info("{} converted to {}".format(val, dt)) except Exception, e: warn("Unparseable value {} in layer {} ignored. Cause {}".format(val, self.layer.name(), e)) pass
def show(self): """Update GUI elements and show the dialog""" self.clear() # determine which layers are vector and can be time controlled idsToIgnore = set(self.getIdsAlreadyInOutTable()) allVectorIds = set(qgs.getAllLayerIds(lambda x: not qgs.isRaster(x))) unsupportedVectorIds = set(qgs.getAllLayerIds(lambda x: qgs.isWFS(x))) # todo: plugin layers, e.g. from QuickMapServices should also be excluded try: self.populate(allVectorIds - idsToIgnore - unsupportedVectorIds) except Exception, e: warn(e) return
def setTimeFrameType(self, timeFrameType): """set timeLayerManager's time frame type from a potentially foreign languange string""" ctx = self.guiControl.dock.objectName() for frame_type in ['microseconds', 'milliseconds', 'seconds', 'minutes', 'hours', 'years', 'months', 'weeks', 'days']: if self.isEqualToUntranslatedString(timeFrameType, frame_type, context=ctx): self.timeLayerManager.setTimeFrameType(frame_type) self.guiControl.refreshMapCanvas('setTimeFrameType') if self.isEqualToUntranslatedString(timeFrameType, "microseconds", ctx) or \ self.isEqualToUntranslatedString(timeFrameType, "milliseconds", ctx): QMessageBox.information(self.iface.mainWindow(), 'Information', "Microsecond and millisecond support works best when the input data " "contains millisecond information (ie, a decimal part)") return warn("Unrecognized time frame type : {}".format(timeFrameType))