Thanks for your reply.
Sometimes it is not possible to do an automatic search/replace and manual input is required. An example of this is when PDF files are converted to ePufb files and the conversion process inserts full stops before a lower case letter, eg the. dog. With this type of error, sometimes the full stop needs to be removed and sometimes the character after the full stop needs to be capitalised (there are other responses with this example eg 'the U.S.A. receives its fair share of rain' but I will ignore these for now).
Ideally, a dialog box would be displayed and the user could press a button to select the required replacement term from a list that is offered. This would be fater than editing matched text every time the unwanted 'phrase' was detected.
It is possible to achieve this effect by using a series of message dialog boxes where each replacement 'phrase' is displayed in turn and if the user clicks Yes the matched text is replaced with the appropriate 'phrase' but if No is clicked, another dialog box appears that shows the alternative 'phrase' and the user can click Yes or No to accept/reject this phrase. However, opening a series of dialog boxes is not an ideal solution.
As an intial step to producing a dialog box, I thought that, as an exercise, if I produced a text input box (where the user enters a number to select the replacement 'phrase') then I could build on this to produce a more complex dialog box that listed alternatives and the user could click a button to select the required replacement 'phrase'
However, if this needs a plugin then I will have to learn how to do this.
For anybody who wants to display a dialog box when a regex function runs, the code is shown below.
import win32api
MB_OK = 0x0
MB_OKCXL = 0x01
MB_YESNOCXL = 0x03
MB_YESNO = 0x04
MB_HELP = 0x4000
ICON_EXCLAIM=0x30
ICON_INFO = 0x40
ICON_STOP = 0x10
MB_SYSTEMMODAL=4096
reply=win32api.MessageBox(None,"Text to display","Caption",MB_YESNOCXL|ICON_EXCLAIM)
The variable reply will contain an number that corresponds to the button clicked by the user. If MB_SYSTEMMODAL is OR'd with the MB value then the dialog box opens as a system modal dialog box.
The code to open the dialog box must be placed after the statement:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
as required by Callibre.
|