![]() |
#1 |
Member
![]() ![]() ![]() Posts: 21
Karma: 289
Join Date: Dec 2006
Device: Sony eReader
|
Create LRS and LRF files from Python with pylrs
I have just uploaded a Python package that I created called pylrs. It is available from the main page of http://www.falstaffshouse.com.
The package can create both lrs anf lrf files. The lrf files are created directly, without the use of a compiler. An example of creating an lrf file using the package is: Code:
from pylrs.pylrs import * b = Book() b.Page().TextBlock().Paragraph("Hello, World!") b.renderLrf("hello.lrf") There are several example programs included in the distribution that illustrate the various features. I created the package in order to format the plays of Shakespeare, which are also available from the same web page. The source code is included in the distribution. The package is optimistically versioned 1.0, but it's never been used by anyone but me, so assume it's an early alpha version at best. The software has only been tested on Windows XP, Python 2.4 and 2.5, and the PRS-500. Last edited by Falstaff; 02-19-2007 at 12:49 AM. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,229
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Atlast! I am really, really happy you did this. Could I ask you to upload the python module to the python package index http://www.python.org/pypi
That will make it easy for other projects to depend on it. If that's too much trouble, I'd be willing to do it for you. Also can you add some platform detection to set the default encoding. Something like if 'linux' in sys.platform.lower() or 'darwin' in sys.platform.lower(): default_encoding = 'utf-8' Thanks and great work. EDIT: Browsing through the code it doesn't look like you have support for embedded images, or did I miss it? |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Member
![]() ![]() ![]() Posts: 21
Karma: 289
Join Date: Dec 2006
Device: Sony eReader
|
You can have embedded images in an ImageBlock, so they can be cover pages or illustrations. You can't use them by themselves in a Header or on a Canvas yet.
Yes, I forgot the default source encoding was set to the windows character set. Is "utf-8" or "latin-1" a better default for non-Windows 8 bit strings? For any real projects, you should probably set the encoding explicitly with Book(sourceencoding="<codec>"). See the russanbook.py example program for an example of this. The code can be uploaded anywhere -- there are no restictions on it's use. But I only plan to maintain the latest version on the web page. Last edited by Falstaff; 02-19-2007 at 10:13 AM. |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,229
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
On most modern Linux systems, utf-8 is a good choice for default encoding. Not so sure about OSX.
|
![]() |
![]() |
![]() |
#5 | |
Junior Member
![]() Posts: 4
Karma: 10
Join Date: Mar 2007
Device: PRS-500
|
Quote:
Yeah, OSX has it's own ver of UTF 8 ( known as UTF 8 MAC) and can cause headaches ( i.e. samba for one ). And thanks for the python scripts, my readers should hopefully be here tomorrow, as an OS X user it looks as if I'm in for a bit of fun. |
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Junior Member
![]() Posts: 9
Karma: 10
Join Date: Mar 2007
Device: Sony reader
|
Jiha!
Hi Mike,
I've played arround with your scripts, and I am really, really happy about them. The only problem is, that I dont know Python at all ![]() ![]() Uwe, tryin' to build a HTML2LRF-script the very moment. |
![]() |
![]() |
![]() |
#7 |
Member
![]() ![]() ![]() Posts: 21
Karma: 289
Join Date: Dec 2006
Device: Sony eReader
|
Sorry, I was out of town and didn't see your message. I think it would be fairly hard to use these scripts without knowing python pretty well, but if you have any specific questions, let me know and I'll try to answer them.
|
![]() |
![]() |
![]() |
#8 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 350
Karma: 705
Join Date: Dec 2006
Location: Mumbai, India
Device: Kindle 1/REB 1200
|
Falstaff: I made some changes in your code, in file pylrs.py:587
Code:
if not isinstance(textBlock, TextBlock) and not isinstance(textBlock, ImageBlock): Thanks for the very wonderful library! |
![]() |
![]() |
![]() |
#9 |
Member
![]() ![]() ![]() Posts: 21
Karma: 289
Join Date: Dec 2006
Device: Sony eReader
|
Thanks for the fix -- I'll incorporate it in the next version. I'm glad the code is of use to people.
|
![]() |
![]() |
![]() |
#10 |
Blueberry!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
Falstaff.
Would you mind providing the code for the conversion project you did? The samples are handy, but a more complete example (one that opens files, for example) would be great for a Python newb like myself. -Pie |
![]() |
![]() |
![]() |
#11 |
Blueberry!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
BUMP.
Still hoping for sample code that reads a file for conversion! -Pie |
![]() |
![]() |
![]() |
#12 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 350
Karma: 705
Join Date: Dec 2006
Location: Mumbai, India
Device: Kindle 1/REB 1200
|
Quote:
|
|
![]() |
![]() |
![]() |
#13 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,229
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
@Falstaff
It may be a good idea to change the default blockStyle for an ImageBlock to BlockStyle(blockrule='block-fixed') that way the reader doesn't scale images off the page when going from S->M->L |
![]() |
![]() |
![]() |
#14 | |
Blueberry!
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 888
Karma: 133343
Join Date: Mar 2007
Device: Sony PRS-500 (RIP); PRS-600 (Good Riddance); PRS-505; PRS-650; PRS-350
|
Quote:
Now another questions... I have code to generate UTF-16 smart quotes, which I would want to embed into pylrs. I noted that just pre-pending a "u" to a string flags it as UTF-16, from the (super ultra crappy) Python reference I used. Problem is, this foregoes any algorithmic conversion. EG... text = u"This is text"; But I need to scan the text and look for preceding and following characters to decide which curly-quote to apply (open or close). Once a string has the "u" prepended, I have no idea what I'm dealing with. My lack of python knowledge really shows here. So let me break this down into two basic questions. (1) Where would I parse text and convert it to UTF-16? (2) Is there a GOOD Python reference on the Internet? The one I used was the Python Library Reference, is literally the worse documentation I've seen, ever! (http://docs.python.org/lib/lib.html). I really prefer makelrf3, but I have several bugs (and lack of features) that makes pylrs look far more viable... if I can just figure out how to parse a string to apply my curly-quotes algorithm. -Pie |
|
![]() |
![]() |
![]() |
#15 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,229
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
pydoc codecs.decode
pydoc codecs.encode and u'my string' is a python unicode object not a utf-16 encoded string. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pissed off with LRF formatting: LRF/LRS clean tool? | grimborg | LRF | 8 | 02-15-2010 01:14 PM |
How do I Create a Python Plugin? | Sydney's Mom | Plugins | 25 | 01-27-2010 06:26 AM |
Converting LRS to LRF | mcortez | Sony Reader | 1 | 11-28-2007 11:26 AM |
LRS to LRF on Mac OSX - any suggestions? | Lime2K | Sony Reader | 3 | 07-29-2007 10:15 PM |
PRS-500 Span tags in LRS and LRF files -- do I understand them? | Falstaff | Sony Reader Dev Corner | 2 | 01-31-2007 10:34 AM |