From bad6acf8b3d287fcca8aa10f74fd48003b346a6a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 26 Aug 2014 13:08:47 +0530 Subject: [PATCH] Replace deprecated __defineGetter__ and __defineSetter___ __defineGetter__ was not working in Qt 5, this caused the following regressions: PDF Output: Header and footer templates not working in calibre 2.0. Fixes #1361483 [Headers and footers don't appear EPUB to PDF](https://bugs.launchpad.net/calibre/+bug/1361483) E-book viewer: The Table of Contents not displaying the currently viewed section in bold if the section is a link to a location in the middle of a file. --- src/calibre/ebooks/oeb/polish/stats.py | 8 +++----- src/calibre/ebooks/pdf/render/from_html.py | 8 +++----- src/calibre/ebooks/pdf/writer.py | 8 +++----- src/calibre/gui2/viewer/documentview.py | 10 ++++------ 4 files changed, 13 insertions(+), 21 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/stats.py b/src/calibre/ebooks/oeb/polish/stats.py index 118fcdb98d..60b24a6c11 100644 --- a/src/calibre/ebooks/oeb/polish/stats.py +++ b/src/calibre/ebooks/oeb/polish/stats.py @@ -149,11 +149,9 @@ class Page(QWebPage): # {{{ self.mainFrame().addToJavaScriptWindowObject("py_bridge", self) self.evaljs(self.js) self.evaljs(''' - py_bridge.__defineGetter__('value', function() { - return JSON.parse(this._pass_json_value); - }); - py_bridge.__defineSetter__('value', function(val) { - this._pass_json_value = JSON.stringify(val); + Object.defineProperty(py_bridge, 'value', { + get : function() { return JSON.parse(this._pass_json_value); }, + set : function(val) { this._pass_json_value = JSON.stringify(val); } }); ''') # }}} diff --git a/src/calibre/ebooks/pdf/render/from_html.py b/src/calibre/ebooks/pdf/render/from_html.py index d931703420..ba6d605c27 100644 --- a/src/calibre/ebooks/pdf/render/from_html.py +++ b/src/calibre/ebooks/pdf/render/from_html.py @@ -345,11 +345,9 @@ class PDFWriter(QObject): self.load_mathjax() evaljs(''' - py_bridge.__defineGetter__('value', function() { - return JSON.parse(this._pass_json_value); - }); - py_bridge.__defineSetter__('value', function(val) { - this._pass_json_value = JSON.stringify(val); + Object.defineProperty(py_bridge, 'value', { + get : function() { return JSON.parse(this._pass_json_value); }, + set : function(val) { this._pass_json_value = JSON.stringify(val); } }); document.body.style.backgroundColor = "white"; diff --git a/src/calibre/ebooks/pdf/writer.py b/src/calibre/ebooks/pdf/writer.py index 9ba9caf7f1..664f9350b3 100644 --- a/src/calibre/ebooks/pdf/writer.py +++ b/src/calibre/ebooks/pdf/writer.py @@ -250,11 +250,9 @@ class PDFWriter(QObject): # {{{ evaljs = self.view.page().mainFrame().evaluateJavaScript evaljs(self.paged_js) evaljs(''' - py_bridge.__defineGetter__('value', function() { - return JSON.parse(this._pass_json_value); - }); - py_bridge.__defineSetter__('value', function(val) { - this._pass_json_value = JSON.stringify(val); + Object.defineProperty(py_bridge, 'value', { + get : function() { return JSON.parse(this._pass_json_value); }, + set : function(val) { this._pass_json_value = JSON.stringify(val); } }); document.body.style.backgroundColor = "white"; diff --git a/src/calibre/gui2/viewer/documentview.py b/src/calibre/gui2/viewer/documentview.py index 65f21869f8..4480581ee2 100644 --- a/src/calibre/gui2/viewer/documentview.py +++ b/src/calibre/gui2/viewer/documentview.py @@ -180,12 +180,10 @@ class Document(QWebPage): # {{{ def add_window_objects(self): self.mainFrame().addToJavaScriptWindowObject("py_bridge", self) self.javascript(''' - py_bridge.__defineGetter__('value', function() { - return JSON.parse(this._pass_json_value); - }); - py_bridge.__defineSetter__('value', function(val) { - this._pass_json_value = JSON.stringify(val); - }); + Object.defineProperty(py_bridge, 'value', { + get : function() { return JSON.parse(this._pass_json_value); }, + set : function(val) { this._pass_json_value = JSON.stringify(val); } + }); ''') self.loaded_javascript = False