Some utility functions to control the viewer position with page numbers in paged mode

This commit is contained in:
Kovid Goyal 2015-01-31 10:45:40 +05:30
parent 2a32abf933
commit 89cc647009
4 changed files with 35 additions and 0 deletions

Binary file not shown.

View File

@ -350,6 +350,9 @@ class PagedDisplay
else
window.scrollTo(pos, 0)
scroll_to_column: (number) ->
this.scroll_to_xpos(number * this.page_width + 10)
column_at: (xpos) ->
# Return the number of the column that contains xpos
return Math.floor(xpos/this.page_width)

View File

@ -51,6 +51,15 @@ class CalibreUtils
process.stdout.write(msg + '\n')
# }}}
stack_trace: () -> # {{{
currentFunction = arguments.callee.caller
while (currentFunction)
fn = currentFunction.toString()
this.log(fn)
currentFunction = currentFunction.caller
# }}}
window_scroll_pos: (win=window) -> # {{{
# The current scroll position of the browser window
if typeof(win.pageXOffset) == 'number'

View File

@ -460,6 +460,29 @@ class Document(QWebPage): # {{{
self.scroll_to(x=self.xpos, y=npos)
return property(fget=fget, fset=fset)
@dynamic_property
def page_number(self):
' The page number is the number of the page at the left most edge of the screen (starting from 0) '
def fget(self):
if self.in_paged_mode:
return self.javascript(
'ans = 0; if (window.paged_display) ans = window.paged_display.column_boundaries()[0]; ans;', typ='int')
def fset(self, val):
if self.in_paged_mode and self.loaded_javascript:
self.javascript('if (window.paged_display) window.paged_display.scroll_to_column(%d)' % int(val))
return True
return property(fget=fget, fset=fset)
@property
def page_dimensions(self):
if self.in_paged_mode:
return self.javascript(
'''
ans = ''
if (window.paged_display)
ans = window.paged_display.col_width + ':' + window.paged_display.current_page_height;
ans;''', typ='string')
@property
def hscroll_fraction(self):
try: