mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Move opening of device into worker thread as this is expensive operation for 505 and I dont like to have the GUI freeze, however briefly.
This commit is contained in:
parent
03104b2aa7
commit
8a0f67c606
@ -12,7 +12,7 @@
|
|||||||
## You should have received a copy of the GNU General Public License along
|
## 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.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning
|
||||||
import os
|
import os, sys, traceback
|
||||||
|
|
||||||
from PyQt4.QtCore import QThread, SIGNAL, QObject
|
from PyQt4.QtCore import QThread, SIGNAL, QObject
|
||||||
|
|
||||||
@ -45,11 +45,17 @@ class DeviceDetector(QThread):
|
|||||||
try:
|
try:
|
||||||
connected = device[0].is_connected(helper=helper)
|
connected = device[0].is_connected(helper=helper)
|
||||||
except:
|
except:
|
||||||
raise
|
|
||||||
connected = False
|
connected = False
|
||||||
if connected and not device[1]:
|
if connected and not device[1]:
|
||||||
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], True)
|
try:
|
||||||
device[1] ^= True
|
dev = device[0]()
|
||||||
|
dev.open()
|
||||||
|
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), dev, True)
|
||||||
|
except:
|
||||||
|
print 'Unable to open device'
|
||||||
|
traceback.print_exc()
|
||||||
|
finally:
|
||||||
|
device[1] = True
|
||||||
elif not connected and device[1]:
|
elif not connected and device[1]:
|
||||||
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], False)
|
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], False)
|
||||||
device[1] ^= True
|
device[1] ^= True
|
||||||
@ -58,11 +64,10 @@ class DeviceDetector(QThread):
|
|||||||
|
|
||||||
|
|
||||||
class DeviceManager(QObject):
|
class DeviceManager(QObject):
|
||||||
def __init__(self, device_class):
|
def __init__(self, device):
|
||||||
QObject.__init__(self)
|
QObject.__init__(self)
|
||||||
self.device_class = device_class
|
self.device_class = device.__class__
|
||||||
self.device = device_class()
|
self.device = device
|
||||||
self.device.open()
|
|
||||||
|
|
||||||
def device_removed(self):
|
def device_removed(self):
|
||||||
self.device = None
|
self.device = None
|
||||||
|
@ -179,16 +179,16 @@ class Main(MainWindow, Ui_MainWindow):
|
|||||||
|
|
||||||
|
|
||||||
########################## Connect to device ##############################
|
########################## Connect to device ##############################
|
||||||
def device_detected(self, cls, connected):
|
def device_detected(self, device, connected):
|
||||||
'''
|
'''
|
||||||
Called when a device is connected to the computer.
|
Called when a device is connected to the computer.
|
||||||
'''
|
'''
|
||||||
if connected:
|
if connected:
|
||||||
self.device_manager = DeviceManager(cls)
|
self.device_manager = DeviceManager(device)
|
||||||
func = self.device_manager.info_func()
|
func = self.device_manager.info_func()
|
||||||
self.job_manager.run_device_job(self.info_read, func)
|
self.job_manager.run_device_job(self.info_read, func)
|
||||||
self.set_default_thumbnail(cls.THUMBNAIL_HEIGHT)
|
self.set_default_thumbnail(device.THUMBNAIL_HEIGHT)
|
||||||
self.status_bar.showMessage('Device: '+cls.__name__+' detected.', 3000)
|
self.status_bar.showMessage('Device: '+device.__class__.__name__+' detected.', 3000)
|
||||||
self.action_sync.setEnabled(True)
|
self.action_sync.setEnabled(True)
|
||||||
self.device_connected = True
|
self.device_connected = True
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user