mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Hook up open feedback and user feedback to the GUI
This commit is contained in:
parent
eaf72d2866
commit
170dd6539a
@ -17,6 +17,7 @@ from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.config import Config, config_dir
|
||||
from calibre.utils.date import parse_date
|
||||
from calibre.utils.logging import Log
|
||||
from calibre.devices.errors import UserFeedback
|
||||
|
||||
from PIL import Image as PILImage
|
||||
|
||||
@ -26,30 +27,18 @@ if isosx:
|
||||
#if iswindows:
|
||||
# import win32com.client
|
||||
|
||||
class UserInteractionRequired(Exception):
|
||||
pass
|
||||
|
||||
class UserFeedback(Exception):
|
||||
INFO = 0
|
||||
WARN = 1
|
||||
ERROR = 2
|
||||
|
||||
def __init__(self, msg, details, level):
|
||||
Exception.__init__(self, msg)
|
||||
self.level = level
|
||||
self.details = details
|
||||
self.msg = msg
|
||||
|
||||
class ITUNES(DevicePlugin):
|
||||
|
||||
name = 'Apple device interface'
|
||||
gui_name = 'Apple device'
|
||||
icon = I('devices/ipad.png')
|
||||
description = _('Communicate with iBooks through iTunes.')
|
||||
supported_platforms = ['windows','osx']
|
||||
supported_platforms = ['osx']
|
||||
author = 'GRiker'
|
||||
driver_version = '0.1'
|
||||
|
||||
OPEN_FEEDBACK_MESSAGE = _('Apple device detected, launching iTunes')
|
||||
OPEN_FEEDBACK_MESSAGE = _(
|
||||
'Apple device detected, launching iTunes, please wait...')
|
||||
|
||||
FORMATS = ['epub']
|
||||
|
||||
|
@ -25,6 +25,17 @@ class DeviceError(ProtocolError):
|
||||
msg = "Unable to find SONY Reader. Is it connected?"
|
||||
ProtocolError.__init__(self, msg)
|
||||
|
||||
class UserFeedback(DeviceError):
|
||||
INFO = 0
|
||||
WARN = 1
|
||||
ERROR = 2
|
||||
|
||||
def __init__(self, msg, details, level):
|
||||
Exception.__init__(self, msg)
|
||||
self.level = level
|
||||
self.details = details
|
||||
self.msg = msg
|
||||
|
||||
class DeviceBusy(ProtocolError):
|
||||
""" Raised when device is busy """
|
||||
def __init__(self, uerr=""):
|
||||
|
@ -47,6 +47,10 @@ class DevicePlugin(Plugin):
|
||||
# Used by gui2.ui:annotations_fetched() and devices.kindle.driver:get_annotations()
|
||||
UserAnnotation = namedtuple('Annotation','type, value')
|
||||
|
||||
#: GUI displays this as a message if not None. Useful if opening can take a
|
||||
#: long time
|
||||
OPEN_FEEDBACK_MESSAGE = None
|
||||
|
||||
@classmethod
|
||||
def get_gui_name(cls):
|
||||
if hasattr(cls, 'gui_name'):
|
||||
|
@ -81,6 +81,8 @@ class DeviceJob(BaseJob):
|
||||
|
||||
class DeviceManager(Thread):
|
||||
|
||||
open_feedback = pyqtSignal(object)
|
||||
|
||||
def __init__(self, connected_slot, job_manager, sleep_time=2):
|
||||
'''
|
||||
:sleep_time: Time to sleep between device probes in secs
|
||||
@ -114,6 +116,8 @@ class DeviceManager(Thread):
|
||||
|
||||
def do_connect(self, connected_devices, is_folder_device):
|
||||
for dev, detected_device in connected_devices:
|
||||
if dev.OPEN_FEEDBACK_MESSAGE is not None:
|
||||
self.open_feedback.emit(dev.OPEN_FEEDBACK_MESSAGE)
|
||||
dev.reset(detected_device=detected_device,
|
||||
report_progress=self.report_progress)
|
||||
try:
|
||||
|
@ -30,6 +30,7 @@ from calibre.ptempfile import PersistentTemporaryFile
|
||||
from calibre.utils.config import prefs, dynamic
|
||||
from calibre.utils.ipc.server import Server
|
||||
from calibre.utils.search_query_parser import saved_searches
|
||||
from calibre.devices.errors import UserFeedback
|
||||
from calibre.gui2 import warning_dialog, choose_files, error_dialog, \
|
||||
question_dialog,\
|
||||
pixmap_to_data, choose_dir, \
|
||||
@ -234,6 +235,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
####################### Setup device detection ########################
|
||||
self.device_manager = DeviceManager(Dispatcher(self.device_detected),
|
||||
self.job_manager)
|
||||
self.device_manager.open_feedback.connect(self.status.showMessage,
|
||||
type=Qt.QueuedConnection)
|
||||
self.device_manager.start()
|
||||
|
||||
|
||||
@ -2327,6 +2330,14 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
'''
|
||||
Handle exceptions in threaded device jobs.
|
||||
'''
|
||||
if isinstance(getattr(job, 'exception', None), UserFeedback):
|
||||
ex = job.exception
|
||||
func = {UserFeedback.ERROR:error_dialog,
|
||||
UserFeedback.WARNING:warning_dialog,
|
||||
UserFeedback.INFO:info_dialog}[ex.level]
|
||||
return func(self, _('Failed'), ex.msg, det_msg=ex.details if
|
||||
ex.details else '', show=True)
|
||||
|
||||
try:
|
||||
if 'Could not read 32 bytes on the control bus.' in \
|
||||
unicode(job.details):
|
||||
|
Loading…
x
Reference in New Issue
Block a user