11from PyQt4 import QtGui , QtCore , uic
22
33from hexrd .xrd import spacegroup
4+ from hexrd .xrd .material import Material
45from .resources import resources
56
6-
7- class Material (object ):
8-
9- # this is just a placeholder
10- pass
11-
12-
13-
147class MaterialDialogController (QtGui .QDialog ):
158
169
17- @property
18- def material (self ):
19- return None
20-
21-
2210 def __init__ (self , name = None ):
11+
2312 super (MaterialDialogController , self ).__init__ ()
2413 uic .loadUi (resources ['materialsdialog.ui' ], self )
14+
15+ self ._mat = Material ()
16+ # in order: a, b, c, alpha, beta, gamma
17+ self ._lpboxes = [self .doubleSpinBox_2 , self .doubleSpinBox_4 ,
18+ self .doubleSpinBox_3 , self .doubleSpinBox_7 ,
19+ self .doubleSpinBox_5 , self .doubleSpinBox_6 ]
2520 self ._config_ui ()
2621
2722 self .load_settings ()
@@ -43,10 +38,24 @@ def _config_ui(self):
4338
4439 self .spaceGroupComboBox .setCurrentIndex (522 )
4540
41+ def _lp_blocksignals (self , tf ):
42+ self .doubleSpinBox_2 .blockSignals (tf )
43+ self .doubleSpinBox_3 .blockSignals (tf )
44+ self .doubleSpinBox_4 .blockSignals (tf )
45+ self .doubleSpinBox_5 .blockSignals (tf )
46+ self .doubleSpinBox_6 .blockSignals (tf )
47+ self .doubleSpinBox_7 .blockSignals (tf )
4648
4749 def load_settings (self ):
4850 pass
4951
52+ @property
53+ def material (self ):
54+ return self ._mat
55+
56+ @property
57+ def lpboxes (self ):
58+ return self ._lpboxes
5059
5160 @QtCore .pyqtSlot (name = 'on_buttonBox_accepted' )
5261 def save_settings (self ):
@@ -75,6 +84,60 @@ def set_spacegroup(self, val):
7584 self .hallSymbolComboBox .blockSignals (False )
7685 self .hermannMauguinComboBox .blockSignals (False )
7786
87+ @QtCore .pyqtSlot (int , name = 'on_spaceGroupComboBox_currentIndexChanged' )
88+ def enable_latparams (self , val ):
89+ """enable independent lattice parameters"""
90+ # lattice parameters are stored in the old "ValUnit" class
91+ self ._lp_blocksignals (True )
92+ nlp = 6
93+ A = 'angstrom'
94+ D = 'degrees'
95+ m = self .material
96+ sgid = int (self .spaceGroupComboBox .currentText ().split (':' )[0 ])
97+ self .material .sgnum = sgid
98+ reqp = m .spaceGroup .reqParams
99+ lprm = m .latticeParameters
100+ for i in range (nlp ):
101+ boxi = self .lpboxes [i ]
102+ boxi .setEnabled (i in reqp )
103+ u = A if i < 3 else D
104+ boxi .setValue (lprm [i ].getVal (u ))
105+ self ._lp_blocksignals (False )
106+
107+ @QtCore .pyqtSlot (float , name = 'on_doubleSpinBox_2_valueChanged' )
108+ @QtCore .pyqtSlot (float , name = 'on_doubleSpinBox_3_valueChanged' )
109+ @QtCore .pyqtSlot (float , name = 'on_doubleSpinBox_4_valueChanged' )
110+ @QtCore .pyqtSlot (float , name = 'on_doubleSpinBox_5_valueChanged' )
111+ @QtCore .pyqtSlot (float , name = 'on_doubleSpinBox_6_valueChanged' )
112+ @QtCore .pyqtSlot (float , name = 'on_doubleSpinBox_7_valueChanged' )
113+ def set_latparams (self , val ):
114+ """update all the lattice parameter boxes when one changes"""
115+ # note: material takes reduced set of lattice parameters but outputs
116+ # all six
117+ self ._lp_blocksignals (True )
118+ nlp = 6
119+ A = 'angstrom'
120+ D = 'degrees'
121+ m = self .material
122+ reqp = m .spaceGroup .reqParams
123+ nreq = len (reqp )
124+ lp_red = nreq * [0.0 ]
125+ for i in range (nreq ):
126+ boxi = self .lpboxes [reqp [i ]]
127+ lp_red [i ] = boxi .value ()
128+ m .latticeParameters = lp_red
129+ lprm = m .latticeParameters
130+ for i in range (nlp ):
131+ u = A if i < 3 else D
132+ boxi = self .lpboxes [i ]
133+ boxi .setValue (lprm [i ].getVal (u ))
134+ self ._lp_blocksignals (False )
135+
136+ @QtCore .pyqtSlot (name = 'on_lineEdit_6_editingFinished' )
137+ def set_name (self ):
138+ n = self .lineEdit_6 .text ()
139+ print n , type (n )
140+ self .material .name = self .lineEdit_6 .text ()
78141
79142 def not_implemented (self ):
80143 dlg = QtGui .QMessageBox .information (
0 commit comments