def chooseOldProjectFile(self): fileTypes = [FileType('CING', ['project.xml']), FileType('All', ['*'])] popup = FileSelectPopup(self, file_types=fileTypes, title='Select CING project file', dismiss_text='Cancel', selected_file_must_exist=True) fileName = popup.getFile() # dirName = popup.getDirectory() if len(fileName) > 0: # Put text into entry,name widgets dummy, name = cing.Project.rootPath(fileName) self.projEntry.configure(state='normal') self.projEntry.set(fileName) self.nameEntry.configure(state='normal') self.nameEntry.set(name) self.nameEntry.configure(state='disabled') # choose the correct radiobutton self.projOptionsSelect.setIndex(0) self.updateGui() # end if #nd if popup.destroy()
def importNmrStar31(self): if not self.project: showWarning('Failure','Please create a new CCPN project.', parent=self) return fileTypes = [ FileType('STAR', ['*.str']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Import NMR-STAR 3.1 file', dismiss_text='Cancel', selected_file_must_exist=True, multiSelect=False,) fileName = fileSelectPopup.getFile() if not os.path.exists(fileName): showWarning('Failure','No such file.', parent=self) return if fileName: nmrStarObj = NmrStarFormat(self.project, self, verbose=True) nmrStarObj.readProject(fileName, minimalPrompts=True, version='3.1') self.eciFrame.updateAll() return nmrStarObj
def importFastaSeq(self): if not self.project: showWarning('Failure','Please create a new CCPN project.', parent=self) return fileTypes = [ FileType('Fasta', ['*.fsa']), FileType('All', ['*']) ] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Import Fasta sequence file', dismiss_text='Cancel', selected_file_must_exist=True, multiSelect=False,) fileName = fileSelectPopup.getFile() if not os.path.exists(fileName): showWarning('Failure','No such file.', parent=self) return if fileName: name = os.path.split(fileName)[1] if '.' in name: name = name.split('.')[0] fastaObj = FastaFormat(self.project, self, verbose=True) fastaObj.readSequence(fileName, minimalPrompts=True) self.eciFrame.updateAll() return fastaObj
def importPdb(self): if not self.project: showWarning('Failure','Please create a new CCPN project.', parent=self) return fileTypes = [ FileType('PDB', ['*.pdb']), FileType('PDB Entry', ['*.ent']), FileType('All', ['*']) ] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Import PDB 3.20 file', dismiss_text='Cancel', selected_file_must_exist=True, multiSelect=False,) fileName = fileSelectPopup.getFile() if not os.path.exists(fileName): showWarning('Failure','No such file.', parent=self) return if fileName: name = os.path.split(fileName)[1] if '.' in name: name = name.split('.')[0] pdbObj = ReadPdb(fileName, self.project, 'PDB_'+ name, self) self.eciFrame.updateAll() return pdbObj
def body(self, master): self.geometry('600x500') master.grid_rowconfigure(1, weight=1) master.grid_columnconfigure(0, weight=1) label = Label(master, text='Select Project Directory') label.grid(row=0, column=0, sticky=Tkinter.W) file_types = [FileType('Project', ['*.xml']), FileType('All', ['*'])] self.file_select = FileSelect(master, file_types=file_types, show_file=False, double_callback=self.ok, getRowColor=self.getEntryColor, getExtraCell=self.getProjectFileText, extraHeadings=('Status', ), extraJustifies=('left', )) self.file_select.grid(row=1, column=0, sticky=Tkinter.NSEW) texts = ['Open'] commands = [self.ok] buttons = createDismissHelpButtonList(master, texts=texts, commands=commands, dismiss_text='Cancel', help_msg=self.help_msg, help_url=self.help_url) buttons.grid(row=2, column=0, sticky=Tkinter.EW) self.ok_button = buttons.buttons[0]
def importPdbCoords(self): if not self.project: showWarning('Failure','Please create a new CCPN project.', parent=self) return fileTypes = [ FileType('PDB', ['*.pdb']), FileType('PDB Entry', ['*.ent']), FileType('All', ['*']) ] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Import PDB coordinates file', dismiss_text='Cancel', selected_file_must_exist=True, multiSelect=False,) fileName = fileSelectPopup.getFile() if not os.path.exists(fileName): showWarning('Failure','No such file.', parent=self) return if fileName: name = os.path.split(fileName)[1] if '.' in name: name = name.split('.')[0] pdbObj = PseudoPdbFormat(self.project, self, verbose=True) pdbObj.readCoordinates(fileName, minimalPrompts=True) self.eciFrame.updateAll() return pdbObj
def exportText(self, *event): from memops.gui.FileSelect import FileType from memops.gui.FileSelectPopup import FileSelectPopup if self.textOut: fileTypes = [ FileType('Text', ['*.txt']), FileType('CSV', ['*.csv']), FileType('All', ['*']) ] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Save table as text', dismiss_text='Cancel', selected_file_must_exist=False) fileName = fileSelectPopup.getFile() if fileName: file = open(fileName, 'w') if fileName.endswith('.csv'): for textRow in self.textMatrix: file.write(','.join(textRow) + '\n') else: file.write(self.textOut)
def chooseExecutable(self): fileTypes = [FileType('Table', ['*.exe']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup(self, file_types = fileTypes, title = 'Choose 2d BACUS executable', dismiss_text = 'Cancel', selected_file_must_exist = False) fileName = fileSelectPopup.getFile() if fileName: self.executableEntry.set(fileName)
def selectCnsExe(self): fileTypes = [ FileType("All", ["*"]), FileType("EXE", ["*.exe"]) ] popup = FileSelectPopup(self, fileTypes) file = popup.getFile() if file: self.cnsExeEntry.set( file ) popup.destroy() self.updateEntryParams()
def findFile(self): if self.file_select_popup: self.file_select_popup.open() else: file_types = [ FileType('All', ['*']), FileType('PostScript', ['*.ps', '*.eps']), FileType('PDF', ['*.pdf', '*.ai']) ] self.file_select_popup = FileSelectPopup(self, file_types=file_types) file = self.file_select_popup.getFile() if file: self.file_entry.set(file)
def createFileTypes(self, dataTypes): fileTypes = [FileType('all', ['*'])] for dataType in dataTypes: formatNames = fileTypeDict[dataType].keys() formatNames.sort() for formatName in formatNames: if formatName in self.fcWrapper.formatNameLists[dataType]: fileTypes.append( FileType(formatName, fileTypeDict[dataType][formatName])) return fileTypes
def writeScriptFileChange(self): fileTypes = [FileType('python', ['*.py']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup( self, file=os.path.basename(self.scriptEntry.get()), directory=os.path.dirname(self.scriptEntry.get()), file_types=fileTypes, title='Paramagpy script', dismiss_text='Cancel', selected_file_must_exist=False, multiSelect=False, ) self.scriptEntry.set(fileSelectPopup.getFile())
def readPCSFileChange(self): fileTypes = [FileType('PCS', ['*.npc']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup( self, file=os.path.basename(self.calPCSEntry.get()), directory=os.path.dirname(self.calPCSEntry.get()), file_types=fileTypes, title='Save PCS values to file', dismiss_text='Cancel', selected_file_must_exist=False, multiSelect=False, ) self.calPCSEntry.set(fileSelectPopup.getFile())
def body(self, guiParent): guiParent.grid_columnconfigure(1,weight=1) row = 0 file_types = [ FileType('Python', ['*.py']), FileType('All', ['*']) ] self.file_select = FileSelect(guiParent, file_types=file_types, single_callback=self.chooseFile, double_callback=self.chooseFile) self.file_select.grid(row=row, column=0, columnspan=2, sticky='nsew') row = row + 1 headingList=('Function',) self.scrolledMatrix = ScrolledMatrix(guiParent, initialRows=4, headingList=headingList, callback=self.selectFunction) self.scrolledMatrix.grid(row=row, column=0, columnspan=2, sticky='nsew') guiParent.grid_rowconfigure(row,weight=1) row = row + 1 self.moduleLabel1 = Label(guiParent, text='Module: ') self.moduleLabel1.grid(row=row, column=0, sticky='nw') self.moduleLabel2 = Label(guiParent, text=' ') self.moduleLabel2.grid(row=row, column=1, sticky='nw') row = row + 1 self.functionLabel1 = Label(guiParent, text='Function: ') self.functionLabel1.grid(row=row, column=0, sticky='nw') self.functionLabel2 = Label(guiParent, text=' ') self.functionLabel2.grid(row=row, column=1, sticky='nw') row = row + 1 self.nameLabel = Label(guiParent, text='Name: ') self.nameLabel.grid(row=row, column=0, sticky='nw') self.nameEntry = Entry(guiParent, text=' ', width=40) self.nameEntry.grid(row=row, column=1, sticky='nw') row = row + 1 texts = [ 'Load Macro' ] commands = [ self.loadMacro ] buttons = UtilityButtonList(guiParent, texts=texts, commands=commands, helpUrl=self.help_url) buttons.grid(row=row, column=0, columnspan=2, sticky='ew') self.loadButton = buttons.buttons[0] self.loadButton.disable() self.path = None self.module = None self.function = None
def printCanvas(self, *event): from memops.gui.FileSelect import FileType from memops.gui.FileSelectPopup import FileSelectPopup fileTypes = [FileType('PostScript', ['*.ps']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Print canvas to file', dismiss_text='Cancel', selected_file_must_exist=False) fileName = fileSelectPopup.getFile() self.postscript(colormode='color', file=fileName)
def printCanvas(self, *event): fileTypes = [ FileType('PostScript', ['*.ps']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup(self, file_types = fileTypes, title = 'Print canvas to file', dismiss_text = 'Cancel', selected_file_must_exist = False) fileName = fileSelectPopup.getFile() self.bbox = bbox = self.canvas.bbox('all') w = bbox[2] - bbox[0] h = bbox[3] - bbox[1] self.canvas.postscript(colormode='color',file=fileName, x=bbox[0], y=bbox[1], width=w+2, pagewidth='21.c', height=h+2, fontmap='fontmap')
def findFile(self): format = self.format_menu.getSelected() if (format == tabFormat): file_types = [FileType('All', ['*']), FileType('Text', ['*.txt'])] else: file_types = [FileType('All', ['*']), FileType('CSV', ['*.csv'])] popup = FileSelectPopup(self, file_types=file_types) file = popup.getFile() if (file): self.file_entry.set(file) popup.destroy()
def exportText(self, *event): from memops.gui.FileSelect import FileType from memops.gui.FileSelectPopup import FileSelectPopup if self.textOut: fileTypes = [FileType('Text', ['*.txt']), FileType('All', ['*'])] fileSelectPopup = FileSelectPopup(self, file_types=fileTypes, title='Save table as plain text', dismiss_text='Cancel', selected_file_must_exist=False) fileName = fileSelectPopup.getFile() if fileName: file = open(fileName, 'w') file.write(self.textOut)
def chooseValidScript(self): # Prepend default Cyana file extension below fileTypes = [ FileType('Python', ['*.py']), ] popup = FileSelectPopup(self, file_types = fileTypes, title='Python file', dismiss_text='Cancel', selected_file_must_exist = True) fileName = popup.getFile() self.validScriptEntry.set(fileName) popup.destroy()
def chooseZipFile(self): fileTypes = [ FileType('Zip', ['*.zip']), ] popup = FileSelectPopup(self, file_types=fileTypes, file=self.resultFileEntry.get(), title='Results zip file location', dismiss_text='Cancel', selected_file_must_exist=False) fileName = popup.getFile() if fileName: self.resultFileEntry.set(fileName) popup.destroy()
def chooseCcpnFile(self): fileTypes = [FileType('XML', ['*.xml']), FileType('All', ['*'])] popup = FileSelectPopup(self, file_types=fileTypes, title='CCPN project XML file', dismiss_text='Cancel', selected_file_must_exist=True) fileName = popup.getFile() if len(fileName) > 0: self.pdbEntry.configure(state='normal') self.pdbEntry.set(fileName) self.projOptionsSelect.setIndex(1) _dir, name, dummy = nTpath(fileName) self.nameEntry.set(name) #end if self.ccpnEntry.set(fileName) self.projOptionsSelect.setIndex(2) popup.destroy()
def __init__(self, parent, serverLocation=UPDATE_SERVER_LOCATION, serverDirectory=UPDATE_DIRECTORY, dataFile=UPDATE_DATABASE_FILE): UpdateAgent.__init__(self, serverLocation, serverDirectory, dataFile, admin=1) self.fileTypes = [ FileType('Python', ['*.py']), FileType('C', ['*.c']), FileType('All', ['*']) ] self.fileUpdate = None BasePopup.__init__(self, parent=parent, title='CcpNmr Update Administrator', quitFunc=self.quit)
def saveText(self): fileSelectPopup = FileSelectPopup( self, file_types=[ FileType('Text', ['*.txt', '*.out', '*.text']), FileType('All', ['*']) ], title='Select text output save file') fileName = fileSelectPopup.getFile() if fileName: writeFile = 1 if os.path.exists(fileName): if not showYesNo('Overwrite file', 'Overwrite existing file %s?' % fileName): writeFile = 0 if writeFile: fout = open(fileName, 'w') fout.write(self.text.text_area.getText()) fout.close()
def chooseFormat(self, format): if format in ('Bruker', 'Varian'): self.gridDetails(True) else: self.gridDetails(False) file_types = [] file_type = file_type_dict.get(format) if (file_type): file_types.extend([file_type]) file_types.append(FileType('All', ['*'])) file_types.append(self.fileSelect.manualFilter) self.fileSelect.setFileTypes(file_types)
def selectModuleBvExport(self): """ Choose the Back Value file that was exported from MODULE. """ file_types = [ FileType("Back Value files", ["*.back"]), FileType("All files", ["*"]) ] popup = FileSelectPopup(self, file_types, dismiss_text='Cancel', show_file=True) chosenBvFile = popup.getFile() if os.path.isfile(chosenBvFile): moduleBackValueFile = chosenBvFile else: warnPopup = showWarning('MODULE', 'File %s not found.' % chosenBvFile, parent=self) return None popup.destroy() return moduleBackValueFile
def choosePdbFile(self): fileTypes = [FileType('PDB', ['*.pdb']), FileType('All', ['*'])] popup = FileSelectPopup(self, file_types=fileTypes, title='PDB file', dismiss_text='Cancel', selected_file_must_exist=True) fileName = popup.getFile() if len(fileName) > 0: # Put text into entry widget self.pdbEntry.configure(state='normal') self.pdbEntry.set(fileName) # Put text into name widget _dir, name, dummy = nTpath(fileName) self.nameEntry.configure(state='normal') self.nameEntry.set(name) # choose the correct radiobutton self.projOptionsSelect.setIndex(1) self.updateGui() #end if popup.destroy()
def chooseCyanaFile(self): # Prepend default Cyana file extension below fileTypes = [ FileType('All', ['*']), ] popup = FileSelectPopup(self, file_types=fileTypes, title='CYANA fproject file', dismiss_text='Cancel', selected_file_must_exist=True) fileName = popup.getFile() self.cyanaEntry.set(fileName) self.projOptionsSelect.setIndex(3) popup.destroy()
def body(self): '''Setting up the body of this view.''' frame = self.frame file_types = [FileType('pyc', ['*.pyc'])] self.fileselectionBox = FileSelect(frame, multiSelect=False, file_types=file_types) self.fileselectionBox.grid(row=0, column=0, columnspan=6, sticky='nsew') texts = ['Load', 'Save'] commands = [self.loadDataFromPyc, self.saveDataToPyc] self.loadAndSaveButtons = ButtonList(frame, commands=commands, texts=texts) self.loadAndSaveButtons.grid(row=1, column=0, sticky='nsew') frame.grid_rowconfigure(0, weight=1) frame.grid_columnconfigure(0, weight=1)
def body(self, master): master.grid_columnconfigure(0, weight=1) master.grid_rowconfigure(0, weight=1) master.grid_rowconfigure(1, weight=1) self.geometry('500x500') fileNames = [] # All files have to be in same directory! if self.files and self.files[0].find(dirsep) > -1: (path, fileName) = splitPath(self.files[0]) directory = path fileNames.append(fileName) for file in self.files[1:]: (path, fileName) = splitPath(file) fileNames.append(fileName) else: path = None directory = normalisePath(os.path.abspath(os.curdir)) fileNames = [] #print directory #print fileName file_types = [] if fileTypeDict.has_key(self.component): if self.format and fileTypeDict[self.component].has_key( self.format): file_types.extend([ FileType(self.format, fileTypeDict[self.component][self.format]) ]) if fileTypeDict[self.component].has_key('generic'): file_types.extend([ FileType('generic', fileTypeDict[self.component]['generic']) ]) file_types.extend([FileType('All', ['*'])]) self.file_select = FileSelect(master, file_types=file_types, directory=directory, double_callback=self.ok, multiSelect=self.multiSelect) if self.multiSelect: self.file_select.setFiles(fileNames) else: if fileNames: fileName = fileNames[0] else: fileName = '' self.file_select.setFile(fileName) self.file_select.grid(row=0, column=0, sticky=Tkinter.NSEW) texts = [self.selectionText] commands = [self.ok] buttons = createDismissHelpButtonList(master, texts=texts, commands=commands) buttons.grid(row=1, column=0, sticky=Tkinter.EW)
def body(self, guiFrame): self.fileSelect = None names, objects = self.getShiftLists() self.shiftListPulldown = PulldownList(self, callback=self.setShiftList, texts=names, objects=objects) self.windowPulldown = PulldownList(self, texts=WINDOW_OPTS, callback=self.setWindow) self.experimentEntry = Entry(self, width=16, returnCallback=self.setExperiment) self.spectrumEntry = Entry(self, width=16, returnCallback=self.setSpectrum) guiFrame.grid_columnconfigure(0, weight=1) guiFrame.grid_rowconfigure(0, weight=1) guiFrame.grid_rowconfigure(1, weight=1) leftFrame = LabelFrame(guiFrame, text='File Selection') leftFrame.grid(row=0, column=0, sticky='nsew') leftFrame.grid_columnconfigure(3, weight=1) row = 0 label = Label(leftFrame, text='File format:') label.grid(row=row, column=0, sticky='w') tipText = 'Selects which kind of spectrum file is being loaded; what its data matrix format is' self.formatPulldown = PulldownList(leftFrame, callback=self.chooseFormat, texts=file_formats, tipText=tipText, grid=(row, 1)) self.detailsLabel = Label(leftFrame, text='Show details:') tipText = 'Whether to show an annotation that describes the spectrum in the file selection; currently only uses comment fields from Bruker spectra' self.detailsSelect = CheckButton(leftFrame, selected=False, callback=self.showDetails, tipText=tipText) self.titleRow = row self.detailsSelected = False row = row + 1 leftFrame.grid_rowconfigure(row, weight=1) file_types = [FileType('All', ['*'])] self.fileSelect = FileSelect(leftFrame, multiSelect=True, file_types=file_types, single_callback=self.chooseFiles, extraHeadings=('Details', ), extraJustifies=('left', ), displayExtra=False, getExtraCell=self.getDetails, manualFileFilter=True) self.fileSelect.grid(row=row, column=0, columnspan=6, sticky='nsew') rightFrame = LabelFrame(guiFrame, text='Spectra To Open') rightFrame.grid(row=1, column=0, sticky='nsew') rightFrame.grid_columnconfigure(3, weight=1) row = 0 label = Label(rightFrame, text='Skip verification dialogs:', grid=(row, 0)) tipText = 'Whether to allow the user to check file interpretation and referencing information before the spectrum is loaded' self.verifySelect = CheckButton(rightFrame, selected=False, grid=(row, 1), tipText=tipText) label = Label(rightFrame, text='Use shared experiment:', grid=(row, 2)) tipText = 'When selecting multiple spectrum files, whether the loaded spectra will all belong to (derive from) the same experiment; useful for projection spectra etc.' self.sharedExpSelect = CheckButton(rightFrame, selected=False, tipText=tipText, callback=self.useShared, grid=(row, 3)) row = row + 1 rightFrame.grid_rowconfigure(row, weight=1) tipTexts = [ 'A short textual name for the experiment record that the loaded spectrum will belong to; may be a new experiment or the name of an existing one', 'A short textual name to identify the spectrum within its experiment; typically a few characters or spectrum number, rather than a repeat of the experiment name', 'The location of the file, relative to the current directory, that the spectrum data will be loaded from', 'Sets which window or windows the spectrum will initially appear within once loaded', 'Sets which shift list the experiment (and hence loaded spectrum) will use to curate chemical shift information; can be changed after load time' ] headingList = [ 'Experiment', 'Spectrum', 'File', 'Windows', 'Shift List' ] editWidgets = [ self.experimentEntry, self.spectrumEntry, None, self.windowPulldown, self.shiftListPulldown ] editGetCallbacks = [ self.getExperiment, self.getSpectrum, None, self.getWindow, self.getShiftList ] editSetCallbacks = [ self.setExperiment, self.setSpectrum, None, self.setWindow, self.setShiftList ] self.scrolledMatrix = ScrolledMatrix(rightFrame, headingList=headingList, callback=self.selectCell, editWidgets=editWidgets, multiSelect=True, editGetCallbacks=editGetCallbacks, editSetCallbacks=editSetCallbacks, tipTexts=tipTexts, grid=(row, 0), gridSpan=(1, 4)) row = row + 1 tipTexts = [ 'Load spectrum or spectra into the CCPN project using the selected file(s)', ] texts = ['Open Spectrum'] commands = [self.openSpectra] bottomButtons = UtilityButtonList(guiFrame, texts=texts, tipTexts=tipTexts, doClone=False, commands=commands, helpUrl=self.help_url) bottomButtons.grid(row=row, column=0, columnspan=1, sticky='ew') self.openButton = bottomButtons.buttons[0] self.chooseFormat('Azara') self.message()