def __anasignal(self, ddict): if type(ddict) != type({}): return if 'event' in ddict: if ddict['event'].upper() == "PRINT": h = self.__htmlheader() if __name__ == "__main__": self.__print(h + ddict['text']) else: ndict = {} ndict['event'] = "McaSimpleFitPrint" ndict['text'] = h + ddict['text'] ndict['info'] = {} ndict['info'].update(self.info) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaSimpleFitSignal'), (ndict, )) else: self.emit(qt.SIGNAL('McaSimpleFitSignal'), ndict) if ddict['event'] == "McaModeChanged": if ddict['data']: self.estimatebutton.hide() else: self.estimatebutton.show() else: ddict['info'] = {} ddict['info'].update(self.info) if ddict['event'] == 'FitFinished': #write the simple fit output in a form acceptable by McaWindow ddict['event'] = 'McaFitFinished' ddict['data'] = [self.specfitGUI.specfit.mcagetresult()] if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaSimpleFitSignal'), (ddict, )) else: self.emit(qt.SIGNAL('McaSimpleFitSignal'), ddict)
def mySlot(self, ddict={}): if QTVERSION < '4.0.0': self.disconnect(self.concentrationsWidget, qt.PYSIGNAL('ConcentrationsWidgetSignal'), self.mySlot) self.concentrationsTable.setFocus() qt.qApp.processEvents() self.connect(self.concentrationsWidget, qt.PYSIGNAL('ConcentrationsWidgetSignal'), self.mySlot) else: self.disconnect(self.concentrationsWidget, qt.SIGNAL('ConcentrationsWidgetSignal'), self.mySlot) self.concentrationsTable.setFocus() qt.qApp.processEvents() self.connect(self.concentrationsWidget, qt.SIGNAL('ConcentrationsWidgetSignal'), self.mySlot) if ddict['event'] == 'updated': self.concentrationsTool.configure(ddict) if self.__lastKw is not None: addInfo = False if 'addinfo' in self.__lastKw: if self.__lastKw['addinfo']: addInfo = True try: if addInfo: concentrations, info = self.processFitResult(*self.__lastVar, **self.__lastKw) else: concentrations = self.processFitResult(*self.__lastVar, **self.__lastKw) ddict['concentrations'] = concentrations except: self.__lastKw = None raise self.mySignal(ddict)
def _specfitGUISignal(self, ddict): if not hasattr(ddict, "keys"): return if 'event' in ddict: if ddict['event'].upper() == "PRINT": h = self.__htmlheader() if __name__ == "__main__": self.__print(h + ddict['text']) else: ndict = {} ndict['event'] = "ScanFitPrint" ndict['text'] = h + ddict['text'] ndict['info'] = {} ndict['info'].update(self.info) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('ScanFitSignal'), (ndict, )) else: self.emit(qt.SIGNAL('ScanFitSignal'), ndict) else: if self.info is None: self.info = {} ddict['info'] = {} ddict['info'].update(self.info) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('ScanFitSignal'), (ddict, )) else: self.emit(qt.SIGNAL('ScanFitSignal'), ddict)
def startfit(self): if self.specfit.fitconfig['McaMode']: try: mcaresult=self.specfit.mcafit() except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Error on mcafit: %s" % sys.exc_info()[1]) if QTVERSION < '4.0.0': msg.exec_loop() else: msg.exec_() if DEBUG: raise return self.guiparameters.fillfrommca(mcaresult) ddict={} ddict['event'] = 'McaFitFinished' ddict['data'] = mcaresult if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('SpecfitGUISignal'),(ddict,)) else: self.emit(qt.SIGNAL('SpecfitGUISignal'), ddict) #self.guiparameters.removeview(view='Fit') else: #for param in self.specfit.paramlist: # print param['name'],param['group'],param['estimation'] self.specfit.paramlist=self.guiparameters.fillfitfromtable() if DEBUG: for param in self.specfit.paramlist: print(param['name'],param['group'],param['estimation']) print("TESTING") self.specfit.startfit() try: self.specfit.startfit() except: msg = qt.QMessageBox(self) msg.setIcon(qt.QMessageBox.Critical) msg.setText("Error on Fit") if QTVERSION < '4.0.0': msg.exec_loop() else: msg.exec_() if DEBUG: raise return self.guiparameters.fillfromfit(self.specfit.paramlist,current='Fit') self.guiparameters.removeallviews(keep='Fit') ddict={} ddict['event'] = 'FitFinished' ddict['data'] = self.specfit.paramlist if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('SpecfitGUISignal'),(ddict,)) else: self.emit(qt.SIGNAL('SpecfitGUISignal'), ddict) return
def testwidget(): import sys def change(ddict): print("New selection:", ) print(ddict) a = qt.QApplication(sys.argv) qt.QObject.connect(a, qt.SIGNAL("lastWindowClosed()"), a, qt.SLOT("quit()")) w = qt.QTabWidget() if QTVERSION < '4.0.0': f = FitPeakSelect(w) w.addTab(f, "QPeriodicTable") qt.QObject.connect(f, qt.PYSIGNAL("FitPeakSelect"), change) w.show() a.exec_loop() else: f = FitPeakSelect() w.addTab(f, "QPeriodicTable") qt.QObject.connect(f, qt.SIGNAL("FitPeakSelect"), change) w.show() a.exec_()
def __resetBut(self): for key in self.peaklist: self.buttondict[key].setSelected(0) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('selectionChanged'), ([], )) else: self.emit(qt.SIGNAL('selectionChanged'), ([]))
def __init__(self, parent=None, name="Elements Info", fl=0): if qt.qVersion() < '4.0.0': qt.QWidget.__init__(self, parent, name, fl) self.setCaption(name) else: if fl == 0: qt.QWidget.__init__(self, parent) else: qt.QWidget.__init__(self, parent, fl) self.setWindowTitle(name) layout = qt.QVBoxLayout(self) layout.setMargin(0) layout.setSpacing(0) self.energyValue = None self.splitter = qt.QSplitter(self) layout.addWidget(self.splitter) self.splitter.setOrientation(qt.Qt.Horizontal) self.table = QPeriodicTable(self.splitter) self.html = ElementHtml.ElementHtml() self.infoWidget = None if qt.qVersion() < '4.0.0': self.splitter.setResizeMode(self.table, qt.QSplitter.KeepSize) self.connect(self.table, qt.PYSIGNAL("elementClicked"), self.elementClicked) else: self.table.setMinimumSize(500, 400) self.connect(self.table, qt.SIGNAL("elementClicked"), self.elementClicked) self.lastElement = None Elements.registerUpdate(self._updateCallback)
def nameSlot(self, row, col): if col != 0: return if row >= len(self.roilist): if DEBUG: print("deleting???") return if QTVERSION < '4.0.0': text = str(self.text(row, col)) else: item = self.item(row, col) if item is None:text="" else:text = str(item.text()) if len(text) and (text not in self.roilist): old = self.roilist[row] self.roilist[row] = text self.roidict[text] = {} self.roidict[text].update(self.roidict[old]) del self.roidict[old] ddict = {} ddict['event'] = "selectionChanged" ddict['row' ] = row ddict['col' ] = col ddict['roi' ] = self.roidict[self.roilist[row]] ddict['key'] = self.roilist[row] ddict['colheader'] = self.labels[col] ddict['rowheader'] = "%d" % row if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaROITableSignal'), (ddict,)) else: self.emit(qt.SIGNAL('McaROITableSignal'), ddict)
def fillfrommca(self, mcaresult): #for view in self.tables.keys(): # self.removeview(view) self.removeallviews() region = 0 for result in mcaresult: #if result['chisq'] is not None: region = region + 1 self.fillfromfit(result['paramlist'],current='Region '+\ "%d" % region) name = 'MCA' if name in self.tables: table = self.tables[name] else: self.tables[name] = McaTable.McaTable(self) table = self.tables[name] self.tabs.append(name) self.views[name] = table #self.addTab(table,self.trUtf8(name)) self.addTab(table, str(name)) if QTVERSION < '4.0.0': self.connect(table, qt.PYSIGNAL('McaTableSignal'), self.__forward) else: self.connect(table, qt.SIGNAL('McaTableSignal'), self.__forward) table.fillfrommca(mcaresult) self.setview(name=name) return
def __myslot(self, *var): ddict = {} if len(var) == 0: #selection changed event #get the current selection ddict['event'] = 'McaTableClicked' row = self.currentRow() else: #Header click ddict['event'] = 'McaTableRowHeaderClicked' row = var[0] ccol = self.currentColumn() ddict['row'] = row ddict['col'] = ccol ddict['labelslist'] = self.labels if row >= 0: col = 0 for label in self.labels: if QTVERSION < '4.0.0': text = str(self.text(row, col)) else: text = str(self.item(row, col).text()) try: ddict[label] = float(text) except: ddict[label] = text col += 1 if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaTableSignal'), (ddict, )) else: self.emit(qt.SIGNAL('McaTableSignal'), ddict)
def __addClicked(self): if DEBUG: print("select clicked") selkeys = self.__getSelectedKeys() if DEBUG: print("selected keys = ", selkeys) if len(selkeys): #self.eh.event(self.addEvent, selkeys) if DEBUG: print("Select event") sel = {} sel['SourceType'] = SOURCE_TYPE for selection in selkeys: if 'SourceName' not in sel: sel['SourceName'] = selection['SourceName'] arrayname = selection['Key'] if 'Key' not in sel: sel['Key'] = selection['Key'] if arrayname not in sel: sel[arrayname] = {'rows': [], 'cols': []} if selection['plot'] == 'cols': sel[arrayname]['cols'].append({ 'x': selection['x'], 'y': selection['y'] }) if selection['plot'] == 'rows': sel[arrayname]['rows'].append({ 'x': selection['x'], 'y': selection['y'] }) if self.selection is None: self.setSelected([sel], reset=1) else: self.setSelected([sel], reset=0) self.emit(qt.PYSIGNAL("addSelection"), ([sel], ))
def test(): app = qt.QApplication([]) qt.QObject.connect(app, qt.SIGNAL("lastWindowClosed()"), app, qt.SLOT('quit()')) container = StackPluginResultsWindow() data = numpy.arange(20000) data.shape = 2, 100, 100 data[1, 0:100, 0:50] = 100 container.setStackPluginResults( data, spectra=[numpy.arange(100.), numpy.arange(100.) + 10], image_names=["I1", "I2"], spectra_names=["V1", "V2"]) container.show() def theSlot(ddict): print(ddict['event']) if QTVERSION < '4.0.0': qt.QObject.connect(container, qt.PYSIGNAL("MaskImageWidgetSignal"), updateMask) app.setMainWidget(container) app.exec_loop() else: qt.QObject.connect(container, qt.SIGNAL("MaskImageWidgetSignal"), theSlot) app.exec_()
def __del(self): row = self.mcaROITable.currentRow() if row >= 0: index = self.mcaROITable.labels.index('Type') if QTVERSION < '4.0.0': text = str(self.mcaROITable.text(row, index)) else: text = str(self.mcaROITable.item(row, index).text()) if text.upper() != 'DEFAULT': index = self.mcaROITable.labels.index('ROI') if QTVERSION < '4.0.0': key = str(self.mcaROITable.text(row, index)) else: key = str(self.mcaROITable.item(row, index).text()) else:return roilist,roidict = self.mcaROITable.getroilistanddict() row = roilist.index(key) del roilist[row] del roidict[key] self.mcaROITable.fillfromroidict(roilist=roilist, roidict=roidict, currentroi=roilist[0]) ddict={} ddict['event'] = "DelROI" ddict['roilist'] = roilist ddict['roidict'] = roidict #ddict['currentrow'] = self.mcaROITable.currentRow() if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaROIWidgetSignal'), (ddict,)) else: self.emit(qt.SIGNAL('McaROIWidgetSignal'), ddict)
def _myslot(self, *var, **kw): #selection changed event #get the current selection row = self.currentRow() col = self.currentColumn() if row >= 0: ddict = {} ddict['event'] = "selectionChanged" ddict['row' ] = row ddict['col' ] = col if row >= len(self.roilist): if DEBUG: print("deleting???") return row = 0 if QTVERSION < '4.0.0': text = str(self.text(row, 0)) else: item = self.item(row, 0) if item is None: text="" else: text = str(item.text()) self.roilist[row] = text ddict['roi' ] = self.roidict[self.roilist[row]] ddict['key'] = self.roilist[row] ddict['colheader'] = self.labels[col] ddict['rowheader'] = "%d" % row if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaROITableSignal'), (ddict,)) else: self.emit(qt.SIGNAL('McaROITableSignal'), ddict)
def _mySignal(self, dummy=None): ddict = self.getParameters() ddict['event'] = 'updated' if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('ConcentrationsWidgetSignal'), (ddict,)) else: self.emit(qt.SIGNAL('ConcentrationsWidgetSignal'), ddict)
def __init__(self, parent=None): qt.QWidget.__init__(self, parent) self.mainLayout = qt.QVBoxLayout(self) self.mainLayout.setMargin(0) self.mainLayout.setSpacing(0) self.sourceList = [] filetypelist = ["EDF Files (*edf)", "EDF Files (*ccd)", "All Files (*)"] self.sourceSelector = QSourceSelector.QSourceSelector(self, filetypelist = filetypelist) self.sourceSelector.specButton.hide() self.selectorWidget = {} self.selectorWidget[QEdfFileWidget.SOURCE_TYPE] = QEdfFileWidget.\ QEdfFileWidget(self,justviewer=1) self.mainLayout.addWidget(self.sourceSelector) self.mainLayout.addWidget(self.selectorWidget[QEdfFileWidget.SOURCE_TYPE]) if QTVERSION < '4.0.0': self.connect(self.sourceSelector, qt.PYSIGNAL("SourceSelectorSignal"), self._sourceSelectorSlot) else: self.connect(self.sourceSelector, qt.SIGNAL("SourceSelectorSignal"), self._sourceSelectorSlot)
def __replaceClicked(self): if DEBUG: print("replace clicked") selkeys = self.__getSelectedKeys() if len(selkeys): #self.eh.event(self.repEvent, selkeys) if DEBUG: print("Replace event") sel = {} sel['SourceType'] = SOURCE_TYPE for selection in selkeys: if 'SourceName' not in sel: sel['SourceName'] = selection['SourceName'] arrayname = selection['Key'] if 'Key' not in sel: sel['Key'] = selection['Key'] if arrayname not in sel: sel[arrayname] = {'rows': [], 'cols': []} if selection['plot'] == 'cols': sel[arrayname]['cols'].append({ 'x': selection['x'], 'y': selection['y'] }) if selection['plot'] == 'rows': sel[arrayname]['rows'].append({ 'x': selection['x'], 'y': selection['y'] }) """ if selection['plot'] == 0: sel[arrayname]['mca'].append({'x':selection['x'],'y':selection['y']}) """ self.setSelected([sel], reset=1) self.emit(qt.PYSIGNAL("replaceSelection"), ([sel], ))
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 _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 closeEvent(self, event): qt.QWidget.closeEvent(self, event) ddict = {} ddict['event'] = 'closed' if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('closed'), (ddict,)) else: self.emit(qt.SIGNAL('closed'), ddict)
def _sliderChanged(self, value): if DEBUG: print("DoubleSlider._sliderChanged()") ddict = self.__getDict() if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL("doubleSliderValueChanged"), (ddict, )) else: self.emit(qt.SIGNAL("doubleSliderValueChanged"), ddict)
def closeEvent(self, event): ddict = {} ddict["event"] = "McaSimpleFitClosed" if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL('McaSimpleFitSignal'), (ddict, )) else: self.emit(qt.SIGNAL('McaSimpleFitSignal'), ddict) return qt.QWidget.closeEvent(self, event)
def closeEvent(self, event): QTable.closeEvent(self, event) ddict = {} ddict['event'] = 'closed' if qt.qVersion() < '4.0.0': self.emit(qt.PYSIGNAL('closed'), (ddict, )) else: self.emit(qt.SIGNAL('closed'), ddict)
def __selection(self, peak): selection = [] for key in self.peaklist: if self.buttondict[key].isSelected(): selection.append(key) if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL("selectionChanged"), (selection, )) else: self.emit(qt.SIGNAL("selectionChanged"), (selection))
def __selectionChanged(self): if self.cnt == 0: return else: for row in range(self.cnt): if self.table.isSelected(row, 2): self.table.ycheck[row].setChecked(1) else: self.table.ycheck[row].setChecked(0) self.emit(qt.PYSIGNAL("cntSelection"), (self.getSelection, ))
def mouseDoubleClickEvent(self, event): if DEBUG: print("Double Click Event") ddict = {} ddict['event'] = "DoubleClick" ddict['data'] = event if qt.qVersion() < '4.0.0': self.emit(qt.PYSIGNAL("LineDoubleClickEvent"), (ddict, )) else: self.emit(qt.SIGNAL("LineDoubleClickEvent"), ddict)
def mousePressEvent(self, event): if DEBUG: print("Mouse Press Event") ddict = {} ddict['event'] = "MousePress" ddict['data'] = event if qt.qVersion() < '4.0.0': self.emit(qt.PYSIGNAL("PixmapLabelMousePressEvent"), (ddict, )) else: self.emit(qt.SIGNAL("PixmapLabelMousePressEvent"), ddict)
def __init__(self, parent=None, initdict = None): if qt.qVersion() < '4.0.0': qt.QWidget.__init__(self, parent, "TubeWidget",0) else: qt.QWidget.__init__(self, parent) self._build() if qt.qVersion() < '4.0.0': self.connect(self.anodeCombo, qt.PYSIGNAL("MyQComboBoxSignal"), self._anodeSlot) self.connect(self.windowCombo, qt.PYSIGNAL("MyQComboBoxSignal"), self._windowSlot) self.connect(self.filter1Combo, qt.PYSIGNAL("MyQComboBoxSignal"), self._filter1Slot) else: self.connect(self.anodeCombo, qt.SIGNAL("MyQComboBoxSignal"), self._anodeSlot) self.connect(self.windowCombo, qt.SIGNAL("MyQComboBoxSignal"), self._windowSlot) self.connect(self.filter1Combo, qt.SIGNAL("MyQComboBoxSignal"), self._filter1Slot) self.connect(self.transmissionCheckBox, qt.SIGNAL("clicked()"), self._transmissionSlot) if initdict is not None: self.setParameters(initdict) else: d = {} d["transmission"] = 0 d["voltage"] = 30.0 d["anode"] = "Ag" d["anodethickness"] = 0.0002 d["anodedensity"] = Elements.Element["Ag"]["density"] d["window"] = "Be" d["windowthickness"] = 0.0125 d["windowdensity"] = Elements.Element["Be"]["density"] d["filter1"] = "He" d["filter1thickness"]= 0.0 d["filter1density"] = Elements.Element["He"]["density"] d["alphax"] = 90.0 d["alphae"] = 90.0 d["deltaplotting"] = 0.10 self.setParameters(d)
def _removeClicked(self): if DEBUG: print("Overwritten _removeClicked method") #get selected scan keys if QTVERSION < '4.0.0': scan_sel= [sn for sn in self.scans if self.list.findItem(sn,1).isSelected()] else: itemlist = self.list.selectedItems() scan_sel = [str(item.text(1)) for item in itemlist] #get selected counter keys cnt_sel = self.cntTable.getCounterSelection() mca_sel = self.mcaTable.getCurrentlySelectedMca() sel_list = [] #build the appropriate selection for mca's for scan in scan_sel: for mca in mca_sel: sel = {} sel['SourceName'] = self.data.sourceName sel['SourceType'] = self.data.sourceType sel['Key'] = scan sel['Key'] += "."+mca sel['selection'] = None #for the future #sel['scanselection'] = False sel['legend'] = os.path.basename(sel['SourceName'][0]) +" "+sel['Key'] sel_list.append(sel) if len(cnt_sel['cntlist']): if len(cnt_sel['y']): #if there is something to plot sel = {} sel['SourceName'] = self.data.sourceName sel['SourceType'] = self.data.sourceType sel['Key'] = scan sel['selection'] = {} if self.forceMcaBox.isChecked(): sel['scanselection'] = "MCA" else: sel['scanselection'] = True sel['selection']['x'] = cnt_sel['x'] if len(sel['selection']['x']) == 2: if self.meshBox.isChecked(): sel['selection']['selectiontype'] = "2D" sel['selection']['y'] = cnt_sel['y'] sel['selection']['m'] = cnt_sel['m'] sel['selection']['cntlist'] = cnt_sel['cntlist'] sel['legend'] = os.path.basename(sel['SourceName'][0]) +" "+ sel['Key'] sel_list.append(sel) if len(sel_list): if QTVERSION < '4.0.0': self.emit(qt.PYSIGNAL("removeSelection"), (sel_list,)) else: self.emit(qt.SIGNAL("removeSelection"), sel_list)
def __init__(self, parent=None, name=None, fl=0): qt.QComboBox.__init__(self, parent) self.setEditable(True) self._lineEdit = MyQLineEdit() self.setLineEdit(self._lineEdit) if QTVERSION < '4.0.0': self.connect(self._lineEdit, qt.PYSIGNAL("MyQLineEditSignal"), self._mySlot) else: self.connect(self._lineEdit, qt.SIGNAL("MyQLineEditSignal"), self._mySlot)