Added multiselect to add file/directory dialogs

This commit is contained in:
Paweł Jastrzębski committed 2013-07-21 18:24:24 +02:00
1 parent aefa36fef8
commit 743c3b2466
1 file changed
+21 -5
+21 -5
View File
@@ -229,12 +229,25 @@ class WorkerThread(QtCore.QThread):
# noinspection PyBroadException # noinspection PyBroadException
class Ui_KCC(object): class Ui_KCC(object):
def selectDir(self): def selectDir(self):
# Dialog allow to select multiple directories but we can't parse that. QT Bug.
if self.needClean: if self.needClean:
self.needClean = False self.needClean = False
GUI.JobList.clear() GUI.JobList.clear()
dname = QtGui.QFileDialog.getExistingDirectory(MainWindow, 'Select directory', self.lastPath) # Dirty, dirty way but OS native QFileDialogs don't support directory multiselect
dirDialog = QtGui.QFileDialog(MainWindow, 'Select directory', self.lastPath)
dirDialog.setFileMode(dirDialog.Directory)
dirDialog.setOption(dirDialog.ShowDirsOnly, True)
l = dirDialog.findChild(QtGui.QListView, "listView")
t = dirDialog.findChild(QtGui.QTreeView)
if l:
l.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
if t:
t.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection)
if dirDialog.exec_() == 1:
dnames = dirDialog.selectedFiles()
else:
dnames = ""
# Lame UTF-8 security measure # Lame UTF-8 security measure
for dname in dnames:
try: try:
str(dname) str(dname)
except Exception: except Exception:
@@ -242,6 +255,8 @@ class Ui_KCC(object):
QtGui.QMessageBox.Ok) QtGui.QMessageBox.Ok)
return return
if str(dname) != "": if str(dname) != "":
if sys.platform == 'win32':
dname = dname.replace('/', '\\')
self.lastPath = os.path.abspath(os.path.join(str(dname), os.pardir)) self.lastPath = os.path.abspath(os.path.join(str(dname), os.pardir))
GUI.JobList.addItem(dname) GUI.JobList.addItem(dname)
@@ -250,12 +265,13 @@ class Ui_KCC(object):
self.needClean = False self.needClean = False
GUI.JobList.clear() GUI.JobList.clear()
if self.UnRAR: if self.UnRAR:
fname = QtGui.QFileDialog.getOpenFileName(MainWindow, 'Select file', self.lastPath, fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
'*.cbz *.cbr *.zip *.rar *.pdf') '*.cbz *.cbr *.zip *.rar *.pdf')
else: else:
fname = QtGui.QFileDialog.getOpenFileName(MainWindow, 'Select file', self.lastPath, fnames = QtGui.QFileDialog.getOpenFileNames(MainWindow, 'Select file', self.lastPath,
'*.cbz *.zip *.pdf') '*.cbz *.zip *.pdf', None, QtGui.QFileDialog.ShowDirsOnly)
# Lame UTF-8 security measure # Lame UTF-8 security measure
for fname in fnames:
try: try:
str(fname) str(fname)
except Exception: except Exception: