def reload(self): try: reload(self.module) except: raise Implementation.ApiError('could not reload module "' + self.module_name + '"') return try: self.func = getattr(self.module, self.func_name) except: raise Implementation.ApiError('could not find function "' + self.func_name + '" in module "' + self.module_name + '"')
def __init__(self, argumentServer, command_name, module_name, func_name): self.name = command_name self.module_name = module_name self.func_name = func_name self.argumentServer = argumentServer try: self.module = __import__(module_name) except: raise Implementation.ApiError('could not import module "' + self.module_name + '"') try: self.func = getattr(self.module, self.func_name) except: raise Implementation.ApiError('could not find function "' + self.func_name + '" in module "' + self.module_name + '"')
def createPeakMark(peak, lineWidth=1, dashLength=2, gapLength=2, remove=True, axisTypeDict=None): """ Create a mark positioned at a given peak .. describe:: Input Nmr.Peak, Int, Int, Int, Boolean .. describe:: Output Analysis.Mark """ if not axisTypeDict: axisTypeDict = {} peakList = peak.peakList project = peakList.root analysisProject = project.currentAnalysisProject analysisPeakList = peakList.analysisPeakList if analysisPeakList: color = analysisPeakList.symbolColor elif project.currentAnalysisProfile: color = project.currentAnalysisProfile.fgColor else: color = Color.grey.hex mark = analysisProject.newMark(lineWidth=lineWidth, dashLength=dashLength, gapLength=gapLength, color=color) for peakDim in peak.peakDims: axisType = axisTypeDict.get(peakDim) if not axisType: dataDimRef = peakDim.dataDimRef if dataDimRef: expDimRef = dataDimRef.expDimRef isotopeCodes = expDimRef.isotopeCodes axisType = analysisProject.findFirstAxisType(isotopeCodes=isotopeCodes) if not axisType: msg = 'Unknown axis type isotope codes ' + isotopeCodes raise Implementation.ApiError(msg) if axisType: markDim = mark.newMarkDim(position=peakDim.value, axisType=axisType) mark.peak = peak if remove: removeMarks(project) return mark
def registerNotify(notify, classname, funcname, application = None, keyword = None): if application is None or keyword is None: assert application is None and keyword is None, 'application = %s, keyword = %s, both must be None' % (application, keyword) return GenImp.registerNotify(notify, classname, funcname) if funcname not in allowedNotifyFuncs: raise GenImp.ApiError('illegal funcname "%s", must be in %s' % (funcname, allowedNotifyFuncs)) notifies = GenImp.getClassFromFullName(classname)._notifies notifies = notifies.setdefault((funcname, application, keyword), []) notifies.append(notify)
def applyAuto(self, *extra): try: spectrum = self.spectrum scale = self.global_entry.get() changeMode = self.change_mode_buttons.getIndex( ) and 'add' or 'multiply' baseLevel = self.base_entry.get() if (baseLevel <= 0): raise Implementation.ApiError( 'Base level must be set to positive float') numberLevels = self.numberEntry.get() if (numberLevels < 1): raise Implementation.ApiError( 'Number of levels must be set to positive int') levelChanger = self.change_entry.get() if changeMode == 'add': if levelChanger <= 0.0: raise Implementation.ApiError( 'Level adder must be set to number > 0.0') else: if levelChanger <= 1.0: raise Implementation.ApiError( 'Level multiplier must be set to number > 1.0') self.analysisProject.globalContourScale = scale self.doUpdateForm = False analysisSpectrum = spectrum.analysisSpectrum analysisSpectrum.autoBaseLevel = baseLevel analysisSpectrum.autoNumLevels = numberLevels analysisSpectrum.autoLevelChanger = levelChanger analysisSpectrum.autoLevelMode = changeMode self.setContourLevels() self.doUpdateForm = True except Implementation.ApiError, e: showError('Levels error', e.error_msg, parent=self)
def unregisterNotify(notify, classname, funcname, application = None, keyword = None): if application is None or keyword is None: assert application is None and keyword is None, 'application = %s, keyword = %s, both must be None' % (application, keyword) return GenImp.unregisterNotify(notify, classname, funcname) if funcname not in allowedNotifyFuncs: raise GenImp.ApiError('illegal funcname "%s", must be in %s' % (funcname, allowedNotifyFuncs)) try: notifies = GenImp.getClassFromFullName(classname)._notifies notifies = notifies[(funcname, application, keyword)] notifies.remove(notify) except: pass