Пример #1
0
def getFile(parent, title, cb, filter="*.*", dir=None, key=None, multi=False):
    "Ask the user for a file."
    assert not dir or not key
    if not dir:
        dirkey = key+"Directory"
        dir = aqt.mw.pm.profile.get(dirkey, "")
    else:
        dirkey = None
    d = QFileDialog(parent)
    mode = QFileDialog.ExistingFiles if multi else QFileDialog.ExistingFile
    d.setFileMode(mode)
    if os.path.exists(dir):
        d.setDirectory(dir)
    d.setWindowTitle(title)
    d.setNameFilter(filter)
    ret = []
    def accept():
        files = list(d.selectedFiles())
        if dirkey:
            dir = os.path.dirname(files[0])
            aqt.mw.pm.profile[dirkey] = dir
        result = files if multi else files[0]
        if cb:
            cb(result)
        ret.append(result)
    d.accepted.connect(accept)
    if key:
        restoreState(d, key)
    d.exec_()
    if key:
        saveState(d, key)
    return ret and ret[0]
 def pickcmdpath(self):
     # mod of aqt.utils getFile
     d = QFileDialog()
     mode = QFileDialog.ExistingFile
     d.setFileMode(mode)
     if isWin:
         d.setDirectory("C:\\")
     if isMac:
         d.setDirectory("/Applications")
     else:
         d.setDirectory(os.path.expanduser("~"))
     d.setWindowTitle("Anki Add-on: Select Executable")
     if d.exec():
         self.dialog.le_cmd.setText(d.selectedFiles()[0])