Example #1
0
 def addroi(self,roi,key=None):
     nlines=self.numRows()
     self.setNumRows(nlines+1)
     line = nlines
     if key is None:
         key = "%d " % line
     self.roidict[key] = {}
     self.roidict[key]['line'] = line
     self.roidict[key]['type'] = roi['type']
     self.roidict[key]['from'] = roi['from']
     self.roidict[key]['to']   = roi['to']
     ROI = key
     roitype = QString("%s" % roi['type'])
     fromdata= QString("%6g" % (roi['from']))
     todata  = QString("%6g" % (roi['to']))
     if 'rawcounts' in roi:
         rawcounts= QString("%6g" % (roi['rawcounts']))
     else:
         rawcounts = " ?????? "
     self.roidict[key]['rawcounts']   = rawcounts
     if 'netcounts' in roi:
         netcounts= QString("%6g" % (roi['netcounts']))
     else:
         netcounts = " ?????? "
     self.roidict[key]['netcounts']   = netcounts
     fields  = [ROI,roitype,fromdata,todata,rawcounts,netcounts]
     col = 0 
     for field in fields:
         if (ROI == 'ICR') or (ROI.upper() == 'DEFAULT'):
             key=qttable.QTableItem(self,qttable.QTableItem.Never,field)
         else:
             if col == 0:
                 key=qttable.QTableItem(self,qttable.QTableItem.OnTyping,field)                
             else:
                 key=qttable.QTableItem(self,qttable.QTableItem.Never,field)                
         self.setItem(line,col,key)
         col=col+1
     if QTVERSION < '4.0.0':
         self.sortColumn(2,1,1)
     else:
         self.sortByColumn(2, qt.Qt.AscendingOrder)
     for i in range(len(self.roilist)):
         nkey = str(self.text(i,0))
         self.roilist[i] = nkey
         self.roidict[nkey]['line'] = i
     self.selectRow(self.roidict[key]['line'])
     self.ensureCellVisible(self.roidict[key]['line'],0)
Example #2
0
 def setfield(self, parameter, fields, EditType):
     if DEBUG:
         print("setfield. parameter =", parameter)
         print("fields = ", fields)
     if isinstance(parameter, list) or \
        isinstance(parameter, tuple):
         paramlist = parameter
     else:
         paramlist = [parameter]
     if isinstance(fields, list) or \
        isinstance(fields, tuple):
         fieldlist = fields
     else:
         fieldlist = [fields]
     _oldvalue = self.__configuring
     self.__configuring = True
     for param in paramlist:
         if param in self.paramlist:
             try:
                 row = self.paramlist.index(param)
             except ValueError:
                 row = -1
             if row >= 0:
                 for field in fieldlist:
                     if field in self.parameters[param]['fields']:
                         col = self.parameters[param]['fields'].index(field)
                     if field != 'code':
                         key = field + "_item"
                         if QTVERSION < '4.0.0':
                             self.parameters[param][
                                 key] = qttable.QTableItem(
                                     self, EditType,
                                     self.parameters[param][field])
                             self.setItem(row, col,
                                          self.parameters[param][key])
                         else:
                             item = self.item(row, col)
                             if item is None:
                                 item = qt.QTableWidgetItem()
                                 item.setText(self.parameters[param][field])
                                 self.setItem(row, col, item)
                             else:
                                 item.setText(self.parameters[param][field])
                             self.parameters[param][key] = item
                             item.setFlags(EditType)
     self.__configuring = _oldvalue
Example #3
0
 def setfield(self, peak, fields, EditType):
     if DEBUG:
         print("setfield. peak =", peak, "fields = ", fields)
     if type(peak) == type (()) or \
        type(peak) == type ([]):
         peaklist = peak
     else:
         peaklist = [peak]
     if type(fields) == type (()) or \
        type(fields) == type ([]):
         fieldlist = fields
     else:
         fieldlist = [fields]
     for peak in peaklist:
         if peak in self.peaklist:
             try:
                 row = self.peaklist.index(peak)
             except ValueError:
                 row = -1
             if row >= 0:
                 for field in fieldlist:
                     if field in self.peaks[peak]['fields']:
                         col = self.peaks[peak]['fields'].index(field)
                         if (field != 'element') and (field !=
                                                      'elementline'):
                             key = field + "_item"
                             if qt.qVersion() < '4.0.0':
                                 self.peaks[peak][key] = qttable.QTableItem(
                                     self, EditType,
                                     self.peaks[peak][field])
                                 self.setItem(row, col,
                                              self.peaks[peak][key])
                             else:
                                 item = self.item(row, col)
                                 text = "%s" % self.peaks[peak][field]
                                 if item is None:
                                     item = qt.QTableWidgetItem(
                                         text, qt.QTableWidgetItem.Type)
                                     self.setItem(row, col, item)
                                 else:
                                     item.setText(str(text))
                                 item.setFlags(EditType)
Example #4
0
 def fillfromroidict(self,roilist=[],roidict={},currentroi=None):
     self.building = True
     line0  = 0
     self.roilist = []
     self.roidict = {}
     for key in roilist:
         if key in roidict.keys():
             roi = roidict[key]
             self.roilist.append(key)
             self.roidict[key] = {}
             self.roidict[key].update(roi)
             line0 = line0 + 1
             nlines=self.rowCount()
             if (line0 > nlines):
                 self.setRowCount(line0)
             line = line0 -1
             self.roidict[key]['line'] = line
             ROI = key
             roitype = QString("%s" % roi['type'])
             fromdata= QString("%6g" % (roi['from']))
             todata  = QString("%6g" % (roi['to']))
             if 'rawcounts' in roi:
                 rawcounts= QString("%6g" % (roi['rawcounts']))
             else:
                 rawcounts = " ?????? "
             if 'netcounts' in roi:
                 netcounts= QString("%6g" % (roi['netcounts']))
             else:
                 netcounts = " ?????? "
             fields  = [ROI,roitype,fromdata,todata,rawcounts,netcounts]
             col = 0 
             for field in fields:
                 if QTVERSION < '4.0.0':
                     if (ROI.upper() == 'ICR') or (ROI.upper() == 'DEFAULT'):
                         key2=qttable.QTableItem(self,qttable.QTableItem.Never, field)
                     else:
                         if col == 0:
                             key2=qttable.QTableItem(self,qttable.QTableItem.OnTyping,field)
                         else:
                             key2=qttable.QTableItem(self,qttable.QTableItem.Never,field)
                     self.setItem(line, col, key2)
                 else:
                     key2 = self.item(line, col)
                     if key2 is None:
                         key2 = qt.QTableWidgetItem(field,
                                                    qt.QTableWidgetItem.Type)
                         self.setItem(line,col,key2)
                     else:
                         key2.setText(field)
                     if (ROI.upper() == 'ICR') or (ROI.upper() == 'DEFAULT'):
                             key2.setFlags(qt.Qt.ItemIsSelectable|
                                           qt.Qt.ItemIsEnabled) 
                     else:
                         if col in [0, 2, 3]:
                             key2.setFlags(qt.Qt.ItemIsSelectable|
                                           qt.Qt.ItemIsEnabled|
                                           qt.Qt.ItemIsEditable)                        
                         else:
                             key2.setFlags(qt.Qt.ItemIsSelectable|
                                           qt.Qt.ItemIsEnabled) 
                 col=col+1
     self.setRowCount(line0)
     i = 0
     for label in self.labels:
         self.resizeColumnToContents(i)
         i=i+1
     if QTVERSION < '4.0.0':
         self.sortColumn(2,1,1)
     else:
         self.sortByColumn(2, qt.Qt.AscendingOrder)
     for i in range(len(self.roilist)):
         if QTVERSION < '4.0.0':
             key = str(self.text(i, 0))
         else:
             key = str(self.item(i, 0).text())
         self.roilist[i] = key
         self.roidict[key]['line'] = i
     if len(self.roilist) == 1:
         if QTVERSION > '2.3.0':
             self.selectRow(0)
         else:
             if DEBUG:
                 print("Method not implemented, just first cell")
             self.setCurrentCell(0,0)
     else:
         if currentroi in self.roidict.keys():
             self.selectRow(self.roidict[currentroi]['line'])
             if QTVERSION < '4.0.0':
                 self.ensureCellVisible(self.roidict[currentroi]['line'],0)
             else:
                 if DEBUG:
                     print("Qt4 ensureCellVisible to be implemented")
     self.building = False                
    def __build(self, nfilters=12):
        n = 0
        if (not self.matrixMode) and (not self.compoundMode):
            n = 4
            #self.setNumRows(nfilters+n)
            if QTVERSION < '4.0.0':
                self.setNumRows(12)
            else:
                self.setRowCount(12)
        else:
            if QTVERSION < '4.0.0':
                self.setNumRows(nfilters)
            else:
                self.setRowCount(nfilters)
        if QTVERSION > '4.0.0':
            rheight = self.horizontalHeader().sizeHint().height()
            for idx in range(self.rowCount()):
                self.setRowHeight(idx, rheight)

        self.comboList = []
        matlist = list(Elements.Material.keys())
        matlist.sort()
        if self.matrixMode or self.compoundMode:
            if self.matrixMode:
                roottext = "Layer"
            else:
                roottext = "Compound%d" % self.layerindex
            a = []
            #a.append('')
            for key in matlist:
                a.append(key)
            if QTVERSION < '4.0.0':
                for idx in range(self.numRows()):
                    item= qttable.QCheckTableItem(self, roottext + "%d" % idx)
                    self.setItem(idx, 0, item)
                    item.setText(roottext + "%d" % idx)
                    #item= qttable.QTableItem(self,
                    #                         qttable.QTableItem.OnTyping,
                    item= qttable.QTableItem(self, qttable.QTableItem.Never,
                                             self.attenuators[idx])
                    self.setItem(idx, 1, item)
                    combo = MyQComboBox(options=a)
                    combo.setEditable(True)
                    self.setCellWidget(idx, 2, combo)
                    qt.QObject.connect(combo,
                                       qt.PYSIGNAL("MaterialComboBoxSignal"),
                                       self._comboSlot)
            else:
                for idx in range(self.rowCount()):
                    item= qt.QCheckBox(self)
                    self.setCellWidget(idx, 0, item)
                    text = roottext+"%d" % idx
                    item.setText(text)
                    item = self.item(idx, 1)
                    if item is None:
                        item = qt.QTableWidgetItem(text,
                                                   qt.QTableWidgetItem.Type)
                        self.setItem(idx, 1, item)
                    else:
                        item.setText(text)
                    item.setFlags(qt.Qt.ItemIsSelectable|
                                  qt.Qt.ItemIsEnabled)
                    combo = MyQComboBox(self, options=a, row = idx, col = 2)
                    combo.setEditable(True)
                    self.setCellWidget(idx, 2, combo)
                    qt.QObject.connect(combo,
                                       qt.SIGNAL("MaterialComboBoxSignal"),
                                       self._comboSlot)
            return
        if QTVERSION < '4.0.0':
            selfnumRows = self.numRows()
        else:
            selfnumRows = self.rowCount()
            
        for idx in range(selfnumRows - n):
            text = "Filter% 2d" % idx
            if QTVERSION < '4.0.0':
                item = qttable.QCheckTableItem(self, text)
                self.setItem(idx, 0, item)
                item.setText(text)
                if idx < len(self.attenuators):
                    self.setText(idx, 1,self.attenuators[idx])
                else:
                    self.setText(idx, 1,text)
            else:
                item = qt.QCheckBox(self)
                self.setCellWidget(idx, 0, item)
                item.setText(text)
                if idx < len(self.attenuators):
                    text = self.attenuators[idx]

                item = self.item(idx, 1)
                if item is None:
                    item = qt.QTableWidgetItem(text,
                                               qt.QTableWidgetItem.Type)
                    self.setItem(idx, 1, item)
                else:
                    item.setText(text)

            #a = qt.QStringList()
            a = []
            #a.append('')            
            for key in matlist:
                a.append(key)
            combo = MyQComboBox(self, options=a, row=idx, col = 2)
            combo.setEditable(True)
            self.setCellWidget(idx, 2, combo)
            #self.setItem(idx,2,combo)
            if QTVERSION < '4.0.0':
                qt.QObject.connect(combo,
                                   qt.PYSIGNAL("MaterialComboBoxSignal"),
                                   self._comboSlot)
            else:
                qt.QObject.connect(combo,
                                   qt.SIGNAL("MaterialComboBoxSignal"),
                                   self._comboSlot)

        for i in range(2):
            #BeamFilter(i)
            if QTVERSION < '4.0.0':
                item = qttable.QCheckTableItem(self, "BeamFilter%d" % i)
                #,color=qt.Qt.red)
                idx = self.numRows() - (4 - i)
                self.setItem(idx, 0, item)
                item.setText("BeamFilter%d" % i)
                item= qttable.QTableItem(self, qttable.QTableItem.Never,
                                         "BeamFilter%d" % i)
                self.setItem(idx, 1, item)
                item= qttable.QTableItem(self, qttable.QTableItem.Never,
                                         "1.0")
                self.setItem(idx, 5,item)
            else:
                item = qt.QCheckBox(self)
                idx = self.rowCount() - (4 - i)
                self.setCellWidget(idx, 0, item)
                text = "BeamFilter%d" % i
                item.setText(text)

                item = self.item(idx,1)
                if item is None:
                    item = qt.QTableWidgetItem(text,
                                               qt.QTableWidgetItem.Type)
                    self.setItem(idx, 1, item)
                else:
                    item.setText(text)
                item.setFlags(qt.Qt.ItemIsSelectable|
                              qt.Qt.ItemIsEnabled)

                text = "1.0"
                item = self.item(idx, 5)
                if item is None:
                    item = qt.QTableWidgetItem(text,
                                               qt.QTableWidgetItem.Type)
                    self.setItem(idx, 5, item)
                else:
                    item.setText(text)
                item.setFlags(qt.Qt.ItemIsSelectable|
                              qt.Qt.ItemIsEnabled)

            combo = MyQComboBox(self, options=a, row=idx, col=2)
            combo.setEditable(True)
            self.setCellWidget(idx, 2, combo)
            if QTVERSION < '4.0.0':
                qt.QObject.connect(combo,
                                   qt.PYSIGNAL("MaterialComboBoxSignal"),
                                   self._comboSlot)
            else:
                qt.QObject.connect(combo,
                                   qt.SIGNAL("MaterialComboBoxSignal"),
                                   self._comboSlot)
            
        if QTVERSION < '4.0.0':
            #Detector
            item= qttable.QCheckTableItem(self, "Detector")
            #,color=qt.Qt.red)
            idx = self.numRows()-2
            self.setItem(idx, 0, item)
            item.setText("Detector")
            item= qttable.QTableItem(self,
                                     qttable.QTableItem.Never,
                                     "Detector")
            self.setItem(idx, 1, item)
            item= qttable.QTableItem(self,
                                     qttable.QTableItem.Never,
                                     "1.0")
            self.setItem(idx, 5, item)
        else:
            item = qt.QCheckBox(self)
            idx = self.rowCount() - 2
            self.setCellWidget(idx, 0, item)
            text = "Detector"
            item.setText(text)

            item = self.item(idx,1)
            if item is None:
                item = qt.QTableWidgetItem(text,
                                           qt.QTableWidgetItem.Type)
                self.setItem(idx, 1, item)
            else:
                item.setText(text)
            item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled)

            text = "1.0"
            item = self.item(idx, 5)
            if item is None:
                item = qt.QTableWidgetItem(text,
                                           qt.QTableWidgetItem.Type)
                self.setItem(idx, 5, item)
            else:
                item.setText(text)
            item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled)
            
        combo = MyQComboBox(self, options=a, row=idx, col=2)
        combo.setEditable(True)
        self.setCellWidget(idx, 2, combo)
        if QTVERSION < '4.0.0':
            #Matrix            
            item= qttable.QCheckTableItem(self, "Matrix")
            #,color=qt.Qt.red)
            idx = self.numRows() - 1
            self.setItem(idx, 0, item)
            item.setText("Matrix")
            item= qttable.QTableItem(self,
                                     qttable.QTableItem.Never,
                                     "Matrix")
            self.setItem(idx, 1, item)
            item= qttable.QTableItem(self,
                                     qttable.QTableItem.Never,
                                     "1.0")
            self.setItem(idx, 5, item)
        else:
            item = qt.QCheckBox(self)
            idx = self.rowCount() - 1
            self.setCellWidget(idx, 0, item)
            text = "Matrix"
            item.setText(text)
            item = self.item(idx, 1)
            if item is None:
                item = qt.QTableWidgetItem(text,
                                           qt.QTableWidgetItem.Type)
                self.setItem(idx, 1, item)
            else:
                item.setText(text)
            item.setFlags(qt.Qt.ItemIsSelectable |qt.Qt.ItemIsEnabled)

            text = "1.0"
            item = self.item(idx, 5)
            if item is None:
                item = qt.QTableWidgetItem(text,
                                           qt.QTableWidgetItem.Type)
                self.setItem(idx, 5, item)
            else:
                item.setText(text)
            item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled)

        if QTVERSION < '4.0.0':
            qt.QObject.connect(combo,
                               qt.PYSIGNAL("MaterialComboBoxSignal"),
                               self._comboSlot)
        else:
            qt.QObject.connect(combo,
                               qt.SIGNAL("MaterialComboBoxSignal"),
                               self._comboSlot)

        #a = qt.QStringList()
        a = []
        #a.append('')
        for key in matlist:
            a.append(key)
        #combo = qttable.QComboTableItem(self,a)
        self.combo = MyQComboBox(self, options=a, row=idx, col=2)
        self.setCellWidget(idx, 2, self.combo)
        if QTVERSION < '4.0.0':
            self.connect(self.combo,
                         qt.PYSIGNAL("MaterialComboBoxSignal"),
                         self._comboSlot)
        else:
            self.connect(self.combo,
                         qt.SIGNAL("MaterialComboBoxSignal"),
                         self._comboSlot)
Example #6
0
    def fillfrommca(self, mcaresult, diag=1):
        line0 = 0
        region = 0
        alreadyforced = 0
        for result in mcaresult:
            region = region + 1
            if result['chisq'] is not None:
                chisq = QString("%6.2f" % (result['chisq']))
            else:
                chisq = QString("Fit Error")
            if 1:
                xbegin = QString("%6g" % (result['xbegin']))
                xend = QString("%6g" % (result['xend']))
                fitlabel, fitpars, fitsigmas = self.__getfitpar(result)
                if QTVERSION < '4.0.0':
                    qt.QHeader.setLabel(self.horizontalHeader(), 1,
                                        "Fit " + fitlabel)
                else:
                    item = self.horizontalHeaderItem(1)
                    item.setText("Fit " + fitlabel)
                i = 0
                for (pos, area, sigma, fwhm) in result['mca_areas']:
                    line0 = line0 + 1
                    if QTVERSION < '4.0.0':
                        nlines = self.numRows()
                        if (line0 > nlines):
                            self.setNumRows(line0)
                    else:
                        nlines = self.rowCount()
                        if (line0 > nlines):
                            self.setRowCount(line0)
                    line = line0 - 1
                    #pos=QString(str(pos))
                    #area=QString(str(area))
                    #sigma=QString(str(sigma))
                    #fwhm=QString(str(fwhm))
                    tregion = QString(str(region))
                    pos = QString("%6g" % (pos))
                    fitpar = QString("%6g" % (fitpars[i]))
                    if fitlabel == 'Area':
                        sigma = max(sigma, fitsigmas[i])
                    areastr = QString("%6g" % (area))
                    sigmastr = QString("%6.3g" % (sigma))
                    fwhm = QString("%6g" % (fwhm))
                    tregion = QString("%6g" % (region))
                    fields = [
                        pos, fitpar, areastr, sigmastr, fwhm, chisq, tregion,
                        xbegin, xend
                    ]
                    col = 0
                    recolor = 0
                    if fitlabel == 'Area':
                        if diag:
                            if abs(fitpars[i] - area) > (3.0 * sigma):
                                color = qt.QColor(255, 182, 193)
                                recolor = 1
                    for field in fields:
                        if QTVERSION < '4.0.0':
                            if recolor:
                                key = MyQTableItem(self,
                                                   qttable.QTableItem.Never,
                                                   field,
                                                   color=color)
                            else:
                                key = qttable.QTableItem(
                                    self, qttable.QTableItem.Never, field)
                            self.setItem(line, col, key)
                        else:
                            key = self.item(line, col)
                            if key is None:
                                key = qt.QTableWidgetItem(field)
                                self.setItem(line, col, key)
                            else:
                                item.setText(field)
                            if recolor:
                                #function introduced in Qt 4.2.0
                                if QTVERSION >= '4.2.0':
                                    item.setBackground(qt.QBrush(color))
                            item.setFlags(qt.Qt.ItemIsSelectable
                                          | qt.Qt.ItemIsEnabled)
                        col = col + 1
                    if recolor:
                        if not alreadyforced:
                            alreadyforced = 1
                            if QTVERSION < '4.0.0':
                                self.ensureCellVisible(line, 0)
                            else:
                                self.scrollToItem(self.item(line, 0))
                    i += 1

        i = 0
        for label in self.labels:
            if QTVERSION < '4.0.0':
                self.adjustColumn(i)
            else:
                self.resizeColumnToContents(i)
            i = i + 1
        ndict = {}
        ndict['event'] = 'McaTableFilled'
        if QTVERSION < '4.0.0':
            self.emit(qt.PYSIGNAL('McaTableSignal'), (ndict, ))
        else:
            self.emit(qt.SIGNAL('McaTableSignal'), ndict)