def main(): app = qt.QApplication(sys.argv) winpalette = qt.QPalette(qt.QColor(230, 240, 249), qt.QColor(238, 234, 238)) app.setPalette(winpalette) if len(sys.argv) > 1: ene = float(sys.argv[1]) else: ene = 5.9 mw = qt.QWidget() l = qt.QVBoxLayout(mw) l.setSpacing(0) if 0: w = PeakIdentifier(mw, energy=ene) browsertext = qt.QTextView(mw) def myslot(dict): browsertext.setText(dict['text']) mw.connect(w, qt.PYSIGNAL('PeakIdentifierSignal'), myslot) else: w = PeakIdentifier(mw, energy=ene, useviewer=1) #######w.myslot() l.addWidget(w) if QTVERSION < '4.0.0': app.setMainWidget(mw) mw.show() app.exec_loop() else: mw.setWindowTitle("Peak Identifier") mw.show() app.exec_()
def main(): import sys import getopt app=qt.QApplication(sys.argv) winpalette = qt.QPalette(qt.QColor(230,240,249),qt.QColor(238,234,238)) app.setPalette(winpalette) options='' longoptions=[] opts, args = getopt.getopt( sys.argv[1:], options, longoptions) for opt,arg in opts: pass filelist=args qt.QObject.connect(app,qt.SIGNAL("lastWindowClosed()"),app, qt.SLOT("quit()")) w=EdfFileSimpleViewer() if QTVERSION < '4.0.0' : app.setMainWidget(w) w.show() if len(filelist):w.setFileList(filelist) app.exec_loop() else: if len(filelist):w.setFileList(filelist) w.show() app.exec_()
def main(): app = qt.QApplication([]) winpalette = qt.QPalette(qt.QColor(230, 240, 249), qt.QColor(238, 234, 238)) app.setPalette(winpalette) w = ElementsInfo() if qt.qVersion() < '4.0.0': app.setMainWidget(w) w.show() app.exec_loop() else: w.show() app.exec_()
def focusOutEvent(self, event): # TODO remove ? if 0: self.setPaletteBackgroundColor(qt.QColor('white')) if QTVERSION < '4.0.0': self.emit(qt.SIGNAL("returnPressed()"), ()) else: self.emit(qt.SIGNAL("returnPressed()"))
def _mySignal(self): self.setPaletteBackgroundColor(qt.QColor('white')) ddict = {} ddict['event'] = "returnPressed" if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL("MyQLineEditSignal"), (ddict,)) else: self.emit(qt.SIGNAL("MyQLineEditSignal"), ddict)
def drawEllipse(self,x,y,r): self.Item = qt.QGraphicsEllipseItem(x-r/2,y-r/2,r,r) self.Item.setFlag(qt.QGraphicsItem.ItemIsMovable) pen = qt.QPen(qt.Qt.blue) pen.setWidth( 3 ) brush = qt.QBrush(qt.QColor(0xFF, 0, 0, 0x00)) self.Item.setBrush(brush) self.Item.setPen(pen) self.scene.addItem(self.Item)
def _mySignal(self, qstring0): qstring = qstring0 (result, index) = self.ownValidator.validate(qstring, 0) if result != self.ownValidator.Valid: qstring = self.ownValidator.fixup(qstring) (result, index) = self.ownValidator.validate(qstring,0) if result != self.ownValidator.Valid: text = str(qstring) if text.upper() != "MULTILAYER": qt.QMessageBox.critical(self, "Invalid Material '%s'" % text, "The material '%s' is not a valid Formula " \ "nor a valid Material.\n" \ "Please define the material %s or correct the formula\n" % \ (text, text)) if QTVERSION < '4.0.0': self.setCurrentItem(0) else: self.setCurrentIndex(0) for i in range(self.count()): if QTVERSION < '4.0.0': selftext = self.text(i) else: selftext = self.itemText(i) if selftext == qstring0: self.removeItem(i) break return text = str(qstring) self.setCurrentText(text) ddict = {} ddict['event'] = 'activated' ddict['row'] = self.row ddict['col'] = self.col ddict['text'] = text if qstring0 != qstring: self.removeItem(self.count() - 1) insert = True for i in range(self.count()): if QTVERSION < '4.0.0': selftext = self.text(i) else: selftext = self.itemText(i) if qstring == selftext: insert = False if insert: self.insertItem(-1, qstring) if self.lineEdit() is not None: if QTVERSION < '4.0.0': self.lineEdit().setPaletteBackgroundColor(qt.QColor("white")) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('MaterialComboBoxSignal'), (ddict,)) else: self.emit(qt.SIGNAL('MaterialComboBoxSignal'), ddict)
def main(args): app = qt.QApplication(args) #if sys.platform == 'win32': if 1: winpalette = qt.QPalette(qt.QColor(230, 240, 249), qt.QColor(238, 234, 238)) app.setPalette(winpalette) options = '' longoptions = ['spec=', 'shm='] try: opts, args = getopt.getopt(sys.argv[1:], options, longoptions) except getopt.error: print(sys.exc_info()[1]) sys.exit(1) # --- waiting widget if QTVERSION < '4.0.0': wa = qt.QMessageBox("PyMca", "PyMca v. 1.5 loading ...", qt.QMessageBox.NoIcon, qt.QMessageBox.NoButton, qt.QMessageBox.NoButton, qt.QMessageBox.NoButton, None, None) wa.show() kw = {} for opt, arg in opts: if opt in ('--spec'): kw['spec'] = arg elif opt in ('--shm'): kw['shm'] = arg #demo = McaWindow.McaWidget(**kw) demo = PyMca() qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app, qt.SLOT("quit()")) if QTVERSION < '4.0.0': app.setMainWidget(demo) demo.show() # --- close waiting widget wa.close() app.exec_loop() else: demo.show() app.exec_()
def __init__(self, parent, peak): qt.QPushButton.__init__(self, parent) #, peak) self.peak = peak font = self.font() font.setBold(1) self.setText(peak) self.setFlat(1) if QTVERSION < '4.0.0': self.setToggleButton(0) self.setSizePolicy( qt.QSizePolicy(qt.QSizePolicy.Expanding, qt.QSizePolicy.Expanding)) self.selected = 0 self.brush = qt.QBrush(qt.QColor(qt.Qt.yellow)) self.connect(self, qt.SIGNAL("clicked()"), self.clickedSlot)
def __init__(self, parent=None, scene=None, keepratio=True): qt.QGraphicsRectItem.__init__(self, parent, scene) rect = parent.sceneBoundingRect() w = rect.width() h = rect.height() self._newRect = None self.keepRatio = keepratio self.setRect(qt.QRectF(w - 40, h - 40, 40, 40)) if DEBUG: self.setBrush(qt.QBrush(qt.Qt.white, qt.Qt.SolidPattern)) else: pen = qt.QPen() color = qt.QColor(qt.Qt.white) color.setAlpha(0) pen.setColor(color) pen.setStyle(qt.Qt.NoPen) self.setPen(pen) self.setBrush(color) self.setFlag(self.ItemIsMovable, True) self.show()
def _energySlot(self): string = str(self.energy.text()) if len(string): try: value = float(string) except: msg = qt.QMessageBox(self.energy) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Float") msg.exec_loop() self.energy.setFocus() return if self.energyValue is not None: if value != self.energyValue: self.energyValue = value Elements.updateDict(energy=value) else: self.energyValue = value Elements.updateDict(energy=value) self.energy.setPaletteBackgroundColor(qt.QColor('white')) self.infoWidget.setFocus() else: self.energyValue = None self.energy.setText("")
def _mySignal(self, qstring0): qstring = qstring0 text = str(qstring0) if text == '-': return (result, index) = self.ownValidator.validate(qstring, 0) if result != self.ownValidator.Valid: qstring = self.ownValidator.fixup(qstring) (result, index) = self.ownValidator.validate(qstring, 0) if result != self.ownValidator.Valid: text = str(qstring) if text.endswith(" "): msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Material Name '%s'\n" % text + \ "It ends with a space character.\n") msg.exec_() msg = qt.QMessageBox.No else: try: # this test is needed even if pyflakes complains float(text) msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Material Name %s\n" % text + \ "You cannot use a number as material name.\n" +\ "Hint: You can use _%s_" % text) if QTVERSION < '4.0.0': msg.exec_loop() else: msg.exec_() msg = qt.QMessageBox.No except: msg=qt.QMessageBox.information( self, "Invalid Material %s" % str(qstring), "The material %s is not a valid Formula " \ "nor a valid Material.\n" \ "Do you want to define the material %s\n" % \ (str(qstring), str(qstring)), qt.QMessageBox.Yes,qt.QMessageBox.No) if msg == qt.QMessageBox.No: if QTVERSION < '4.0.0': self.setCurrentItem(0) else: self.setCurrentIndex(0) for i in range(self.count()): if QTVERSION < '4.0.0': selftext = self.text(i) else: selftext = self.itemText(i) if selftext == qstring0: self.removeItem(i) return else: qstring = qstring0 text = str(qstring) if Elements.isValidFormula(text): msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Invalid Material Name %s\n" % text + \ "The material is a valid Formula.\n " \ "There is no need to define it.") if QTVERSION < '4.0.0': msg.exec_loop() else: msg.exec_() if QTVERSION < '4.0.0': self.setCurrentItem(0) else: self.setCurrentIndex(0) for i in range(self.count()): if QTVERSION < '4.0.0': selftext = self.text(i) else: selftext = self.itemText(i) if selftext == qstring0: self.removeItem(i) break return self.setCurrentText(text) dict = {} dict['event'] = 'activated' dict['row'] = self.row dict['col'] = self.col dict['text'] = text if qstring0 != qstring: self.removeItem(self.count() - 1) insert = True for i in range(self.count()): if QTVERSION < '4.0.0': selftext = self.text(i) else: selftext = self.itemText(i) if qstring == selftext: insert = False if insert: if QTVERSION < '4.0.0': self.insertItem(qstring, -1) else: self.insertItem(self.count(), qstring) if self.lineEdit() is not None: if QTVERSION < '4.0.0': self.lineEdit().setPaletteBackgroundColor(qt.QColor("white")) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('MaterialComboBoxSignal'), (dict, )) else: self.emit(qt.SIGNAL('MaterialComboBoxSignal'), (dict))
def __init__(self, parent = None, printer = None, name = "PyMcaPrintPreview", \ modal = 0, fl = 0): qt.QDialog.__init__(self, parent) self.setWindowTitle(name) self.setModal(modal) self.resize(400, 500) self.printDialog = None if printer is None: printer = qt.QPrinter(qt.QPrinter.HighResolution) printer.setPageSize(qt.QPrinter.A4) printerName = "%s" % printer.printerName() if printerName in ['id24b2u']: #id24 printer very slow in color mode printer.setColorMode(qt.QPrinter.GrayScale) printer.setFullPage(True) if (printer.width() <= 0) or (printer.height() <= 0): if QTVERSION < '4.2.0': #this is impossible (no QGraphicsView) filename = "PyMCA_print.pdf" else: filename = "PyMCA_print.ps" if sys.platform == 'win32': home = os.getenv('USERPROFILE') try: l = len(home) directory = os.path.join(home, "My Documents") except: home = '\\' directory = '\\' if os.path.isdir('%s' % directory): directory = os.path.join(directory, "PyMca") else: directory = os.path.join(home, "PyMca") if not os.path.exists('%s' % directory): os.mkdir('%s' % directory) finalfile = os.path.join(directory, filename) else: home = os.getenv('HOME') directory = os.path.join(home, "PyMca") if not os.path.exists('%s' % directory): os.mkdir('%s' % directory) finalfile = os.path.join(directory, filename) printer.setOutputFileName(finalfile) printer.setColorMode(qt.QPrinter.Color) if (printer.width() <= 0) or (printer.height() <= 0): self.message = qt.QMessageBox(self) self.message.setIcon(qt.QMessageBox.Critical) self.message.setText( "Unknown library error \non printer initialization") self.message.setWindowTitle("Library Error") self.message.setModal(0) self.badNews = True self.printer = None return else: self.badNews = False self.printer = printer self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setMargin(0) self.mainLayout.setSpacing(0) self._buildToolbar() self.scene = qt.QGraphicsScene() self.scene.setBackgroundBrush(qt.QColor(qt.Qt.lightGray)) self.page = qt.QGraphicsRectItem(0, 0, printer.width(), printer.height()) self.page.setBrush(qt.QColor(qt.Qt.white)) self.scene.setSceneRect( qt.QRectF(0, 0, printer.width(), printer.height())) self.scene.addItem(self.page) self.view = qt.QGraphicsView(self.scene) self.mainLayout.addWidget(self.view) self._buildStatusBar() self.view.fitInView(self.page.rect(), qt.Qt.KeepAspectRatio) self._viewScale = 1.00
def focusInEvent(self, event): if QTVERSION < '4.0.0': self.setPaletteBackgroundColor(qt.QColor('yellow'))
def main(): import getopt options = 'f' longoptions = ['outdir=', 'listfile=', 'mcastep='] filelist = None outdir = None listfile = None mcastep = 1 opts, args = getopt.getopt(sys.argv[1:], options, longoptions) for opt, arg in opts: if opt in ('--outdir'): outdir = arg elif opt in ('--listfile'): listfile = arg elif opt in ('--mcastep'): mcastep = int(arg) if listfile is None: filelist = [] for item in args: filelist.append(item) else: fd = open(listfile) filelist = fd.readlines() fd.close() for i in range(len(filelist)): filelist[i] = filelist[i].replace('\n', '') app = qt.QApplication(sys.argv) winpalette = qt.QPalette(qt.QColor(230, 240, 249), qt.QColor(238, 234, 238)) app.setPalette(winpalette) if len(filelist) == 0: qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app, qt.SLOT("quit()")) w = Mca2EdfGUI(actions=1) if QTVERSION < '4.0.0': app.setMainWidget(w) w.show() app.exec_loop() else: w.show() sys.exit(app.exec_()) else: qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app, qt.SLOT("quit()")) text = "Batch from %s to %s" % (os.path.basename( filelist[0]), os.path.basename(filelist[-1])) window = Mca2EdfWindow(name=text, actions=1) b = Mca2EdfBatch(window, filelist, outdir, mcastep) def cleanup(): b.pleasePause = 0 b.pleaseBreak = 1 b.wait() qt.qApp.processEvents() def pause(): if b.pleasePause: b.pleasePause = 0 window.pauseButton.setText("Pause") else: b.pleasePause = 1 window.pauseButton.setText("Continue") qt.QObject.connect(window.pauseButton, qt.SIGNAL("clicked()"), pause) qt.QObject.connect(window.abortButton, qt.SIGNAL("clicked()"), window.close) qt.QObject.connect(app, qt.SIGNAL("aboutToQuit()"), cleanup) window.show() b.start() if QTVERSION < '4.0.0': app.setMainWidget(window) app.exec_loop() else: sys.exit(app.exec_())
def focusOutEvent(self, event): self.setPaletteBackgroundColor(qt.QColor('white')) if qt.qVersion() < '4.0.0': self.emit(qt.PYSIGNAL("focusOut"), ()) else: self.emit(qt.SIGNAL("focusOut"), ())
def focusOutEvent(self, event): self.setPaletteBackgroundColor(qt.QColor('white')) self.emit(qt.SIGNAL("returnPressed()"), ())
def fillFromResult(self, result): if 'mmolar' in result: mmolarflag = True else: mmolarflag = False groupsList = result['groups'] nrows = len(groupsList) if nrows != self.rowCount(): self.setRowCount(nrows) if mmolarflag: self.labels = ['Element', 'Group', 'Fit Area', 'Sigma Area', 'mM concentration'] else: self.labels = ['Element', 'Group', 'Fit Area', 'Sigma Area', 'Mass fraction'] if 'layerlist' in result: for label in result['layerlist']: self.labels += [label] self.setColumnCount(len(self.labels)) if QTVERSION < '4.0.0': i = 0 for label in self.labels: qt.QHeader.setLabel(self.horizontalHeader(), i, label) #self.adjustColumn(i) i += 1 else: for i in range(len(self.labels)): item = self.horizontalHeaderItem(i) if item is None: item = qt.QTableWidgetItem(self.labels[i], qt.QTableWidgetItem.Type) item.setText(self.labels[i]) self.setHorizontalHeaderItem(i, item) line = 0 for group in groupsList: element, group0 = group.split() # transitions = group0 + " xrays" fitarea = QString("%.6e" % (result['fitarea'][group])) sigmaarea = QString("%.2e" % (result['sigmaarea'][group])) area = QString("%.6e" % (result['area'][group])) if result['mass fraction'][group] < 0.0: fraction = QString("Unknown") else: if mmolarflag: fraction = QString("%.4g" % (result['mmolar'][group])) else: fraction = QString("%.4g" % (result['mass fraction'][group])) if line % 2: color = qt.QColor(255, 250, 205) else: color = qt.QColor('white') if 'Expected Area' in self.labels: fields = [element, group0, fitarea, sigmaarea, area, fraction] else: fields = [element, group0, fitarea, sigmaarea, fraction] if 'layerlist' in result: for layer in result['layerlist']: if result[layer]['mass fraction'][group] < 0.0: fraction = QString("Unknown") else: if mmolarflag: fraction = QString("%.4g" % (result[layer]['mmolar'][group])) else: fraction = QString("%.4g" % (result[layer]['mass fraction'][group])) fields += [fraction] col = 0 for field in fields: if QTVERSION < '4.0.0': key = ColorQTableItem(self, qttable.QTableItem.Never, field, color=color) self.setItem(line, col, key) else: item = self.item(line, col) if item is None: item = qt.QTableWidgetItem(field, qt.QTableWidgetItem.Type) self.setItem(line, col, item) else: item.setText(field) item.setBackgroundColor(color) item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled) col += 1 line += 1 for i in range(self.columnCount()): if (i > 1) and (i < 5): self.resizeColumnToContents(i)
def __init__(self, parent=None, name="FitPeakSelect", peakdict={}, fl=0, energyTable=None): qt.QWidget.__init__(self, parent) if QTVERSION < '4.0.0': self.setSizePolicy( qt.QSizePolicy(qt.QSizePolicy.Minimum, qt.QSizePolicy.Minimum)) layout = qt.QVBoxLayout(self) layout.setMargin(0) layout.setSpacing(10) hbox = qt.QWidget(self) hboxLayout = qt.QHBoxLayout(hbox) hboxLayout.setMargin(0) hboxLayout.setSpacing(20) hboxLayout.addWidget(qt.HorizontalSpacer(hbox)) l1 = MyQLabel(hbox, bold=True, color=qt.QColor(0, 0, 0)) hboxLayout.addWidget(l1) self.energyValue = None if energyTable is not None: text = '<b><nobr>Excitation Energy (keV)</nobr></b>' l1.setFixedWidth(l1.fontMetrics().width("##" + text + "####")) l1.setText(text) self.energyTable = energyTable add = 0 self.energy = MyQLabel(hbox) hboxLayout.addWidget(self.energy) self.energy.setFixedWidth( self.energy.fontMetrics().width('########.###')) self.energy.setAlignment(qt.Qt.AlignLeft) #self.energy.setForegroundColor(qt.Qt.red) else: l1.setText('<b><nobr>Excitation Energy (keV)</nobr></b>') self.energyTable = EnergyTable.EnergyTable(self) add = 1 self.energy = qt.QLineEdit(hbox) hboxLayout.addWidget(self.energy) self.energy.setFixedWidth( self.energy.fontMetrics().width('########.###')) self.energyButton = qt.QPushButton(hbox) hboxLayout.addWidget(self.energyButton) self.energyButton.setText("Update") self.connect(self.energyButton, qt.SIGNAL('clicked()'), self._energyClicked) hboxLayout.addWidget(qt.HorizontalSpacer(hbox)) layout.addSpacing(20) layout.addWidget(hbox) self.table = QPeriodicTable(self) line = qt.QFrame(self) line.setFrameShape(qt.QFrame.HLine) line.setFrameShadow(qt.QFrame.Sunken) self.peaks = PeakButtonList(self) self.peaks.setDisabled(['K', 'Ka', 'Kb', 'L', 'L1', 'L2', 'L3', 'M']) if QTVERSION < '4.0.0': self.connect(self.energyTable, qt.PYSIGNAL("EnergyTableSignal"), self._energyTableAction) self.connect(self.table, qt.PYSIGNAL("elementClicked"), self.elementClicked) self.connect(self.peaks, qt.PYSIGNAL("selectionChanged"), self.peakSelectionChanged) else: self.connect(self.energyTable, qt.SIGNAL("EnergyTableSignal"), self._energyTableAction) self.connect(self.table, qt.SIGNAL("elementClicked"), self.elementClicked) self.connect(self.peaks, qt.SIGNAL("selectionChanged"), self.peakSelectionChanged) #Reset All self.resetAllButton = qt.QPushButton(self.peaks) palette = qt.QPalette(self.resetAllButton.palette()) role = self.resetAllButton.foregroundRole() palette.setColor(role, qt.Qt.red) self.resetAllButton.setPalette(palette) self.resetAllButton.setText("Reset All") self.peaks.layout().addWidget(self.resetAllButton) self.connect(self.resetAllButton, qt.SIGNAL("clicked()"), self.__resetAll) layout.addWidget(self.table) layout.addWidget(line) layout.addWidget(self.peaks) if add: layout.addWidget(self.energyTable) layout.addStretch(1) self.current = None self.setSelection(peakdict)
def focusInEvent(self, event): if self.lineEdit() is not None: if QTVERSION < '4.0.0': self.lineEditBackgroundColor = self.lineEdit( ).paletteBackgroundColor() self.lineEdit().setPaletteBackgroundColor(qt.QColor('yellow'))
def addPixmap(self, pixmap, title=None, comment=None, commentposition=None): """ add a pixmap to the print preview scene """ if title is None: title = ' ' title += ' ' if comment is None: comment = ' ' comment += ' ' if commentposition is None: commentposition = "CENTER" if self.badNews: self.message.exec_() return rectItem = qt.QGraphicsRectItem(self.page, self.scene) scale = float(0.5 * self.scene.width() / pixmap.width()) rectItem.setRect(qt.QRectF(1, 1, pixmap.width(), pixmap.height())) pen = rectItem.pen() color = qt.QColor(qt.Qt.red) color.setAlpha(1) pen.setColor(color) rectItem.setPen(pen) rectItem.setZValue(1) rectItem.setFlag(qt.QGraphicsItem.ItemIsSelectable, True) rectItem.setFlag(qt.QGraphicsItem.ItemIsMovable, True) rectItem.setFlag(qt.QGraphicsItem.ItemIsFocusable, False) #I add the resize tool rectItemResizeRect = GraphicsResizeRectItem(rectItem, self.scene) rectItemResizeRect.setZValue(2) #I add a pixmap item pixmapItem = qt.QGraphicsPixmapItem(rectItem, self.scene) pixmapItem.setPixmap(pixmap) #pixmapItem.moveBy(0, 0) pixmapItem.setZValue(0) #I add the title textItem = qt.QGraphicsTextItem(title, rectItem, self.scene) textItem.setTextInteractionFlags(qt.Qt.TextEditorInteraction) offset = 0.5 * textItem.boundingRect().width() textItem.moveBy(0.5 * pixmap.width() - offset, -20) textItem.setZValue(2) #I add the comment commentItem = qt.QGraphicsTextItem(comment, rectItem, self.scene) commentItem.setTextInteractionFlags(qt.Qt.TextEditorInteraction) offset = 0.5 * commentItem.boundingRect().width() if commentposition.upper() == "LEFT": x = 1 else: x = 0.5 * pixmap.width() - offset commentItem.moveBy(x, pixmap.height() + 20) commentItem.setZValue(2) #I should adjust text size here #textItem.scale(2,2) #commentItem.scale(2,2) rectItem.scale(scale, scale) rectItem.moveBy(20, 40)
def _mySlot(self): if QTVERSION < '4.0.0': self.lineEdit().setPaletteBackgroundColor(qt.QColor("white")) self._mySignal(self.currentText())
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)
def focusOutEvent(self, event): self.setPaletteBackgroundColor(qt.QColor('white')) self.__mySlot()
def focusInEvent(self, event): if qt.qVersion() < '4.0.0 ': self.backgroundcolor = self.paletteBackgroundColor() self.setPaletteBackgroundColor(qt.QColor('yellow')) else: self.setPaletteBackgroundColor(qt.QColor('yellow'))
def focusInEvent(self, event): self.setPaletteBackgroundColor(qt.QColor('yellow'))
def focusInEvent(self, event): self.setPaletteBackgroundColor(qt.QColor('yellow')) # TODO not like focusOutEvent ? '''
def focusOutEvent(self, event): self.setPaletteBackgroundColor(qt.QColor('white')) if QTVERSION > '4.0.0': qt.QLineEdit.focusOutEvent(self, event)
def fillfrommca(self, result, diag=1): line = 0 #calculate the number of rows nrows = 0 for group in result['groups']: nrows += 1 for peak in result[group]['peaks']: nrows += 1 for peak0 in result[group]['escapepeaks']: peak = peak0 + "esc" if result[group][peak]['ratio'] > 0.0: nrows += 1 self.setRowCount(nrows) for group in result['groups']: ele, group0 = group.split() fitarea = QString("%.4e" % (result[group]['fitarea'])) sigmaarea = QString("%.2e" % (result[group]['sigmaarea'])) fields = [ele, group0, fitarea, sigmaarea] col = 0 color = qt.QColor('white') nlines = self.rowCount() if (line + 1) > nlines: self.setRowCount(line + 1) for i in range(len(self.labels)): if i < len(fields): if qt.qVersion() < '4.0.0': item = ColorQTableItem(self, qttable.QTableItem.OnTyping, fields[i], color=color, bold=1) self.setItem(line, col, item) else: item = self.item(line, col) text = fields[i] if item is None: item = qt.QTableWidgetItem( text, qt.QTableWidgetItem.Type) self.setItem(line, col, item) else: item.setText(text) item.setBackgroundColor(color) item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled) else: if qt.qVersion() < '4.0.0': self.clearCell(line, col) self.setItem(line, col, item) else: item = self.item(line, col) if item is not None: item.setText("") #self.setItem(line, col, item) col = col + 1 line += 1 #Lemon Chiffon = (255,250,205) color = qt.QColor(255, 250, 205) for peak in result[group]['peaks']: name = peak energy = QString("%.3f" % (result[group][peak]['energy'])) ratio = QString("%.5f" % (result[group][peak]['ratio'])) area = QString("%.4e" % (result[group][peak]['fitarea'])) sigma = QString("%.2e" % (result[group][peak]['sigmaarea'])) fwhm = QString("%.3f" % (result[group][peak]['fwhm'])) chisq = QString("%.2f" % (result[group][peak]['chisq'])) if (line + 1) > nlines: self.setRowCount(line + 1) fields = [name, area, sigma, energy, ratio, fwhm, chisq] col = 1 for field in fields: if qt.qVersion() < '4.0.0': item = ColorQTableItem(self, qttable.QTableItem.Never, field, color=color) self.setItem(line, col, item) else: item = self.item(line, col) text = field if item is None: item = qt.QTableWidgetItem( text, qt.QTableWidgetItem.Type) self.setItem(line, col, item) else: item.setText(text) item.setBackgroundColor(color) item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled) col = col + 1 line += 1 for peak0 in result[group]['escapepeaks']: peak = peak0 + "esc" if result[group][peak]['ratio'] > 0.0: energy = QString("%.3f" % (result[group][peak]['energy'])) ratio = QString("%.5f" % (result[group][peak]['ratio'])) area = QString("%.4e" % (result[group][peak]['fitarea'])) sigma = QString("%.2e" % (result[group][peak]['sigmaarea'])) fwhm = QString("%.3f" % (result[group][peak]['fwhm'])) chisq = QString("%.2f" % (result[group][peak]['chisq'])) if (line + 1) > nlines: self.setRowCount(line + 1) fields = [peak, area, sigma, energy, ratio, fwhm, chisq] col = 1 for field in fields: if qt.qVersion() < '4.0.0': item = ColorQTableItem(self, qttable.QTableItem.Never, field, color=color) self.setItem(line, col, item) else: item = self.item(line, col) if item is None: item = qt.QTableWidgetItem( field, qt.QTableWidgetItem.Type) self.setItem(line, col, item) else: item.setText(field) item.setBackgroundColor(color) item.setFlags(qt.Qt.ItemIsSelectable | qt.Qt.ItemIsEnabled) col = col + 1 line += 1 for i in range(self.columnCount()): if i > -1: self.resizeColumnToContents(i)