Added multiselect to add file/directory dialogs
This commit is contained in:
1 parent
aefa36fef8
commit
743c3b2466
1 file changed
+40
-24
+40
-24
@@ -229,42 +229,58 @@ 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
|
||||||
try:
|
for dname in dnames:
|
||||||
str(dname)
|
try:
|
||||||
except Exception:
|
str(dname)
|
||||||
QtGui.QMessageBox.critical(MainWindow, 'KCC Error', "Path cannot contain non-ASCII characters.",
|
except Exception:
|
||||||
QtGui.QMessageBox.Ok)
|
QtGui.QMessageBox.critical(MainWindow, 'KCC Error', "Path cannot contain non-ASCII characters.",
|
||||||
return
|
QtGui.QMessageBox.Ok)
|
||||||
if str(dname) != "":
|
return
|
||||||
self.lastPath = os.path.abspath(os.path.join(str(dname), os.pardir))
|
if str(dname) != "":
|
||||||
GUI.JobList.addItem(dname)
|
if sys.platform == 'win32':
|
||||||
|
dname = dname.replace('/', '\\')
|
||||||
|
self.lastPath = os.path.abspath(os.path.join(str(dname), os.pardir))
|
||||||
|
GUI.JobList.addItem(dname)
|
||||||
|
|
||||||
def selectFile(self):
|
def selectFile(self):
|
||||||
if self.needClean:
|
if self.needClean:
|
||||||
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
|
||||||
try:
|
for fname in fnames:
|
||||||
str(fname)
|
try:
|
||||||
except Exception:
|
str(fname)
|
||||||
QtGui.QMessageBox.critical(MainWindow, 'KCC Error', "Path cannot contain non-ASCII characters.",
|
except Exception:
|
||||||
QtGui.QMessageBox.Ok)
|
QtGui.QMessageBox.critical(MainWindow, 'KCC Error', "Path cannot contain non-ASCII characters.",
|
||||||
return
|
QtGui.QMessageBox.Ok)
|
||||||
if str(fname) != "":
|
return
|
||||||
self.lastPath = os.path.abspath(os.path.join(str(fname), os.pardir))
|
if str(fname) != "":
|
||||||
GUI.JobList.addItem(fname)
|
self.lastPath = os.path.abspath(os.path.join(str(fname), os.pardir))
|
||||||
|
GUI.JobList.addItem(fname)
|
||||||
|
|
||||||
def clearJobs(self):
|
def clearJobs(self):
|
||||||
GUI.JobList.clear()
|
GUI.JobList.clear()
|
||||||
|
|||||||
Reference in new issue
Block a user