-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathdatabase_ui.py
351 lines (268 loc) · 12.4 KB
/
database_ui.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
# -*- coding: utf-8 -*-
"""
Copyright 2017 Bernard Giroux, Elie Dumas-Lefebvre, Jerome Simon
email: [email protected]
This file is part of BhTomoPy.
BhTomoPy 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 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import time
import os
import sys
from PyQt5 import QtGui, QtWidgets, QtCore
from borehole_ui import BoreholeUI
from database import BhTomoDb
from model_ui import ModelUI
from mog_ui import MOGUI, MergeMog
from utils_ui import MyQLabel, auto_create_scrollbar, save_warning
class DatabaseUI(QtWidgets.QWidget):
def __init__(self, parent=None):
super(DatabaseUI, self).__init__(parent)
self.setWindowTitle("BhTomoPy/Database")
# --- Other Modules Instances --- #
self.db = BhTomoDb()
self.bh = BoreholeUI(self.db)
self.mog = MOGUI(self.db)
self.model = ModelUI(self.db)
self.info = InfoUI()
self.mergemog = MergeMog(self.mog)
self.init_UI()
self.action_list = []
# DatabaseUI receives the signals, which were emitted by different modules, and transmits the signal to the other
# modules in order to update them
self.bh.bhUpdateSignal.connect(self.update_MogUI)
self.bh.bhInfoSignal.connect(self.update_borehole_info)
self.mog.mogInfoSignal.connect(self.update_mog_info)
self.mog.ntraceSignal.connect(self.update_trace_info)
self.model.modelInfoSignal.connect(self.update_model_info)
self.mergemog.mergemoglogSignal.connect(self.update_log)
self.bh.bhlogSignal.connect(self.update_log)
self.mog.moglogSignal.connect(self.update_log)
self.model.modellogSignal.connect(self.update_log)
def update_spectra(self, Tx_list):
self.mog.update_spectra_Tx_num_combo(Tx_list)
self.mog.update_spectra_Tx_elev_value_label(Tx_list)
def update_MogUI(self, list_bh):
self.mog.update_Tx_and_Rx_Widget(list_bh)
def update_database_info(self, name):
self.info.update_database(name)
def update_borehole_info(self, num):
self.info.update_borehole(num)
def update_mog_info(self, num):
self.info.update_mog(num)
def update_model_info(self, num):
self.info.update_model(num)
def update_trace_info(self, num):
self.info.update_trace(num)
def update_log(self, action):
# Clears the log to make sure any action is not written more than once
self.log.clear()
# Appends the time and the action that was done
self.action_list.append("[{}] {} ".format(time.asctime()[11:16], action))
# Shows the Error messages in red and the others in black
for item in self.action_list:
if "Error:" in item:
self.log.setTextColor(QtGui.QColor(QtCore.Qt.red))
self.log.append(item)
else:
self.log.setTextColor(QtGui.QColor(QtCore.Qt.black))
self.log.append(item)
def update_widgets(self):
self.bh.update_list_widget()
self.bh.bh_list.setCurrentRow(0)
self.bh.update_list_edits()
self.mog.update_list_widget()
self.mog.update_edits()
self.mog.MOG_list.setCurrentRow(0)
self.mog.update_spectra_and_coverage_Tx_num_list()
self.mog.update_spectra_and_coverage_Tx_elev_value_label()
self.mog.update_edits()
self.mog.update_prune_edits_info()
self.mog.update_prune_info()
self.model.update_model_list()
self.model.update_model_mog_list()
self.update_database_info(self.db.name)
def show(self, dbname):
super(DatabaseUI, self).show()
if dbname != '':
try:
self.db.load(dbname)
except Exception as e:
QtWidgets.QMessageBox.warning(self, 'Error', str(e))
# Gets initial geometry of the widget:
qr = self.frameGeometry()
# Shows it at the center of the screen
cp = QtWidgets.QDesktopWidget().availableGeometry().center()
# Moves the window's center at the center of the screen
qr.moveCenter(cp)
# Then moves it at the top left
translation = qr.topLeft()
self.move(translation)
self.update_widgets()
def openfile(self): # TODO: On Windows, access to folders containing special characters fails. May be due to the fact that Windows doesn't use Unicode.
if save_warning(self.db):
filename = QtWidgets.QFileDialog.getOpenFileName(self, 'Open Database','','Database (*.h5)')[0]
if filename:
self.db.load(filename)
self.update_database_info(os.path.basename(filename))
self.update_widgets()
self.update_log("Database '{}' was loaded successfully".format(os.path.basename(filename)))
def savefile(self):
try:
if self.db.filename == '':
self.saveasfile()
return
self.db.save()
self.update_log("Database was saved successfully")
QtWidgets.QMessageBox.information(self, 'Success', "Database was saved successfully",
buttons=QtWidgets.QMessageBox.Ok)
except Exception as e:
QtWidgets.QMessageBox.warning(self, 'Warning', "Database could not be saved : " + str(e),
buttons=QtWidgets.QMessageBox.Ok)
def saveasfile(self):
filename = QtWidgets.QFileDialog.getSaveFileName(self, 'Save Database as ...',
filter='Database (*.h5)', )[0]
if filename:
self.db.save(filename)
self.update_database_info(os.path.basename(filename))
self.update_log("Database '{}' was saved successfully".format(os.path.basename(filename)))
def init_UI(self):
# --- Log Widget --- #
self.log = QtWidgets.QTextEdit()
self.log.setReadOnly(True)
self.log.setLineWrapMode(0)
# --- Actions --- #
openAction = QtWidgets.QAction('Open', self)
openAction.setShortcut('Ctrl+O')
openAction.triggered.connect(self.openfile)
saveAction = QtWidgets.QAction('Save', self)
saveAction.setShortcut('Ctrl+S')
saveAction.triggered.connect(self.savefile)
saveasAction = QtWidgets.QAction('Save as', self)
saveasAction.setShortcut('Ctrl+A')
saveasAction.triggered.connect(self.saveasfile)
exportBHAction = QtWidgets.QAction('Export boreholes', self)
exportBHAction.setShortcut('Ctrl+B')
exportBHAction.triggered.connect(self.bh.export_boreholes)
# --- Menubar --- #
self.menu = QtWidgets.QMenuBar()
filemenu = self.menu.addMenu('&File')
filemenu.addAction(openAction)
filemenu.addAction(saveAction)
filemenu.addAction(saveasAction)
filemenu.addAction(exportBHAction)
# --- GroupBoxes --- #
# - Boreholes GroupBox - #
bh_GroupBox = QtWidgets.QGroupBox("Boreholes")
bh_Sub_Grid = QtWidgets.QGridLayout()
bh_Sub_Grid.addWidget(self.bh)
bh_GroupBox.setLayout(bh_Sub_Grid)
# - MOGs GroupBox - #
MOGs_GroupBox = QtWidgets.QGroupBox("MOGs")
MOGs_Sub_Grid = QtWidgets.QGridLayout()
MOGs_Sub_Grid.addWidget(self.mog)
MOGs_GroupBox.setLayout(MOGs_Sub_Grid)
# - Models GroupBox - #
Models_GroupBox = QtWidgets.QGroupBox("Models")
Models_Sub_Grid = QtWidgets.QGridLayout()
Models_Sub_Grid.addWidget(self.model)
Models_GroupBox.setLayout(Models_Sub_Grid)
# - Info GroupBox - #
Info_GroupBox = QtWidgets.QGroupBox("Infos")
Info_Sub_Grid = QtWidgets.QGridLayout()
Info_Sub_Grid.addWidget(self.info)
Info_GroupBox.setLayout(Info_Sub_Grid)
# - Big SubWidget - #
sub_big_widget = QtWidgets.QWidget()
sub_big_grid = QtWidgets.QGridLayout()
sub_big_grid.addWidget(bh_GroupBox, 0, 0, 1, 1)
sub_big_grid.addWidget(MOGs_GroupBox, 0, 1, 1, 3)
sub_big_grid.addWidget(Models_GroupBox, 1, 0, 2, 2)
sub_big_grid.addWidget(Info_GroupBox, 1, 2, 2, 3)
sub_big_grid.setColumnStretch(0, 1)
sub_big_grid.setColumnStretch(1, 1)
sub_big_grid.setColumnStretch(2, 1)
sub_big_widget.setLayout(sub_big_grid)
# - Scroll bar - #
scrollbar = auto_create_scrollbar(sub_big_widget)
# --- Grid --- #
master_grid = QtWidgets.QGridLayout()
master_grid.addWidget(self.menu, 0, 0, 1, 3)
master_grid.addWidget(scrollbar, 1, 0, 1, 3)
master_grid.addWidget(self.log, 2, 0, 2, 3)
master_grid.setContentsMargins(0, 0, 0, 0)
master_grid.setVerticalSpacing(5)
self.setLayout(master_grid)
class InfoUI(QtWidgets.QFrame):
def __init__(self, parent=None):
super(InfoUI, self).__init__()
self.setWindowTitle("BhTomoPy/Info")
self.init_UI()
# ------- Updating the information ------- #
def update_database(self, name):
self.live_database_label.setText(name)
def update_borehole(self, value):
self.num_boreholes_label.setText(str(value))
def update_mog(self, value):
self.num_mogs_label.setText(str(value))
def update_model(self, value):
self.num_models_label.setText(str(value))
def update_trace(self, value):
self.num_traces_label.setText(str(value))
def init_UI(self):
# --- Widget --- #
self.database_label = QtWidgets.QLabel("Database : ")
self.live_database_label = MyQLabel('', ha='left')
self.boreholes_label = QtWidgets.QLabel(" Borehole(s)")
self.num_boreholes_label = MyQLabel('0', ha='right')
self.mogs_label = QtWidgets.QLabel(" MOG(s)")
self.num_mogs_label = MyQLabel('0', ha='right')
self.models_label = QtWidgets.QLabel(" Model(s)")
self.num_models_label = MyQLabel('0', ha='right')
self.traces_label = QtWidgets.QLabel(" Traces")
self.num_traces_label = MyQLabel('0', ha='right')
# --- Grid --- #
master_grid = QtWidgets.QGridLayout()
master_grid.addWidget(self.database_label, 0, 0)
master_grid.addWidget(self.live_database_label, 0, 1)
master_grid.addWidget(self.num_boreholes_label, 2, 0)
master_grid.addWidget(self.boreholes_label, 2, 1)
master_grid.addWidget(self.num_mogs_label, 3, 0)
master_grid.addWidget(self.mogs_label, 3, 1)
master_grid.addWidget(self.num_models_label, 4, 0)
master_grid.addWidget(self.models_label, 4, 1)
master_grid.addWidget(self.num_traces_label, 6, 0)
master_grid.addWidget(self.traces_label, 6, 1)
master_grid.setAlignment(QtCore.Qt.AlignCenter)
self.setLayout(master_grid)
class MyLogWidget(QtWidgets.QTextEdit):
def __init__(self, parent=None):
super(MyLogWidget, self).__init__(parent)
def append(self, txt):
super(MyLogWidget, self).append(txt)
bottom = self.verticalScrollBar().maximum()
self.verticalScrollBar().setValue(bottom)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
Database_ui = DatabaseUI()
Database_ui.show('/Users/giroux/Desktop/sussargues2D.h5')
# Database_ui.update_log("Welcome to BH TOMO Python Edition's Database")
# Database_ui.bh.load_borehole('testData/testConstraints/F3.xyz')
# Database_ui.bh.load_borehole('testData/testConstraints/F2.xyz')
# Database_ui.mog.load_file_MOG('testData/formats/ramac/t0302.rad')
# Database_ui.mog.load_file_MOG('testData/formats/ramac/t0102.rad')
# Database_ui.model.load_model("t0302's model")
# Database_ui.model.load_model("test")
# Database_ui.model.load_model("test2")
# Database_ui.mog.plot_spectra()
# Database_ui.mog.plot_zop()
# Database_ui.saveasfile()
sys.exit(app.exec_())