Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Sigil > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old 05-08-2018, 09:50 AM   #406
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 27,441
Karma: 192992430
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by Doitsu View Post
How do I need to change the code to gracefully exit the plugin, if the Plugin Runner window is closed?
I honestly don't think you can. There's no way for the plugin's code to know which of the Plugin Runner dialog's buttons have been clicked.

We'll probably have to find a way (on the C++ side of things) to catch the control-box 'X' button-click and map it to match the cancel button's behavior. But even then, there's a possibility that clicking the escape key (with the Plugin Runner window active) will behave the same way--but without a closeEvent() to capture.

Not sure why doing so only crashes on Windows, but it doesn't surprise me. I'll try and look into it.
DiapDealer is offline   Reply With Quote
Old 05-08-2018, 02:27 PM   #407
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,469
Karma: 5432724
Join Date: Nov 2009
Device: many
Sigil’s plugin runner forks the process that runs the actual plugin. Closing the Plugin Runner Dialog window without cancelling the plugin being run can end up with strange results.

Does Windows still crash when using the Cancel button to properly stop the forked process?

Last edited by KevinH; 05-08-2018 at 03:56 PM.
KevinH is offline   Reply With Quote
Old 05-08-2018, 04:40 PM   #408
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by KevinH View Post
Does Windows still crash when using the Cancel button to properly stop the forked process?
When I click the Cancel button, Sigil only displays the following messages in the Plugin Runner window:

Code:
Plugin cancelled
Launcher process crashed
and in a message box:

Code:
Error Parsing Result XML: Premature end of document.
I can then use the close button to close the Plugin Runner window.
Doitsu is offline   Reply With Quote
Old 05-08-2018, 04:50 PM   #409
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,469
Karma: 5432724
Join Date: Nov 2009
Device: many
Yes, the cancel button sends a kill signal to the forked process, which then terminates resulting in the Launcher process crashed message.

Since no result xml was written then we get the last Error Parsing message. I could change it so that when a Launcher Process crashes (or is killed) that the result xml is simply never read to prevent the last error message if that is causing some problem for Windows.
KevinH is offline   Reply With Quote
Old 05-09-2018, 05:42 AM   #410
BeckyEbook
Guru
BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.BeckyEbook ought to be getting tired of karma fortunes by now.
 
BeckyEbook's Avatar
 
Posts: 643
Karma: 2180076
Join Date: Jan 2017
Location: Poland
Device: Kindle (Key3, PW2, PW3), Nook (ST, GLP), Kobo Touch, Tolino Vision 2
Improved code cleanup_file_name procedure, because it can also handle book titles in non-Latin characters.
Applies to many plugins: Borkify, ePub2, ePub3-itizer, FolderOut, iBooksFix, KEPUB, NCXRemove, sampleOutput and probably some others.

Code:
# borrowed from calibre from calibre/src/calibre/__init__.py; updated by KevinH for epub3 output plugin
def cleanup_file_name(name):
    import unicodedata
    _filename_sanitize = re.compile(r'[\xae\0\\|\?\*<":>\+/]')
    substitute='_'
    one = ''.join(char for char in unicodedata.normalize(
            'NFKD', name
        ) if unicodedata.category(char) != 'Mn')
    one = one.replace(u'\u2013', '-').replace(u'\u2014', '-')\
                   .replace(u'\u0142', 'l').replace(u'\u0141', 'L')
    one = _filename_sanitize.sub(substitute, one)
    one = re.sub(r'\s', '_', one).strip()
    one = re.sub(r'^\.+$', '_', one)
    one = one.replace('..', substitute)
    # Windows doesn't like path components that end with a period
    if one.endswith('.'):
        one = one[:-1]+substitute
    # Mac and Unix don't like file names that begin with a full stop
    if len(one) > 0 and one[0:1] == '.':
        one = substitute+one[1:]
    return one

This line:
Code:
    one = one.replace(u'\u2013', '-').replace(u'\u2014', '-')\
                   .replace(u'\u0142', 'l').replace(u'\u0141', 'L')
applies to en dash, em dash, latin small letter l with stroke, latin capital letter L with stroke (https://en.wikipedia.org/wiki/%C5%81).
BeckyEbook is offline   Reply With Quote
Old 06-19-2018, 04:38 AM   #411
Gergely
Member
Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'
 
Posts: 19
Karma: 42210
Join Date: May 2018
Device: Kobo Aura H2O
Highlighting text in an epub

Followup to

https://www.mobileread.com/forums/sh...=1#post3708168

My goal is to write a plugin that imports highlighting information from my Kobo Aura H20 reader, especially from its sqlite database. Using python to extract data from an sqlite database should be straightforward and is not a concern here.

To put the highlighting manually I have inserted span tags with class "highlighting" and inserted

span.highlight { background: #ccc }

into publisher CSS.

In the above post I have managed to do this manually, and Icecream ebook reader software did show my modification.

I would like to do this with a Sigil plugin automatically.

I have skimmed through

https://github.com/Sigil-Ebook/Sigil...work_rev8.epub

but it was not clear how could I

* search for the text to be highlighted in all of the html files

* insert span and /span to the proper position

* insert my one-line CSS into the proper style file

Could you help me what part of the BookContainer class should I use?
Gergely is offline   Reply With Quote
Old 06-19-2018, 08:17 AM   #412
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,469
Karma: 5432724
Join Date: Nov 2009
Device: many
You want an "edit" plugin. The easiest way to get started on plugin writing is to play around with the testme3_v031.zip example plugin that is linked to in the first post of this very thread. There are examples in that plugin for iterating over all xhtml files in an epub, examples on how to use Quickparser to parse the xhtml, examples of using sigil gumbo to do the same, how to save file changes, and etc.

Give that a try first.
KevinH is offline   Reply With Quote
Old 06-19-2018, 08:59 AM   #413
Gergely
Member
Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'
 
Posts: 19
Karma: 42210
Join Date: May 2018
Device: Kobo Aura H2O
Quote:
Originally Posted by KevinH View Post
You want an "edit" plugin. The easiest way to get started on plugin writing is to play around with the testme3_v031.zip example plugin that is linked to in the first post of this very thread. There are examples in that plugin for iterating over all xhtml files in an epub, examples on how to use Quickparser to parse the xhtml, examples of using sigil gumbo to do the same, how to save file changes, and etc.

Give that a try first.
Thanks indeed.
Gergely is offline   Reply With Quote
Old 06-19-2018, 11:16 AM   #414
Gergely
Member
Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'Gergely understands when you whisper 'The dog barks at midnight.'
 
Posts: 19
Karma: 42210
Join Date: May 2018
Device: Kobo Aura H2O
Valid filename from href?

Still want to highlight text in an epub.

I thought of ignoring html parsing as my replacement is not about html structure. I just want to find a text in the html and replace it with span and /span enclosed. Simple python string replace would do it:

https://www.tutorialspoint.com/pytho...ng_replace.htm

The html file iterator is the following in the testme3 plugin:

# all xhtml/html files
print("\nExercising: bk.text_iter()")
for (id, href) in bk.text_iter():
print(id, href)
lastid = id

I get a href for the html files in the ebook.

with open(href, 'r') as myfile:
data=myfile.read()

leads to error message

FileNotFoundError: [Errno 2] No such file or directory: 'Text/9781118087220cover.xhtml'

How can I create a valid filename from href?
Gergely is offline   Reply With Quote
Old 06-19-2018, 11:43 AM   #415
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by Gergely View Post
FileNotFoundError: [Errno 2] No such file or directory: 'Text/9781118087220cover.xhtml'
You can't use open() in plugins. You'll need to use bk.readfile(id) instead. For example, the following minimal code will wrap "the" in all html files in <b> tags:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os

# main routine    
def run(bk):
    # iterate over all html files
    for html_id, href in bk.text_iter():
        # read orignal html code from file
        original_html = bk.readfile(html_id)
        # modify html code
        modified_html = original_html.replace('the', '<b>the</b>') 
        if modified_html != original_html:
            # write modified html code to file
            bk.writefile(html_id, modified_html)
            print(os.path.basename(href) + ' updated')
    return 0

def main():
    print('I reached main when I should not have\n')
    return -1

if __name__ == "__main__":
    sys.exit(main())
Doitsu is offline   Reply With Quote
Old 12-03-2018, 02:30 PM   #416
goroke
Member
goroke began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jul 2011
Device: none
Has anyone ever tried to create a plugin that will convert British spelling/quotation marks to US spelling/quotation marks, and vice-versa?
goroke is offline   Reply With Quote
Old 12-03-2018, 02:55 PM   #417
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 7,469
Karma: 5432724
Join Date: Nov 2009
Device: many
There are already plugins to handle changing to smart quotation marks.

And spellchecking an American English document with a British English dictionary, and visa versa should easily handle your second request without needing a plugin. Start by adding you own MySpell/Hunspell dictionaries to Sigil and cset the current language to spellcheck in by setting the language metadata tag in the opf.
KevinH is offline   Reply With Quote
Old 12-03-2018, 03:07 PM   #418
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by goroke View Post
Has anyone ever tried to create a plugin that will convert British spelling/quotation marks to US spelling/quotation marks, and vice-versa?
AFAIK, the only free tool that does this is VarCon, which comes with a Perl converter script.
Doitsu is offline   Reply With Quote
Old 12-04-2018, 02:24 AM   #419
goroke
Member
goroke began at the beginning.
 
Posts: 10
Karma: 10
Join Date: Jul 2011
Device: none
Thanks for the tips!
goroke is offline   Reply With Quote
Old 01-12-2019, 05:19 AM   #420
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
I recently stumbled upon QScintilla, which comes with very easy to use Python bindings.

For example, the following proof-of-concept code that I found on the Internet is enough to display an editor with document-based autocompletion:

Code:
"""Base code originally from: http://kib2.free.fr/tutos/PyQt4/QScintilla2.html"""
import sys
import os
from PyQt5 import QtWidgets, Qsci

app = QtWidgets.QApplication(sys.argv)
editor = Qsci.QsciScintilla()
lexer = Qsci.QsciLexerPython(editor)
editor.setLexer(lexer)
editor.setAutoCompletionThreshold(1)
editor.setAutoCompletionSource(Qsci.QsciScintilla.AcsDocument)

editor.show()
editor.setText(open(sys.argv[0]).read())
sys.exit(app.exec_())
QScintilla/Scintilla also supports code folding, code highlighting and recordable macros. IMHO, it'd make for a useful addition to the Python interpreter bundled with Sigil. (The Windows version of the library would only add about 7.5MB.)

@KevinH @DiapDealer what do you guys think about this idea?

Last edited by Doitsu; 01-12-2019 at 05:21 AM.
Doitsu is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading Plugin in development Sladd Development 6 06-17-2014 06:57 PM
Question for plugin development gurus DiapDealer Plugins 2 02-04-2012 11:33 PM
DR800 Plugin development for DR800/DR1000 yuri_b iRex Developer's Corner 0 09-18-2010 09:46 AM
Device plugin development reader42 Plugins 10 03-29-2010 12:39 PM
Calibre plugin development - Newbie problems minstrel Plugins 5 04-12-2009 12:44 PM


All times are GMT -4. The time now is 01:55 AM.


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