View Single Post
Old 09-08-2020, 02:28 PM   #7
EbookMakers
Enthusiast
EbookMakers began at the beginning.
 
Posts: 26
Karma: 38
Join Date: Nov 2019
Location: Paris, France
Device: none
I am interested in this topic. I have a complex regex-function which tries to correct a common mistake in French ebooks. This regex claims to reliably correct, say, 95% of cases. The corresponding branches of the regex can be executed automatically. There are, however, cases that are undecidable by regex. These cases can only be resolved by user choice.

As this error is frequent, one could imagine adding, for undecidable cases, a branch to the regex executed automatically. When the regex selects in that branch, and hands over to the function, the function might ask the user to decide what to do.

As I am ignorant of Python, I tried to run a little test with a function on the above model:

regex : \b([aà])\b

fonction :

Code:
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
    from PyQt5.Qt import QInputDialog
    from calibre.gui2.tweak_book.boss import get_boss
    if  match.group(1):
        text, ok = QInputDialog().getText(get_boss().gui, "QInputDialog().getText()", "a ou à")
        if ok and text:
           return "{}".format(text)    
        return "{}".format(match.group(1))
Step by step, this regex-function seems to work as expected.

In automatic mode, when the regex selects something, then the function displays the input window, whatever I click on, the window is displayed again indefinitely. I have to kill ebook-edit.

What's wrong ?
EbookMakers is offline   Reply With Quote