Allow device drivers to show feedback to users if their open() methods fail

This commit is contained in:
Kovid Goyal 2010-12-14 09:35:48 -07:00
parent 240b371ad5
commit 65021a0f0e
3 changed files with 12 additions and 1 deletions

View File

@ -36,6 +36,11 @@ class UserFeedback(DeviceError):
self.details = details
self.msg = msg
class OpenFeedback(DeviceError):
def __init__(self, msg):
self.feedback_msg = msg
DeviceError.__init__(self, msg)
class DeviceBusy(ProtocolError):
""" Raised when device is busy """
def __init__(self, uerr=""):

View File

@ -216,6 +216,9 @@ class DevicePlugin(Plugin):
an implementation of
this function that should serve as a good example for USB Mass storage
devices.
This method can raise an OpenFeedback exception to display a message to
the user.
'''
raise NotImplementedError()

View File

@ -12,7 +12,7 @@ from PyQt4.Qt import QMenu, QAction, QActionGroup, QIcon, SIGNAL, \
from calibre.customize.ui import available_input_formats, available_output_formats, \
device_plugins
from calibre.devices.interface import DevicePlugin
from calibre.devices.errors import UserFeedback
from calibre.devices.errors import UserFeedback, OpenFeedback
from calibre.gui2.dialogs.choose_format import ChooseFormatDialog
from calibre.utils.ipc.job import BaseJob
from calibre.devices.scanner import DeviceScanner
@ -163,6 +163,9 @@ class DeviceManager(Thread): # {{{
dev.reset(detected_device=detected_device,
report_progress=self.report_progress)
dev.open()
except OpenFeedback, e:
self.open_feedback_slot(e.feedback_msg)
continue
except:
tb = traceback.format_exc()
if DEBUG or tb not in self.reported_errors: