forked from JanusWind/FC
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjanus_widget_nln_pop.py
384 lines (266 loc) · 11.1 KB
/
janus_widget_nln_pop.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
################################################################################
##
## Janus -- GUI Software for Processing Thermal-Ion Measurements from the
## Wind Spacecraft's Faraday Cups
##
## Copyright (C) 2016 Bennett A. Maruca ([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 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/.
##
################################################################################
################################################################################
## LOAD THE NECESSARY MODULES.
################################################################################
# Load the modules necessary for the graphical interface.
from PyQt4.QtCore import SIGNAL, Qt
from PyQt4.QtGui import QGridLayout, QLabel, QLineEdit, QWidget
# Load the customized push button and one-line text editor.
from janus_event_CheckBox import event_CheckBox
from janus_event_ComboBox import event_ComboBox
from janus_event_LineEdit import event_LineEdit
# Load the necessary "numpy" array modules.
from numpy import tile
# Load the necessary threading modules.
from threading import Thread
from janus_thread import n_thread, thread_chng_nln_pop
################################################################################
## DEFINE THE "widget_nln_ion" CLASS TO CUSTOMIZE "QWidget" FOR NLN ION SPECIES.
################################################################################
class widget_nln_pop( QWidget ) :
#-----------------------------------------------------------------------
# DEFINE THE INITIALIZATION FUNCTION.
#-----------------------------------------------------------------------
def __init__( self, core ) :
# Inherit all attributes of an instance of "QWidget".
super( widget_nln_pop, self ).__init__( )
# Store the Janus core.
self.core = core
# Prepare to respond to signals received from the Janus core.
self.connect( self.core, SIGNAL('janus_chng_nln_ion'),
self.resp_chng_nln_ion )
# Give this widget a grid layout, "self.grd".
self.grd = QGridLayout( )
self.setLayout( self.grd )
# | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
# +-----+-----+-----+-----+-----+-----+-----+-----+
# |Use? |Species |Pop. Name | Sym |Drft?|Anis?|
# |Check| |LineE |LineE|Check|Check|
# Initialize the labels, check boxes, and text areas that
# comprise this widget.
self.hdr_use = QLabel( '' )
self.hdr_ion = QLabel( 'Species' )
self.hdr_name = QLabel( 'Pop. Name' )
self.hdr_sym = QLabel( 'Symbol' )
self.hdr_drift = QLabel( 'Drift' )
self.hdr_aniso = QLabel( 'Aniso' )
self.arr_use = tile( None, self.core.nln_n_pop )
self.arr_ion = tile( None, self.core.nln_n_pop )
self.arr_name = tile( None, self.core.nln_n_pop )
self.arr_sym = tile( None, self.core.nln_n_pop )
self.arr_drift = tile( None, self.core.nln_n_pop )
self.arr_aniso = tile( None, self.core.nln_n_pop )
for i in range( self.core.nln_n_pop ) :
txt_i = str( i )
self.arr_ion[i] = event_ComboBox( self, 'i'+txt_i )
self.arr_name[i] = event_LineEdit( self, 'n'+txt_i )
self.arr_sym[i] = event_LineEdit( self, 's'+txt_i )
self.arr_aniso[i] = event_CheckBox( self, 'a'+txt_i )
if ( i == 0 ) :
continue
self.arr_use[i] = event_CheckBox( self, 'u'+txt_i )
self.arr_drift[i] = event_CheckBox( self, 'd'+txt_i )
# Row by row, add the labels, check boxes, and text areas, to
# this widget's grid.
self.grd.addWidget( self.hdr_use , 0, 0, 1, 1, Qt.AlignCenter )
self.grd.addWidget( self.hdr_ion , 0, 1, 1, 2 )
self.grd.addWidget( self.hdr_name , 0, 3, 1, 2 )
self.grd.addWidget( self.hdr_sym , 0, 5, 1, 1, Qt.AlignCenter )
self.grd.addWidget( self.hdr_drift, 0, 6, 1, 1, Qt.AlignCenter )
self.grd.addWidget( self.hdr_aniso, 0, 7, 1, 1, Qt.AlignCenter )
for i in range( self.core.nln_n_pop ) :
if ( self.arr_use[i] is not None ) :
self.grd.addWidget( self.arr_use[i],
i+1, 0, 1, 1,
Qt.AlignCenter )
if ( self.arr_ion[i] is not None ) :
self.grd.addWidget( self.arr_ion[i],
i+1, 1, 1, 2 )
if ( self.arr_name[i] is not None ) :
self.grd.addWidget( self.arr_name[i],
i+1, 3, 1, 2 )
if ( self.arr_sym[i] is not None ) :
self.grd.addWidget( self.arr_sym[i],
i+1, 5, 1, 1,
Qt.AlignCenter )
if ( self.arr_drift[i] is not None ) :
self.grd.addWidget( self.arr_drift[i],
i+1, 6, 1, 1,
Qt.AlignCenter )
if ( self.arr_aniso[i] is not None ) :
self.grd.addWidget( self.arr_aniso[i],
i+1, 7, 1, 1,
Qt.AlignCenter )
# Regularize the grid spacing.
for i in range( 8 ) :
self.grd.setColumnStretch( i, 1 )
for i in range( self.core.nln_n_pop + 1 ) :
self.grd.setRowStretch( i, 1 )
# Populate the text areas.
self.make_txt( )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR DISPLAYING TEXT AND CHECK MARKS.
#-----------------------------------------------------------------------
def make_txt( self ) :
# Display the parameters for each ion population.
for i in range( self.core.nln_n_pop ) :
# Extract the values from the core.
tmp_use = self.core.nln_pop_use[i]
tmp_ion = self.core.nln_pyon.arr_pop[i]['spec']
tmp_name = self.core.nln_pyon.arr_pop[i]['name']
tmp_sym = self.core.nln_pyon.arr_pop[i]['sym']
tmp_drift = self.core.nln_pyon.arr_pop[i]['drift']
tmp_aniso = self.core.nln_pyon.arr_pop[i]['aniso']
# Construct the list of ion-species names/symbols.
lst_ion = [ str( s['name'] )
for s in self.core.nln_pyon.arr_spec ]
lst_ion = [ '' ]
for s in self.core.nln_pyon.arr_spec :
txt = ''
if ( s['name'] is not None ) :
txt += s['name']
txt += ' ('
if ( s['sym'] is not None ) :
txt += s['sym']
txt += ')'
lst_ion.append( txt )
# Update the text of each each "LineEdit" and "CheckBox"
# widget.
if ( self.arr_use[i] is not None ) :
self.arr_use[i].setChecked( tmp_use )
if ( ( self.arr_name[i] is not None ) and
( tmp_name is not None ) ) :
self.arr_name[i].setTextUpdate( tmp_name )
if ( ( self.arr_sym[i] is not None ) and
( tmp_sym is not None ) ) :
self.arr_sym[i].setTextUpdate( tmp_sym )
if ( self.arr_drift[i] is not None ) :
self.arr_drift[i].setChecked( tmp_drift )
if ( self.arr_aniso[i] is not None ) :
self.arr_aniso[i].setChecked( tmp_aniso )
# Update each "ComboBox" widget.
if ( self.arr_ion[i] is not None ) :
self.arr_ion[i].clear( )
self.arr_ion[i].addItems( lst_ion )
try :
s = self.core.nln_pyon.arr_spec.index(
tmp_ion ) + 1
except :
s = 0
if ( tmp_ion is None ) :
s = 0
self.arr_ion[i].setCurrentIndex( s )
"""
# If a spectrum has been loaded but it has no magnetic
# field data, disable the option of temperature
# anisotropy; otherwise, enable it.
if ( self.arr_aniso[i] is not None ) :
if ( ( self.core.n_vel > 0 ) and
( self.core.n_mfi <= 0 ) ) :
self.arr_aniso[i].setVisible( False )
else :
self.arr_aniso[i].setVisible( True )
# Disable the paralle differential flow option if one of
# more of the following conditions are met:
# -- A spectrum has been loaded but it has no magnetic
# field data.
# -- The species "i" is being modeled as having no
# differential flow.
# Otherwise, enable this option.
if ( self.arr_par[i] is not None ) :
if ( ( ( self.core.n_vel > 0 ) and
( self.core.n_mfi <= 0 ) ) or
( not self.core.nln_ion_drift[i] ) ) :
self.arr_par[i].setVisible( False )
else :
self.arr_par[i].setVisible( True )
"""
# Format the text boxes (background and text colors).
if ( tmp_use ) :
ss_name = 'background-color: white;\n'
ss_sym = 'background-color: white;\n'
else :
ss_name = 'background-color: gray;\n'
ss_sym = 'background-color: gray;\n'
if ( ( self.arr_name[i] is not None ) and
( tmp_name is None ) and
( len( self.arr_name[i].text( ) ) > 0 ) ) :
ss_name += 'color: red;'
else :
ss_name += 'color: black;'
if ( ( self.arr_sym[i] is not None ) and
( tmp_sym is None ) and
( len( self.arr_sym[i].text( ) ) > 0 ) ) :
ss_sym += 'color: red;'
else :
ss_sym += 'color: black;'
self.arr_name[i].setStyleSheet( ss_name )
self.arr_sym[i].setStyleSheet( ss_sym )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESPONDING TO A USER-INITIATED EVENT.
#-----------------------------------------------------------------------
def user_event( self, event, fnc ) :
# If a "thread_*" computation thread is already running, reset
# the text in the text box and abort.
if ( n_thread( ) != 0 ) :
self.make_txt( )
return
# Determine which population has been changed by the user.
i = int( fnc[1:] )
# Determine which parameter has been changed by the user and
# what its new value is.
pop_name = None
pop_sym = None
if ( fnc[0] == 'u' ) :
param = 'use'
val = self.arr_use[i].isChecked( )
elif ( fnc[0] == 'i' ) :
param = 'spec'
val = self.arr_ion[i].currentIndex( ) - 1
pop_name = str( self.arr_name[i].text( ) )
pop_sym = str( self.arr_sym[i].text( ) )
elif ( fnc[0] == 'n' ) :
param = 'name'
val = str( self.arr_name[i].text( ) )
elif ( fnc[0] == 's' ) :
param = 'sym'
val = str( self.arr_sym[i].text( ) )
elif ( fnc[0] == 'd' ) :
param = 'drift'
val = self.arr_drift[i].isChecked( )
elif ( fnc[0] == 'a' ) :
param = 'aniso'
val = self.arr_aniso[i].isChecked( )
else :
return
# Instruct the core to update its ion-population parameters
# appropriately.
Thread( target=thread_chng_nln_pop,
args=( self.core, i, param, val,
pop_name, pop_sym ) ).start( )
#-----------------------------------------------------------------------
# DEFINE THE FUNCTION FOR RESPONDING TO THE "chng_nln_ion" SIGNAL.
#-----------------------------------------------------------------------
def resp_chng_nln_ion( self ) :
# Repopulate the text and checkmarks in this widget.
self.make_txt( )