def launchApplication(filename=None): global top root = Tkinter.Tk() root.withdraw() top = ApplicationPopup(root) project = None if filename: file = normalisePath(filename) askdir = lambda title, prompt, initial_value, default_dir: askDir( title, prompt, initial_value, parent=top, extra_dismiss_text='Skip', default_dir=default_dir) askfile = lambda title, prompt, initial_value: askFile( title, prompt, initial_value, parent=top, extra_dismiss_text='Skip') try: project = loadProject(path=file, showWarning=showWarning, askDir=askdir, askFile=askfile) except ApiError, e: showError('Reading project', e.error_msg)
def setPeakSize(self, *extra): axisType = self.getAxisType() try: axisType.peakSize = self.peakSizeEntry.get() except Implementation.ApiError, e: showError('Setting peak size', e.error_msg, parent=self)
def setDecimal(self, *extra): axisType = self.getAxisType() try: axisType.numDecimals = self.decimalEntry.get() except Implementation.ApiError, e: showError('Setting number of decimals', e.error_msg, parent=self)
def setRegion(self, *extra): axisType = self.getAxisType() try: axisType.region = self.regionEntry.get() except Implementation.ApiError, e: showError('Setting region', e.error_msg, parent=self)
def setContourLevels(self): spectrum = self.spectrum if not spectrum or spectrum.isDeleted is True: return try: analysisSpectrum = spectrum.analysisSpectrum baseLevel = analysisSpectrum.autoBaseLevel numberLevels = analysisSpectrum.autoNumLevels levelChanger = analysisSpectrum.autoLevelChanger changeMode = analysisSpectrum.autoLevelMode posLevels = [] if self.which_buttons.isIndexSelected(0): posLevels.extend( calcContourLevels(baseLevel, numberLevels, levelChanger, changeMode)) negLevels = [] if self.which_buttons.isIndexSelected(1): if changeMode == 'add': levelChanger = -levelChanger negLevels.extend( calcContourLevels(-baseLevel, numberLevels, levelChanger, changeMode)) self.posLevelsEntry.set(posLevels) self.negLevelsEntry.set(negLevels) analysisSpectrum.posLevels = posLevels analysisSpectrum.negLevels = negLevels except Implementation.ApiError, e: showError('Contour levels error', e.error_msg, parent=self)
def setFiles(self, fileNames): if not self.fileList.multiSelect: self.setFile(fileNames[0]) return dirA = None files = [] for fileName in fileNames: dirB, file = splitPath(fileName) if dirA is None: dirA = dirB elif dirA != dirB: msg = 'Cannot select files from different directories' showError('Set files failure', msg, parent=self) return if file in self.fileList.objectList: files.append(file) if dirA: self.setDirectory(dirA) self.fileList.selectObjects(files)
def apply(self): columnInfoLong = [] for colIndex in range(0, self.columnLen): columnInfoLongName = self.columnInfoWidgets[colIndex].getSelected() if columnInfoLongName != 'None' and columnInfoLongName in columnInfoLong: showError( "Unique names", "Each column needs a unique content - %s repeated twice." % columnInfoLongName) return False columnInfoLong.append(columnInfoLongName) if columnInfoLong.count('None') == len(columnInfoLong): showError("Need identifiers", "Need content for at least one column.") return False self.columnConvert = [] for i in range(self.columnLen): for (longName, attrName, function) in self.columnContents: if longName == columnInfoLong[i]: if attrName: self.columnConvert.append((attrName, function)) else: self.columnConvert.append(None) break return True
def apply(self): # protect against repeated double-clicking if (self.project): return False path = self.file_select.getDirectory() if not doesRepositoryContainProject( path) and not getPossibleProjectFiles(path): self.file_select.changeDir(path) return False self.disableOk() self.project = None if not path: showError('No path', 'Need to select path', self) self.enableOk() return False try: self.project = self.load_project(path) except ApiError, e: showError('Loading project', e.error_msg, self) self.enableOk() return False
def apply(self): shiftListLabel = self.shiftListSelect.getSelected() shiftList = self.shiftListDict[shiftListLabel] try: chainLabel = self.chainListSelect.getSelected() chain = self.chainDict[chainLabel] except: showError( "No chains", "No chains were present or selected. Try running linkResonances first." ) return False fileName = self.fileButton.__getitem__('text') if fileName == self.defaultText: return False fileCreated = writeBmrbChemShiftDeposition(self.guiParent, chain, shiftList, fileName) if fileCreated: showInfo("Success", "Succesfully wrote chemical shift deposition file") else: showError("Not written", "Error writing file %s. File not written" % fileName) return False return True
def apply(self, *extra): params = {} params['scale'] = self.scale_entry.get() params['buffer'] = self.buffer_entry.get() params['thickness'] = self.thickness_entry.get() params['drop'] = self.drop_entry.get() params['volumeMethod'] = self.method_menu.getText() n = self.adjacent_buttons.getIndex() if (n == 0): nonadjacent = False else: nonadjacent = True params['nonadjacent'] = nonadjacent n = self.extrema_buttons.getIndex() if (n == 0): have_high = True have_low = True elif (n == 1): have_high = True have_low = False elif (n == 2): have_high = False have_low = True params['haveHigh'] = have_high params['haveLow'] = have_low project = self.project try: PeakFindParams.setPeakFindParams(project, params) except Implementation.ApiError, e: showError('Parameter error', e.error_msg, parent=self)
def __init__(self, parent, project): self.project = project self.guiParent = parent self.selectedFormats = [] self.defaultText = 'Select file' self.chainDict = {} self.chainList = [] self.shiftListDict = {} self.shiftLists = [] for shiftList in self.project.currentNmrProject.findAllMeasurementLists( className='ShiftList'): if shiftList.measurements != (): label = str(shiftList.serial) + ':' + str(shiftList.name) self.shiftListDict[label] = shiftList self.shiftLists.append(label) if not self.shiftLists: showError('Error', 'No shift lists available!') return BasePopup.__init__(self, parent=parent, title="Project '%s': " % project.name + 'Write BMRB chemical shift deposition file', modal=False, transient=True)
def apply(self): if not 0: showError("No root spectrum","Can't continue: need a root spectrum...") return False return True
def launchApplication(projectDir=None): global top root = Tkinter.Tk() root.withdraw() top = EntryCompletionGui(root) project = None if projectDir: projectDir = normalisePath(projectDir) askdir = lambda title, prompt, initial_value, default_dir: askDir(title, prompt, initial_value, parent=top, extra_dismiss_text='Skip') askfile = lambda title, prompt, initial_value: askFile(title, prompt, initial_value, parent=top, extra_dismiss_text='Skip') try: project = loadProject(path=projectDir, showWarning=showWarning, askDir=askdir, askFile=askfile) userRepos = project.findFirstRepository(name='userData') chemCompPackLoc = project.findFirstPackageLocator(targetName='ccp.molecule.ChemComp') if userRepos not in chemCompPackLoc.repositories: chemCompPackLoc.addRepository(userRepos) except ApiError, e: showError('Reading project', e.error_msg, parent=top)
def printStructure(self): w = self.winfo_width() h = self.winfo_height() popup = PrintPopup(self, width=w, height=h, title='Print Structure', modal=True, project=self.project, getOption=self.getPrintOption, setOption=self.setPrintOption) outputHandler = popup.outputHandler popup.destroy() if (not outputHandler): return (x0, y0, x1, y1) = self.handler.getRegion() try: printHandler = PrintHandler.PrintHandler(outputHandler, xRegion=(x0, x1), yRegion=(y0, y1)) self.drawStructure(handler=printHandler) file_name = outputHandler.file_name printHandler.close( ) # clears file_name, hence first need to save, as above showInfo('Wrote file', 'Successfully wrote file "%s"' % file_name, parent=self) except IOError, e: showError('IO Error', str(e), parent=self)
def readGLE(self, gleFile): if not os.path.isfile(gleFile): msg = 'No scorogram Res_%d.pgm\nin directory %s.' % ( resNum, self.dangleDir) showError('File Reading Error', msg, parent=self) return None fopen = open(gleFile, 'r') lines = fopen.readlines() dims = lines[2].split() lines = lines[4:] fopen.close() # only read the top left corner of a 10X10 square bin # all readings in the same bin are identical binSize = 10 matrix = [] for j in range(36): x = j * binSize * binSize * 36 for i in range(36): y = i * binSize v = int(lines[x + y].strip()) matrix.append(v) maxVal = float(max(matrix)) for i in range(len(matrix)): matrix[i] = matrix[i] / maxVal return matrix
def setSelectedFile(self, *event): file = self.file_entry.getEntry() try: self.fileList.selectObject(file) except: showError('Some err', 'some err')
def save(self): projName = self.proj_name_entry.get() directory = self.proj_dir_select.getDirectory() directory = joinPath(directory, projName) if self.isProjectDirectory(directory): if not showOkCancel('Overwrite directory', 'Overwrite existing project directory?', parent=self): return self.updateInfo() self.did_save = False changeDataLocations = self.dataCheckButton.isSelected() done = False try: done = Io.saveProject(self.project, newPath=directory, newProjectName=projName, createFallback=True, showYesNo=showYesNo, changeDataLocations=changeDataLocations, showWarning=showWarning) if done: showInfo('Project saved', 'Project saved successfully') self.did_save = True if self.callback: self.callback(self.project) elif self.modal: return # give another chance except Implementation.ApiError, e: showError('Save project', e.error_msg)
def entryDir(self, *event): dirName = self.directory_entry.getEntry() try: self.changeDir(dirName) except: showError('Not a directory', '"' + dirName + '" is not a directory.')
def changeMolName(self, molName): newMolName = askString('Enter molecule name', 'New name for molecule', molName, self) if newMolName and newMolName != molName: if newMolName in self.molNames: showError("Molecule name present", "This molecule name is already present!") elif self.project.findFirstMolecule(name=newMolName): # TODO TODO: allow user to select an existing molecule?!?! showError( "Molecule exists", "A molecule with this name already exists in the data model." ) else: moleculeInfo = self.localCreateMoleculeDict[molName] self.localCreateMoleculeDict[newMolName] = moleculeInfo del self.localCreateMoleculeDict[molName] # # Clean out text... # for molName in self.molNames: self.warningCode[molName].set("") self.resetInfo() self.setupWidgets()
def doExport(self): if self.exportFileName: chain = self.chainDict[self.chainSelect.getSelected()] returnValue = self.autoAssignFormat.writeProject( self.exportFileName, chain=chain, setTag=self.dateTimeFlag) if not returnValue: showError( "No export file written", "There were problems while exporting the %s project file." % self.format) else: showInfo("File written", "File written successfully") cdtsTag = "%s-%s" % (self.chainSelect.getSelected(), self.dateTimeFlag) if not cdtsTag in self.chainDateTimeSelect.entries: if "<None>" in self.chainDateTimeSelect.entries: self.chainDateTimeSelect.entries.pop( self.chainDateTimeSelect.entries.index("<None>")) self.chainDateTimeSelect.replace( [cdtsTag] + self.chainDateTimeSelect.entries) self.chainDateTimeStampDict[cdtsTag] = chain else: showError( "No export file defined", "Please define a name for the %s project file to export to." % self.format)
def launchApplication(projectDir=None): global top root = Tkinter.Tk() root.withdraw( ) # get rid of the root window Tkinter would otherwise put up top = ApplicationPopup( root) # creates our controlled window (this class in fact) project = None if projectDir: projectDir = normalisePath(projectDir) askdir = lambda title, prompt, initial_value, default_dir: askDir( title, prompt, initial_value, parent=top, extra_dismiss_text='Skip') askfile = lambda title, prompt, initial_value: askFile( title, prompt, initial_value, parent=top, extra_dismiss_text='Skip') try: project = loadProject(path=projectDir, showWarning=showWarning, askDir=askdir, askFile=askfile) except ApiError, e: showError('Reading project', e.error_msg, parent=top)
def apply(self): try: self.outputHandler = self.printFrame.getOutputHandler( self.width, self.height) except IOError, e: showError('IO Error', str(e), parent=self) return False
def unsetLink(self, role): if (self.editMode): try: func = getattr(self.object, 'set%s' % upperFirst(role.baseName)) func(None) except Implementation.ApiError, e: showError('Unsetting link', e.error_msg, parent=self)
def pickAdaptive(self): if self.spectrum: segLevel, threshold, maxPeaks = self.getEntryData() try: findAuremolPeaksAdaptive(spectrum=self.spectrum, mode=self.peakMode, number=maxPeaks, seglevel=segLevel) except Exception, e: showError('pickAdaptive', str(e), parent=self)
def fetchValues(self): directory = self.directoryEntry.get() template = self.templateEntry.get() try: values = getSampledValues(directory, template) except ApiError, e: showError('Fetch Values', e.error_msg, parent=self) return
def pickThreshold(self): if self.spectrum: segLevel, threshold, maxPeaks = self.getEntryData() try: findAuremolPeaksThreshold(spectrum=self.spectrum, mode=self.peakMode, useAutoThreshold=0, threshold=threshold, seglevel=segLevel) except Exception, e: showError('pickThreshold', str(e), parent=self)
def apply(self): selected = self.table.currentObject if (not selected): showError('No selection', "No object selected", parent=self) return False self.selected = selected return True
def apply(self): self.result = '' file = self.file_select.getFile() if (self.selected_file_must_exist and not os.path.exists(file)): showError('No file', 'File does not exist', self) return False self.result = file return True
def updateParams(self): params = self.params if self.pseudoButton.get() == self.pseudoEntries[0]: npts = self.nptsEntry.get() params.npts[self.dim] = npts values = self.valueEntry.get() try: params.setSampledDim(self.dim, values) except ApiError, e: showError('Set Sampled Dim', e.error_msg, parent=self) return
def saveFile(self): if not self.project: return False try: saveProject(self.project, createFallback=True) print 'successfully saved project' return True except IOError, e: showError('Saving file', str(e), parent=self) return False