def actionPerformed(self, actionEvent): chooser = JFileChooser() #chooser.setCurrentDirectory(".") chooser.setDialogTitle("Choose file") chooser.setFileSelectionMode(JFileChooser.FILES_ONLY) chooser.setAcceptAllFileFilterUsed(False) if chooser.showOpenDialog(self) == JFileChooser.APPROVE_OPTION: print chooser.getCurrentDirectory() print chooser.getSelectedFile() self.field.setText(str(chooser.getSelectedFile())) else: print "No file selected"
def FolderDialog(title, folder): fc = JFileChooser() fc.setMultiSelectionEnabled(False) fc.setDialogTitle(title) fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(False); if folder ==None: sdir = OpenDialog.getDefaultDirectory() else: sdir = folder if sdir!=None: fdir = File(sdir) if fdir!=None: fc.setCurrentDirectory(fdir) returnVal = fc.showOpenDialog(IJ.getInstance()) if returnVal!=JFileChooser.APPROVE_OPTION: return folder = fc.getSelectedFile(); path = os.path.join(folder.getParent(), folder.getName()) return path
return file_extension argvs = sys.argv argc = len(argvs) defaultpath = '/' frontoutputpath2 = '/' xmlfil = XMLFilter('kike') print xmlfil.getDescription() chooser = JFileChooser() fakefile = File(defaultpath) chooser.setCurrentDirectory(fakefile) chooser.setDialogTitle("Select xml file") chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES) chooser.setAcceptAllFileFilterUsed(False) InputFolderPath = '' if (chooser.showOpenDialog(None) == JFileChooser.APPROVE_OPTION): IJ.log("getCrrentDirectory(): " + chooser.getCurrentDirectory().toString()) InputFolderPath = chooser.getSelectedFile().toString() else: IJ.log("No selection") file = File(InputFolderPath) # We have to feed a logger to the reader. logger = Logger.IJ_LOGGER #------------------- # Instantiate reader #-------------------