mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
parent
08d7a000c9
commit
1381fe9160
@ -459,6 +459,18 @@ def force_unicode(obj, enc=preferred_encoding):
|
||||
obj = obj.decode('utf-8')
|
||||
return obj
|
||||
|
||||
def as_unicode(obj, enc=preferred_encoding):
|
||||
if not isbytestring(obj):
|
||||
try:
|
||||
obj = unicode(obj)
|
||||
except:
|
||||
try:
|
||||
obj = str(obj)
|
||||
except:
|
||||
obj = repr(obj)
|
||||
return force_unicode(obj, enc=enc)
|
||||
|
||||
|
||||
|
||||
def human_readable(size):
|
||||
""" Convert a size in bytes into a human readable form """
|
||||
|
@ -26,6 +26,7 @@ from calibre.gui2.search_box import SearchBox2
|
||||
from calibre.ebooks.metadata import MetaInformation
|
||||
from calibre.customize.ui import available_input_formats
|
||||
from calibre.gui2.viewer.dictionary import Lookup
|
||||
from calibre import as_unicode
|
||||
|
||||
class TOCItem(QStandardItem):
|
||||
|
||||
@ -632,7 +633,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
else:
|
||||
r = getattr(worker.exception, 'reason', worker.exception)
|
||||
error_dialog(self, _('Could not open ebook'),
|
||||
unicode(r), det_msg=worker.traceback, show=True)
|
||||
as_unicode(r), det_msg=worker.traceback, show=True)
|
||||
self.close_progress_indicator()
|
||||
else:
|
||||
self.metadata.show_opf(self.iterator.opf, os.path.splitext(pathtoebook)[1][1:])
|
||||
|
Loading…
x
Reference in New Issue
Block a user