mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #4849 (drap and drop)
This commit is contained in:
parent
c1e7185590
commit
762fc52310
@ -6,7 +6,7 @@ from threading import RLock
|
||||
|
||||
from PyQt4.QtCore import QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt, QSize, \
|
||||
QByteArray, QTranslator, QCoreApplication, QThread, \
|
||||
QEvent, QTimer
|
||||
QEvent, QTimer, pyqtSignal
|
||||
from PyQt4.QtGui import QFileDialog, QMessageBox, QPixmap, QFileIconProvider, \
|
||||
QIcon, QTableView, QApplication, QDialog, QPushButton
|
||||
|
||||
@ -236,16 +236,17 @@ def human_readable(size):
|
||||
return size + " " + suffix
|
||||
|
||||
class Dispatcher(QObject):
|
||||
'''Convenience class to ensure that a function call always happens in the GUI thread'''
|
||||
SIGNAL = SIGNAL('dispatcher(PyQt_PyObject,PyQt_PyObject)')
|
||||
'''Convenience class to ensure that a function call always happens in the
|
||||
thread the reciver was created in.'''
|
||||
dispatch_signal = pyqtSignal(object, object)
|
||||
|
||||
def __init__(self, func):
|
||||
QObject.__init__(self)
|
||||
self.func = func
|
||||
self.connect(self, self.SIGNAL, self.dispatch, Qt.QueuedConnection)
|
||||
self.dispatch_signal.connect(self.dispatch, type=Qt.QueuedConnection)
|
||||
|
||||
def __call__(self, *args, **kwargs):
|
||||
self.emit(self.SIGNAL, args, kwargs)
|
||||
self.dispatch_signal.emit(args, kwargs)
|
||||
|
||||
def dispatch(self, args, kwargs):
|
||||
self.func(*args, **kwargs)
|
||||
@ -551,8 +552,9 @@ class Application(QApplication):
|
||||
|
||||
def _send_file_open_events(self):
|
||||
with self._file_open_lock:
|
||||
self.file_event_hook(self._file_open_paths)
|
||||
self._file_open_paths = []
|
||||
if self._file_open_paths:
|
||||
self.file_event_hook(self._file_open_paths)
|
||||
self._file_open_paths = []
|
||||
|
||||
|
||||
def load_translations(self):
|
||||
@ -568,7 +570,7 @@ class Application(QApplication):
|
||||
if os.access(path, os.R_OK):
|
||||
with self._file_open_lock:
|
||||
self._file_open_paths.append(path)
|
||||
QTimer.singleShot(self._send_file_open_events, 1000)
|
||||
QTimer.singleShot(1000, self._send_file_open_events)
|
||||
return True
|
||||
else:
|
||||
return QApplication.event(self, e)
|
||||
|
@ -601,6 +601,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
if dynamic.get('tag_view_visible', False):
|
||||
self.status_bar.tag_view_button.toggle()
|
||||
|
||||
self._add_filesystem_book = Dispatcher(self.__add_filesystem_book)
|
||||
|
||||
|
||||
def resizeEvent(self, ev):
|
||||
MainWindow.resizeEvent(self, ev)
|
||||
@ -988,10 +990,11 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
self.cover_cache.refresh([cid])
|
||||
self.library_view.model().current_changed(current_idx, current_idx)
|
||||
|
||||
def _add_filesystem_book(self, paths, allow_device=True):
|
||||
def __add_filesystem_book(self, paths, allow_device=True):
|
||||
print 222, paths
|
||||
if isinstance(paths, basestring):
|
||||
paths = [paths]
|
||||
books = [os.path.abspath(path) for path in paths is os.access(path,
|
||||
books = [path for path in map(os.path.abspath, paths) if os.access(path,
|
||||
os.R_OK)]
|
||||
|
||||
if books:
|
||||
@ -1003,7 +1006,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
|
||||
|
||||
def add_filesystem_book(self, paths, allow_device=True):
|
||||
Dispatcher(self._add_filesystem_book)(paths, allow_device=allow_device)
|
||||
self._add_filesystem_book(paths, allow_device=allow_device)
|
||||
|
||||
def add_books(self, checked):
|
||||
'''
|
||||
@ -1054,12 +1057,13 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
self.library_view.model().books_added(self._adder.number_of_books_added)
|
||||
if hasattr(self, 'db_images'):
|
||||
self.db_images.reset()
|
||||
if getattr(self._adder, 'critical', None) is not None:
|
||||
if getattr(self._adder, 'critical', None):
|
||||
det_msg = []
|
||||
for name, log in self._adder.critical.items():
|
||||
if isinstance(name, str):
|
||||
name = name.decode(filesystem_encoding, 'replace')
|
||||
det_msg.append(name+'\n'+log)
|
||||
|
||||
warning_dialog(self, _('Failed to read metadata'),
|
||||
_('Failed to read metadata from the following')+':',
|
||||
det_msg='\n\n'.join(det_msg), show=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user