06-15-2011, 10:02 AM | #16 |
Well trained by Cats
Posts: 29,974
Karma: 56143930
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
|
06-16-2011, 02:57 AM | #17 |
Connoisseur
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
|
Kovid
Thank you for all your help. |
Advert | |
|
06-16-2011, 03:04 AM | #18 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
1. There is plenty of code that does these kinds of things all over calibre, look in the ebooks.oeb module, or oeb.iterator or the code used in epub fix.
2. calibre uses lxml |
06-16-2011, 12:34 PM | #19 |
Connoisseur
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
|
Hi,
A basic version of this plugin is almost ready, but I am having trouble figuring out how to utilize calibre's classes (they aren't too heavily commented, and I'm still somewhat of a beginer). I need to:
I could write new code for all of this but is there a point? All the updating manifest etc will take forever to implement correctly! If someone has some time, please could you point out the basic classes/methods/arguments for accomplishing these tasks? Or maybe point me to a well commented utilization of these classes/methods/arguments to perform similar tasks? |
06-16-2011, 02:05 PM | #20 | |
Well trained by Cats
Posts: 29,974
Karma: 56143930
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
You need to reverse engineer each and every stylesheet. True, you will see common use. That is probably derived the the books all had a style in common. |
|
Advert | |
|
06-16-2011, 09:37 PM | #21 |
Wizard
Posts: 1,337
Karma: 123455
Join Date: Apr 2009
Location: Malaysia
Device: PRS-650, iPhone
|
@theducks, he means python code classes. ;-)
@burbleburble, if you want to join the HTML before processing it then look at the htmlz output format, it has code to join HTML files. I don't know that it updates the manifest for you, you may still need to implement that. Anyway I think you'll find your task easier to not join the files. If the file was originally split in the wrong place the user can use htmlz conversion to re-join it, then convert back to ePub using heuristics, structure detection, etc to get the correct split points, then use your tool for further cleanup. Last edited by ldolse; 06-16-2011 at 09:42 PM. |
06-19-2011, 04:33 AM | #22 |
Connoisseur
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
|
Thank you for your responses.
I have searched google, qt documentation, everywhere, and I cant figure it out how to do these things, esp #1 which is essential to editing the html. Thank you for any help. |
06-19-2011, 11:04 AM | #23 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Look at comments_editor.py the trick is to use QWebPage::WebAction
You can use javascript to subscribe to the content edited events and then have your javascript listener call a python method via a bridge. See documentview.py for an example. |
06-20-2011, 09:41 AM | #24 |
Connoisseur
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
|
@Kovid: Thanks for the references. They helped alot.
Some questions: 1) I'm still having trouble creating the bridge. In the following example code the bridge only works if the pyqtSignature is set to QVariant, or someother setup. It never works when set to QWebElement (and if I don't set anything, it apparently can't pass values)! But I very much need this functionality, and it shoud work as per the instructions on http://doc.qt.nokia.com/4.7-snapshot...it-bridge.html (under the section entitled 'QWebElement'). Here is an example of the code I am trying to use (it runs as a module, and the javascript should respond 'onclick'): Code:
import sys from PyQt4 import QtCore, QtGui, QtWebKit, Qt class JSObject(QtCore.QObject): @Qt.pyqtSignature('QWebElement') def test(self, webelement): print('Comunication with jsobject worked!') #print(webelement.tagName()) #test if actually returned a webelement def loadJSObject(): webview.page().mainFrame().addToJavaScriptWindowObject("py_bridge", JSObject()) webview.page().mainFrame().evaluateJavaScript('document.onclick = function test(event){window.py_bridge.test(event.target)}') if __name__ == '__main__': app = QtGui.QApplication(sys.argv) webview = QtWebKit.QWebView() webview.page().connect(webview.page(), QtCore.SIGNAL('loadFinished(bool)'), loadJSObject) webview.setHtml('<html><body><p>This is a test html!</body></html>') webview.show() sys.exit(app.exec_()) 2)Its very confusing for me to figure out how exactly to interface with the multiple files/classes dealing with epub/oeb. Is there a simple interface for the following two actions (a class and method to call, or something): a)retrieve the html's from the epub. (a getHtml() type interface) b)rewrite the epub, providing the html/toc/stylesheet information (a writeEpub(html, toc) type interface) Thank you for your help! Last edited by burbleburble; 06-20-2011 at 10:47 AM. |
06-20-2011, 11:44 AM | #25 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
1) I doubt you can pass a JS DOM object and have that automatically converted to a QWebElement. Instead pass either the path to the object, or set an id on it and pass the id and construct the QWebElement from it. Though if I was you, I'd just load jquery and do my manipulations in javascript directly
2) No, there are no reusable APIs for this. You are better off writing your own classes. |
06-22-2011, 12:06 PM | #26 | |
Connoisseur
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
|
Ok, I have posted a first (test) version in the first post of this thread.
If anyone could read the information, and test it, I would be grateful for the feedback regarding issues and ideas. @pualfiera: Quote:
@theducks: I looked into friendly-name/number by font-weight; it appears that for many browsers there is no difference between 100-400, 500-600, etc. Could you provide me with a source that 400 must equal regular, etc? |
|
06-22-2011, 12:18 PM | #27 | |
Well trained by Cats
Posts: 29,974
Karma: 56143930
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
|
Quote:
As I read it: the current is treat 400 as Regular and map 100-300) to regular. (allows for Browser compatibility to exist for future 100-300 use? BTW those number are continuous. 345 is valid) |
|
06-22-2011, 12:23 PM | #28 |
Connoisseur
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
|
@theducks
Got it. @Kovid, anyone
Last edited by burbleburble; 06-22-2011 at 12:48 PM. |
06-22-2011, 12:29 PM | #29 | |
Groupie
Posts: 156
Karma: 10001
Join Date: Feb 2011
Device: sony
|
Quote:
If you're just working with typical normal/bold fonts the renderer will pick the best match. So if you specify 300, it will use normal (400), etc. |
|
06-22-2011, 01:30 PM | #30 |
creator of calibre
Posts: 44,017
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
1) Look at the functions in calibre.ptempfile
2) That's what webkit does. 3) P simply resolves relative paths to files in the resources folder of your calibre install to absolute paths (look at calibre.utils.resources) |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[GUI Plugin] Find Duplicates | kiwidude | Plugins | 1102 | Yesterday 09:59 AM |
[GUI Plugin] Reading List | kiwidude | Plugins | 1332 | 06-05-2024 06:31 PM |
[GUI Plugin] Open With | kiwidude | Plugins | 403 | 04-01-2024 08:39 AM |
[GUI Plugin] User Category | kiwidude | Plugins | 123 | 03-16-2024 11:59 PM |
[GUI Plugin] Plugin Updater **Deprecated** | kiwidude | Plugins | 159 | 06-19-2011 12:27 PM |