Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 06-15-2011, 10:02 AM   #16
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by burbleburble View Post
Thanks for your response theducks.

Please forgive my ignorance of your terminology, but what exacty are you refering to when you say ?


Thank you for all your help.
weight - friendly name
100
200
300
400 - Regular
500
600
700 - Bold
800 - Heavy
900
theducks is offline   Reply With Quote
Old 06-16-2011, 02:57 AM   #17
burbleburble
Connoisseur
burbleburble began at the beginning.
 
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
Kovid
  1. I need to extract the html from the epub and rewrite it to the epub. I also need to combine them if the epub has seperated htmls. And I also need to be able to update the manifest, spine, and toc.ncx.... Does calibre have classes for handling these actions that I can access from the plugin? Is there code I can look at (like your answer before of actions/tweak_epub) that I can adjust for my needs? Is it better, and is there a way, to convert the epub to the xhtml intermediate form used for all conversions and let calibre handle rewriting it?
  2. I tried importing html.parser and noticed that the binaries are not included in calibre's python. What parser does calibre use in conversions? How can I access it?

Thank you for all your help.
burbleburble is offline   Reply With Quote
Advert
Old 06-16-2011, 03:04 AM   #18
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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
kovidgoyal is offline   Reply With Quote
Old 06-16-2011, 12:34 PM   #19
burbleburble
Connoisseur
burbleburble began at the beginning.
 
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:
  1. retrieve an unsplit version of the epub's html, and its stylesheet.
  2. a.split b.rewrite the html, and stylesheet.

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?
burbleburble is offline   Reply With Quote
Old 06-16-2011, 02:05 PM   #20
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by burbleburble View Post
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:
  1. retrieve an unsplit version of the epub's html, and its stylesheet.
  2. a.split b.rewrite the html, and stylesheet.

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?
Calibre's 'classes' are generated on the fly and repetitive appearance of say 'calibre6' will not always be "Chapter heading centered"

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.
theducks is offline   Reply With Quote
Advert
Old 06-16-2011, 09:37 PM   #21
ldolse
Wizard
ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.ldolse is an accomplished Snipe hunter.
 
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.
ldolse is offline   Reply With Quote
Old 06-19-2011, 04:33 AM   #22
burbleburble
Connoisseur
burbleburble began at the beginning.
 
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
Thank you for your responses.
  1. Using pyqt webkit, how does one get the QWebElement underlying the user selection and change it.
    • for ex., the user selects a range, and presses the button to make it italic. How do I get the underlying QWebElement to set its attribute to italic?!
  2. Also, how do I get signals describing changes to the document (in content editable mode) so that I know what the user deleted, or what he added, without processeing the entire document in comparison to the older one.

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.
burbleburble is offline   Reply With Quote
Old 06-19-2011, 11:04 AM   #23
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 06-20-2011, 09:41 AM   #24
burbleburble
Connoisseur
burbleburble began at the beginning.
 
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.
burbleburble is offline   Reply With Quote
Old 06-20-2011, 11:44 AM   #25
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 06-22-2011, 12:06 PM   #26
burbleburble
Connoisseur
burbleburble began at the beginning.
 
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:
Something to clean up bad markup - check those epubs generated by Word export to HTML and how many font definitions they have on every single page- , CSS and removing embedded fonts would be a terrific feature.
I am still not terribly familiar with word htmls/htmls in general. If you would elaborate on what embedded fonts and font definitions are, and how they should be dealt with in cleaning them up, I can easly add it to my parser.

@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?
burbleburble is offline   Reply With Quote
Old 06-22-2011, 12:18 PM   #27
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 29,689
Karma: 54369090
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by burbleburble View Post
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:

I am still not terribly familiar with word htmls/htmls in general. If you would elaborate on what embedded fonts and font definitions are, and how they should be dealt with in cleaning them up, I can easly add it to my parser.

@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?
I looked at the Table (as you did).
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)
theducks is offline   Reply With Quote
Old 06-22-2011, 12:23 PM   #28
burbleburble
Connoisseur
burbleburble began at the beginning.
 
Posts: 52
Karma: 38
Join Date: Jun 2011
Device: Kindle 3
@theducks
Got it.

@Kovid, anyone
  1. How do I utilize the calibre interface with the temp directory (get the path, and allow for auto cleanup)?
  2. Webkit seems to sometimes create something called 'apple stylespan' when edited. What in the world is this?
  3. Where is the source/how to use object 'P' in calibre. It is found in documentview to load jquery, which I need.

Last edited by burbleburble; 06-22-2011 at 12:48 PM.
burbleburble is offline   Reply With Quote
Old 06-22-2011, 12:29 PM   #29
capnm
Groupie
capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'capnm knows the difference between 'who' and 'whom'
 
Posts: 156
Karma: 10001
Join Date: Feb 2011
Device: sony
Quote:
Originally Posted by burbleburble View Post
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?
The additional granularity of 100-900 is only useful if the renderer can do something with it. Most of the time it can't, yet.

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.
capnm is offline   Reply With Quote
Old 06-22-2011, 01:30 PM   #30
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,776
Karma: 22666666
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)
kovidgoyal is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[GUI Plugin] User Category kiwidude Plugins 123 03-16-2024 11:59 PM
[GUI Plugin] Reading List kiwidude Plugins 1309 03-16-2024 11:52 PM
[GUI Plugin] Open With kiwidude Plugins 402 03-16-2024 11:44 PM
[GUI Plugin] Find Duplicates kiwidude Plugins 1096 03-16-2024 11:28 PM
[GUI Plugin] Plugin Updater **Deprecated** kiwidude Plugins 159 06-19-2011 12:27 PM


All times are GMT -4. The time now is 06:44 PM.


MobileRead.com is a privately owned, operated and funded community.