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:
@ -274,9 +274,13 @@ 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)')