More QVariant porting

This commit is contained in:
Kovid Goyal 2014-04-23 13:23:16 +05:30
parent fc2842108c
commit 8518d8f7dc
3 changed files with 25 additions and 17 deletions

View File

@ -53,6 +53,7 @@ def detect_qvariant():
'src/calibre/gui2/viewer/gestures.py': {'toPoint'}, 'src/calibre/gui2/viewer/gestures.py': {'toPoint'},
'src/calibre/utils/serve_coffee.py': {'toString()'}, 'src/calibre/utils/serve_coffee.py': {'toString()'},
'src/calibre/gui2/job_indicator.py': {'toPoint'}, 'src/calibre/gui2/job_indicator.py': {'toPoint'},
'src/calibre/ebooks/pdf/render/engine.py': {'toRect'},
} }
for path in all_py_files(): for path in all_py_files():
if os.path.basename(path) in { if os.path.basename(path) in {

View File

@ -302,12 +302,12 @@ class PDFWriter(QObject):
mjpath = P(u'viewer/mathjax').replace(os.sep, '/') mjpath = P(u'viewer/mathjax').replace(os.sep, '/')
if iswindows: if iswindows:
mjpath = u'/' + mjpath mjpath = u'/' + mjpath
if evaljs(''' if bool(evaljs('''
window.mathjax.base = %s; window.mathjax.base = %s;
mathjax.check_for_math(); mathjax.math_present mathjax.check_for_math(); mathjax.math_present
'''%(json.dumps(mjpath, ensure_ascii=False))).toBool(): '''%(json.dumps(mjpath, ensure_ascii=False)))):
self.log.debug('Math present, loading MathJax') self.log.debug('Math present, loading MathJax')
while not evaljs('mathjax.math_loaded').toBool(): while not bool(evaljs('mathjax.math_loaded')):
self.loop.processEvents(self.loop.ExcludeUserInputEvents) self.loop.processEvents(self.loop.ExcludeUserInputEvents)
evaljs('document.getElementById("MathJax_Message").style.display="none";') evaljs('document.getElementById("MathJax_Message").style.display="none";')
@ -392,11 +392,14 @@ class PDFWriter(QObject):
self.painter.save() self.painter.save()
mf.render(self.painter) mf.render(self.painter)
self.painter.restore() self.painter.restore()
nsl = evaljs('paged_display.next_screen_location()').toInt() try:
self.doc.end_page() nsl = int(evaljs('paged_display.next_screen_location()'))
if not nsl[1] or nsl[0] <= 0: except (TypeError, ValueError):
break break
evaljs('window.scrollTo(%d, 0); paged_display.position_header_footer();'%nsl[0]) self.doc.end_page()
if nsl <= 0:
break
evaljs('window.scrollTo(%d, 0); paged_display.position_header_footer();'%nsl)
if self.doc.errors_occurred: if self.doc.errors_occurred:
break break
col += 1 col += 1

View File

@ -24,7 +24,7 @@ from calibre.ebooks.oeb.display.webview import load_html
def get_custom_size(opts): def get_custom_size(opts):
custom_size = None custom_size = None
if opts.custom_size != None: if opts.custom_size is not None:
width, sep, height = opts.custom_size.partition('x') width, sep, height = opts.custom_size.partition('x')
if height: if height:
try: try:
@ -35,7 +35,7 @@ def get_custom_size(opts):
custom_size = None custom_size = None
return custom_size return custom_size
def get_pdf_printer(opts, for_comic=False, output_file_name=None): # {{{ def get_pdf_printer(opts, for_comic=False, output_file_name=None): # {{{
from calibre.gui2 import is_ok_to_use_qt from calibre.gui2 import is_ok_to_use_qt
if not is_ok_to_use_qt(): if not is_ok_to_use_qt():
raise Exception('Not OK to use Qt') raise Exception('Not OK to use Qt')
@ -89,7 +89,7 @@ def draw_image_page(printer, painter, p, preserve_aspect_ratio=True):
nw, nh = page_rect.width(), page_rect.height() nw, nh = page_rect.width(), page_rect.height()
if aspect_ratio > 1: if aspect_ratio > 1:
nh = int(page_rect.width()/aspect_ratio) nh = int(page_rect.width()/aspect_ratio)
else: # Width is smaller than height else: # Width is smaller than height
nw = page_rect.height()*aspect_ratio nw = page_rect.height()*aspect_ratio
__, nnw, nnh = fit_image(nw, nh, page_rect.width(), __, nnw, nnh = fit_image(nw, nh, page_rect.width(),
page_rect.height()) page_rect.height())
@ -101,7 +101,7 @@ def draw_image_page(printer, painter, p, preserve_aspect_ratio=True):
painter.drawPixmap(page_rect, p, p.rect()) painter.drawPixmap(page_rect, p, p.rect())
class Page(QWebPage): # {{{ class Page(QWebPage): # {{{
def __init__(self, opts, log): def __init__(self, opts, log):
self.log = log self.log = log
@ -134,7 +134,7 @@ class Page(QWebPage): # {{{
self.log(unicode(msg)) self.log(unicode(msg))
# }}} # }}}
class PDFWriter(QObject): # {{{ class PDFWriter(QObject): # {{{
def __init__(self, opts, log, cover_data=None, toc=None): def __init__(self, opts, log, cover_data=None, toc=None):
from calibre.gui2 import is_ok_to_use_qt from calibre.gui2 import is_ok_to_use_qt
@ -274,15 +274,19 @@ class PDFWriter(QObject): # {{{
self.current_page_num += 1 self.current_page_num += 1
self.first_page = False self.first_page = False
mf.render(self.painter) mf.render(self.painter)
nsl = evaljs('paged_display.next_screen_location()').toInt() try:
if not nsl[1] or nsl[0] <= 0: break nsl = int(evaljs('paged_display.next_screen_location()'))
evaljs('window.scrollTo(%d, 0)'%nsl[0]) except (TypeError, ValueError):
break
if nsl <= 0:
break
evaljs('window.scrollTo(%d, 0)'%nsl)
self.bridge_value = tuple(self.outline.anchor_map[self.current_item]) self.bridge_value = tuple(self.outline.anchor_map[self.current_item])
evaljs('py_bridge.value = book_indexing.anchor_positions(py_bridge.value)') evaljs('py_bridge.value = book_indexing.anchor_positions(py_bridge.value)')
amap = self.bridge_value amap = self.bridge_value
if not isinstance(amap, dict): if not isinstance(amap, dict):
amap = {} # Some javascript error occurred amap = {} # Some javascript error occurred
self.outline.set_pos(self.current_item, None, start_page, 0) self.outline.set_pos(self.current_item, None, start_page, 0)
for anchor, x in amap.iteritems(): for anchor, x in amap.iteritems():
pagenum, ypos = x pagenum, ypos = x
@ -339,7 +343,7 @@ class PDFWriter(QObject): # {{{
# }}} # }}}
class ImagePDFWriter(object): # {{{ class ImagePDFWriter(object): # {{{
def __init__(self, opts, log, cover_data=None, toc=None): def __init__(self, opts, log, cover_data=None, toc=None):
self.opts = opts self.opts = opts