-
Notifications
You must be signed in to change notification settings - Fork 4
/
envdialog.py
108 lines (86 loc) · 4.07 KB
/
envdialog.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
98
99
100
101
102
103
104
105
106
107
108
# -*- coding: utf-8 -*-
"""
/***************************************************************************
EnvDialog
A QGIS plugin
FSC QGIS plugin for biological recorders
-------------------
begin : 2014-02-17
copyright : (C) 2014 by Rich Burkmar, Field Studies Council
email : [email protected]
***************************************************************************/
/***************************************************************************
* *
* 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. *
* *
***************************************************************************/
"""
#from ui_env import Ui_Env
#from envmanager import *
from . import ui_env, envmanager
import os.path
import csv
#from PyQt5 import QtCore, QtGui, QtWidgets, QtNetwork
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtNetwork import *
from PyQt5.QtWidgets import *
from qgis import *
from qgis.core import *
from qgis.gui import *
from qgis.utils import *
class EnvDialog(QWidget, ui_env.Ui_Env):
def __init__(self, iface):
QWidget.__init__(self)
ui_env.Ui_Env.__init__(self)
self.setupUi(self)
self.__canvas = iface.mapCanvas()
self.iface = iface
#self.pathPlugin = "%s%s%%s" % ( os.path.dirname( __file__ ), os.path.sep )
self.pathPlugin = os.path.dirname( __file__ )
# Load the environment stuff
self.env = envmanager.envManager()
self.pteEnvironment.setPlainText(self.env.getTextEnv())
self.leExternalEnvFile.setText(self.env.getExternalFilePath())
self.leExternalEnvFile.setEnabled(False)
self.exampleText = self.env.getTextExample()
self.pteExample.setPlainText(self.exampleText)
self.pbSaveToNewEnvFile.clicked.connect(self.saveToNewEnvFile)
self.pbExternalEnvFile.clicked.connect(self.browseEnvFile)
self.bbButtons.accepted.connect(self.okayClicked)
self.bbButtons.rejected.connect(self.cancelClicked)
self.pteExample.textChanged.connect(self.editingExample)
def browseEnvFile(self):
dlg = QFileDialog
fileName = dlg.getOpenFileName(self, "Open environment file", "", "Text Files (*.txt)")[0]
if fileName:
self.leExternalEnvFile.setText(fileName)
self.env.setExternalEnvFile(fileName, True)
self.pteEnvironment.setPlainText(self.env.getTextEnv())
def saveToNewEnvFile(self):
dlg = QFileDialog
fileName = dlg.getSaveFileName(self, "Specify location for environment file", "", "Text Files (*.txt)")[0]
if fileName:
self.leExternalEnvFile.setText(fileName)
self.env.setExternalEnvFile(fileName, False)
def editingExample(self):
self.iface.messageBar().pushMessage("Warning", "You are editing the example environment file - changes will not be saved", level=Qgis.Warning, duration=1)
self.pteExample.blockSignals(True)
self.pteExample.setPlainText(self.exampleText)
self.pteExample.blockSignals(False)
def okayClicked(self):
self.env.setTextEnv(self.pteEnvironment.toPlainText())
self.env.saveEnvironment()
self.close()
def cancelClicked(self):
self.pteEnvironment.setPlainText(self.env.getTextEnv())
self.close()
def hideEvent(self, event):
#QWidget.hideEvent(event)
self.visChanged(False)
def visChanged(self, vis):
if vis == False:
self.cancelClicked()