From cf77ec2c4a70c914cd8628caf7805a493de59653 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 16 Apr 2009 10:25:55 -0700 Subject: [PATCH] Speed up device detection in windows and Fix #2287 (Calibre 0.5.7 No Longer Detects Kindle 2 When Plugged In) --- src/calibre/devices/prs505/driver.py | 2 +- src/calibre/devices/usbms/device.py | 2 +- src/calibre/gui2/device.py | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/calibre/devices/prs505/driver.py b/src/calibre/devices/prs505/driver.py index 6e21c60d1b..b32c7e702e 100644 --- a/src/calibre/devices/prs505/driver.py +++ b/src/calibre/devices/prs505/driver.py @@ -150,7 +150,7 @@ class PRS505(Device): time.sleep(6) drives = [] wmi = __import__('wmi', globals(), locals(), [], -1) - c = wmi.WMI() + c = wmi.WMI(find_classes=False) for drive in c.Win32_DiskDrive(): if self.__class__.is_device(str(drive.PNPDeviceID)): if drive.Partitions == 0: diff --git a/src/calibre/devices/usbms/device.py b/src/calibre/devices/usbms/device.py index 5a1b5ef40d..5bcc384b00 100644 --- a/src/calibre/devices/usbms/device.py +++ b/src/calibre/devices/usbms/device.py @@ -186,7 +186,7 @@ class Device(_Device): time.sleep(6) drives = {} wmi = __import__('wmi', globals(), locals(), [], -1) - c = wmi.WMI() + c = wmi.WMI(find_classes=False) for drive in c.Win32_DiskDrive(): if self.windows_match_device(str(drive.PNPDeviceID), self.WINDOWS_MAIN_MEM): drives['main'] = self.windows_get_drive_prefix(drive) diff --git a/src/calibre/gui2/device.py b/src/calibre/gui2/device.py index 0ef4191b84..03a6220f87 100644 --- a/src/calibre/gui2/device.py +++ b/src/calibre/gui2/device.py @@ -11,6 +11,7 @@ from PyQt4.Qt import QMenu, QAction, QActionGroup, QIcon, SIGNAL, QPixmap, \ Qt from calibre.devices import devices +from calibre.constants import iswindows from calibre.gui2.dialogs.choose_format import ChooseFormatDialog from calibre.parallel import Job from calibre.devices.scanner import DeviceScanner @@ -69,7 +70,14 @@ class DeviceManager(Thread): if connected and not device[1]: try: dev = device[0]() - dev.open() + if iswindows: + import pythoncom + pythoncom.CoInitialize() + try: + dev.open() + finally: + if iswindows: + pythoncom.CoUninitialize() self.device = dev self.device_class = dev.__class__ self.connected_slot(True)