-
Notifications
You must be signed in to change notification settings - Fork 3
/
feature_import.py
421 lines (375 loc) · 13.2 KB
/
feature_import.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
"""
This python module import the following features
: QCombobox feature and it's associated label name
: QlineEditor feature and its associated label name
"""
from PyQt5.QtGui import QFont, QPixmap
# from qgis.utils import iface
from qgis.core import QgsProject
from PyQt5 import QtGui, QtCore
import os
# from .help_function import save_config_msg
from .clear_features import hide_all_combo_list, clear_all_label
# from .help_function import welcome_msg
def update_file_path(filename, list_of_roi_names):
"""
This function is used to update the layer path name once ROI is used
The name of the layer will be replaced by the clipped name
"""
oldname = [a for a in filename.split("\\")][-1]
ext = oldname.split(".")[-1]
newname = (
[b for b in list_of_roi_names if oldname.split(".")[0] in b][0] + "." + str(ext)
)
# print('oldname {} '.format(oldname))
maxreplace = 1
result = newname.join(filename.rsplit(oldname, maxreplace))
return result
def dynamic_qeditor(label, X1, Y1):
"""
This function create dynamic QLineEditor which is then move into X1,Y1 position.
"""
label.move(X1, Y1)
return
def dynamic_label(Sill_Msg, label, X1, Y1):
"""
This function create dynamic QLabel which is then move into X1,Y1 position.
:Sill_Msg: Label name that could explain the meaning of the value to enter into the QlineEditor.
:label: qt label name, i.e .self.sill_label.
:X1,Y1 is the (x,y) coordinate of the label feature into Qt MainWindow.
"""
label.setText(Sill_Msg)
label.setFont(QFont("Sanserif", 10))
label.move(X1, Y1)
def label_mover(self, geol_comboHeader):
"""
This function create dynamic label which is then move into X1,Y1*idx position.
: The label break is to constraint empty label into Qt framework.
"""
self.label_list = [
self.moving_Label_1,
self.moving_Label_2,
self.moving_Label_3,
self.moving_Label_4,
self.moving_Label_5,
self.moving_Label_6,
self.moving_Label_7,
self.moving_Label_8,
self.moving_Label_9,
self.moving_Label_10,
]
for idx, combo_elt in enumerate(geol_comboHeader):
self.label_list[idx].setText(geol_comboHeader[idx])
self.label_list[idx].setFont(QFont("Sanserif", 10))
if idx == len(geol_comboHeader) - 1:
break
def qline_and_label_mover(X1, Y1, X2, Y2, msg1, label1, label2):
"""
This function is a purpose built to move both Qlabel and QLineEditor.
"""
dynamic_label(msg1, label1, X1, Y1)
dynamic_qeditor(label2, X2, Y2)
def qlineeditor_default_string(self, string1, string2):
"""
This function enter default string value into QLineEditor.
"""
self.Sill_LineEditor.setText(str(string1))
self.Intrusion_LineEditor.setText(str(string2))
def welcoming_image(self, flag):
"""
This function is used to show the welcome image for flag variable equal to 1.
This code sets an image file as the background of a label widget in a PyQt5 application.
It starts by defining the base directory and the image file path, and then sets the image as the background of the label.
The image is then scaled to fit the label while keeping its aspect ratio and is set as the pixmap of the label.
The scaled contents are set to false to meet image ratio versus label ratio.
"""
if flag == 1:
BASE_DIR = os.path.dirname(__file__)
Image_path = str(BASE_DIR) + "/ImageMapToLoop.png"
self.ImageLabel.setStyleSheet(
"background-image : url(" + str(Image_path) + ");border : 0.5px solid blue"
)
self.pixmap = QPixmap(str(Image_path)).scaled(
self.ImageLabel.size(),
QtCore.Qt.KeepAspectRatio,
QtCore.Qt.SmoothTransformation,
)
self.ImageLabel.setPixmap(self.pixmap)
self.ImageLabel.setScaledContents(False)
else:
self.ImageLabel.hide()
def save_activator(self, flag):
"""
This function is used to activate the save button)
"""
if flag == 0:
self.Map2Loop_Button.setEnabled(False)
self.Saveconfig_pushButton.setEnabled(False)
self.LoopStructural_Button.setEnabled(False)
elif flag == 1:
self.Map2Loop_Button.setVisible(True)
self.Saveconfig_pushButton.setVisible(True)
self.LoopStructural_Button.setVisible(True)
else:
pass
def icon_indexer(self):
"""
This function is used to append the icon to the QPushButton
"""
BASE_DIR = os.path.dirname(__file__)
Image_path = str(BASE_DIR) + "/Icon/"
list_of_images = [
"project.png",
"geol.png",
"fault.png",
"struct.png",
"orient.png",
"dtm.png",
"roi.png",
"dh.png",
"section.png",
"fold.png",
"config.png",
]
items = [
self.PrjImage,
self.GeolButton,
self.FaultButton,
self.StructButton,
self.OrientationButton,
self.DTMButton,
self.ROIButton,
self.DrillholesButton,
self.SectionsButton,
self.FoldButton,
self.ConfigButton,
]
for idx, label in enumerate(items):
if idx == 0:
label.setPixmap(QPixmap(str(Image_path) + str(list_of_images[idx])))
label.setScaledContents(True)
else:
label.setIcon(QtGui.QIcon(str(Image_path) + str(list_of_images[idx])))
label.setStyleSheet("QPushButton { text-align: left; }")
# label.setLayoutDirection(QtCore.Qt.RightToLeft) #RightToLeft #LeftToRight
# self.GeolButton.setIcon(QtGui.QIcon(str(Image_path)+'geol.png'))
def list_all_layers(self):
"""
This function return the list of layers availaible in qgis-layer panel
"""
layers_list = QgsProject.instance().mapLayers().values()
names = [layer.name() for layer in layers_list]
paths = [name.dataProvider().dataSourceUri() for name in layers_list]
self.layer_dict = dict(zip(names, paths))
self.objec_dict = dict(zip(names, layers_list))
if (
self.sender().objectName() == "Qgis_checkBox"
and self.GeolButton.isEnabled() == True
and self.sender_name == "GeolButton"
):
names = [
a.name()
for a in layers_list
if type(a).__name__ == "QgsVectorLayer" and a.wkbType() == 6
]
elif (
self.sender().objectName() == "Qgis_checkBox"
and self.FaultButton.isEnabled() == True
and self.sender_name == "FaultButton"
):
names = [
a.name()
for a in layers_list
if type(a).__name__ == "QgsVectorLayer" and a.wkbType() == 5
]
elif (
self.sender().objectName() == "Qgis_checkBox"
and self.StructButton.isEnabled() == True
and self.sender_name == "StructButton"
):
names = [
a.name()
for a in layers_list
if type(a).__name__ == "QgsVectorLayer"
and a.wkbType() == 1
or type(a).__name__ == "QgsVectorLayer"
and a.wkbType() == 1001
]
elif (
self.sender().objectName() == "Qgis_checkBox"
and self.DTMButton.isEnabled() == True
):
names = [a.name() for a in layers_list if type(a).__name__ == "QgsRasterLayer"]
else:
pass
self.Qgis_comboBox.addItems(names)
return self.layer_dict, self.objec_dict
def activate_config_file(self):
"""
This function activate the Save Config File Qpushbutton only when the dtm,geol,struct,and fault parameters are all saved.
"""
try:
if (
self.Geology_checkBox.isChecked() == True
and self.Fault_checkBox.isChecked() == True
and self.Structure_checkBox.isChecked() == True
and self.DTM_checkBox.isChecked() == True
and self.folder_name == "FolderSearch_Button"
):
self.Saveconfig_pushButton.setEnabled(True)
else:
self.Saveconfig_pushButton.setEnabled(False)
except:
pass
return
def activate_loader_checkbox(self, flag):
"""
This function activate and desactivate(greyed it or disabled it) the Load layer tick box all saved.
# flag =0: to setEnabled to False
# flag =1: to setEnabled to True
"""
try:
L = [
self.Geology_checkBox,
self.Fault_checkBox,
self.Structure_checkBox,
self.DTM_checkBox,
]
if flag == 0:
for i in range(len(L)):
L[i].setEnabled(False)
else:
for i in range(len(L)):
L[i].setEnabled(True)
except:
pass
return
def reset_all_features(self):
"""
This method resets all the features.
The code define a method called "reset_all_features" for an object (presumably a GUI element) in Python.
The method uncheck four checkboxes Geology_checkBox, Fault_checkBox, Structure_checkBox, DTM_checkBox
and enable it associated pushbutton FaultButton, GeolButton, StructButton, DTMButton, respectively.
"""
# Loader Checkbox options
self.Qgis_checkBox.setChecked(False)
self.Aus_checkBox.setChecked(False)
self.File_checkBox.setChecked(False)
self.Http_checkBox.setChecked(False)
self.Qgis_comboBox.clear()
self.Qgis_comboBox.setVisible(False)
self.Ok_pushButton.setVisible(False)
# Main option checkbox
self.Geology_checkBox.setChecked(False)
self.Fault_checkBox.setChecked(False)
self.Structure_checkBox.setChecked(False)
self.DTM_checkBox.setChecked(False)
try:
if self.reset_flag == "File_checkBox":
self.ImageLabel.setVisible(True)
welcoming_image(self, 1)
self.close()
except:
pass
return
def set_to_tristate(label):
"""
This function set to tristate any checkbox
"""
if label.isCheckable():
label.setTristate(True)
return
def reset_after_run(self):
"""
This function reset the all pyqt features
"""
hide_all_combo_list(self, 0)
self.CRS_LineEditor.setVisible(False)
self.CRS_label.setVisible(False)
self.SearchFolder.clear()
# reset all checkbox and reactivate all pushbutton
self.GeolButton.setEnabled(True)
self.FaultButton.setEnabled(True)
self.StructButton.setEnabled(True)
self.DTMButton.setEnabled(True)
# reset all checkbox pushbutton
reset_all_features(self)
# reset all checkbox
clear_all_label(self)
def qpush_desactivator(self, flag):
"""
This function enable qpush based on some permutations.
"""
try:
list = [self.GeolButton, self.FaultButton, self.StructButton]
clist = [self.Geology_checkBox, self.Fault_checkBox, self.Structure_checkBox]
if flag == "GeolButton":
try:
if len(self.a) == 2:
list = self.a
clist = self.b
if len(self.a) == 1:
self.DTMButton.setEnabled(True)
except:
pass
self.a = list
self.b = clist
for val, cval in zip(self.a, self.b):
if cval.isChecked() == True:
val.setEnabled(False)
else:
val.setEnabled(True)
self.GeolButton.setEnabled(False)
if self.Fault_checkBox.isChecked() == True:
self.FaultButton.setEnabled(False)
if self.Struct_checkBox.isChecked() == True:
self.StructButton.setEnabled(False)
return self.a, self.b
elif flag == "FaultButton":
try:
if len(self.a) == 2:
list = self.a
clist = self.b
if len(self.a) == 1:
self.DTMButton.setEnabled(True)
except:
pass
self.a = list
self.b = clist
for val, cval in zip(self.a, self.b):
if cval.isChecked() == True:
val.setEnabled(False)
else:
val.setEnabled(True)
self.FaultButton.setEnabled(False)
if self.Struct_checkBox.isChecked() == True:
self.StructButton.setEnabled(False)
if self.Geology_checkBox.isChecked() == True:
self.GeolButton.setEnabled(False)
return self.a, self.b
elif flag == "StructButton":
try:
if len(self.a) == 2:
list = self.a
clist = self.b
if len(self.a) == 1:
self.DTMButton.setEnabled(True)
except:
pass
self.a = list
self.b = clist
for val, cval in zip(self.a, self.b):
if cval.isChecked() == True:
val.setEnabled(False)
else:
val.setEnabled(True)
self.StructButton.setEnabled(False)
if self.Fault_checkBox.isChecked() == True:
self.FaultButton.setEnabled(False)
if self.Geology_checkBox.isChecked() == True:
self.GeolButton.setEnabled(False)
return self.a, self.b
except:
pass
# print('passed the fault stage')
return