class ResonanceSelectPopup(BasePopup): def __init__(self, parent, resonanceList, resonanceDict, code3Letter, resName, helpText, multi, title='Select resonances'): # Constructor doesn't do much except call body # The parent is self.parent (parent of the popup) self.selectedResonances = None self.resonanceList = resonanceList self.resonanceDict = resonanceDict self.code3Letter = code3Letter self.resName = resName self.helpText = helpText if multi: self.selectmode = Tkinter.MULTIPLE else: self.selectmode = Tkinter.SINGLE # modal = true means that it won't continue unless this one returns value BasePopup.__init__(self, parent=parent, title=title, modal=True, transient=True) def body(self, master): master.grid_columnconfigure(0, weight=1) for i in range(6): master.grid_rowconfigure(i, weight=1) self.geometry('600x400') # # Popup window # row = 0 label = Label(master, text="Residue type '%s'" % self.code3Letter) label.grid(row=row, column=0, sticky=Tkinter.EW) row = row + 1 label = Label(master, text="Resonance '%s'" % self.resName) label.grid(row=row, column=0, sticky=Tkinter.EW) row = row + 1 label = Label(master, text="Pick resonance(s):") label.grid(row=row, column=0, sticky=Tkinter.W) row = row + 1 self.list = ScrolledListbox(master, width=50, height=5, selectmode=self.selectmode, initial_list=self.resonanceList) self.list.grid(row=row, column=0, sticky=Tkinter.EW) row = row + 1 label = Label(master, text=self.helpText, fg='blue') label.grid(row=row, column=0, sticky=Tkinter.EW) row = row + 1 texts = ['OK'] commands = [ self.ok ] # This calls 'ok' in BasePopup, this then calls 'apply' in here buttons = createDismissHelpButtonList(master, texts=texts, commands=commands) buttons.grid(row=row, column=0) def apply(self): selectedResNames = self.list.getSelectedItems() # # Return value depends on whether multi or not # if selectedResNames: if type(selectedResNames) == type([]): self.selectedResonances = [] for selectedResName in selectedResNames: self.selectedResonances.append( self.resonanceDict[selectedResName]) else: self.selectedResonances = [ self.resonanceDict[selectedResNames] ] else: return False return True
class MultiSelectionListSkeleton: def __init__(self, parent, selectionList, selectionDict = {}, selectedItems = [], title = 'MultiSelect', text = 'MultiSelect', endText = None, dismissText = 'dismiss', urlFile = None, modal = False): self.selectionList = selectionList self.selectionDict = selectionDict self.selectedItems = selectedItems self.text = text self.endText = endText self.dismissText = dismissText self.isSelectedList = None self.setUrlFile(urlFile) self.startBasePopup(parent,title,modal,True) def startBasePopup(self,parent,title,modal,True): pass def setUrlFile(self,urlFile): self.help_url = None def body(self, master): # # Popup window # row = 0 label = Label(master, text= self.text) label.grid(row=row, column=0, sticky=Tkinter.EW) row = row + 1 self.multiSelect = ScrolledListbox(master, width = 50, height = 5, selectmode = Tkinter.MULTIPLE, initial_list = self.selectionList) self.multiSelect.grid(row=row, column=0, sticky=Tkinter.E, ipadx = 20) master.grid_columnconfigure(0, weight=1) master.grid_rowconfigure(row, weight=1) if self.selectedItems: self.multiSelect.setSelectedItems(self.selectedItems) if self.endText: row = row + 1 label = Label(master, text= self.endText) label.grid(row=row, column=0, sticky=Tkinter.EW) row = row + 1 texts = [ 'OK' ] commands = [ self.ok ] # This calls 'ok' in BasePopup, this then calls 'apply' in here buttons = createDismissHelpButtonList(master, texts=texts, commands=commands, dismiss_text = self.dismissText, help_url=self.help_url) buttons.grid(row=row, column=0) def apply(self): self.isSelectedList = [] for selectedItem in self.multiSelect.getSelectedItems(): if self.selectionDict.has_key(selectedItem): self.isSelectedList.append(self.selectionDict[selectedItem]) else: self.isSelectedList.append(selectedItem) return True
class CreateShiftListPopup(BasePopup): help_url = joinPath(getHelpUrlDir(), 'CreateShiftList.html') def __init__(self, parent, project): self.project = project self.peakLists = [] BasePopup.__init__(self, parent=parent, title="Project '%s': " % project.name + 'Create shift list from peak lists', modal=False, transient=True) def body(self, master): # # Peaklist setup # self.peakListDict = {} for experiment in self.project.currentNmrProject.sortedExperiments(): for dataSource in experiment.sortedDataSources(): for peakList in dataSource.sortedPeakLists(): peakListLabel = "%s:%s:%d:%s" % ( experiment.name, dataSource.name, peakList.serial, peakList.name) self.peakListDict[peakListLabel] = peakList peakListLabels = self.peakListDict.keys() peakListLabels.sort() # # chemical shift list setup # self.shiftListDict = {} self.shiftListDict['None'] = None for shiftList in self.project.currentNmrProject.findAllMeasurementLists( className='ShiftList'): shiftListLabel = "%d:%s" % (shiftList.serial, shiftList.name) self.shiftListDict[shiftListLabel] = shiftList shiftListLabels = self.shiftListDict.keys() shiftListLabels.sort() row = 0 label = Label(master, text="Generation of chemical shift list") label.grid(row=row, column=0, columnspan=2, sticky=Tkinter.W) row += 1 label = Label(master, text="Peak lists:") label.grid(row=row, column=0, sticky=Tkinter.W) self.peakListBox = ScrolledListbox(master, width=50, height=5, selectmode=Tkinter.MULTIPLE, initial_list=peakListLabels) self.peakListBox.grid(row=row, column=1, sticky=Tkinter.EW) row += 1 label = Label(master, text="Use existing shift list:") label.grid(row=row, column=0, sticky=Tkinter.W) self.shiftListSelect = PulldownMenu(master, entries=shiftListLabels) self.shiftListSelect.grid(row=row, column=1, sticky=Tkinter.EW) row += 1 label = Label(master, text="Use multiple assignments:") label.grid(row=row, column=0, sticky=Tkinter.W) self.useAllContribs = CheckButton(master) self.useAllContribs.grid(row=row, column=1, sticky=Tkinter.W) # # Setup the default shift error per nucleus # self.defaultShiftError = {} for (nucl, text, defValue) in [('1H', 'proton', '0.002'), ('13C', 'carbon', '0.1'), ('15N', 'nitrogen', '0.1')]: row += 1 label = Label(master, text="Default %s shift error:" % text) label.grid(row=row, column=0, sticky=Tkinter.W) self.defaultShiftError[nucl] = Entry(master, text=defValue) self.defaultShiftError[nucl].grid(row=row, column=1, sticky=Tkinter.W) row += 1 texts = ['Create shift list'] commands = [ self.ok ] # This calls 'ok' in BasePopup, this then calls 'apply' in here buttons = createDismissHelpButtonList(master, texts=texts, commands=commands, help_url=self.help_url) buttons.grid(row=row, columnspan=2, column=0) def apply(self): selectedPeakLists = self.peakListBox.getSelectedItems() for peakListLabel in selectedPeakLists: self.peakLists.append(self.peakListDict[peakListLabel]) chemShiftList = self.shiftListDict[self.shiftListSelect.getSelected()] if not chemShiftList: chemShiftListName = askString("Enter chemical shift list name", "New chemical shift list name", '', self) else: chemShiftListName = chemShiftList.name useAllContribs = self.useAllContribs.isSelected() defaultShiftError = {} for nucl in self.defaultShiftError.keys(): defaultShiftError[nucl] = returnFloat( self.defaultShiftError[nucl].get()) listCreated = createChemShifts(self.peakLists, guiParent=self.parent, multiDialog=self.parent.multiDialog, shiftList=chemShiftList, useAllContribs=useAllContribs, defaultShiftError=defaultShiftError, shiftListName=chemShiftListName) if listCreated: showInfo( "Success", "Succesfully created a chemical shift list from peaklist(s)") return True
class WriteMappingPopup(BasePopup): help_url = joinPath(getHelpUrlDir(),'WriteMapping.html') def __init__(self, parent, project): self.project = project self.selectedFormats = [] self.defaultText = 'Select file' self.formats = allFormatsDict.keys() self.formats.sort() BasePopup.__init__(self, parent=parent, title= "Project '%s': " % project.name + 'Write ccpNmr mapping file', modal=False, transient=True) def body(self, master): row = 0 label = Label(master, text= "CcpNmr resonance -> atom mapping file writer.") label.grid(row=row, column=0, columnspan = 2, sticky=Tkinter.W) row += 1 label = Label(master, text= "File formats:") label.grid(row=row, column=0, sticky=Tkinter.W) self.formatListBox = ScrolledListbox(master, width = 50, height = 5, selectmode = Tkinter.MULTIPLE, initial_list = self.formats) self.formatListBox.grid(row=row, column=1, sticky=Tkinter.EW) # Default is all formats selected... self.formatListBox.setSelectedItems(self.formatListBox.getItems()) row += 1 label = Label(master, text= "Mapping output file:") label.grid(row=row, column=0, sticky=Tkinter.W) self.fileButton = Tkinter.Button(master, text = self.defaultText, command = self.selectFile) self.fileButton.grid(row=row, column=1, sticky=Tkinter.W) row += 1 texts = [ 'Write mapping' ] commands = [ self.ok ] # This calls 'ok' in BasePopup, this then calls 'apply' in here buttons = createDismissHelpButtonList(master, texts=texts, commands=commands, help_url=self.help_url) buttons.grid(row=row, columnspan = 2, column=0) def selectFile(self): fileName = self.fileButton.__getitem__('text') if fileName == self.defaultText: fileName = 'ccpNmr.map' popup = FormatFilePopup(self, file = fileName, component = 'mapping', format = ccpNmr_kw) if popup.fileSelected: self.fileButton.config(text = popup.file) popup.destroy() def apply(self): self.selectedFormats = self.formatListBox.getSelectedItems() fileName = self.fileButton.__getitem__('text') if fileName == self.defaultText: return False fileCreated = writeMappingFile(self.project,fileName,originalFormats = self.selectedFormats) if fileCreated: showInfo("Success","Succesfully wrote mapping file") else: showError("Not written","Error writing file %s. File not written" % fileName) return False return True