本文整理汇总了Python中javax.swing.JFileChooser.showOpenDialog方法的典型用法代码示例。如果您正苦于以下问题:Python JFileChooser.showOpenDialog方法的具体用法?Python JFileChooser.showOpenDialog怎么用?Python JFileChooser.showOpenDialog使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFileChooser
的用法示例。
在下文中一共展示了JFileChooser.showOpenDialog方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: chooseFile
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def chooseFile():
global frame, dataPath
global systemPanel, chartPanel
global isTemporal
fc = JFileChooser(dataPath)
retVal = fc.showOpenDialog(frame)
if retVal != JFileChooser.APPROVE_OPTION:
return
fname = fc.getSelectedFile().getAbsolutePath()
dataPath = os.sep.join(fname.split(os.sep)[:-1])
if isTemporal:
info(frame, "We need a file with information about the temporal point of each sample")
tfc = JFileChooser(dataPath)
tRetVal = tfc.showOpenDialog(frame)
if retVal != JFileChooser.APPROVE_OPTION:
return
tname = tfc.getSelectedFile().getAbsolutePath()
systemPanel.enableChartFun = False
chartPanel.resetData()
loadGenePop(fname)
if isTemporal:
if not loadTemporal(tname):
return
updateAll()
enablePanel(empiricalPanel)
示例2: MultiFileDialog
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def MultiFileDialog(title):
#hide/show debug prints
verbose = 0
# Choose image file(s) to open
fc = JFileChooser()
fc.setMultiSelectionEnabled(True)
fc.setDialogTitle(title)
sdir = OpenDialog.getDefaultDirectory()
if sdir!=None:
fdir = File(sdir)
if fdir!=None:
fc.setCurrentDirectory(fdir)
returnVal = fc.showOpenDialog(IJ.getInstance())
if returnVal!=JFileChooser.APPROVE_OPTION:
return
files = fc.getSelectedFiles()
paths = []
for i in range(len(files)):
paths.append(os.path.join(files[i].getParent(), files[i].getName()))
if verbose > 0:
for i in range(len(files)):
path = os.path.join(files[i].getParent(), files[i].getName())
print "Path: " + path
return paths
示例3: FileManager
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
class FileManager(object):
def __init__(self, pywin):
self.fc = JFileChooser()
self.fc.fileFilter = FileNameExtensionFilter("Python Files", ["py"])
self.pywin = pywin
self.load_path = None
self.script_path = None
@property
def script_area(self):
return self.pywin.script_pane.script_area
def show_open_dialog(self, title):
self.fc.dialogTitle = title
res = self.fc.showOpenDialog(self.pywin.frame)
if res == JFileChooser.APPROVE_OPTION:
return self.fc.selectedFile
def show_save_dialog(self, title):
self.fc.dialogTitle = title
res = self.fc.showSaveDialog(self.pywin.frame)
if res == JFileChooser.APPROVE_OPTION:
return self.fc.selectedFile
def save_script(self):
if self.script_path is None:
return
with codecs.open(self.script_path, "wb", "utf-8") as stream:
stream.write(self.script_area.input)
def open_script(self):
f = self.show_open_dialog("Select script file to open")
if f is None:
return
self.script_path = f.absolutePath
with codecs.open(self.script_path, "rb", "utf-8") as stream:
self.script_area.input = stream.read()
def save_script_as(self):
f = self.show_save_dialog("Select file to write script to")
if f is None:
return
self.script_path = f.absolutePath
self.save_script()
def load_script(self):
f = self.show_open_dialog("Select script file to load")
if f is None:
return
self.load_path = f.absolutePath
self.reload_script()
def reload_script(self):
print "*** Loading", self.load_path, "***"
try:
self.pywin.execfile(self.load_path)
except Exception, e:
self.pywin.outputpane.addtext(str(e) + '\n', 'error')
示例4: loadPopNames
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def loadPopNames():
global frame, empiricalPanel
fc = JFileChooser(dataPath)
retVal = fc.showOpenDialog(frame)
if retVal == JFileChooser.APPROVE_OPTION:
file = fc.getSelectedFile()
loadFilePopNames(file)
updateAll()
enablePanel(empiricalPanel)
示例5: getFile
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def getFile(self,button):
dlg = JFileChooser()
result = dlg.showOpenDialog(None)
if result == JFileChooser.APPROVE_OPTION:
f = dlg.getSelectedFile()
path = f.getPath()
self.FileText.setText(path)
try:
self.getIPList(path)
except:
exit(0)
示例6: GnitPickFileChooser
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
class GnitPickFileChooser(ActionListener):
def __init__(self,frm):
self.frame = frm
def actionPerformed(self,e):
self.chooser = JFileChooser()
self.option = self.chooser.showOpenDialog(self.frame)
if (self.option == JFileChooser.APPROVE_OPTION):
self.frame.statusbar.setText("You chose " + self.chooser.getSelectedFile().getName())
else:
self.frame.statusbar.setText("You cancelled.")
示例7: get_image_file
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def get_image_file(self) :
file_dialog = JFileChooser()
#image files
image_filter = FileNameExtensionFilter("Image Files",
["jpg","bmp","png","gif"])
print image_filter.getExtensions()
file_dialog.setFileFilter(image_filter)
x = file_dialog.showOpenDialog(None)
if x == JFileChooser.APPROVE_OPTION :
return file_dialog.getSelectedFile()
else :
return None
示例8: _configFileDialogue
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def _configFileDialogue(self):
from javax.swing import JFileChooser
from javax.swing.filechooser import FileNameExtensionFilter
fileDialogue = JFileChooser(self.dssFilePath)
filter = FileNameExtensionFilter("Configuration file (*.yml; *.yaml)",
["yaml", "yml"])
fileDialogue.setFileFilter(filter)
ret = fileDialogue.showOpenDialog(self.mainWindow)
if ret == JFileChooser.APPROVE_OPTION:
return fileDialogue.getSelectedFile().getAbsolutePath()
else:
raise CancelledError("Config file selection was cancelled.")
示例9: set_from_file
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def set_from_file(self, event):
fileChooser = JFileChooser()
if self.filename is not None:
fileChooser.setSelectedFile(java.io.File(self.filename))
if fileChooser.showOpenDialog(self) == JFileChooser.APPROVE_OPTION:
self.filename = fileChooser.selectedFile.absolutePath
#TODO: this doesn't for for nested FunctionInputs
input = self.view.network.getNode(self.name)
from nef.functions import Interpolator
interp = Interpolator(self.filename)
interp.load_into_function(input)
示例10: check_directory
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def check_directory(path):
if (os.path.lexists(path)):
contents=os.listdir(path)
if (contents.count("install-birch")==0):
print_console("The selected directory "+path+" does NOT contain a BIRCH installation!")
message="The selected path does NOT contain a BIRCH installation.\nPlease select the base directory of the installation that you wish to update,\nOr click \"no\" to cancel update."
reload = JOptionPane.showConfirmDialog(None,message, "Input",JOptionPane.YES_NO_OPTION);
if (reload==JOptionPane.NO_OPTION):
print_console("User aborted install.")
commonlib.shutdown()
fc = JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.showOpenDialog(None);
path = fc.getSelectedFile().getPath();
check_directory(path)
else:
ARGS.install_dir=path
print_console("The selected directory "+path+" contains a BIRCH installation, it will be updated")
示例11: browse
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def browse(self, event=None):
'''
Open new dialog for the user to select a path as default working dir.
'''
default_path = self.wd_field.getText()
if not os.path.isdir(default_path):
default_path = os.getcwd()
fileChooser = JFileChooser(default_path)
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)
# Fixed showDialog bug using showOpenDialog instead. The former was
# duplicating the last folder name in the path due to a Java bug in
# OSX in the implementation of JFileChooser!
status = fileChooser.showOpenDialog(self)
if status == JFileChooser.APPROVE_OPTION:
self.wd_field.setText(fileChooser.getSelectedFile().toString())
示例12: openGVL
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def openGVL():
from javax.swing import JFileChooser
GUIUtil=PluginServices.getPluginServices("com.iver.cit.gvsig.cad").getClassLoader().loadClass("com.iver.cit.gvsig.gui.GUIUtil")
chooser = JFileChooser()
chooser.setFileFilter(GUIUtil().createFileFilter("GVL Legend File",["gvl"]))
from java.util.prefs import Preferences
lastPath = Preferences.userRoot().node("gvsig.foldering").get("DataFolder", "null")
chooser.setCurrentDirectory(File(lastPath))
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY)
returnVal = chooser.showOpenDialog(None)
if returnVal == chooser.APPROVE_OPTION:
gvlPath = chooser.getSelectedFile().getPath()
elif returnVal == chooser.CANCEL_OPTION:
JOptionPane.showMessageDialog(None, "You have to open a .gvl file. Retry!","Batch Legend",JOptionPane.WARNING_MESSAGE)
gvlPath = ""
return gvlPath
示例13: __init__
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def __init__(self, configFileName=None, dssFilePath=None):
"""
A tool is defined by providing a `yaml` configuration file
``configFileName`` and a HEC-DSS database ``dssFilePath`` to operate on.
If ``dssFilePath`` is not set, the active DSS-file in the HEC-DSSVue
window will be used. If ``configFileName`` is not set, a file selection
dialogue is displayed prompting for a configuration file.
The attribute :attr:`.config` will be set containing the parsed yaml
config file.
"""
if dssFilePath:
self.dssFilePath = dssFilePath
self.mainWindow = None
else:
from hec.dssgui import ListSelection
self.mainWindow = ListSelection.getMainWindow()
self.dssFilePath = self.mainWindow.getDSSFilename()
if not configFileName:
from javax.swing import JFileChooser
from javax.swing.filechooser import FileNameExtensionFilter
fileDialogue = JFileChooser(self.dssFilePath)
filter = FileNameExtensionFilter("Configuration file (*.yml; *.yaml)",
["yaml", "yml"])
fileDialogue.setFileFilter(filter)
ret = fileDialogue.showOpenDialog(self.mainWindow)
if ret == JFileChooser.APPROVE_OPTION:
self.configFilePath = (fileDialogue.getSelectedFile().
getAbsolutePath())
else:
raise CancelledError("Config file selection was cancelled.")
if configFileName:
self.configFilePath = path.join(path.dirname(self.dssFilePath),
configFileName)
elif dssFilePath:
raise ValueError("`configFileName` argument must be provided if `dssFilePath` is specified.")
#: Message to be displayed in HEC-DSSVue after running the tool. This
#: attribute is typically set in the :meth:`main`.
self.message = ""
if self._toolIsValid():
with codecs.open(self.configFilePath, encoding='utf-8') as configFile:
self.config = yaml.load(configFile.read())
self._configIsValid()
示例14: generate_board
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def generate_board(self, event):
chooser = JFileChooser()
status = chooser.showOpenDialog(self.frame)
if status != JFileChooser.APPROVE_OPTION:
return
imageFile = chooser.getSelectedFile()
self.puzzle = SimplePyzzle(float(int(self.combo_box.getSelectedItem())))
self.draw_board()
self.load_images(imageFile, self.puzzle.level())
self.canvas.set_puzzle(self.puzzle)
width = self.images_dict[0].getWidth()
height = self.images_dict[0].getHeight()
size = Dimension(width * self.puzzle.level(), height * self.puzzle.level())
self.frame.setPreferredSize(size)
self.frame.setSize(size)
示例15: saveas
# 需要导入模块: from javax.swing import JFileChooser [as 别名]
# 或者: from javax.swing.JFileChooser import showOpenDialog [as 别名]
def saveas(self, e):
c = None
if "lastdir" in self.settings.keys():
c = JFileChooser(self.settings["lastdir"])
else:
c = JFileChooser()
r = c.showOpenDialog(self.frame)
if r == JFileChooser.APPROVE_OPTION:
f = c.getSelectedFile()
self.f = f
s = f.getAbsolutePath()
self.settings["lastdir"] = f.getParent()
self.settings.save()
o = FileOutputStream(s)
self.text.setoutput(o)