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:
Kovid Goyal 2007-11-12 21:03:42 +00:00
parent 03104b2aa7
commit 8a0f67c606
2 changed files with 17 additions and 12 deletions

View File

@ -12,7 +12,7 @@
## 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.,
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.Warning
import os
import os, sys, traceback
from PyQt4.QtCore import QThread, SIGNAL, QObject
@ -45,11 +45,17 @@ class DeviceDetector(QThread):
try:
connected = device[0].is_connected(helper=helper)
except:
raise
connected = False
if connected and not device[1]:
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], True)
device[1] ^= True
try:
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]:
self.emit(SIGNAL('connected(PyQt_PyObject, PyQt_PyObject)'), device[0], False)
device[1] ^= True
@ -58,11 +64,10 @@ class DeviceDetector(QThread):
class DeviceManager(QObject):
def __init__(self, device_class):
def __init__(self, device):
QObject.__init__(self)
self.device_class = device_class
self.device = device_class()
self.device.open()
self.device_class = device.__class__
self.device = device
def device_removed(self):
self.device = None

View File

@ -179,16 +179,16 @@ class Main(MainWindow, Ui_MainWindow):
########################## Connect to device ##############################
def device_detected(self, cls, connected):
def device_detected(self, device, connected):
'''
Called when a device is connected to the computer.
'''
if connected:
self.device_manager = DeviceManager(cls)
self.device_manager = DeviceManager(device)
func = self.device_manager.info_func()
self.job_manager.run_device_job(self.info_read, func)
self.set_default_thumbnail(cls.THUMBNAIL_HEIGHT)
self.status_bar.showMessage('Device: '+cls.__name__+' detected.', 3000)
self.set_default_thumbnail(device.THUMBNAIL_HEIGHT)
self.status_bar.showMessage('Device: '+device.__class__.__name__+' detected.', 3000)
self.action_sync.setEnabled(True)
self.device_connected = True
else: