openlp/openlp/core/lib/filedialog.py

59 lines
2.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2014-06-09 08:59:52 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2015-12-31 22:46:06 +00:00
# Copyright (c) 2008-2016 OpenLP Developers #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
2013-08-22 05:33:19 +00:00
Provide a work around for a bug in QFileDialog <https://bugs.launchpad.net/openlp/+bug/1209515>
"""
import logging
import os
2013-09-15 19:27:40 +00:00
from urllib import parse
2015-11-07 00:49:40 +00:00
from PyQt5 import QtWidgets
2013-11-16 21:04:16 +00:00
from openlp.core.common import UiStrings
log = logging.getLogger(__name__)
2013-12-24 08:56:50 +00:00
2015-11-07 00:49:40 +00:00
class FileDialog(QtWidgets.QFileDialog):
"""
2013-08-22 05:33:19 +00:00
Subclass QFileDialog to work round a bug
"""
@staticmethod
def getOpenFileNames(parent, *args, **kwargs):
"""
Reimplement getOpenFileNames to fix the way it returns some file names that url encoded when selecting multiple
files
"""
2015-11-07 00:49:40 +00:00
files, filter_used = QtWidgets.QFileDialog.getOpenFileNames(parent, *args, **kwargs)
file_list = []
for file in files:
if not os.path.exists(file):
2013-12-24 08:56:50 +00:00
log.info('File not found. Attempting to unquote.')
2013-09-15 19:27:40 +00:00
file = parse.unquote(file)
if not os.path.exists(file):
2013-09-15 19:27:40 +00:00
log.error('File %s not found.' % file)
2015-11-07 00:49:40 +00:00
QtWidgets.QMessageBox.information(parent, UiStrings().FileNotFound,
UiStrings().FileNotFoundMessage % file)
continue
file_list.append(file)
2014-03-20 19:10:31 +00:00
return file_list