~ubuntu-branches/debian/sid/calibre/sid

« back to all changes in this revision

Viewing changes to src/calibre/gui2/toc/location.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2014-02-27 07:48:06 UTC
  • mto: This revision was merged to the branch mainline in revision 74.
  • Revision ID: package-import@ubuntu.com-20140227074806-64wdebb3ptosxhhx
Tags: upstream-1.25.0+dfsg
ImportĀ upstreamĀ versionĀ 1.25.0+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
8
8
__docformat__ = 'restructuredtext en'
9
9
 
 
10
import json
10
11
from base64 import b64encode
11
12
 
12
13
from PyQt4.Qt import (QWidget, QGridLayout, QListWidget, QSize, Qt, QUrl,
20
21
 
21
22
class Page(QWebPage):  # {{{
22
23
 
23
 
    elem_clicked = pyqtSignal(object, object, object, object)
 
24
    elem_clicked = pyqtSignal(object, object, object, object, object)
24
25
 
25
26
    def __init__(self):
26
27
        self.log = default_log
42
43
    def shouldInterruptJavaScript(self):
43
44
        return True
44
45
 
45
 
    @pyqtSlot(QWebElement, float)
46
 
    def onclick(self, elem, frac):
 
46
    @pyqtSlot(QWebElement, str, str, float)
 
47
    def onclick(self, elem, loc, totals, frac):
47
48
        elem_id = unicode(elem.attribute('id')) or None
48
49
        tag = unicode(elem.tagName()).lower()
49
 
        parent = elem
50
 
        loc = []
51
 
        while unicode(parent.tagName()).lower() != 'body':
52
 
            num = 0
53
 
            sibling = parent.previousSibling()
54
 
            while not sibling.isNull():
55
 
                num += 1
56
 
                sibling = sibling.previousSibling()
57
 
            loc.insert(0, num)
58
 
            parent = parent.parent()
59
 
        self.elem_clicked.emit(tag, frac, elem_id, tuple(loc))
 
50
        self.elem_clicked.emit(tag, frac, elem_id, json.loads(str(loc)), json.loads(str(totals)))
60
51
 
61
52
    def load_js(self):
62
53
        if self.js is None:
69
60
 
70
61
class WebView(QWebView):  # {{{
71
62
 
72
 
    elem_clicked = pyqtSignal(object, object, object, object)
 
63
    elem_clicked = pyqtSignal(object, object, object, object, object)
73
64
 
74
65
    def __init__(self, parent):
75
66
        QWebView.__init__(self, parent)
294
285
            loctext =  _('Approximately %d%% from the top')%frac
295
286
        return loctext
296
287
 
297
 
    def elem_clicked(self, tag, frac, elem_id, loc):
298
 
        self.current_frag = elem_id or loc
 
288
    def elem_clicked(self, tag, frac, elem_id, loc, totals):
 
289
        self.current_frag = elem_id or (loc, totals)
299
290
        base = _('Location: A &lt;%s&gt; tag inside the file')%tag
300
291
        loctext = base + ' [%s]'%self.get_loctext(frac)
301
292
        self.dest_label.setText(self.base_msg + '<br>' +