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

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-31-2025, 03:33 PM   #1426
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Nicolas.Laurent View Post
is there any documentation on the syntax to use for Action Chains?
Not really. The Run Python Code in intended to interact with the calibre API, which has some documentation. Besides the issue of variables we just mentioned, I don't think there anything in the action chains code could be of help to someone using this action.
capink is offline   Reply With Quote
Old 02-02-2025, 04:46 AM   #1427
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Sorry to bother you again, but I can now transfer my variable from one Run Python module to another. But my goal is to modify the value of a field (title in this case) and I can't get my variable from a Single Field Edit module.
What should I do?
Nicolas.Laurent is offline   Reply With Quote
Old 02-02-2025, 05:25 AM   #1428
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Nicolas.Laurent View Post
Sorry to bother you again, but I can now transfer my variable from one Run Python module to another. But my goal is to modify the value of a field (title in this case) and I can't get my variable from a Single Field Edit module.
What should I do?
The Single Field Edit action—like many other actions—has template option, with which you can use the code in the previous post:

Quote:
Originally Posted by capink View Post
To retrieve the variable using calibre template language:
Code:
program:
    my_retrieved_variable = globals(variable_name)
capink is offline   Reply With Quote
Old 02-07-2025, 12:56 PM   #1429
Nicolas.Laurent
Member
Nicolas.Laurent began at the beginning.
 
Posts: 20
Karma: 10
Join Date: Jun 2016
Location: France
Device: PocketBook Touch Lux 2
Hello everyone

I'm back with a new problem.

I wrote this template for the Single Field Edit module, the idea being to copy author names into a dialog box and format them before assigning them to the authors field.
Everything works perfectly, except that my dialog box opens twice, and also opens when I save the code. It works, so it's not too bad, but a bit annoying.
What should I do to solve the problem?

And once again, thank you so much for this incredible plugin, which has saved me a lot of time!

Code:
Code:
python:

def evaluate(book, context):

	from PyQt5.QtWidgets import QInputDialog

	sortie = ""
	nom = ", ".join(book.authors)

	source, ok = QInputDialog.getText(None, "Modification des auteurs", "Entrez les auteurs :")

	if not ok:
	        return nom

	source = source.replace(" (Auteur)", "").replace(" & ", ", ").replace(" et ", ", ").strip()
    
	nom_transforme = []
	for auteur in source.split(", "):  
		parts = auteur.split(" ", 1)
		if len(parts) == 2:
			prenom, nom_famille = parts
			nom_transforme.append(f"{nom_famille.upper()}, {prenom.title()}")
		else:
			nom_transforme.append(auteur)

	return " & ".join(nom_transforme)
Nicolas.Laurent is offline   Reply With Quote
Old 02-10-2025, 07:20 PM   #1430
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,269
Karma: 71500357
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is there a way to do an action (chain caller) only if the previous selection modifier took anything?

Last edited by ownedbycats; 02-10-2025 at 09:00 PM.
ownedbycats is offline   Reply With Quote
Old 02-12-2025, 04:12 AM   #1431
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by Nicolas.Laurent View Post
Hello everyone

I'm back with a new problem.

I wrote this template for the Single Field Edit module, the idea being to copy author names into a dialog box and format them before assigning them to the authors field.
Everything works perfectly, except that my dialog box opens twice, and also opens when I save the code. It works, so it's not too bad, but a bit annoying.
What should I do to solve the problem?

And once again, thank you so much for this incredible plugin, which has saved me a lot of time!

Code:
Code:
python:

def evaluate(book, context):

	from PyQt5.QtWidgets import QInputDialog

	sortie = ""
	nom = ", ".join(book.authors)

	source, ok = QInputDialog.getText(None, "Modification des auteurs", "Entrez les auteurs :")

	if not ok:
	        return nom

	source = source.replace(" (Auteur)", "").replace(" & ", ", ").replace(" et ", ", ").strip()
    
	nom_transforme = []
	for auteur in source.split(", "):  
		parts = auteur.split(" ", 1)
		if len(parts) == 2:
			prenom, nom_famille = parts
			nom_transforme.append(f"{nom_famille.upper()}, {prenom.title()}")
		else:
			nom_transforme.append(auteur)

	return " & ".join(nom_transforme)
Don't put GUI code in templates. Put it in a module and pass the result as a chain variable as discussed previously.
capink is offline   Reply With Quote
Old 02-12-2025, 04:13 AM   #1432
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
only if the previous selection modifier took anything?
I don't understand what you mean by this.
capink is offline   Reply With Quote
Old 02-12-2025, 06:06 AM   #1433
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,269
Karma: 71500357
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
If the selection modifier... has anything. I can't think of word.

Last edited by ownedbycats; 02-12-2025 at 06:08 AM.
ownedbycats is offline   Reply With Quote
Old 02-12-2025, 06:12 AM   #1434
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
If you mean Selection Modifier has resulted in books selection as opposed to none, you can test that with this condition:

Code:
program:
    list_count(from_selection('id'),',')
Datatype: number
Comparison: >
Condition value: 0
capink is offline   Reply With Quote
Old 02-12-2025, 06:51 AM   #1435
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,269
Karma: 71500357
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Yes, thank you.
ownedbycats is offline   Reply With Quote
Old 02-23-2025, 11:35 AM   #1436
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 10,269
Karma: 71500357
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Is it possible to use these in Action Chains? There's no menu option:

Click image for larger version

Name:	2025-02-23 12_35_07-Editing metadata for one book.png
Views:	67
Size:	18.8 KB
ID:	213835
ownedbycats is offline   Reply With Quote
Old 02-23-2025, 01:48 PM   #1437
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
No. Your best bet to re-create those with templates.
capink is offline   Reply With Quote
Old 02-25-2025, 01:01 PM   #1438
WorldTeacher
Junior Member
WorldTeacher began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Apr 2019
Device: Calibre
Question on how to create two chains

Hi,

i want to use action chains to make my management a bit easier. For that, I would like to have two chains:

Chain 1:
runs when books are added though "Add books > add books from folder and subfolders" and uses the plugin "count pages" to count the pages

I have the basics of this chain working, but it only counts the pages of the last book that was added, not every book added in the process

Chain 2:
runs on calibre shutdown and:
for all books added that day:
runs pluin "embed metadata"
runs plugin "epub extended metadata"
copies the books to another library

how would I create these chains?

any help is welcome, thanks in advance
WorldTeacher is offline   Reply With Quote
Old 02-26-2025, 04:41 PM   #1439
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,167
Karma: 1988646
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by WorldTeacher View Post
Hi,

i want to use action chains to make my management a bit easier. For that, I would like to have two chains:

Chain 1:
runs when books are added though "Add books > add books from folder and subfolders" and uses the plugin "count pages" to count the pages

I have the basics of this chain working, but it only counts the pages of the last book that was added, not every book added in the process

Chain 2:
runs on calibre shutdown and:
for all books added that day:
runs pluin "embed metadata"
runs plugin "epub extended metadata"
copies the books to another library

how would I create these chains?

any help is welcome, thanks in advance
I never used "Count Pages" or "epub extended metadata", so any specific advice regarding these two plugins I will leave to people who actually use them.

But in general, plugins can be called from an action called "Calibre Actions". But there are two caveats:
  • The plugin must have an action that can be associated menu item. Most plugins do.
  • Any interactive dialogs that are popped up by the plugins, will have to be dealt with manually, you cannot pre-answer them.

As for the first chain, you can use the event manager, with a custom event called "Books added", which you can get from here. You can attach the chain to the event, and it will fire every times new book(s) are added. This event has an option to select all added books, which I guess was the problem you had with count pages acting on only one books.

Note: The event posted above can be added to the plugin by copy/pasting the code into the plugin's module editor: Action Chains > Manage Modules > add > copy/paste

For the second chain, you can use the event manager with the builtin event "Shutting down". All the actions should be doable with "Calibre Actions", with the two caveats mentioned above holding.
capink is offline   Reply With Quote
Old 03-02-2025, 04:48 PM   #1440
WorldTeacher
Junior Member
WorldTeacher began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Apr 2019
Device: Calibre
thanks for the help ^^

I have managed to create both chains, they work without issues.
WorldTeacher 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
Action Chains Resources capink Plugins 68 01-20-2025 01:06 PM
[Editor Plugin] Editor Chains capink Plugins 94 07-03-2024 07:26 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 06:47 AM.


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