Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 02-11-2022, 01:59 AM   #481
AxaRu
Member
AxaRu will become famous soon enoughAxaRu will become famous soon enoughAxaRu will become famous soon enoughAxaRu will become famous soon enoughAxaRu will become famous soon enoughAxaRu will become famous soon enough
 
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.
AxaRu is offline   Reply With Quote
Old 02-11-2022, 09:34 AM   #482
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,683
Karma: 5433388
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.

Quote:
Originally Posted by AxaRu View Post
Yes. This good way.
I think if you adds to API class like cursor you will get more interactivity in plugins.
KevinH is offline   Reply With Quote
Advert
Old 02-11-2022, 09:52 AM   #483
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,577
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.
DiapDealer is offline   Reply With Quote
Old 03-13-2022, 10:53 AM   #484
The_book
Zealot
The_book began at the beginning.
 
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.
The_book is offline   Reply With Quote
Old 03-13-2022, 11:32 AM   #485
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,683
Karma: 5433388
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.
KevinH is offline   Reply With Quote
Advert
Old 03-29-2022, 10:54 AM   #486
The_book
Zealot
The_book began at the beginning.
 
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?
The_book is offline   Reply With Quote
Old 03-29-2022, 10:59 AM   #487
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,577
Karma: 193191846
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by The_book View Post
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?
Plugins are written in Python. If you want user input, you need to create a gui using Python's tkinter or Python for Qt to collect that user input.

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.
DiapDealer is offline   Reply With Quote
Old 03-29-2022, 11:20 AM   #488
The_book
Zealot
The_book began at the beginning.
 
Posts: 100
Karma: 10
Join Date: Aug 2019
Device: none
Quote:
Originally Posted by DiapDealer View Post
Plugins are written in Python. If you want user input, you need to create a gui using Python's tkinter or Python for Qt to collect that user input.
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
The_book is offline   Reply With Quote
Old 04-10-2022, 01:16 PM   #489
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,577
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.
DiapDealer is offline   Reply With Quote
Old 01-30-2023, 12:52 PM   #490
philm
Member
philm began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Jul 2022
Location: France
Device: Kobo Clara
Smile 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
philm is offline   Reply With Quote
Old 01-30-2023, 01:21 PM   #491
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,589
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by philm View Post
I'd need to count selected words. I didn't find a way to do it with existing functions and plugins.
Unfortunately, there are no API functions for detecting the cursor position or selected text.
As a workaround, you could copy selected text to the clipboard, read the clipboard contents with Python and then count the words.
Doitsu is offline   Reply With Quote
Old 01-30-2023, 01:59 PM   #492
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,683
Karma: 5433388
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.
KevinH is offline   Reply With Quote
Old 01-31-2023, 04:28 AM   #493
philm
Member
philm began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Jul 2022
Location: France
Device: Kobo Clara
Smile

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:
Originally Posted by KevinH View Post
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.
When I select text in preview and search > mark selected text it only unmarks, as stated in the info bar: "Text selection unmarked". I'm using Ubuntu 22.04

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.
philm is offline   Reply With Quote
Old 01-31-2023, 04:59 AM   #494
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,589
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by philm View Post
I need to count rendered words, not everything from code.
Tools > Reports > HTML Files > All words

Quote:
Originally Posted by philm View Post
Actually I need to spot every 280th rendered word.
You could use BeautifulSoup as a text filter:

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

# main routine
def run(bk):

    # iterate over all html files
    for html_id, href in bk.text_iter():

        # read orignal html code from file
        html = bk.readfile(html_id)
        name = os.path.basename(href)

        # use BeautifulSoup to remove the tags
        soup = BeautifulSoup(html, 'html.parser')
        text = soup.get_text()

        # split text 
        words = text.split(' ')
        
        # get the 280th word
        if len(words) >= 280:
            print(name, '280:', words[279])

    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 01-31-2023, 05:15 AM   #495
philm
Member
philm began at the beginning.
 
Posts: 24
Karma: 10
Join Date: Jul 2022
Location: France
Device: Kobo Clara
Smile

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.
philm is offline   Reply With Quote
Reply


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 09:00 AM.


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