mirror of
https://github.com/ankitects/anki.git
synced 2025-11-08 21:57:12 -05:00
Extend getFile with support for multi-file selection
This commit is contained in:
parent
3037bf6ef8
commit
85955722c7
1 changed files with 8 additions and 6 deletions
14
aqt/utils.py
14
aqt/utils.py
|
|
@ -239,7 +239,7 @@ def getTag(parent, deck, question, tags="user", **kwargs):
|
||||||
# File handling
|
# File handling
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
||||||
def getFile(parent, title, cb, filter="*.*", dir=None, key=None):
|
def getFile(parent, title, cb, filter="*.*", dir=None, key=None, multi=False):
|
||||||
"Ask the user for a file."
|
"Ask the user for a file."
|
||||||
assert not dir or not key
|
assert not dir or not key
|
||||||
if not dir:
|
if not dir:
|
||||||
|
|
@ -248,20 +248,22 @@ def getFile(parent, title, cb, filter="*.*", dir=None, key=None):
|
||||||
else:
|
else:
|
||||||
dirkey = None
|
dirkey = None
|
||||||
d = QFileDialog(parent)
|
d = QFileDialog(parent)
|
||||||
d.setFileMode(QFileDialog.ExistingFile)
|
mode = QFileDialog.ExistingFiles if multi else QFileDialog.ExistingFile
|
||||||
|
d.setFileMode(mode)
|
||||||
if os.path.exists(dir):
|
if os.path.exists(dir):
|
||||||
d.setDirectory(dir)
|
d.setDirectory(dir)
|
||||||
d.setWindowTitle(title)
|
d.setWindowTitle(title)
|
||||||
d.setNameFilter(filter)
|
d.setNameFilter(filter)
|
||||||
ret = []
|
ret = []
|
||||||
def accept():
|
def accept():
|
||||||
file = str(list(d.selectedFiles())[0])
|
files = list(d.selectedFiles())
|
||||||
if dirkey:
|
if dirkey:
|
||||||
dir = os.path.dirname(file)
|
dir = os.path.dirname(files[0])
|
||||||
aqt.mw.pm.profile[dirkey] = dir
|
aqt.mw.pm.profile[dirkey] = dir
|
||||||
|
result = files if multi else files[0]
|
||||||
if cb:
|
if cb:
|
||||||
cb(file)
|
cb(result)
|
||||||
ret.append(file)
|
ret.append(result)
|
||||||
d.accepted.connect(accept)
|
d.accepted.connect(accept)
|
||||||
if key:
|
if key:
|
||||||
restoreState(d, key)
|
restoreState(d, key)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue