00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2005 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 __facility__ = "Online" 00011 __abstract__ = "Parameter verifier dialog" 00012 __author__ = "S. Tuvi <STuvi@SLAC.Stanford.edu>" 00013 __date__ = "2005/01/27 23:00:27" 00014 __updated__ = "$Date: 2006/01/31 17:36:54 $" 00015 __version__ = "$Revision: 2.6 $" 00016 __release__ = "$Name: R04-12-00 $" 00017 __credits__ = "SLAC" 00018 00019 import LATTE.copyright_SLAC 00020 00021 from qt import * 00022 from qttable import * 00023 import sys 00024 from rcParamVerifyGUI import rcParamVerifyGUI 00025 00026 class rcParamVerifyGUIImpl(rcParamVerifyGUI): 00027 """!\brief Parameter verifier GUI 00028 00029 """ 00030 class ParamCheckTableItem(QTableItem): 00031 """!\brief Checkbox table item for the parameter verifier. 00032 00033 """ 00034 RTTI = 1000 00035 00036 def __init__(self, *args): 00037 """!\brief ParamCheckTableItem constructor. 00038 00039 """ 00040 QTableItem.__init__(self, *args) 00041 self.__cb = None 00042 self.__checked = 0 00043 00044 #def alignment(self): 00045 # return Qt.AlignRight 00046 00047 def rtti(self): 00048 """!\brief Return the runtime type information value. 00049 00050 \return RTTI 00051 """ 00052 return self.RTTI 00053 00054 def isChecked(self): 00055 """!\brief Find out if the item is checked. 00056 00057 \return 1: Checked, 0: Is not checked 00058 """ 00059 return self.__cb.isChecked() 00060 00061 # def paint(self, p, cg, cr, selected): 00062 # if selected: 00063 # br = QColorGroup.Highlight 00064 # else: 00065 # br = QColorGroup.Base 00066 # p.fillRect(0, 0, cr.width(), cr.height(), cg.brush(br)) 00067 00068 # c = QColorGroup(cg); 00069 # c.setBrush(QColorGroup.Background, c.brush(QColorGroup.Base)); 00070 # flags = QStyle.Style_Default; 00071 # if self.isEnabled(): 00072 # flags |= QStyle.Style_Enabled 00073 # if self.isChecked(): 00074 # flags |= QStyle.Style_On 00075 # else: 00076 # flags |= QStyle.Style_Off 00077 # if self.isEnabled() and self.table().isEnabled(): 00078 # flags |= QStyle.Style_Enabled 00079 00080 # sz = QSize(self.table().style().pixelMetric( QStyle.PM_IndicatorWidth ), 00081 # self.table().style().pixelMetric( QStyle.PM_IndicatorHeight ) ) 00082 00083 ## self.table().style().drawPrimitive( QStyle.PE_Indicator, p, 00084 ## QRect(0, (cr.height() - sz.height()) / 2, sz.width(), sz.height() ), c, flags ) 00085 00086 # intCenterGap = ( self.table().cellGeometry( self.row(), self.col() ).width() - sz.width())/2 00087 # #self.table().style().drawPrimitive( QStyle.PE_Indicator, p, 00088 # # QRect(intCenterGap, ( cr.height() - sz.height() ) / 2, 00089 # # sz.width(), sz.height()), c, flags ) 00090 00091 def createEditor(self): 00092 """!\brief Create an editor for the checkbox table item. 00093 00094 """ 00095 self.__pwdg = QWidget(self.table().viewport(), "wdg_checkparent") 00096 self.__cb = QCheckBox(self.__pwdg, "qt_editor_checkbox" ) 00097 #self.__cb = QCheckBox(self.table().viewport(), "qt_editor_checkbox" ) 00098 self.__pwdg.setFocusProxy(self.__cb) 00099 self.__cb.setChecked( self.__checked ) 00100 self.__cb.adjustSize() 00101 self.__cb.setText(self.text()) 00102 self.__cb.move( ( (self.table().cellGeometry( self.row(), self.col() ).width() - self.__cb.size().width() )/2) , ( self.table().cellGeometry( self.row(), self.col() ).height() - self.__cb.size().height() )/2 ) 00103 self.__cb.setEraseColor(self.table().viewport().eraseColor()) 00104 self.__pwdg.setEraseColor(self.table().viewport().eraseColor()) 00105 QObject.connect(self.__cb, SIGNAL("toggled(bool)"), self.doValueChanged) 00106 #return self.__cb 00107 return self.__pwdg 00108 00109 def setContentFromEditor(self, w): 00110 """!\brief Set content from the editor. 00111 00112 \param w Widget 00113 """ 00114 if self.__cb: 00115 self.__checked = self.__cb.isChecked() 00116 00117 def doValueChanged(self): 00118 """!\brief Emit a valueChanged signal. 00119 00120 """ 00121 self.table().setCurrentCell(self.row(), self.col()) 00122 self.table().emit(SIGNAL('valueChanged'), (self.row(), self.col())) 00123 00124 class ParamTextTableItem(QTableItem): 00125 """!\brief Text table item for the parameter verifier. 00126 00127 """ 00128 def __init__(self, *args): 00129 """!\brief ParamTextTableItem constructor. 00130 00131 \param *args Parameters 00132 """ 00133 QTableItem.__init__(self, *args) 00134 self.__bold = 0 00135 00136 def alignment(self): 00137 """!\brief Set alignment to left and center. 00138 00139 """ 00140 return Qt.AlignLeft | Qt.AlignVCenter 00141 00142 def paint(self, p, cg, rect, selected): 00143 """!\brief Paint the table item. 00144 00145 \param p Painter 00146 \param cg Color group 00147 \param rect Rectangle 00148 \param selected Selected 00149 """ 00150 f = p.font() 00151 f.setBold(self.__bold) 00152 p.setFont(f) 00153 # Do the standard painting 00154 QTableItem.paint(self,p,cg,rect,selected) 00155 00156 def setBold(self, bold): 00157 """!\brief Set the text item in bold. 00158 00159 \param bold Boolean 00160 """ 00161 self.__bold = bold 00162 00163 00164 def __init__(self, common, parent = None, name = None, fl = 0): 00165 """!\brief rcParamVerifyGUIImpl constructor. 00166 00167 \param common ScriptEngineCommon instance. 00168 \param parent Parent GUI 00169 \param name GUI name 00170 \param fl GUI flags 00171 """ 00172 rcParamVerifyGUI.__init__(self, parent, name, fl) 00173 self.__common = common 00174 self.parTable.setLeftMargin(0) 00175 self.parTable.setNumCols(3) 00176 colLabels = QStringList("Parameter") 00177 colLabels.append("Value") 00178 colLabels.append("") 00179 self.parTable.setColumnLabels(colLabels) 00180 self.parTable.setColumnReadOnly(0, 1) 00181 self.parTable.setColumnReadOnly(1, 1) 00182 self.parTable.setColumnReadOnly(2, 0) 00183 self.parTable.setColumnWidth(0,200) 00184 self.parTable.setColumnWidth(1,50) 00185 self.parTable.setColumnWidth(2,20) 00186 self.parTable.horizontalHeader().setResizeEnabled(0, 2) 00187 self.parTable.setColumnStretchable(0, 1) 00188 self.parTable.setColumnStretchable(1, 1) 00189 #self.parTable.horizontalHeader().setClickEnabled(0, 2) 00190 self.__paramCount = 0 00191 QObject.connect(self.parTable, 00192 SIGNAL("valueChanged(int,int)"), self.parameterClicked) 00193 QObject.connect(self.buttonCancel,SIGNAL("clicked()"),self.cancel) 00194 QObject.connect(self.buttonConfirm,SIGNAL("clicked()"),self.confirm) 00195 self.__certifyText = str(self.textCertify.text()) 00196 00197 # Dummy up some entries 00198 #self.textCertify.setText(str(self.textCertify.text()) % ("Selim Tuvi", "testAppCal")) 00199 #self.__paramCount = 6 00200 #ti = self.addParameter("Layers Selection", "(X0,Y0)") 00201 #ti = self.addParameter("No. of strobes per setting", 1) 00202 #ti = self.addParameter("Thr DAC", 30) 00203 #ti = self.addParameter("Thr Range", 0) 00204 #ti = self.addParameter("Cal DAC", 20) 00205 #ti = self.addParameter("Cal Range", 1) 00206 00207 def initialize(self, testName): 00208 """!\brief Initialize the GUI. 00209 00210 \param testName Name of the test script 00211 """ 00212 prefs = self.__common.prefMan().preferences() 00213 user = prefs['operatorobj'] 00214 self.textTestName.setText(testName) 00215 self.textUserName.setText(user.getName()) 00216 self.textCertify.setText(self.__certifyText % (user.getName(), testName)) 00217 self.buttonConfirm.setEnabled(0) 00218 self.txtPassword.setEnabled(0) 00219 self.__paramCount = 0 00220 self.txtPassword.setText("") 00221 self.clearAllRows() 00222 00223 def clearAllRows(self): 00224 """!\brief Clear all rows. 00225 00226 """ 00227 for row in range(self.parTable.numRows()): 00228 self.parTable.removeRow(row) 00229 00230 def cancel(self): 00231 """!\brief Cancel button is clicked. 00232 00233 """ 00234 QDialog.done(self, QDialog.Rejected) 00235 00236 def confirm(self): 00237 """!\brief Confirm button is clicked. 00238 00239 """ 00240 prefs = self.__common.prefMan().preferences() 00241 secMan = self.__common.getSecurityMan() 00242 if secMan is None: 00243 QDialog.done(self, QDialog.Accepted) 00244 else: 00245 user = prefs['operatorobj'] 00246 if secMan.authenticateUser(user.getLoginId(), str(self.txtPassword.text())) == 0: 00247 QDialog.done(self, QDialog.Accepted) 00248 else: 00249 QMessageBox.critical( None, "Authentication Error", 00250 "Incorrect Password", 00251 QMessageBox.Ok + QMessageBox.Default ) 00252 self.txtPassword.selectAll() 00253 00254 def addParameter(self, name, value): 00255 """!\brief Add parameter. 00256 00257 \param name Parameter name 00258 \param value Parameter value 00259 """ 00260 self.parTable.setNumRows(self.__paramCount+1) 00261 ti = self.ParamTextTableItem(self.parTable, QTableItem.Never, name) 00262 self.parTable.setItem(self.__paramCount, 0, ti) 00263 ti = self.ParamTextTableItem(self.parTable, QTableItem.Never, str(value)) 00264 self.parTable.setItem(self.__paramCount, 1, ti) 00265 ti = self.ParamCheckTableItem(self.parTable, QTableItem.Always, "") 00266 self.parTable.setItem(self.__paramCount, 2, ti) 00267 self.__paramCount+=1 00268 return ti 00269 00270 def parameterClicked(self, row, col): 00271 """!\brief Signal that a table item has been changed. 00272 00273 \param row Table row 00274 \param col Table column 00275 """ 00276 if col == 2: 00277 chk = self.parTable.item(row, col) 00278 if chk.isChecked(): 00279 self.parTable.item(row, 0).setBold(1) 00280 self.parTable.item(row, 1).setBold(1) 00281 self.parTable.repaintSelections() 00282 else: 00283 self.parTable.item(row, 0).setBold(0) 00284 self.parTable.item(row, 1).setBold(0) 00285 self.parTable.repaintSelections() 00286 00287 if self.allParametersChecked(): 00288 self.buttonConfirm.setEnabled(1) 00289 self.txtPassword.setEnabled(1) 00290 else: 00291 self.buttonConfirm.setEnabled(0) 00292 self.txtPassword.setEnabled(0) 00293 00294 def allParametersChecked(self): 00295 """!\brief Check if all parameters have been checked. 00296 00297 \return True: If all parameters have been checked. 00298 False: Not all parameters have been checked. 00299 """ 00300 for row in range(self.__paramCount): 00301 chk = self.parTable.item(row, 2) 00302 if not chk.isChecked(): 00303 return False 00304 return True 00305 00306 if __name__ == "__main__": 00307 a = QApplication(sys.argv) 00308 QObject.connect(a,SIGNAL("lastWindowClosed()"),a,SLOT("quit()")) 00309 w = rcParamVerifyGUIImpl(None) 00310 a.setMainWidget(w) 00311 w.show() 00312 a.exec_loop()