Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-05-2014, 10:46 AM   #1
ShellShock
Wizard
ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.
 
ShellShock's Avatar
 
Posts: 1,178
Karma: 2431850
Join Date: Sep 2008
Device: IPad Mini 2 Retina
Calling smarten_punctuation from edit book

Re: https://www.mobileread.com/forums/sho...d.php?t=230684.

I have enhanced ebook-polish to add a new command line parameter:

Code:
-s SMARTEN_PUNCTUATION_OPT, --smarten-punctuation-opt=SMARTEN_PUNCTUATION_OPT
SMARTEN_PUNCTUATION_OPT gets passed to smartyPants as the attr (the options which control which conversions are done). I have also added additional conversions (for space+hyphen to em-dash etc) to smartyPants.

This all works fine.

But I am not clear on exactly how edit-book can call my new smarten_punctuation_opt command (in ebooks\oeb\polish\main.py) with parameters:

So in gui2\tweak_book\ui.py I have

Code:
self.action_smarten_punctuation = reg(
    'smarten-punctuation.png', _('&Smarten punctuation'), partial(
        self.boss.polish, 'smarten_punctuation_opt', _('Smarten punctuation')), 'smarten-punctuation', (), _('Smarten punctuation'))
smarten_punctuation_opt is my new smarten punctuation in ebooks\oeb\polish\main.py:

Code:
if opts.smarten_punctuation_opt:
    rt(_('Smartening punctuation'))
    smarten_punctuation(ebook, opts.smarten_punctuation_opt, report)
    #smarten_punctuation(ebook, "H", report)
    report('')
(If I use the commented out line I get the "H" conversion, so I know this call works when the smarten_punctuation options are hard coded).

I need to able to set opts.smarten_punctuation_opt when I call this from edit-book (obviously edit book is also going to need a UI to specify the smarten punctuation options but I will worry about that later).
ShellShock is offline   Reply With Quote
Old 01-05-2014, 09:46 PM   #2
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: 45,168
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You need to modify tweak_polish().
kovidgoyal is online now   Reply With Quote
Advert
Old 01-06-2014, 04:06 PM   #3
ShellShock
Wizard
ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.
 
ShellShock's Avatar
 
Posts: 1,178
Karma: 2431850
Join Date: Sep 2008
Device: IPad Mini 2 Retina
Many thanks.

Am I right in thinking that edit book will be getting saved Find and Replace? If so, then another way to achieve a configurable smarten punctuation would be executing a previously saved Find & Replace, something like this:

The saved Find & Replace would need to include all the parameters in the Find and Replace GUI, including Mode, the files to be affected, case sensitivity etc, the action to be performed when executed (Find, Replace, Replace all etc).

The user could automatically execute the saved Find & Replace, without having to first load it into the Find and Replace dialog and execute it from there.

Multiple saved Find & Replaces could be chained together, or executed as children of a parent container.

The overall effect is that a single menu/button click would execute multiple, previously configured regexes. This would be a very powerful feature to enable the user to make a lot of bespoke, automated changes, and goes beyond what Sigil supports. It also solves the problem of the currently hard coded regexes in smartyPants.

Any thoughts on this?
ShellShock is offline   Reply With Quote
Old 01-06-2014, 10:04 PM   #4
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: 45,168
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
There will be saved find replace. However, it wont store a list fo files to operate on, as that would make them useless across books. Instead you will have to specify the files when you run them.
kovidgoyal is online now   Reply With Quote
Old 01-07-2014, 01:47 PM   #5
ShellShock
Wizard
ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.ShellShock ought to be getting tired of karma fortunes by now.
 
ShellShock's Avatar
 
Posts: 1,178
Karma: 2431850
Join Date: Sep 2008
Device: IPad Mini 2 Retina
I was thinking more that when you configure the find replace, you could choose the run-time target as, e.g.,

"Current file" - at run-time this would find and replace in whatever is the current file.
"All HTML files". At run-time this would find and replace in all HTML files in the current ebook.
"All CSS files". At run-time this would find and replace in all CSS files in the current ebook.
"All files". At run-time this would find and replace in all files in the current ebook.
etc

And you could also automatically execute the saved find replace when you load it.
ShellShock is offline   Reply With Quote
Advert
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
New DRM to edit your book for you... VydorScope Writers' Corner 3 06-19-2013 11:34 PM
Edit a converted book GeePee Conversion 16 03-05-2011 05:31 PM
Free Book (Kindle) - Calling Home koland Deals and Resources (No Self-Promotion or Affiliate Links) 1 07-28-2010 12:29 PM
Write and edit your own book now frostine Lounge 15 05-24-2009 10:54 PM
What is the Worst Book you have had to Edit? andyafro Sony Reader 2 12-01-2007 09:40 PM


All times are GMT -4. The time now is 08:17 PM.


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