forked from apryet/Qgridder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgridder_dialog_settings.py
211 lines (160 loc) · 6.55 KB
/
qgridder_dialog_settings.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# -*- coding: utf-8 -*-
"""
/***************************************************************************
qgridder_dialog_settings.py
Qgridder - A QGIS plugin
This file handles Qgridder graphical user interface
Qgridder Builds 2D regular and unstructured grids and comes together with
pre- and post-processing capabilities for spatially distributed modeling.
-------------------
begin : 2013-04-08
copyright : (C) 2013 by Pryet
email : alexandre.pryet@ensegid.fr
***************************************************************************/
/***************************************************************************
* *
* 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 PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgridder_dialog_base import QGridderDialog
from ui_qgridder_settings import Ui_QGridderSettings
import ftools_utils
class QGridderDialogSettings(QGridderDialog, Ui_QGridderSettings):
"""
Qgridder settings dialog class
"""
def __init__(self,iface, settings):
"""
Description
-----------
Initialize settings window
"""
# Set up the user interface
QDialog.__init__(self)
self.iface = iface
self.settings = settings
self.setupUi(self)
self.proj = QgsProject.instance()
# Connect buttons
QObject.connect(self.buttonBrowseModelSrcDir, SIGNAL("clicked()"), self.browse_model_src_dir)
QObject.connect(self.buttonBrowseObsDir, SIGNAL("clicked()"), self.browse_obs_dir)
QObject.connect(self.buttonBrowseSimulFile, SIGNAL("clicked()"), self.browse_simul_file)
QObject.connect(self.buttonOK, SIGNAL("clicked()"), self.commit_changes)
QObject.connect(self.buttonCancel, SIGNAL("clicked()"), self.exit)
# Populate model type list
model_types = self.settings.model_types
for model_type in self.settings.model_types :
self.listModelTypes.addItem(unicode(model_type))
# update dialog from settings
self.load_settings_to_dialog()
def load_settings_to_dialog(self):
# Populate model name list
self.populate_layer_list(self.listGridLayer)
# (re)load settings
# self.settings.load_settings(self.proj)
# load settings
model_type = self.settings.dic_settings['model_type']
obs_dir = self.settings.dic_settings['obs_dir']
simul_file = self.settings.dic_settings['simul_file']
model_src_dir = self.settings.dic_settings['model_src_dir']
simul_start_date = self.settings.dic_settings['simul_start_date']
support_grid_layer_name = self.settings.dic_settings['support_grid_layer_name']
plot_obs = self.settings.dic_settings['plot_obs']
plot_simul = self.settings.dic_settings['plot_simul']
grid_backup = self.settings.dic_settings['grid_backup']
self.listModelTypes.setCurrentIndex(self.listModelTypes.findText(model_type))
self.listGridLayer.setCurrentIndex(self.listGridLayer.findText(support_grid_layer_name))
self.textObsDir.setText(str(obs_dir))
self.textModelDir.setText(str(model_src_dir))
self.textSimulStartDate.setText(str(simul_start_date))
self.textSimulFile.setText(str(simul_file))
if plot_obs == 'True' :
self.checkPlotObs.setChecked( True )
else :
self.checkPlotObs.setChecked( False )
if plot_simul == 'True' :
self.checkPlotSimul.setChecked( True )
else :
self.checkPlotSimul.setChecked( False )
if grid_backup == 'True' :
self.checkGridBackup.setChecked( True )
else :
self.checkGridBackup.setChecked( False )
def browse_simul_file(self):
"""
Description
----------
Select simulation file. This file will be used to load simulation results.
Note that this is model-dependent.
"""
self.textSimulFile.clear()
( simul_file, encoding ) = ftools_utils.openDialog( self, filtering="All files (*.*)" )
if simul_file is None or encoding is None:
return
self.textSimulFile.setText( simul_file )
def browse_obs_dir(self):
"""
Description
----------
Select observation directory which contains CSV observations files
"""
self.textObsDir.clear()
( obs_dir, encoding ) = ftools_utils.dirDialog( self )
if obs_dir is None or encoding is None :
return
self.textObsDir.setText( obs_dir )
def browse_model_src_dir(self):
"""
Description
----------
Select path to model python modules (e.g. Flopy)
"""
self.textModelDir.clear()
( model_src_dir, encoding ) = ftools_utils.dirDialog( self )
if model_src_dir is None or encoding is None :
return
self.textModelDir.setText( model_src_dir )
def commit_changes(self):
"""
Description
----------
Save changes to project instance and close settings
"""
dic_settings = self.settings.dic_settings.copy()
dic_settings['model_type'] = str(self.listModelTypes.currentText())
dic_settings['obs_dir'] = str(self.textObsDir.text())
dic_settings['simul_file'] = str(self.textSimulFile.text())
dic_settings['simul_start_date'] = str(self.textSimulStartDate.text())
dic_settings['model_src_dir'] = str(self.textModelDir.text())
dic_settings['support_grid_layer_name'] = str(self.listGridLayer.currentText())
dic_settings['plot_obs'] = str(self.checkPlotObs.isChecked())
dic_settings['plot_simul'] = str(self.checkPlotSimul.isChecked())
dic_settings['grid_backup'] = str(self.checkGridBackup.isChecked())
QMessageBox.information(self, self.tr("Gridder"),
self.tr(" dic_settings grid_backup" + str(dic_settings['grid_backup']) )
)
# update self.settings.dic_settings
self.settings.update_settings(dic_settings)
QMessageBox.information(self, self.tr("Gridder"),
self.tr(" self. dic_settings grid_backup" + str(self.settings.dic_settings['grid_backup']) )
)
# save settings to project
self.settings.save_settings(self.proj)
QMessageBox.information(self, self.tr("Gridder"),
self.tr("reloaded self. dic_settings grid_backup" + str(self.settings.dic_settings['grid_backup']) )
)
self.reject()
def exit(self):
"""
Description
----------
Close settings without saving
"""
self.reject()