mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
E-book viewer: Fix viewer losing place in very long single file documents when window resized. Fixes #745001 (Book jumps ahead several pages when closing the table of contents window)
This commit is contained in:
parent
22b7eb2ed1
commit
49a8d773c0
@ -483,7 +483,6 @@ class Amazon(Source):
|
||||
log.exception('Failed to download cover from:', cached_url)
|
||||
# }}}
|
||||
|
||||
|
||||
if __name__ == '__main__': # tests {{{
|
||||
# To run these test use: calibre-debug -e
|
||||
# src/calibre/ebooks/metadata/sources/amazon.py
|
||||
|
@ -76,9 +76,9 @@ class xISBN(object):
|
||||
xisbn = xISBN()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
import sys, pprint
|
||||
isbn = sys.argv[-1]
|
||||
print xisbn.get_data(isbn)
|
||||
print pprint.pprint(xisbn.get_data(isbn))
|
||||
print
|
||||
print xisbn.get_associated_isbns(isbn)
|
||||
|
||||
|
@ -171,10 +171,11 @@ class Document(QWebPage): # {{{
|
||||
self.misc_config()
|
||||
self.after_load()
|
||||
|
||||
def __init__(self, shortcuts, parent=None):
|
||||
def __init__(self, shortcuts, parent=None, resize_callback=lambda: None):
|
||||
QWebPage.__init__(self, parent)
|
||||
self.setObjectName("py_bridge")
|
||||
self.debug_javascript = False
|
||||
self.resize_callback = resize_callback
|
||||
self.current_language = None
|
||||
self.loaded_javascript = False
|
||||
|
||||
@ -237,6 +238,12 @@ class Document(QWebPage): # {{{
|
||||
if self.loaded_javascript:
|
||||
return
|
||||
self.loaded_javascript = True
|
||||
self.javascript(
|
||||
'''
|
||||
window.onresize = function(event) {
|
||||
window.py_bridge.window_resized();
|
||||
}
|
||||
''')
|
||||
if jquery is None:
|
||||
jquery = P('content_server/jquery.js', data=True)
|
||||
self.javascript(jquery)
|
||||
@ -298,6 +305,10 @@ class Document(QWebPage): # {{{
|
||||
def debug(self, msg):
|
||||
prints(msg)
|
||||
|
||||
@pyqtSignature('')
|
||||
def window_resized(self):
|
||||
self.resize_callback()
|
||||
|
||||
def reference_mode(self, enable):
|
||||
self.javascript(('enter' if enable else 'leave')+'_reference_mode()')
|
||||
|
||||
@ -424,12 +435,19 @@ class Document(QWebPage): # {{{
|
||||
def xpos(self):
|
||||
return self.mainFrame().scrollPosition().x()
|
||||
|
||||
@property
|
||||
@dynamic_property
|
||||
def scroll_fraction(self):
|
||||
try:
|
||||
return float(self.ypos)/(self.height-self.window_height)
|
||||
except ZeroDivisionError:
|
||||
return 0.
|
||||
def fget(self):
|
||||
try:
|
||||
return float(self.ypos)/(self.height-self.window_height)
|
||||
except ZeroDivisionError:
|
||||
return 0.
|
||||
def fset(self, val):
|
||||
npos = val * (self.height - self.window_height)
|
||||
if npos < 0:
|
||||
npos = 0
|
||||
self.scroll_to(x=self.xpos, y=npos)
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@property
|
||||
def hscroll_fraction(self):
|
||||
@ -493,7 +511,8 @@ class DocumentView(QWebView): # {{{
|
||||
self._size_hint = QSize(510, 680)
|
||||
self.initial_pos = 0.0
|
||||
self.to_bottom = False
|
||||
self.document = Document(self.shortcuts, parent=self)
|
||||
self.document = Document(self.shortcuts, parent=self,
|
||||
resize_callback=self.viewport_resized)
|
||||
self.setPage(self.document)
|
||||
self.manager = None
|
||||
self._reference_mode = False
|
||||
@ -630,9 +649,13 @@ class DocumentView(QWebView): # {{{
|
||||
def sizeHint(self):
|
||||
return self._size_hint
|
||||
|
||||
@property
|
||||
@dynamic_property
|
||||
def scroll_fraction(self):
|
||||
return self.document.scroll_fraction
|
||||
def fget(self):
|
||||
return self.document.scroll_fraction
|
||||
def fset(self, val):
|
||||
self.document.scroll_fraction = float(val)
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
@property
|
||||
def hscroll_fraction(self):
|
||||
@ -968,9 +991,11 @@ class DocumentView(QWebView): # {{{
|
||||
def resizeEvent(self, event):
|
||||
ret = QWebView.resizeEvent(self, event)
|
||||
QTimer.singleShot(10, self.initialize_scrollbar)
|
||||
return ret
|
||||
|
||||
def viewport_resized(self):
|
||||
if self.manager is not None:
|
||||
self.manager.viewport_resized(self.scroll_fraction)
|
||||
return ret
|
||||
|
||||
def event(self, ev):
|
||||
typ = ev.type()
|
||||
|
@ -240,7 +240,7 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
self.connect(self.action_reference_mode, SIGNAL('triggered(bool)'),
|
||||
lambda x: self.view.reference_mode(x))
|
||||
self.connect(self.action_metadata, SIGNAL('triggered(bool)'), lambda x:self.metadata.setVisible(x))
|
||||
self.connect(self.action_table_of_contents, SIGNAL('toggled(bool)'), lambda x:self.toc.setVisible(x))
|
||||
self.action_table_of_contents.toggled[bool].connect(self.set_toc_visible)
|
||||
self.connect(self.action_copy, SIGNAL('triggered(bool)'), self.copy)
|
||||
self.connect(self.action_font_size_larger, SIGNAL('triggered(bool)'),
|
||||
self.font_size_larger)
|
||||
@ -310,6 +310,9 @@ class EbookViewer(MainWindow, Ui_EbookViewer):
|
||||
|
||||
self.restore_state()
|
||||
|
||||
def set_toc_visible(self, yes):
|
||||
self.toc.setVisible(yes)
|
||||
|
||||
def clear_recent_history(self, *args):
|
||||
vprefs.set('viewer_open_history', [])
|
||||
self.build_recent_menu()
|
||||
|
Loading…
x
Reference in New Issue
Block a user