def __init__(self, iface): """Constructor. :param iface: An interface instance that will be passed to this class which provides the hook by which you can manipulate the QGIS application at run time. :type iface: QgsInterface """ global haz, ecat, imp, eatt, evaluation, indicators, rapi, first, haz_cat, rlayers # Save reference to the QGIS interface self.iface = iface # initialize plugin directory self.plugin_dir = os.path.dirname(__file__) self.cache_dir = os.path.dirname(__file__)+'/rapi_cache' # initialize locale locale = QSettings().value('locale/userLocale')[0:2] locale_path = os.path.join(self.plugin_dir,'i18n','rasor_{}.qm'.format(locale)) if os.path.exists(locale_path): self.translator = QTranslator() self.translator.load(locale_path) if qVersion() > '4.3.3': QCoreApplication.installTranslator(self.translator) # Create the dialog (after translation) and keep reference self.dlg = rasorDialog() self.dlg_down = rasorDownDialog() # Declare instance attributes self.actions = [] self.menu = self.tr(u'&Rasor Plugin') # TODO: We are going to let the user set this up in a future iteration self.toolbar = self.iface.addToolBar(u'rasor') self.toolbar.setObjectName(u'rasor') # Get RASOR info on QGIS startup (load plugin) if first: # Saved user preferences (server) server=rapi.load_file(self.cache_dir+'/server') rapi.set_server(server) first=0 # Saved impacts/hazards/exposures/attributes/values (optional, cache, only download if internet access) online=rapi.check_connection() if online==True: print 'ONLINE: Downloading metadata from RASOR platform' else: print 'OFFLINE: You will not be able to upload/download layers to the platform' imp=rapi.download_json(self.cache_dir+'/impact_types.json','/rasorapi/db/impact/types', online) haz=rapi.download_json(self.cache_dir+'/hazard_types.json','/rasorapi/db/hazard/hazards', online) ecat=rapi.download_json(self.cache_dir+'/exposure_categories.json','/rasorapi/db/exposure/categories', online) eatt=rapi.download_json(self.cache_dir+'/exposure_attributes.json','/rasorapi/db/exposure/attributes', online) evaluation=rapi.download_json(self.cache_dir+'/exposure_values.json','/rasorapi/db/exposure/valuesdecode', online) indicators=rapi.download_json(self.cache_dir+'/indicators.json','/rasorapi/db/impact/indicators', online) rlayers=rapi.download_json(self.cache_dir+'/rasor_layers.json','/api/layers', online) # Saved hazard evaluations haz_cat={} for elem in ecat['objects']: haz_cat[str(elem['id'])]=rapi.download_json(self.cache_dir+'/haz_cat'+str(elem['id'])+'.json','/rasorapi/db/hazard/hazardsattributes/?category='+str(elem['id']), online)
def setUp(self): """Runs before each test.""" self.dialog = rasorDialog(None)