本文整理汇总了Python中PyQt4.Qt.QFileDialog.getOpenFileNames方法的典型用法代码示例。如果您正苦于以下问题:Python QFileDialog.getOpenFileNames方法的具体用法?Python QFileDialog.getOpenFileNames怎么用?Python QFileDialog.getOpenFileNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QFileDialog
的用法示例。
在下文中一共展示了QFileDialog.getOpenFileNames方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: select_images_on_disk
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileNames [as 别名]
def select_images_on_disk(uim, start_path=None):
dlg = QFileDialog()
logmsg('Select one or more images to add.')
image_list = dlg.getOpenFileNames(caption='Select one or more images to add.',\
directory=uim.hs.db_dpath)
image_list = [str(fpath) for fpath in image_list]
return image_list
示例2: __init__
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileNames [as 别名]
def __init__(self, title=_('Choose Files'),
filters=[],
add_all_files_filter=True,
parent=None,
modal=True,
name='',
mode=QFileDialog.ExistingFiles,
default_dir=u'~',
no_save_dir=False,
combine_file_and_saved_dir=False
):
QObject.__init__(self)
ftext = ''
if filters:
for filter in filters:
text, extensions = filter
extensions = ['*'+(i if i.startswith('.') else '.'+i) for i in
extensions]
ftext += '%s (%s);;'%(text, ' '.join(extensions))
if add_all_files_filter or not ftext:
ftext += 'All files (*)'
if ftext.endswith(';;'):
ftext = ftext[:-2]
self.dialog_name = name if name else 'dialog_' + title
self.selected_files = None
self.fd = None
if combine_file_and_saved_dir:
bn = os.path.basename(default_dir)
prev = dynamic.get(self.dialog_name,
expanduser(u'~'))
if os.path.exists(prev):
if os.path.isfile(prev):
prev = os.path.dirname(prev)
else:
prev = expanduser(u'~')
initial_dir = os.path.join(prev, bn)
elif no_save_dir:
initial_dir = expanduser(default_dir)
else:
initial_dir = dynamic.get(self.dialog_name,
expanduser(default_dir))
if not isinstance(initial_dir, basestring):
initial_dir = expanduser(default_dir)
if not initial_dir or (not os.path.exists(initial_dir) and not (
mode == QFileDialog.AnyFile and (no_save_dir or combine_file_and_saved_dir))):
initial_dir = select_initial_dir(initial_dir)
self.selected_files = []
use_native_dialog = 'CALIBRE_NO_NATIVE_FILEDIALOGS' not in os.environ
with SanitizeLibraryPath():
opts = QFileDialog.Option()
if not use_native_dialog:
opts |= QFileDialog.DontUseNativeDialog
if mode == QFileDialog.AnyFile:
f = unicode(QFileDialog.getSaveFileName(parent, title,
initial_dir, ftext, "", opts))
if f:
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFile:
f = unicode(QFileDialog.getOpenFileName(parent, title,
initial_dir, ftext, "", opts))
if f and os.path.exists(f):
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFiles:
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir,
ftext, "", opts)
for f in fs:
f = unicode(f)
if not f:
continue
if not os.path.exists(f):
# QFileDialog for some reason quotes spaces
# on linux if there is more than one space in a row
f = unquote(f)
if f and os.path.exists(f):
self.selected_files.append(f)
else:
if mode == QFileDialog.Directory:
opts |= QFileDialog.ShowDirsOnly
f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
if os.path.exists(f):
self.selected_files.append(f)
if self.selected_files:
self.selected_files = [unicode(q) for q in self.selected_files]
saved_loc = self.selected_files[0]
if os.path.isfile(saved_loc):
saved_loc = os.path.dirname(saved_loc)
if not no_save_dir:
dynamic[self.dialog_name] = saved_loc
self.accepted = bool(self.selected_files)
示例3: __init__
# 需要导入模块: from PyQt4.Qt import QFileDialog [as 别名]
# 或者: from PyQt4.Qt.QFileDialog import getOpenFileNames [as 别名]
def __init__(
self,
title=_("Choose Files"),
filters=[],
add_all_files_filter=True,
parent=None,
modal=True,
name="",
mode=QFileDialog.ExistingFiles,
default_dir="~",
no_save_dir=False,
):
QObject.__init__(self)
ftext = ""
if filters:
for filter in filters:
text, extensions = filter
extensions = ["*" + (i if i.startswith(".") else "." + i) for i in extensions]
ftext += "%s (%s);;" % (text, " ".join(extensions))
if add_all_files_filter or not ftext:
ftext += "All files (*)"
if ftext.endswith(";;"):
ftext = ftext[:-2]
self.dialog_name = name if name else "dialog_" + title
self.selected_files = None
self.fd = None
if no_save_dir:
initial_dir = os.path.expanduser(default_dir)
else:
initial_dir = dynamic.get(self.dialog_name, os.path.expanduser(default_dir))
if not isinstance(initial_dir, basestring):
initial_dir = os.path.expanduser(default_dir)
self.selected_files = []
use_native_dialog = "CALIBRE_NO_NATIVE_FILEDIALOGS" not in os.environ
with SanitizeLibraryPath():
opts = QFileDialog.Option()
if not use_native_dialog:
opts |= QFileDialog.DontUseNativeDialog
if mode == QFileDialog.AnyFile:
f = unicode(QFileDialog.getSaveFileName(parent, title, initial_dir, ftext, "", opts))
if f:
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFile:
f = unicode(QFileDialog.getOpenFileName(parent, title, initial_dir, ftext, "", opts))
if f and os.path.exists(f):
self.selected_files.append(f)
elif mode == QFileDialog.ExistingFiles:
fs = QFileDialog.getOpenFileNames(parent, title, initial_dir, ftext, "", opts)
for f in fs:
f = unicode(f)
if not f:
continue
if not os.path.exists(f):
# QFileDialog for some reason quotes spaces
# on linux if there is more than one space in a row
f = unquote(f)
if f and os.path.exists(f):
self.selected_files.append(f)
else:
if mode == QFileDialog.Directory:
opts |= QFileDialog.ShowDirsOnly
f = unicode(QFileDialog.getExistingDirectory(parent, title, initial_dir, opts))
if os.path.exists(f):
self.selected_files.append(f)
if self.selected_files:
self.selected_files = [unicode(q) for q in self.selected_files]
saved_loc = self.selected_files[0]
if os.path.isfile(saved_loc):
saved_loc = os.path.dirname(saved_loc)
if not no_save_dir:
dynamic[self.dialog_name] = saved_loc
self.accepted = bool(self.selected_files)