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.config import Config, config_dir
|
||||||
from calibre.utils.date import parse_date
|
from calibre.utils.date import parse_date
|
||||||
from calibre.utils.logging import Log
|
from calibre.utils.logging import Log
|
||||||
|
from calibre.devices.errors import UserFeedback
|
||||||
|
|
||||||
from PIL import Image as PILImage
|
from PIL import Image as PILImage
|
||||||
|
|
||||||
@ -26,30 +27,18 @@ if isosx:
|
|||||||
#if iswindows:
|
#if iswindows:
|
||||||
# import win32com.client
|
# 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):
|
class ITUNES(DevicePlugin):
|
||||||
|
|
||||||
name = 'Apple device interface'
|
name = 'Apple device interface'
|
||||||
gui_name = 'Apple device'
|
gui_name = 'Apple device'
|
||||||
icon = I('devices/ipad.png')
|
icon = I('devices/ipad.png')
|
||||||
description = _('Communicate with iBooks through iTunes.')
|
description = _('Communicate with iBooks through iTunes.')
|
||||||
supported_platforms = ['windows','osx']
|
supported_platforms = ['osx']
|
||||||
author = 'GRiker'
|
author = 'GRiker'
|
||||||
driver_version = '0.1'
|
driver_version = '0.1'
|
||||||
|
|
||||||
OPEN_FEEDBACK_MESSAGE = _('Apple device detected, launching iTunes')
|
OPEN_FEEDBACK_MESSAGE = _(
|
||||||
|
'Apple device detected, launching iTunes, please wait...')
|
||||||
|
|
||||||
FORMATS = ['epub']
|
FORMATS = ['epub']
|
||||||
|
|
||||||
|
@ -22,9 +22,20 @@ class DeviceError(ProtocolError):
|
|||||||
""" Raised when device is not found """
|
""" Raised when device is not found """
|
||||||
def __init__(self, msg=None):
|
def __init__(self, msg=None):
|
||||||
if msg is None:
|
if msg is None:
|
||||||
msg = "Unable to find SONY Reader. Is it connected?"
|
msg = "Unable to find SONY Reader. Is it connected?"
|
||||||
ProtocolError.__init__(self, msg)
|
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):
|
class DeviceBusy(ProtocolError):
|
||||||
""" Raised when device is busy """
|
""" Raised when device is busy """
|
||||||
def __init__(self, uerr=""):
|
def __init__(self, uerr=""):
|
||||||
@ -57,8 +68,8 @@ class ControlError(ProtocolError):
|
|||||||
self.query = query
|
self.query = query
|
||||||
self.response = response
|
self.response = response
|
||||||
ProtocolError.__init__(self, desc)
|
ProtocolError.__init__(self, desc)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
if self.query and self.response:
|
if self.query and self.response:
|
||||||
return "Got unexpected response:\n" + \
|
return "Got unexpected response:\n" + \
|
||||||
"query:\n"+str(self.query.query)+"\n"+\
|
"query:\n"+str(self.query.query)+"\n"+\
|
||||||
|
@ -47,6 +47,10 @@ class DevicePlugin(Plugin):
|
|||||||
# Used by gui2.ui:annotations_fetched() and devices.kindle.driver:get_annotations()
|
# Used by gui2.ui:annotations_fetched() and devices.kindle.driver:get_annotations()
|
||||||
UserAnnotation = namedtuple('Annotation','type, value')
|
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
|
@classmethod
|
||||||
def get_gui_name(cls):
|
def get_gui_name(cls):
|
||||||
if hasattr(cls, 'gui_name'):
|
if hasattr(cls, 'gui_name'):
|
||||||
|
@ -81,6 +81,8 @@ class DeviceJob(BaseJob):
|
|||||||
|
|
||||||
class DeviceManager(Thread):
|
class DeviceManager(Thread):
|
||||||
|
|
||||||
|
open_feedback = pyqtSignal(object)
|
||||||
|
|
||||||
def __init__(self, connected_slot, job_manager, sleep_time=2):
|
def __init__(self, connected_slot, job_manager, sleep_time=2):
|
||||||
'''
|
'''
|
||||||
:sleep_time: Time to sleep between device probes in secs
|
: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):
|
def do_connect(self, connected_devices, is_folder_device):
|
||||||
for dev, detected_device in connected_devices:
|
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,
|
dev.reset(detected_device=detected_device,
|
||||||
report_progress=self.report_progress)
|
report_progress=self.report_progress)
|
||||||
try:
|
try:
|
||||||
|
@ -30,6 +30,7 @@ from calibre.ptempfile import PersistentTemporaryFile
|
|||||||
from calibre.utils.config import prefs, dynamic
|
from calibre.utils.config import prefs, dynamic
|
||||||
from calibre.utils.ipc.server import Server
|
from calibre.utils.ipc.server import Server
|
||||||
from calibre.utils.search_query_parser import saved_searches
|
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, \
|
from calibre.gui2 import warning_dialog, choose_files, error_dialog, \
|
||||||
question_dialog,\
|
question_dialog,\
|
||||||
pixmap_to_data, choose_dir, \
|
pixmap_to_data, choose_dir, \
|
||||||
@ -234,6 +235,8 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
####################### Setup device detection ########################
|
####################### Setup device detection ########################
|
||||||
self.device_manager = DeviceManager(Dispatcher(self.device_detected),
|
self.device_manager = DeviceManager(Dispatcher(self.device_detected),
|
||||||
self.job_manager)
|
self.job_manager)
|
||||||
|
self.device_manager.open_feedback.connect(self.status.showMessage,
|
||||||
|
type=Qt.QueuedConnection)
|
||||||
self.device_manager.start()
|
self.device_manager.start()
|
||||||
|
|
||||||
|
|
||||||
@ -2327,6 +2330,14 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
'''
|
'''
|
||||||
Handle exceptions in threaded device jobs.
|
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:
|
try:
|
||||||
if 'Could not read 32 bytes on the control bus.' in \
|
if 'Could not read 32 bytes on the control bus.' in \
|
||||||
unicode(job.details):
|
unicode(job.details):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user