View Single Post
Old 04-10-2012, 09:21 PM   #1
idea00
Junior Member
idea00 will become famous soon enoughidea00 will become famous soon enoughidea00 will become famous soon enoughidea00 will become famous soon enoughidea00 will become famous soon enoughidea00 will become famous soon enough
 
Posts: 7
Karma: 684
Join Date: Apr 2012
Device: android
Improved UI for Search/Replace

Hi,

I'm working on an improved UI for Search/Replace that adds the following capabilities:

- Unlimited search/replace definitions instead of just the fixed three.
- Ability to save/load the definitions for subsequent use.

The code can be found at:
lp:~idea00/calibre/search_replace

but is not yet ready for merge (have a few questions below.)

A screen shot of the UI implementation can be found at:

http://img37.imageshack.us/img37/9321/searchreplace.png


Rationale
The reason I made this change is that I have several badly converted epubs with leftover PML markup (\aXXX characters the full list is in PML Characters) and was converting them manually (unzip, search/replace with a text editor, zip.)

So I thought:
"This is stupid, I should just write a script to do this"
"Wait, this is a problem others may have, maybe I should add this functionality to Calibre"
"How? Where? Lets look at the develop docs."
"Ahh... a plugin!"
"Wait... Wait... Wait... before I write a new plugin lets make sure this has not already been implemented."
"Ok.. Calibre conversion settings... look and feel, heuristic processing... search and replace,..."
"What was that SEARCH AND REPLACE? Calibre has search and replace?!"

Long story short I need more than three search and replace definitions and I'd like to be able to save them so I don't need to input them every time I need to do this conversion (or any other common one.)
Now for the questions:

Backwards Compatibility
I changed the options 'sr1_search', 'sr1_replace', 'sr2_search', 'sr2_replace', 'sr3_search', 'sr3_replace' with a single 'search_replace' option (plumber.py and cli.py). This means any plugins that modifies the old search/replace options will not work, but I found no evidence of a plugin changing the user preferences so I believe this is okay. I think I can make my change backward compatible by introducing srX_search/srX_replace options dynamically based on the number of actual search/replace definitions, but I'd probably need to make substantial (ugly) changes.

Internationalization
I'm guessing the underscore function '_()' used around strings is the hash look-up for the language specific string, but I haven't deciphered this fully so pointers would be welcome. Specifically how are strings in the *.ui files handled and what else needs to be done to add new strings.
I used the help string for "SEARCH AND REPLACE" in 'cli.py' as the help string in the OptionRecomendation for the new search_replace option so that should be okay, but now the old help strings for srX_search/srX_replace are just laying around unused so are there any tools for cleaning up unused strings or should this be done manually (and how?)

User Experience
The new UI works by adding the search/replace definitions to the table widget. This means a user may enter (and test) a search/replace definition in the RegexEdit/Textbox widgets and forget to press Add.
There are two ways I can think to solve this:

1. Leave it as it is, the user will learn.
2. Pop a dialog asking the user whether to add the definition in the RegexEdit/Textbox widgets if it not already there when the leaving the Search/Replace window.

Anything Else
Anything else I need to do to make this change merge worthy?
idea00 is offline   Reply With Quote