|
|
#406 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 28,899
Karma: 207182180
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
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. |
|
|
|
|
|
|
#407 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,073
Karma: 6361556
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 04:56 PM. |
|
|
|
| Advert | |
|
|
|
|
#408 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,763
Karma: 24088559
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
Plugin cancelled Launcher process crashed Code:
Error Parsing Result XML: Premature end of document. |
|
|
|
|
|
|
#409 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,073
Karma: 6361556
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. |
|
|
|
|
|
#410 |
|
Guru
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 900
Karma: 3501166
Join Date: Jan 2017
Location: Poland
Device: Various
|
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')
|
|
|
|
| Advert | |
|
|
|
|
#411 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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? |
|
|
|
|
|
#412 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,073
Karma: 6361556
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. |
|
|
|
|
|
#413 | |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 19
Karma: 42210
Join Date: May 2018
Device: Kobo Aura H2O
|
Quote:
|
|
|
|
|
|
|
#414 |
|
Member
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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? |
|
|
|
|
|
#415 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,763
Karma: 24088559
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
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())
|
|
|
|
|
|
|
#416 |
|
Member
![]() 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?
|
|
|
|
|
|
#417 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,073
Karma: 6361556
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. |
|
|
|
|
|
#418 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,763
Karma: 24088559
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
|
|
|
|
|
|
|
#419 |
|
Member
![]() Posts: 10
Karma: 10
Join Date: Jul 2011
Device: none
|
Thanks for the tips!
|
|
|
|
|
|
#420 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,763
Karma: 24088559
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_()) @KevinH @DiapDealer what do you guys think about this idea? Last edited by Doitsu; 01-12-2019 at 06:21 AM. |
|
|
|
![]() |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Loading Plugin in development | Sladd | Development | 6 | 06-17-2014 07:57 PM |
| Question for plugin development gurus | DiapDealer | Plugins | 2 | 02-05-2012 12:33 AM |
| DR800 Plugin development for DR800/DR1000 | yuri_b | iRex Developer's Corner | 0 | 09-18-2010 10:46 AM |
| Device plugin development | reader42 | Plugins | 10 | 03-29-2010 01:39 PM |
| Calibre plugin development - Newbie problems | minstrel | Plugins | 5 | 04-12-2009 01:44 PM |