forked from esc-unil/Visualist
-
Notifications
You must be signed in to change notification settings - Fork 0
/
visualist_main.py
97 lines (76 loc) · 3.5 KB
/
visualist_main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
"""
/***************************************************************************
Visualist
A QGIS plugin
Plugin for Crime Analysts
Generated by Plugin Builder: http://g-sherman.github.io/Qgis-Plugin-Builder/
-------------------
begin : 2019-04-15
copyright : (C) 2019 by Quentin Rossy
email : quentin.rossy@unil.ch
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
"""
__author__ = 'Quentin Rossy'
__date__ = '2019-04-15'
__copyright__ = '(C) 2019 by Quentin Rossy'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
import os
import sys
import inspect
import yaml
from qgis.PyQt.QtCore import QSettings, QTranslator, qVersion, QCoreApplication, Qt
from qgis.core import QgsProcessingAlgorithm, QgsApplication, QgsMessageLog, QgsSettings
from .visualist_provider import VisualistProvider
from . import resources
cmd_folder = os.path.split(inspect.getfile(inspect.currentframe()))[0]
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
# for alg in QgsApplication.processingRegistry().algorithms():
# feedback.pushInfo("{}:{} --> {}".format(alg.provider().name(), alg.name(), alg.displayName()))
#Convenient function to debug
NAME = "Visualist"
log = lambda m: QgsMessageLog.logMessage(m, NAME)
class VisualistPlugin(object):
def __init__(self):
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value('locale/userLocale')[0:2]
log('Locale: {}'.format(locale))
log('Plugin directory: {}'.format(self.plugin_dir))
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'visualist_{}.qm'.format(locale))
log('Translation file: {}'.format(locale_path))
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
log('Translator added')
#Store settings used by the plugin
s = QgsSettings()
s.setValue("visualist/homepage", "https://ipsac2.unil.ch/main/")
yaml_path = os.path.join(
self.plugin_dir,'visualist.yaml')
yaml_stream = open(yaml_path, 'r')
yaml_document = yaml.safe_load(yaml_stream)
for helper in yaml_document:
s.setValue("visualist/help/"+helper, yaml_document[helper])
#initialize provider
self.provider = VisualistProvider()
def initGui(self):
QgsApplication.processingRegistry().addProvider(self.provider)
def unload(self):
QgsApplication.processingRegistry().removeProvider(self.provider)