02-11-2022, 01:59 AM | #481 |
Member
Posts: 22
Karma: 624
Join Date: May 2013
Location: Moscow
Device: Kobo Aura H2o, Kobo Aura One, Kobo Forma
|
Yes. This good way.
I think if you adds to API class like cursor you will get more interactivity in plugins. |
02-11-2022, 09:34 AM | #482 |
Sigil Developer
Posts: 7,736
Karma: 5446592
Join Date: Nov 2009
Device: many
|
Not straightforward, as we use copy on write file interface in a separate process to protect Sigil from plugin errors. In addition, internally everything Qt is encoded as utf-16 with no carriage returns, but the files themselves utf-8 encoded and carriage returns are included but only on Windows. And finally, each xhtml parser treats DOM building and especially how whitespace and text is handled differently making cfi and path approaches incorrect as well.
So even something simple such as a cursor position is in a Qt based QPlainTextEdit internal to Sigil is hard to translate to a utf-8 encoded file with platform specific line endings, tab expansions, etc, being parsed by a different xhtml parser. So using a marker such as an inserted comment, class or id, is the most reliable way to handle cursor/text marking in xhtml that works cross platform across file formats. Furthermore, there is very little simple text manipulation that can not be handled internal to Sigil using Regular Expressions, clips, Saved Searches, etc. |
Advert | |
|
02-11-2022, 09:52 AM | #483 |
Grand Sorcerer
Posts: 27,614
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Cross-platform/line-ending issues aside, how would one even go about translating a C++ QTextCursor object (or any reliable representation thereof) to the plugin framework's independent python process in a way that could be used? I'm certainly at a loss.
|
03-13-2022, 10:53 AM | #484 |
Zealot
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
|
Is there any plugin API to get "current file" and 'tabbed file' like it in find/replace?
Last edited by The_book; 03-13-2022 at 11:00 AM. |
03-13-2022, 11:32 AM | #485 |
Sigil Developer
Posts: 7,736
Karma: 5446592
Join Date: Nov 2009
Device: many
|
There is an interface to get the list of files that are selected in BookBrowser.
So if you only want the current file or a specific subset of files, make sure they are properly selected in BookBrowser before launching your plugin. The interface call is here: https://github.com/Sigil-Ebook/Sigil...tainer.py#L313 Alternatively your plugin can use either Tk or Qt to allow the user to select any set of files they desire. |
Advert | |
|
03-29-2022, 10:54 AM | #486 |
Zealot
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
|
Can I use exec in pulgin file? It seems changes nothing.
If I can't, how can I run some code from user's input?Create python file from user's input and then import it? |
03-29-2022, 10:59 AM | #487 | |
Grand Sorcerer
Posts: 27,614
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Quote:
You cannot use the plugin framework to collect user input on the command-line. Last edited by DiapDealer; 03-29-2022 at 11:02 AM. |
|
03-29-2022, 11:20 AM | #488 |
Zealot
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
|
I know this. And when I write replay to you, I know what make me wrong. I run exec in function, and exec changes global. I need get my change from global
|
04-10-2022, 01:16 PM | #489 |
Grand Sorcerer
Posts: 27,614
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
|
Upcoming Sigil Qt6 migration and GUI plugin development changes as a result.
See this sticky thread for details. |
01-30-2023, 12:52 PM | #490 |
Member
Posts: 24
Karma: 10
Join Date: Jul 2022
Location: France
Device: Kobo Clara
|
Noob developing a plugin to learn :)
Hello and Happy New Year!
I'd need to count selected words. I didn't find a way to do it with existing functions and plugins. I downloaded and studied testme3 but can't find how to access selected text. Would you please point me in the right direction to access text selection from preview and work from there? Or if you have a complete idea how to count words in selection, please let me know |
01-30-2023, 01:21 PM | #491 | |
Grand Sorcerer
Posts: 5,611
Karma: 23187563
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
As a workaround, you could copy selected text to the clipboard, read the clipboard contents with Python and then count the words. |
|
01-30-2023, 01:59 PM | #492 |
Sigil Developer
Posts: 7,736
Karma: 5446592
Join Date: Nov 2009
Device: many
|
You can restrict searches to marked text in Sigil and use Find to count anything you want. If do not want counts of specific words you can use regular expressions to count all words in marked text.
|
01-31-2023, 04:28 AM | #493 | |
Member
Posts: 24
Karma: 10
Join Date: Jul 2022
Location: France
Device: Kobo Clara
|
Thank you very much for your replies!
Actually, I need to know where the 280th -ish word is, so I thought to select some text approximately, and have a word count (\w+ ) but you open up possibilities. Quote:
When I select text in source xhtml, CTRL+SHIFT+M does mark text but searching for "\w+ " results in all tags content to be counted as words, like "a " in `<a href...` or elsewhere in tags (style, etc). I need to count rendered words, not everything from code. Actually I need to spot every 280th rendered word. Sorry for not being clearer in my first draft. Any idea welcome! Last edited by philm; 01-31-2023 at 04:41 AM. |
|
01-31-2023, 04:59 AM | #494 |
Grand Sorcerer
Posts: 5,611
Karma: 23187563
Join Date: Dec 2010
Device: Kindle PW2
|
|
01-31-2023, 05:15 AM | #495 |
Member
Posts: 24
Karma: 10
Join Date: Jul 2022
Location: France
Device: Kobo Clara
|
Thank you again! Unfortunately, I don't know how to add Beautiful Soup to make a Sigil plugin, and reports doesn't count in a selection (spot every 280th).
chatGPT threw me something that partially works, except it also count words in links but it doesn't happen often in my texts: `(\b\w+\b)(?=(?:[^<>]*<[^<>]*>)*[^<>]*$)` PS: Well, after adding some small improvements (space, parenthesis and punctuation added) it gets pretty decent: `((|\()\b\w+\b( |:|,|\)))(?=(?:[^<>]*<[^<>]*>)*[^<>]*$)` Hmm, nope, too limiting. FYI: It misses the word " a " since it's alone and still counts some content in html tags. Last edited by philm; 01-31-2023 at 05:18 AM. |
Thread Tools | Search this Thread |
|
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 |